Skip to content

Commit

Permalink
Add external commit_id
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Dec 10, 2020
1 parent 51d4ef4 commit 5ec5781
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ public void testCommitIdInSearcher() throws Exception {
try (Engine.SearcherSupplier searcherSupplier = shard.acquireSearcherSupplier(randomFrom(Engine.SearcherScope.values()))) {
assertThat(searcherSupplier.getCommitId(), equalTo(commitId));
}
assertAcked(client().admin().indices().prepareUpdateSettings(indexName)
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)).get());
internalCluster().ensureAtLeastNumDataNodes(2);
ensureGreen(indexName);
for (String nodeName : internalCluster().nodesInclude(indexName)) {
final IndexShard indexShard = internalCluster().getInstance(IndicesService.class, nodeName)
.indexService(resolveIndex(indexName)).getShard(0);
try (Engine.SearcherSupplier searcherSupplier = indexShard.acquireSearcherSupplier(randomFrom(Engine.SearcherScope.values()))) {
assertThat(searcherSupplier.getCommitId(), equalTo(commitId));
}
}
}

private static void closeIndices(final String... indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
public abstract class Engine implements Closeable {

public static final String SYNC_COMMIT_ID = "sync_id"; // TODO: Remove sync_id in 9.0
public static final String ES_COMMIT_ID = "commit_id";
public static final String HISTORY_UUID_KEY = "history_uuid";
public static final String FORCE_MERGE_UUID_KEY = "force_merge_uuid";
public static final String MIN_RETAINED_SEQNO = "min_retained_seq_no";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lucene.LoggerInfoStream;
import org.elasticsearch.common.lucene.Lucene;
Expand Down Expand Up @@ -2377,12 +2378,13 @@ protected void commitIndexWriter(final IndexWriter writer, final Translog transl
* {@link IndexWriter#commit()} call flushes all documents, we defer computation of the maximum sequence number to the time
* of invocation of the commit data iterator (which occurs after all documents have been flushed to Lucene).
*/
final Map<String, String> commitData = new HashMap<>(7);
final Map<String, String> commitData = new HashMap<>(8);
commitData.put(Translog.TRANSLOG_UUID_KEY, translog.getTranslogUUID());
commitData.put(SequenceNumbers.LOCAL_CHECKPOINT_KEY, Long.toString(localCheckpoint));
commitData.put(SequenceNumbers.MAX_SEQ_NO, Long.toString(localCheckpointTracker.getMaxSeqNo()));
commitData.put(MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID, Long.toString(maxUnsafeAutoIdTimestamp.get()));
commitData.put(HISTORY_UUID_KEY, historyUUID);
commitData.put(ES_COMMIT_ID, UUIDs.randomBase64UUID());
final String currentForceMergeUUID = forceMergeUUID;
if (currentForceMergeUUID != null) {
commitData.put(FORCE_MERGE_UUID_KEY, currentForceMergeUUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ReadOnlyEngine(EngineConfig config, SeqNoStats seqNoStats, TranslogStats
// yet this makes sure nobody else does. including some testing tools that try to be messy
indexWriterLock = obtainLock ? directory.obtainLock(IndexWriter.WRITE_LOCK_NAME) : null;
this.lastCommittedSegmentInfos = Lucene.readSegmentInfos(directory);
this.commitId = Lucene.getCommitId(lastCommittedSegmentInfos);
this.commitId = lastCommittedSegmentInfos.userData.get(ES_COMMIT_ID);
if (seqNoStats == null) {
seqNoStats = buildSeqNoStats(config, lastCommittedSegmentInfos);
ensureMaxSeqNoEqualsToGlobalCheckpoint(seqNoStats);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ public void createEmpty() throws IOException {
map.put(SequenceNumbers.LOCAL_CHECKPOINT_KEY, Long.toString(SequenceNumbers.NO_OPS_PERFORMED));
map.put(SequenceNumbers.MAX_SEQ_NO, Long.toString(SequenceNumbers.NO_OPS_PERFORMED));
map.put(Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID, "-1");
map.put(Engine.ES_COMMIT_ID, UUIDs.randomBase64UUID());
updateCommitData(writer, map);
} finally {
metadataLock.writeLock().unlock();
Expand Down

0 comments on commit 5ec5781

Please sign in to comment.