|
@@ -65,7 +65,6 @@ import org.apache.lucene.store.MockDirectoryWrapper;
|
|
import org.apache.lucene.util.Bits;
|
|
import org.apache.lucene.util.Bits;
|
|
import org.apache.lucene.util.BytesRef;
|
|
import org.apache.lucene.util.BytesRef;
|
|
import org.apache.lucene.util.FixedBitSet;
|
|
import org.apache.lucene.util.FixedBitSet;
|
|
-import org.elasticsearch.core.internal.io.IOUtils;
|
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
import org.elasticsearch.ElasticsearchException;
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.action.index.IndexRequest;
|
|
import org.elasticsearch.action.index.IndexRequest;
|
|
@@ -91,6 +90,7 @@ import org.elasticsearch.common.util.BigArrays;
|
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
|
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
|
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
|
+import org.elasticsearch.core.internal.io.IOUtils;
|
|
import org.elasticsearch.index.IndexSettings;
|
|
import org.elasticsearch.index.IndexSettings;
|
|
import org.elasticsearch.index.VersionType;
|
|
import org.elasticsearch.index.VersionType;
|
|
import org.elasticsearch.index.codec.CodecService;
|
|
import org.elasticsearch.index.codec.CodecService;
|
|
@@ -1141,8 +1141,9 @@ public class InternalEngineTests extends EngineTestCase {
|
|
engine.flushAndClose();
|
|
engine.flushAndClose();
|
|
}
|
|
}
|
|
if (randomBoolean()) {
|
|
if (randomBoolean()) {
|
|
- EngineDiskUtils.createNewTranslog(store.directory(), config.getTranslogConfig().getTranslogPath(),
|
|
|
|
|
|
+ final String translogUUID = Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(),
|
|
SequenceNumbers.UNASSIGNED_SEQ_NO, shardId);
|
|
SequenceNumbers.UNASSIGNED_SEQ_NO, shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
}
|
|
}
|
|
engine = new InternalEngine(config);
|
|
engine = new InternalEngine(config);
|
|
engine.recoverFromTranslog();
|
|
engine.recoverFromTranslog();
|
|
@@ -2354,6 +2355,84 @@ public class InternalEngineTests extends EngineTestCase {
|
|
assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
|
|
assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testCurrentTranslogIDisCommitted() throws IOException {
|
|
|
|
+ final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
|
|
|
|
+ try (Store store = createStore()) {
|
|
|
|
+ EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null, null, globalCheckpoint::get);
|
|
|
|
+
|
|
|
|
+ // create
|
|
|
|
+ {
|
|
|
|
+ store.createEmpty();
|
|
|
|
+ final String translogUUID =
|
|
|
|
+ Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
|
|
+ ParsedDocument doc = testParsedDocument(Integer.toString(0), null, testDocument(), new BytesArray("{}"), null);
|
|
|
|
+ Engine.Index firstIndexRequest = new Engine.Index(newUid(doc), doc, SequenceNumbers.UNASSIGNED_SEQ_NO, 0,
|
|
|
|
+ Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, System.nanoTime(), -1, false);
|
|
|
|
+
|
|
|
|
+ try (InternalEngine engine = createEngine(config)) {
|
|
|
|
+ engine.index(firstIndexRequest);
|
|
|
|
+ globalCheckpoint.set(engine.getLocalCheckpointTracker().getCheckpoint());
|
|
|
|
+ expectThrows(IllegalStateException.class, () -> engine.recoverFromTranslog());
|
|
|
|
+ Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
|
|
|
|
+ assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ assertEquals(engine.getTranslog().getTranslogUUID(), userData.get(Translog.TRANSLOG_UUID_KEY));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // open and recover tlog
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < 2; i++) {
|
|
|
|
+ try (InternalEngine engine = new InternalEngine(config)) {
|
|
|
|
+ assertTrue(engine.isRecovering());
|
|
|
|
+ Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
|
|
|
|
+ if (i == 0) {
|
|
|
|
+ assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ } else {
|
|
|
|
+ // creating an empty index will create the first translog gen and commit it
|
|
|
|
+ // opening the empty index will make the second translog file but not commit it
|
|
|
|
+ // opening the engine again (i=0) will make the third translog file, which then be committed
|
|
|
|
+ assertEquals("3", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ }
|
|
|
|
+ assertEquals(engine.getTranslog().getTranslogUUID(), userData.get(Translog.TRANSLOG_UUID_KEY));
|
|
|
|
+ engine.recoverFromTranslog();
|
|
|
|
+ userData = engine.getLastCommittedSegmentInfos().getUserData();
|
|
|
|
+ assertEquals("3", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ assertEquals(engine.getTranslog().getTranslogUUID(), userData.get(Translog.TRANSLOG_UUID_KEY));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // open index with new tlog
|
|
|
|
+ {
|
|
|
|
+ final String translogUUID =
|
|
|
|
+ Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
|
|
+ try (InternalEngine engine = new InternalEngine(config)) {
|
|
|
|
+ Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
|
|
|
|
+ assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ assertEquals(engine.getTranslog().getTranslogUUID(), userData.get(Translog.TRANSLOG_UUID_KEY));
|
|
|
|
+ engine.recoverFromTranslog();
|
|
|
|
+ assertEquals(2, engine.getTranslog().currentFileGeneration());
|
|
|
|
+ assertEquals(0L, engine.getTranslog().stats().getUncommittedOperations());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // open and recover tlog with empty tlog
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < 2; i++) {
|
|
|
|
+ try (InternalEngine engine = new InternalEngine(config)) {
|
|
|
|
+ Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
|
|
|
|
+ assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ assertEquals(engine.getTranslog().getTranslogUUID(), userData.get(Translog.TRANSLOG_UUID_KEY));
|
|
|
|
+ engine.recoverFromTranslog();
|
|
|
|
+ userData = engine.getLastCommittedSegmentInfos().getUserData();
|
|
|
|
+ assertEquals("no changes - nothing to commit", "1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
|
|
|
|
+ assertEquals(engine.getTranslog().getTranslogUUID(), userData.get(Translog.TRANSLOG_UUID_KEY));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testMissingTranslog() throws IOException {
|
|
public void testMissingTranslog() throws IOException {
|
|
// test that we can force start the engine , even if the translog is missing.
|
|
// test that we can force start the engine , even if the translog is missing.
|
|
engine.close();
|
|
engine.close();
|
|
@@ -2369,7 +2448,8 @@ public class InternalEngineTests extends EngineTestCase {
|
|
// expected
|
|
// expected
|
|
}
|
|
}
|
|
// when a new translog is created it should be ok
|
|
// when a new translog is created it should be ok
|
|
- EngineDiskUtils.createNewTranslog(store.directory(), primaryTranslogDir, SequenceNumbers.UNASSIGNED_SEQ_NO, shardId);
|
|
|
|
|
|
+ final String translogUUID = Translog.createEmptyTranslog(primaryTranslogDir, SequenceNumbers.UNASSIGNED_SEQ_NO, shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
EngineConfig config = config(defaultSettings, store, primaryTranslogDir, newMergePolicy(), null);
|
|
EngineConfig config = config(defaultSettings, store, primaryTranslogDir, newMergePolicy(), null);
|
|
engine = new InternalEngine(config);
|
|
engine = new InternalEngine(config);
|
|
}
|
|
}
|
|
@@ -2432,7 +2512,9 @@ public class InternalEngineTests extends EngineTestCase {
|
|
final Path translogPath = createTempDir();
|
|
final Path translogPath = createTempDir();
|
|
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
|
|
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
|
|
final LongSupplier globalCheckpointSupplier = () -> globalCheckpoint.get();
|
|
final LongSupplier globalCheckpointSupplier = () -> globalCheckpoint.get();
|
|
- EngineDiskUtils.createEmpty(store.directory(), translogPath, shardId);
|
|
|
|
|
|
+ store.createEmpty();
|
|
|
|
+ final String translogUUID = Translog.createEmptyTranslog(translogPath, globalCheckpoint.get(), shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
try (InternalEngine engine =
|
|
try (InternalEngine engine =
|
|
new InternalEngine(config(indexSettings, store, translogPath, newMergePolicy(), null, null,
|
|
new InternalEngine(config(indexSettings, store, translogPath, newMergePolicy(), null, null,
|
|
globalCheckpointSupplier)) {
|
|
globalCheckpointSupplier)) {
|
|
@@ -3223,7 +3305,8 @@ public class InternalEngineTests extends EngineTestCase {
|
|
}
|
|
}
|
|
try (Store store = createStore(newFSDirectory(storeDir))) {
|
|
try (Store store = createStore(newFSDirectory(storeDir))) {
|
|
if (randomBoolean() || true) {
|
|
if (randomBoolean() || true) {
|
|
- EngineDiskUtils.createNewTranslog(store.directory(), translogDir, SequenceNumbers.NO_OPS_PERFORMED, shardId);
|
|
|
|
|
|
+ final String translogUUID = Translog.createEmptyTranslog(translogDir, SequenceNumbers.NO_OPS_PERFORMED, shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
}
|
|
}
|
|
try (Engine engine = new InternalEngine(configSupplier.apply(store))) {
|
|
try (Engine engine = new InternalEngine(configSupplier.apply(store))) {
|
|
assertEquals(maxTimestamp12, engine.segmentsStats(false).getMaxUnsafeAutoIdTimestamp());
|
|
assertEquals(maxTimestamp12, engine.segmentsStats(false).getMaxUnsafeAutoIdTimestamp());
|
|
@@ -4025,10 +4108,12 @@ public class InternalEngineTests extends EngineTestCase {
|
|
final Path translogPath = createTempDir();
|
|
final Path translogPath = createTempDir();
|
|
store = createStore();
|
|
store = createStore();
|
|
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
|
|
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
|
|
|
|
+ store.createEmpty();
|
|
|
|
+ final String translogUUID = Translog.createEmptyTranslog(translogPath, globalCheckpoint.get(), shardId);
|
|
|
|
+ store.associateIndexWithNewTranslog(translogUUID);
|
|
|
|
|
|
final EngineConfig engineConfig = config(indexSettings, store, translogPath, NoMergePolicy.INSTANCE, null, null,
|
|
final EngineConfig engineConfig = config(indexSettings, store, translogPath, NoMergePolicy.INSTANCE, null, null,
|
|
() -> globalCheckpoint.get());
|
|
() -> globalCheckpoint.get());
|
|
- EngineDiskUtils.createEmpty(store.directory(), translogPath, shardId);
|
|
|
|
try (Engine engine = new InternalEngine(engineConfig) {
|
|
try (Engine engine = new InternalEngine(engineConfig) {
|
|
@Override
|
|
@Override
|
|
protected void commitIndexWriter(IndexWriter writer, Translog translog, String syncId) throws IOException {
|
|
protected void commitIndexWriter(IndexWriter writer, Translog translog, String syncId) throws IOException {
|
|
@@ -4042,7 +4127,6 @@ public class InternalEngineTests extends EngineTestCase {
|
|
}) {
|
|
}) {
|
|
engine.recoverFromTranslog();
|
|
engine.recoverFromTranslog();
|
|
int numDocs = scaledRandomIntBetween(10, 100);
|
|
int numDocs = scaledRandomIntBetween(10, 100);
|
|
- final String translogUUID = engine.getTranslog().getTranslogUUID();
|
|
|
|
for (int docId = 0; docId < numDocs; docId++) {
|
|
for (int docId = 0; docId < numDocs; docId++) {
|
|
ParseContext.Document document = testDocumentWithTextField();
|
|
ParseContext.Document document = testDocumentWithTextField();
|
|
document.add(new Field(SourceFieldMapper.NAME, BytesReference.toBytes(B_1), SourceFieldMapper.Defaults.FIELD_TYPE));
|
|
document.add(new Field(SourceFieldMapper.NAME, BytesReference.toBytes(B_1), SourceFieldMapper.Defaults.FIELD_TYPE));
|