Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONJUBILEE-2783: SaaS Connectors: Support for Partitioning Aggregation #60

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './connector-handler'
export * from './connector-customizer-handler'
export * from './response'
export * from './logger'
export * from './partitionAdapter'
13 changes: 13 additions & 0 deletions lib/partition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Partition {
public name: string
public size: number
public attributes: Map<string, any>
public objectType: string

constructor(name: string, size: number, attributes: Map<string, any>, objectType: string) {
this.name = name;
this.size = size;
this.attributes = attributes;
this.objectType = objectType;
}
}
36 changes: 36 additions & 0 deletions lib/partitionAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Context, readConfig, Response, StdAccountListInput, StdAccountListOutput } from ".";
import { Partition } from "./partition";

export interface PartitionedAdapter {
getPartitions(context: Context, input: StdAccountListInput): Promise<Array<Partition>>
list(context: Context, input: StdAccountListInput, res: Response<StdAccountListOutput>, partition?: Partition): Promise<void>
}

export class Partitioned {
public h;

constructor(h: PartitionedAdapter) {
this.h = h;
}

async handler(context: Context, input: StdAccountListInput, res: Response<StdAccountListOutput>): Promise<void> {

const config = await readConfig();
const isPatitionEnabled = config.partitionAggregationEnabled;
var partitionList: Array<Partition> | undefined;

if (isPatitionEnabled) {
partitionList = await this.h.getPartitions(context, input);
}

if (!partitionList) {
let promises = [];
for (const partition of partitionList!) {
promises.push(this.h.list(context, input, res, partition));
}
await Promise.all(promises);
} else {
return await this.h.list(context, input, res, undefined);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add logging here to allow troubleshooters to determine if:

  1. We used partition aggregation or not.
  2. How long retrieving the partitions took.
  3. The number of partitions returned.
  4. Might also be useful to log when we finishing aggregating a specific partition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point 1-3 addressed.
Point 4 - Shouldn't this get logged at the connector level? I think we do not have control to check when a particular partition is finishing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 4 I was thinking we could do something like:

let partitionsDone = 0
for (const partition of partitionList!) {
  promises.push(async () => {
    let startTime = new Date().getTime();
    await this.partitionAdapter.list(context, input, res, partition);
    partitionsDone += 1
    this.childLogger.info(`Partition ${} of ${} done after ${}`)
  })
}
await Promise.all()

The reason I think this is valuable at the library level is because it gives us a good idea of how good of a job the connector is doing at creating equally sized partitions. I remember seeing a case of partitioning on java connectors where one of the partitions ended up being much larger than the others so we weren't taking advantage of as much parallelism as we could have.

Copy link
Collaborator Author

@abhishek-hedaoo-sp abhishek-hedaoo-sp Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Updated the code.

}
}
Loading