Skip to content

Commit 77d719d

Browse files
dnhatnjkakavas
authored andcommitted
Only verify global checkpoint if translog sync occurred (elastic#45980)
We only sync translog if the given offset hasn't synced yet. We can't verify the global checkpoint from the latest translog checkpoint unless a sync has occurred. Closes elastic#46065 Relates elastic#45634
1 parent 6073b94 commit 77d719d

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

server/src/test/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncIT.java

+33
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import org.elasticsearch.common.xcontent.XContentType;
3232
import org.elasticsearch.index.IndexService;
3333
import org.elasticsearch.index.IndexSettings;
34+
import org.elasticsearch.index.shard.IndexShard;
3435
import org.elasticsearch.index.translog.Translog;
36+
import org.elasticsearch.indices.IndicesService;
3537
import org.elasticsearch.plugins.Plugin;
3638
import org.elasticsearch.test.ESIntegTestCase;
3739
import org.elasticsearch.test.InternalSettingsPlugin;
@@ -226,4 +228,35 @@ private void runGlobalCheckpointSyncTest(
226228
}
227229
}
228230

231+
public void testPersistGlobalCheckpoint() throws Exception {
232+
internalCluster().ensureAtLeastNumDataNodes(2);
233+
Settings.Builder indexSettings = Settings.builder()
234+
.put(IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING.getKey(), randomTimeValue(100, 1000, "ms"))
235+
.put("index.number_of_replicas", randomIntBetween(0, 1));
236+
if (randomBoolean()) {
237+
indexSettings.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)
238+
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), randomTimeValue(100, 1000, "ms"));
239+
}
240+
prepareCreate("test", indexSettings).get();
241+
if (randomBoolean()) {
242+
ensureGreen("test");
243+
}
244+
int numDocs = randomIntBetween(1, 20);
245+
for (int i = 0; i < numDocs; i++) {
246+
client().prepareIndex("test", "test", Integer.toString(i)).setSource("{}", XContentType.JSON).get();
247+
}
248+
ensureGreen("test");
249+
assertBusy(() -> {
250+
for (IndicesService indicesService : internalCluster().getDataNodeInstances(IndicesService.class)) {
251+
for (IndexService indexService : indicesService) {
252+
for (IndexShard shard : indexService) {
253+
final SeqNoStats seqNoStats = shard.seqNoStats();
254+
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
255+
assertThat(shard.getLastKnownGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
256+
assertThat(shard.getLastSyncedGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
257+
}
258+
}
259+
}
260+
});
261+
}
229262
}

server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -3305,21 +3305,25 @@ public void testSyncConcurrently() throws Exception {
33053305
}
33063306
assertNotNull(location);
33073307
long globalCheckpoint = lastGlobalCheckpoint.get();
3308+
final boolean synced;
33083309
if (randomBoolean()) {
3309-
translog.ensureSynced(location);
3310+
synced = translog.ensureSynced(location);
33103311
} else {
33113312
translog.sync();
3313+
synced = true;
33123314
}
33133315
for (Translog.Operation op : ops) {
33143316
assertThat("seq# " + op.seqNo() + " was not marked as persisted", persistedSeqNos, hasItem(op.seqNo()));
33153317
}
33163318
Checkpoint checkpoint = translog.getLastSyncedCheckpoint();
33173319
assertThat(checkpoint.offset, greaterThanOrEqualTo(location.translogLocation));
3318-
assertThat(checkpoint.globalCheckpoint, greaterThanOrEqualTo(globalCheckpoint));
33193320
for (Translog.Operation op : ops) {
33203321
assertThat(checkpoint.minSeqNo, lessThanOrEqualTo(op.seqNo()));
33213322
assertThat(checkpoint.maxSeqNo, greaterThanOrEqualTo(op.seqNo()));
33223323
}
3324+
if (synced) {
3325+
assertThat(checkpoint.globalCheckpoint, greaterThanOrEqualTo(globalCheckpoint));
3326+
}
33233327
} catch (Exception e) {
33243328
throw new AssertionError(e);
33253329
}

0 commit comments

Comments
 (0)