Skip to content

Commit

Permalink
Make S3 anti-contention delay configurable (#101245) (#101251)
Browse files Browse the repository at this point in the history
The anti-contention delay in the S3 repository's compare-and-exchange
operation is hard-coded at 1 second today, but sometimes we encounter a
repository that needs much longer to perform a compare-and-exchange
operation when under contention. With this commit we make the
anti-contention delay configurable.
  • Loading branch information
DaveCTurner authored Oct 24, 2023
1 parent 028d10d commit d36df51
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/101245.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 101245
summary: Make S3 anti-contention delay configurable
area: Snapshot/Restore
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,9 @@ void run(BytesReference expected, BytesReference updated, ActionListener<Optiona

if (uploadIndex > 0) {
threadPool.scheduleUnlessShuttingDown(
TimeValue.timeValueMillis(TimeValue.timeValueSeconds(uploadIndex).millis() + Randomness.get().nextInt(50)),
TimeValue.timeValueMillis(
uploadIndex * blobStore.getCompareAndExchangeAntiContentionDelay().millis() + Randomness.get().nextInt(50)
),
blobStore.getSnapshotExecutor(),
cancelConcurrentUpdates
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public TimeValue getCompareAndExchangeTimeToLive() {
return service.compareAndExchangeTimeToLive;
}

public TimeValue getCompareAndExchangeAntiContentionDelay() {
return service.compareAndExchangeAntiContentionDelay;
}

// metrics collector that ignores null responses that we interpret as the request not reaching the S3 endpoint due to a network
// issue
private abstract static class IgnoreNoResponseMetricsCollector extends RequestMetricCollector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class S3Service implements Closeable {
Setting.Property.NodeScope
);

private static final Setting<TimeValue> REPOSITORY_S3_CAS_ANTI_CONTENTION_DELAY_SETTING = Setting.timeSetting(
"repository_s3.compare_and_exchange.anti_contention_delay",
TimeValue.timeValueSeconds(1),
TimeValue.timeValueMillis(1),
TimeValue.timeValueHours(24),
Setting.Property.NodeScope
);

private volatile Map<S3ClientSettings, AmazonS3Reference> clientsCache = emptyMap();

/**
Expand All @@ -79,6 +87,7 @@ class S3Service implements Closeable {
final CustomWebIdentityTokenCredentialsProvider webIdentityTokenCredentialsProvider;

final TimeValue compareAndExchangeTimeToLive;
final TimeValue compareAndExchangeAntiContentionDelay;

S3Service(Environment environment, Settings nodeSettings) {
webIdentityTokenCredentialsProvider = new CustomWebIdentityTokenCredentialsProvider(
Expand All @@ -88,6 +97,7 @@ class S3Service implements Closeable {
Clock.systemUTC()
);
compareAndExchangeTimeToLive = REPOSITORY_S3_CAS_TTL_SETTING.get(nodeSettings);
compareAndExchangeAntiContentionDelay = REPOSITORY_S3_CAS_ANTI_CONTENTION_DELAY_SETTING.get(nodeSettings);
}

/**
Expand Down

0 comments on commit d36df51

Please sign in to comment.