Skip to content

Commit 4e84a95

Browse files
committed
renamed ChunkProcessor to ChunkWorker
1 parent d2d88d2 commit 4e84a95

File tree

2 files changed

+44
-42
lines changed

2 files changed

+44
-42
lines changed

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ void prepare(Client leaderClient, Client followerClient, ShardFollowNodeTask tas
134134
fetchGlobalCheckpoint(leaderClient, leaderShard, leaderGlobalCheckPoint -> {
135135
logger.debug("{} fetching write operations, leaderGlobalCheckPoint={}, followGlobalCheckPoint={}", followerShard,
136136
leaderGlobalCheckPoint, followGlobalCheckPoint);
137-
ChunksCoordinator coordinator = new ChunksCoordinator(followerClient, leaderClient, threadPool, imdVersionChecker, params.getMaxChunkSize(),
138-
params.getNumConcurrentChunks(), params.getProcessorMaxTranslogBytes(), leaderShard, followerShard, task::markAsFailed,
139-
task::isRunning, task::updateProcessedGlobalCheckpoint);
137+
ChunksCoordinator coordinator = new ChunksCoordinator(followerClient, leaderClient, threadPool, imdVersionChecker,
138+
params.getMaxChunkSize(), params.getNumConcurrentChunks(), params.getProcessorMaxTranslogBytes(), leaderShard,
139+
followerShard, task::markAsFailed, task::isRunning, task::updateProcessedGlobalCheckpoint);
140140
coordinator.start(followGlobalCheckPoint, leaderGlobalCheckPoint);
141141
}, task::markAsFailed);
142142
}
@@ -165,6 +165,7 @@ static class ChunksCoordinator {
165165
private final Client followerClient;
166166
private final Client leaderClient;
167167
private final ThreadPool threadPool;
168+
private final Executor ccrExecutor;
168169
private final IndexMetadataVersionChecker imdVersionChecker;
169170

170171
private final long batchSize;
@@ -178,7 +179,6 @@ static class ChunksCoordinator {
178179

179180
private final AtomicInteger activeWorkers;
180181
private final AtomicLong lastPolledGlobalCheckpoint;
181-
private final AtomicLong lastProcessedGlobalCheckPoint;
182182
private final Queue<long[]> chunks = new ConcurrentLinkedQueue<>();
183183

184184
ChunksCoordinator(Client followerClient,
@@ -197,6 +197,7 @@ static class ChunksCoordinator {
197197
this.leaderClient = leaderClient;
198198
this.threadPool = threadPool;
199199
this.imdVersionChecker = imdVersionChecker;
200+
this.ccrExecutor = threadPool.executor(Ccr.CCR_THREAD_POOL_NAME);
200201
this.batchSize = batchSize;
201202
this.maxConcurrentWorker = maxConcurrentWorker;
202203
this.processorMaxTranslogBytes = processorMaxTranslogBytes;
@@ -207,7 +208,6 @@ static class ChunksCoordinator {
207208
this.processedGlobalCheckpointUpdater = processedGlobalCheckpointUpdater;
208209
this.activeWorkers = new AtomicInteger();
209210
this.lastPolledGlobalCheckpoint = new AtomicLong();
210-
this.lastProcessedGlobalCheckPoint = new AtomicLong();
211211
}
212212

213213
void createChucks(long from, long to) {
@@ -218,8 +218,8 @@ void createChucks(long from, long to) {
218218
}
219219
}
220220

221-
void update() {
222-
schedule(() -> {
221+
void updateChunksQueue() {
222+
schedule(CHECK_LEADER_GLOBAL_CHECKPOINT_INTERVAL, () -> {
223223
if (stateSupplier.get() == false) {
224224
return;
225225
}
@@ -234,7 +234,7 @@ void update() {
234234
} else {
235235
LOGGER.debug("{} no write operations to fetch", followerShard);
236236
}
237-
update();
237+
updateChunksQueue();
238238
}, failureHandler);
239239
});
240240
}
@@ -245,7 +245,7 @@ void start(long followerGlobalCheckpoint, long leaderGlobalCheckPoint) {
245245
LOGGER.debug("{} Start coordination of [{}] chunks with [{}] concurrent processors",
246246
leaderShard, chunks.size(), maxConcurrentWorker);
247247
initiateChunkWorkers();
248-
update();
248+
updateChunksQueue();
249249
}
250250

251251
void initiateChunkWorkers() {
@@ -257,7 +257,7 @@ void initiateChunkWorkers() {
257257

258258
LOGGER.debug("{} Starting [{}] new chunk workers", followerShard, workersToStart);
259259
for (int i = 0; i < workersToStart; i++) {
260-
threadPool.executor(Ccr.CCR_THREAD_POOL_NAME).execute(new AbstractRunnable() {
260+
ccrExecutor.execute(new AbstractRunnable() {
261261
@Override
262262
public void onFailure(Exception e) {
263263
assert e != null;
@@ -299,14 +299,13 @@ void processNextChunk() {
299299
failureHandler.accept(e);
300300
}
301301
};
302-
Executor ccrExecutor = threadPool.executor(Ccr.CCR_THREAD_POOL_NAME);
303-
ChunkProcessor processor = new ChunkProcessor(leaderClient, followerClient, chunks, ccrExecutor, imdVersionChecker,
302+
ChunkWorker worker = new ChunkWorker(leaderClient, followerClient, chunks, ccrExecutor, imdVersionChecker,
304303
leaderShard, followerShard, processorHandler);
305-
processor.start(chunk[0], chunk[1], processorMaxTranslogBytes);
304+
worker.start(chunk[0], chunk[1], processorMaxTranslogBytes);
306305
}
307306

308-
void schedule(Runnable runnable) {
309-
threadPool.schedule(CHECK_LEADER_GLOBAL_CHECKPOINT_INTERVAL, Ccr.CCR_THREAD_POOL_NAME, new AbstractRunnable() {
307+
void schedule(TimeValue delay, Runnable runnable) {
308+
threadPool.schedule(delay, Ccr.CCR_THREAD_POOL_NAME, new AbstractRunnable() {
310309
@Override
311310
public void onFailure(Exception e) {
312311
failureHandler.accept(e);
@@ -325,7 +324,7 @@ Queue<long[]> getChunks() {
325324

326325
}
327326

328-
static class ChunkProcessor {
327+
static class ChunkWorker {
329328

330329
private final Client leaderClient;
331330
private final Client followerClient;
@@ -338,9 +337,9 @@ static class ChunkProcessor {
338337
private final Consumer<Exception> handler;
339338
final AtomicInteger retryCounter = new AtomicInteger(0);
340339

341-
ChunkProcessor(Client leaderClient, Client followerClient, Queue<long[]> chunks, Executor ccrExecutor,
342-
BiConsumer<Long, Consumer<Exception>> indexVersionChecker,
343-
ShardId leaderShard, ShardId followerShard, Consumer<Exception> handler) {
340+
ChunkWorker(Client leaderClient, Client followerClient, Queue<long[]> chunks, Executor ccrExecutor,
341+
BiConsumer<Long, Consumer<Exception>> indexVersionChecker, ShardId leaderShard, ShardId followerShard,
342+
Consumer<Exception> handler) {
344343
this.leaderClient = leaderClient;
345344
this.followerClient = followerClient;
346345
this.chunks = chunks;

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.elasticsearch.test.ESTestCase;
1515
import org.elasticsearch.threadpool.ThreadPool;
1616
import org.elasticsearch.xpack.ccr.Ccr;
17-
import org.elasticsearch.xpack.ccr.action.ShardFollowTasksExecutor.ChunkProcessor;
17+
import org.elasticsearch.xpack.ccr.action.ShardFollowTasksExecutor.ChunkWorker;
1818
import org.elasticsearch.xpack.ccr.action.ShardFollowTasksExecutor.ChunksCoordinator;
1919
import org.elasticsearch.xpack.ccr.action.ShardFollowTasksExecutor.IndexMetadataVersionChecker;
2020
import org.elasticsearch.xpack.ccr.action.bulk.BulkShardOperationsAction;
@@ -32,6 +32,7 @@
3232
import java.util.concurrent.atomic.AtomicBoolean;
3333
import java.util.concurrent.atomic.AtomicReference;
3434
import java.util.function.BiConsumer;
35+
import java.util.function.BiConsumer;
3536
import java.util.function.Consumer;
3637
import java.util.function.LongConsumer;
3738

@@ -122,7 +123,8 @@ public void testCoordinator() throws Exception {
122123
IndexMetadataVersionChecker checker = new IndexMetadataVersionChecker(leaderShardId.getIndex(),
123124
followShardId.getIndex(), client, client);
124125
ChunksCoordinator coordinator = new ChunksCoordinator(client, client, threadPool, checker, batchSize,
125-
concurrentProcessors, Long.MAX_VALUE, leaderShardId, followShardId, handler, () -> true, value -> {});
126+
concurrentProcessors, Long.MAX_VALUE, leaderShardId, followShardId, handler,
127+
() -> true, value -> {});
126128

127129
int numberOfOps = randomIntBetween(batchSize, batchSize * 20);
128130
long from = randomInt(1000);
@@ -163,8 +165,9 @@ public void testCoordinator_failure() throws Exception {
163165
assertThat(e, sameInstance(expectedException));
164166
};
165167
IndexMetadataVersionChecker checker = new IndexMetadataVersionChecker(leaderShardId.getIndex(),
166-
followShardId.getIndex(), client, client);ChunksCoordinator coordinator =
167-
new ChunksCoordinator(client, client, threadPool, checker,10, 1, Long.MAX_VALUE, leaderShardId, followShardId, handler, () -> true, value -> {});
168+
followShardId.getIndex(), client, client);
169+
ChunksCoordinator coordinator = new ChunksCoordinator(client, client, threadPool, checker,10, 1, Long.MAX_VALUE,
170+
leaderShardId, followShardId, handler, () -> true, value -> {});
168171
coordinator.start(0, 20);
169172

170173
assertThat(coordinator.getChunks().size(), equalTo(1));
@@ -209,7 +212,7 @@ public void testCoordinator_concurrent() throws Exception {
209212
assertThat(calledOnceChecker.get(), is(false));
210213
}
211214

212-
public void testChunkProcessor() {
215+
public void testChunkWorker() {
213216
Client client = createClientMock();
214217
Queue<long[]> chunks = new LinkedList<>();
215218
mockShardChangesApiCall(client);
@@ -223,14 +226,14 @@ public void testChunkProcessor() {
223226
boolean[] invoked = new boolean[1];
224227
Exception[] exception = new Exception[1];
225228
Consumer<Exception> handler = e -> {invoked[0] = true;exception[0] = e;};
226-
ChunkProcessor chunkProcessor = new ChunkProcessor(client, client, chunks, ccrExecutor, checker, leaderShardId,
229+
ChunkWorker chunkWorker = new ChunkWorker(client, client, chunks, ccrExecutor, checker, leaderShardId,
227230
followShardId, handler);
228-
chunkProcessor.start(0, 10, Long.MAX_VALUE);
231+
chunkWorker.start(0, 10, Long.MAX_VALUE);
229232
assertThat(invoked[0], is(true));
230233
assertThat(exception[0], nullValue());
231234
}
232235

233-
public void testChunkProcessorRetry() {
236+
public void testChunkWorkerRetry() {
234237
Client client = createClientMock();
235238
Queue<long[]> chunks = new LinkedList<>();
236239
mockBulkShardOperationsApiCall(client);
@@ -246,15 +249,15 @@ public void testChunkProcessorRetry() {
246249
boolean[] invoked = new boolean[1];
247250
Exception[] exception = new Exception[1];
248251
Consumer<Exception> handler = e -> {invoked[0] = true;exception[0] = e;};
249-
ChunkProcessor chunkProcessor = new ChunkProcessor(client, client, chunks, ccrExecutor, checker, leaderShardId,
252+
ChunkWorker chunkWorker = new ChunkWorker(client, client, chunks, ccrExecutor, checker, leaderShardId,
250253
followShardId, handler);
251-
chunkProcessor.start(0, 10, Long.MAX_VALUE);
254+
chunkWorker.start(0, 10, Long.MAX_VALUE);
252255
assertThat(invoked[0], is(true));
253256
assertThat(exception[0], nullValue());
254-
assertThat(chunkProcessor.retryCounter.get(), equalTo(testRetryLimit + 1));
257+
assertThat(chunkWorker.retryCounter.get(), equalTo(testRetryLimit + 1));
255258
}
256259

257-
public void testChunkProcessorRetryTooManyTimes() {
260+
public void testChunkWorkerRetryTooManyTimes() {
258261
Client client = createClientMock();
259262
Queue<long[]> chunks = new LinkedList<>();
260263
mockBulkShardOperationsApiCall(client);
@@ -270,17 +273,17 @@ public void testChunkProcessorRetryTooManyTimes() {
270273
boolean[] invoked = new boolean[1];
271274
Exception[] exception = new Exception[1];
272275
Consumer<Exception> handler = e -> {invoked[0] = true;exception[0] = e;};
273-
ChunkProcessor chunkProcessor = new ChunkProcessor(client, client, chunks, ccrExecutor, checker, leaderShardId,
276+
ChunkWorker chunkWorker = new ChunkWorker(client, client, chunks, ccrExecutor, checker, leaderShardId,
274277
followShardId, handler);
275-
chunkProcessor.start(0, 10, Long.MAX_VALUE);
278+
chunkWorker.start(0, 10, Long.MAX_VALUE);
276279
assertThat(invoked[0], is(true));
277280
assertThat(exception[0], notNullValue());
278281
assertThat(exception[0].getMessage(), equalTo("retrying failed [17] times, aborting..."));
279282
assertThat(exception[0].getCause().getMessage(), equalTo("connection exception"));
280-
assertThat(chunkProcessor.retryCounter.get(), equalTo(testRetryLimit));
283+
assertThat(chunkWorker.retryCounter.get(), equalTo(testRetryLimit));
281284
}
282285

283-
public void testChunkProcessorNoneRetryableError() {
286+
public void testChunkWorkerNoneRetryableError() {
284287
Client client = createClientMock();
285288
Queue<long[]> chunks = new LinkedList<>();
286289
mockBulkShardOperationsApiCall(client);
@@ -295,16 +298,16 @@ public void testChunkProcessorNoneRetryableError() {
295298
boolean[] invoked = new boolean[1];
296299
Exception[] exception = new Exception[1];
297300
Consumer<Exception> handler = e -> {invoked[0] = true;exception[0] = e;};
298-
ChunkProcessor chunkProcessor = new ChunkProcessor(client, client, chunks, ccrExecutor, checker, leaderShardId,
301+
ChunkWorker chunkWorker = new ChunkWorker(client, client, chunks, ccrExecutor, checker, leaderShardId,
299302
followShardId, handler);
300-
chunkProcessor.start(0, 10, Long.MAX_VALUE);
303+
chunkWorker.start(0, 10, Long.MAX_VALUE);
301304
assertThat(invoked[0], is(true));
302305
assertThat(exception[0], notNullValue());
303306
assertThat(exception[0].getMessage(), equalTo("unexpected"));
304-
assertThat(chunkProcessor.retryCounter.get(), equalTo(0));
307+
assertThat(chunkWorker.retryCounter.get(), equalTo(0));
305308
}
306309

307-
public void testChunkProcessorExceedMaxTranslogsBytes() {
310+
public void testChunkWorkerExceedMaxTranslogsBytes() {
308311
long from = 0;
309312
long to = 20;
310313
long actualTo = 10;
@@ -335,9 +338,9 @@ public void testChunkProcessorExceedMaxTranslogsBytes() {
335338
Exception[] exception = new Exception[1];
336339
Consumer<Exception> handler = e -> {invoked[0] = true;exception[0] = e;};
337340
BiConsumer<Long, Consumer<Exception>> versionChecker = (indexVersiuon, consumer) -> consumer.accept(null);
338-
ChunkProcessor chunkProcessor =
339-
new ChunkProcessor(client, client, chunks, ccrExecutor, versionChecker, leaderShardId, followShardId, handler);
340-
chunkProcessor.start(from, to, Long.MAX_VALUE);
341+
ChunkWorker chunkWorker = new ChunkWorker(client, client, chunks, ccrExecutor, versionChecker, leaderShardId,
342+
followShardId, handler);
343+
chunkWorker.start(from, to, Long.MAX_VALUE);
341344
assertThat(invoked[0], is(true));
342345
assertThat(exception[0], nullValue());
343346
assertThat(chunks.size(), equalTo(1));

0 commit comments

Comments
 (0)