forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 22
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
CNDB-11070: Limited backport of CASSANDRA-19534 #1393
Open
jkni
wants to merge
8
commits into
cc-main-migration-release
Choose a base branch
from
CNDB-11070-cc-migration-main
base: cc-main-migration-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+352
−6
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d06a17
CNDB-11070: Limited backport of CASSANDRA-19534, with message sheddin…
jkni a650d84
Add test coverage for load-shedding at NTR and async stages. Make rel…
jkni 2ef4458
Improve reliability of NativeTransportTimeoutTest
jkni 6088de6
Clean up ClientMetrics names as suggested by SonarCloud
jkni a0043ec
Add totalQueueTime/totalAsyncQueueTime to expose queue metrics as tim…
jkni 8bb0800
Use byteman to mock NTR timeouts for only sentinel-laden messages, so…
jkni 58440b2
Clean up formatting, remove dead code.
jkni a4e4489
Incorporate review feedback
jkni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
|
@@ -34,10 +35,14 @@ | |
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.cassandra.config.DatabaseDescriptor; | ||
import org.apache.cassandra.exceptions.OverloadedException; | ||
import org.apache.cassandra.metrics.ClientMetrics; | ||
import org.apache.cassandra.service.StorageService; | ||
import org.apache.cassandra.tracing.Tracing; | ||
import org.apache.cassandra.transport.messages.*; | ||
import org.apache.cassandra.service.QueryState; | ||
import org.apache.cassandra.utils.MonotonicClock; | ||
import org.apache.cassandra.utils.UUIDGen; | ||
|
||
/** | ||
|
@@ -201,6 +206,7 @@ public String debugString() | |
public static abstract class Request extends Message | ||
{ | ||
private boolean tracingRequested; | ||
private final long creationTimeNanos = MonotonicClock.approxTime.now(); | ||
jkni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
protected Request(Type type) | ||
{ | ||
|
@@ -215,10 +221,31 @@ protected boolean isTraceable() | |
return false; | ||
} | ||
|
||
/** | ||
* Returns the time elapsed since this request was created. Note that this is the total lifetime of the request | ||
* in the system, so we expect increasing returned values across multiple calls to elapsedTimeSinceCreation. | ||
* | ||
* @param timeUnit the time unit in which to return the elapsed time | ||
* @return the time elapsed since this request was created | ||
*/ | ||
protected long elapsedTimeSinceCreation(TimeUnit timeUnit) | ||
{ | ||
return timeUnit.convert(MonotonicClock.approxTime.now() - creationTimeNanos, TimeUnit.NANOSECONDS); | ||
} | ||
|
||
protected abstract CompletableFuture<Response> maybeExecuteAsync(QueryState queryState, long queryStartNanoTime, boolean traceRequest); | ||
|
||
public final CompletableFuture<Response> execute(QueryState queryState, long queryStartNanoTime) | ||
{ | ||
// at the time of the check, this is approximately the time spent in the NTR stage's queue | ||
long elapsedTimeSinceCreation = elapsedTimeSinceCreation(TimeUnit.NANOSECONDS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So async queue time includes sync queue time? Could you please make the relation clear in the comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, will do. |
||
ClientMetrics.instance.recordQueueTime(elapsedTimeSinceCreation, TimeUnit.NANOSECONDS); | ||
if (elapsedTimeSinceCreation > DatabaseDescriptor.getNativeTransportTimeout(TimeUnit.NANOSECONDS)) | ||
{ | ||
ClientMetrics.instance.markTimedOutBeforeProcessing(); | ||
return CompletableFuture.completedFuture(ErrorMessage.fromException(new OverloadedException("Query timed out before it could start"))); | ||
} | ||
|
||
boolean shouldTrace = false; | ||
UUID tracingSessionId = null; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should have something simlar for other verbs? Maybe reads?
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.
Reads handle this much more extensively through
Monitorable
implementation (https://issues.apache.org/jira/browse/CASSANDRA-7392). CASSANDRA-19534 added this as a very minimal load-shedding point for expired mutations, but reads already have much more extensive infrastructure to handle this.