Skip to content

chore(affinity): add support for custom affinity key bind and unbind via calloptions#207

Open
alkatrivedi wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
alkatrivedi:feat/metadata-affinity-control
Open

chore(affinity): add support for custom affinity key bind and unbind via calloptions#207
alkatrivedi wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
alkatrivedi:feat/metadata-affinity-control

Conversation

@alkatrivedi

@alkatrivedi alkatrivedi commented May 3, 2026

Copy link
Copy Markdown
  • This PR contains changes for handling support for custom affinity key changes

  • The binding and unbinding logic for a custom affinity key

@alkatrivedi alkatrivedi marked this pull request as draft May 3, 2026 00:59
@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch 2 times, most recently from 178db59 to b656bd2 Compare May 10, 2026 18:58
@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch from 63613f8 to 7b2d24e Compare May 24, 2026 19:19
@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch 2 times, most recently from 8ef4f50 to cf6dad8 Compare June 4, 2026 07:40
@alkatrivedi

Copy link
Copy Markdown
Author

/gcbrun

1 similar comment
@murgatroid99

Copy link
Copy Markdown
Collaborator

/gcbrun

@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch 2 times, most recently from 2e18593 to f88f6c3 Compare June 21, 2026 14:56
@alkatrivedi alkatrivedi changed the title feat: support affinity key override and unbind via metadata headers chore(affinity): add support for custom affinity key bind and unbind via calloptions Jun 21, 2026
@alkatrivedi

Copy link
Copy Markdown
Author

/gcbrun

@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch 4 times, most recently from e239b3e to 2fc8798 Compare June 22, 2026 09:22
@alkatrivedi alkatrivedi marked this pull request as ready for review June 22, 2026 09:33
@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch 4 times, most recently from eef6e10 to a2e0fea Compare June 23, 2026 05:00
@alkatrivedi alkatrivedi force-pushed the feat/metadata-affinity-control branch from a2e0fea to de4d036 Compare June 23, 2026 06:10
@surbhigarg92

Copy link
Copy Markdown

/gemini review

@alkatrivedi

Copy link
Copy Markdown
Author

/gcbrun

this.addChannel();
}

this.cleanupTimer = setInterval(() => this.cleanupIdleKeys(), 30000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add comment/documentation

this.addChannel();
}

this.cleanupTimer = setInterval(() => this.cleanupIdleKeys(), 30000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

move these interval configurations to const

const CLEANUP_INTERVAL_MS = 30000; // Sweep every 30 seconds
const IDLE_TIMEOUT_MS = 180000; // Keys are considered idle if unused for more than 3 minutes

existingChannelRef.affinityCountIncr();
}

isBound(affinityKey: string): boolean {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add documentation

Comment thread src/index.ts
next: Function
) => {
// Always decrement stream count on status receive (stream closed)
channelRef.activeStreamsCountDecr();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if the status is retryable like "Unavailable" ? When we retry the stream with resume token , the request should go on the same channel or different ?

This should have been applicable for previous implementation as well when session was used as affinity key ?

Comment thread src/index.ts
// eslint-disable-next-line @typescript-eslint/no-explicit-any
argument?: any
argument?: any,
overrideAffinityKey?: string

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Update the method definition with this new parameter.

Comment thread src/index.ts
channelFactory.unbind(boundKey);
}
}
channelRef.activeStreamsCountDecr();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why did we remove this ? Is it because we decrementing the count when we receive the status ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is postProcess not called for all scenarios ?

Comment thread src/index.ts
const callback = callProperties.callback;

const preProcessResult = preProcess(channelFactory, path, argument);
const affinityConfig = channelFactory.getAffinityConfig(path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We already call channelFactory.getAffinityConfig(path) in preProcess method, could we have moved fetching "affinityKeyFromCallOptions" in "preProcess" method to avoid multiple calls to this ?

Comment thread package.json
"@grpc/proto-loader": "^0.7.0",
"@google-cloud/spanner": "^6.0.0",
"@grpc/proto-loader": "^0.7.0",
"@types/glob": "8.1.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do we need these extra imports ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants