chore(spanner): add missing commit ts logging#13037
chore(spanner): add missing commit ts logging#13037sakthivelmanii wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances error reporting and logging in TransactionRunnerImpl.java when a commitTimestamp is missing by including details about precommit tokens and retry attempts. Feedback suggests addressing a missing state in the logging logic and refactoring the code to reduce redundancy and improve maintainability.
| if (proto.hasPrecommitToken() && retryAttemptDueToCommitProtocolExtension) { | ||
| txnLogger.log( | ||
| Level.FINE, | ||
| "Missing commitTimestamp, response has precommit token " | ||
| + "and client has already attempted commit retry"); | ||
| span.addAnnotation( | ||
| "Missing commitTimestamp, response has precommit token " | ||
| + "and client has already attempted commit retry"); | ||
| } else if (!proto.hasPrecommitToken()) { | ||
| txnLogger.log( | ||
| Level.FINE, "Missing commitTimestamp, response has no precommit token"); | ||
| span.addAnnotation( | ||
| "Missing commitTimestamp, " + "response has no precommit token"); | ||
| } | ||
| throw newSpannerException( | ||
| ErrorCode.INTERNAL, "Missing commitTimestamp:\n" + session.getName()); | ||
| ErrorCode.INTERNAL, | ||
| "Missing commitTimestamp:\n" | ||
| + session.getName() | ||
| + "\nHas precommit token: " | ||
| + proto.hasPrecommitToken() | ||
| + "\nAlready attempted commit retry: " | ||
| + retryAttemptDueToCommitProtocolExtension); |
There was a problem hiding this comment.
The current implementation misses logging and annotations for the case where proto.hasPrecommitToken() is true but retryAttemptDueToCommitProtocolExtension is false. This is an important state to capture for debugging the commit protocol extension. Additionally, the logic can be simplified to reduce redundancy and avoid unnecessary string literal concatenation.
String message =
"Missing commitTimestamp, response has "
+ (proto.hasPrecommitToken() ? "precommit token" : "no precommit token")
+ (proto.hasPrecommitToken() && retryAttemptDueToCommitProtocolExtension
? " and client has already attempted commit retry"
: "");
txnLogger.log(Level.FINE, message);
span.addAnnotation(message);
throw newSpannerException(
ErrorCode.INTERNAL,
message
+ ":\n"
+ session.getName()
+ "\nHas precommit token: "
+ proto.hasPrecommitToken()
+ "\nAlready attempted commit retry: "
+ retryAttemptDueToCommitProtocolExtension);
No description provided.