Skip to content

Commit 47bc37c

Browse files
committed
extract just updating the leaderGlobalCheckpoint in a new helper method,
this will make testing easier with out changing leaderGlobalCheckpoint field's visibility
1 parent 82f27f5 commit 47bc37c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public abstract class ShardFollowNodeTask extends AllocatedPersistentTask {
6161
private final BiConsumer<TimeValue, Runnable> scheduler;
6262

6363
private volatile long lastRequestedSeqno;
64-
// package-protected visibility for testing only:
65-
volatile long leaderGlobalCheckpoint;
64+
private volatile long leaderGlobalCheckpoint;
6665

6766
private volatile int numConcurrentReads = 0;
6867
private volatile int numConcurrentWrites = 0;
@@ -182,7 +181,7 @@ void handleReadResponse(long from, long maxRequiredSeqNo, ShardChangesAction.Res
182181
}
183182

184183
synchronized void innerHandleReadResponse(long from, long maxRequiredSeqNo, ShardChangesAction.Response response) {
185-
leaderGlobalCheckpoint = Math.max(leaderGlobalCheckpoint, response.getGlobalCheckpoint());
184+
updateLeaderGlobalCheckpoint(response.getGlobalCheckpoint());
186185
final long newMinRequiredSeqNo;
187186
if (response.getOperations().length == 0) {
188187
newMinRequiredSeqNo = from;
@@ -221,6 +220,11 @@ synchronized void innerHandleReadResponse(long from, long maxRequiredSeqNo, Shar
221220
}
222221
}
223222

223+
void updateLeaderGlobalCheckpoint(long newGlobalCheckpoint) {
224+
assert Thread.holdsLock(this);
225+
leaderGlobalCheckpoint = Math.max(leaderGlobalCheckpoint, newGlobalCheckpoint);
226+
}
227+
224228
private void sendBulkShardOperationsRequest(List<Translog.Operation> operations) {
225229
sendBulkShardOperationsRequest(operations, new AtomicInteger(0));
226230
}

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTaskTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ public void testCoordinateReads_taskCancelled() {
117117
assertThat(shardChangesRequests.get(0)[1], equalTo(64L));
118118

119119
shardChangesRequests.clear();
120-
task.leaderGlobalCheckpoint = 128L;
120+
synchronized (task) {
121+
task.updateLeaderGlobalCheckpoint(128L);
122+
}
121123
task.markAsCompleted();
122124
task.coordinateReads();
123125
assertThat(shardChangesRequests.size(), equalTo(0));
@@ -657,7 +659,9 @@ void startTask(ShardFollowNodeTask task, long leaderGlobalCheckpoint, long follo
657659
task.start(followerGlobalCheckpoint);
658660
// Shortcut to just set leaderGlobalCheckpoint, calling for example handleReadResponse() has side effects that
659661
// complicates testing in isolation.
660-
task.leaderGlobalCheckpoint = leaderGlobalCheckpoint;
662+
synchronized (task) {
663+
task.updateLeaderGlobalCheckpoint(leaderGlobalCheckpoint);
664+
}
661665
}
662666

663667

0 commit comments

Comments
 (0)