-
Notifications
You must be signed in to change notification settings - Fork 132
chore(spanner): add multiplexed session flag in executor code #3030
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
chore(spanner): add multiplexed session flag in executor code #3030
Conversation
...loud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudExecutorImpl.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/WorkerProxy.java
Show resolved
Hide resolved
...loud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudExecutorImpl.java
Outdated
Show resolved
Hide resolved
...loud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudExecutorImpl.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/WorkerProxy.java
Outdated
Show resolved
Hide resolved
@gyang-google Can you help review this? |
// multiplexedSessionOperationsRatio from command line is > 0.0 | ||
if (multiplexedSessionOperationsRatio > 0.0) { | ||
SessionPoolOptions.Builder sessionPoolOptionsBuilder; | ||
if (request.getAction().getSpannerOptions().hasSessionPoolOptions()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check like request.getAction().hasSpannerOptions()
before doing getSpannerOptions
. Else this will throw a NullPointerException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autogenerated methods from the proto always returns a default instance of the class and not null
. In this case getAction()
, getSpannerOptions
etc will never be null
. Hence, we are safe from not getting an NullPointerException
Reference:
Lines 112 to 115 in 6f522dd
public com.google.spanner.executor.v1.SpannerAction getAction() { | |
return action_ == null | |
? com.google.spanner.executor.v1.SpannerAction.getDefaultInstance() | |
: action_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it.
SpannerOptions.Builder optionsBuilder = | ||
request | ||
.getAction() | ||
.getSpannerOptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think getSpannerOptions
will throw a NullPointerException
since no one is passing it today. Add a handling similar to what you did for SessionPoolOptions
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autogenerated methods from the proto always returns a default instance of the class and not null
. In this case getAction()
, getSpannerOptions
etc will never be null
eventhough they are not set in input. Hence, we are safe from not getting an NullPointerException
Reference:
Lines 112 to 115 in 6f522dd
public com.google.spanner.executor.v1.SpannerAction getAction() { | |
return action_ == null | |
? com.google.spanner.executor.v1.SpannerAction.getDefaultInstance() | |
: action_; |
.setSessionPoolOptions(sessionPoolOptionsBuilder); | ||
SpannerAction.Builder actionBuilder = | ||
request.getAction().toBuilder().setSpannerOptions(optionsBuilder); | ||
request = request.toBuilder().setAction(actionBuilder).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't have unit tests, can you please link a before/after log object of this request object before and after your change? This is to ensure we are not mis-constructing the entire input object and avoid bugs like above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a short log here.
@@ -95,10 +98,22 @@ public static void main(String[] args) throws Exception { | |||
usePlainTextChannel = commandLine.hasOption(OPTION_USE_PLAIN_TEXT_CHANNEL); | |||
enableGrpcFaultInjector = commandLine.hasOption(OPTION_ENABLE_GRPC_FAULT_INJECTOR); | |||
|
|||
if (commandLine.hasOption(OPTION_MULTIPLEXED_SESSION_OPERATIONS_RATIO)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you made sure this works when the value is null? Do we have some manual logs to validate that this is working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPTION_MULTIPLEXED_SESSION_OPERATIONS_RATIO
flag value will never be null
. The default value passed from systest is 0.0
.
@@ -95,10 +98,22 @@ public static void main(String[] args) throws Exception { | |||
usePlainTextChannel = commandLine.hasOption(OPTION_USE_PLAIN_TEXT_CHANNEL); | |||
enableGrpcFaultInjector = commandLine.hasOption(OPTION_ENABLE_GRPC_FAULT_INJECTOR); | |||
|
|||
if (commandLine.hasOption(OPTION_MULTIPLEXED_SESSION_OPERATIONS_RATIO)) { | |||
multiplexedSessionOperationsRatio = | |||
Double.parseDouble( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If value is not null, we can add a validation that it is between 0 and 100. Similar validation is present for ports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a validation for multiplexed session ratio flag value to be between 0.0
and 1.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please take care of the testing before merging. And if possible, attach the test results.
Tested the code changes by running systests locally. The runs were successful. Test Driver Link - https://sigma.corp.google.com/job/ir/spanner-test/systest-sriharshach-cloudclientquickmainline.driver/4208880026702?terminated=true Backend Metrics that show Multiplexed session as enabled - https://screenshot.googleplex.com/966zkSeBPhseGAg |
This PR has the changes to accept a new flag
--multiplexed_session_operations_ratio
as input argument when running the executor artifact.Based on the value of multiplexed_session_operations_ratio flag the client will either use regular sessions or multiplexed sessions
Note: To start with, we are converting this ratio (double) into boolean property. In future we will use this ratio to perform a load splitter operation where some transactions use multiplexed sessions whereas the rest uses regular sessions.