testUpgradeOldIndex should properly set index setting. They are needed for assertions

This commit is contained in:
Boaz Leskes 2016-11-12 11:42:02 +01:00
parent 1ea69b1a80
commit fac6cf0d4e
2 changed files with 16 additions and 9 deletions

View File

@ -47,7 +47,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.lucene.LoggerInfoStream;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
@ -531,14 +530,17 @@ public class InternalEngine extends Engine {
private boolean assertSequenceNumber(final Engine.Operation.Origin origin, final long seqNo) {
if (engineConfig.getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1) && origin == Operation.Origin.LOCAL_TRANSLOG_RECOVERY) {
// legacy support
return seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO;
assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "old op recovering but it already has a seq no." +
" index version: " + engineConfig.getIndexSettings().getIndexVersionCreated() + ". seq no: " + seqNo;
} else if (origin == Operation.Origin.PRIMARY) {
// sequence number should not be set when operation origin is primary
return seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO;
assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "primary ops should never an assigned seq no. got: " + seqNo;
} else {
// sequence number should be set when operation origin is not primary
return seqNo >= 0;
assert seqNo >= 0 : "replica ops should an assigned seq no. origin: " + origin +
" index version: " + engineConfig.getIndexSettings().getIndexVersionCreated();
}
return true;
}
private IndexResult innerIndex(Index index) throws IOException {

View File

@ -273,7 +273,10 @@ public class InternalEngineTests extends ESTestCase {
}
protected Store createStore(final Directory directory) throws IOException {
final DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) {
return createStore(INDEX_SETTINGS, directory);
}
protected Store createStore(final IndexSettings indexSettings, final Directory directory) throws IOException {
final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) {
@Override
public Directory newDirectory() throws IOException {
return directory;
@ -284,7 +287,7 @@ public class InternalEngineTests extends ESTestCase {
return 0;
}
};
return new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId));
return new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
}
protected Translog createTranslog() throws IOException {
@ -2120,11 +2123,13 @@ public class InternalEngineTests extends ESTestCase {
final long size = Files.size(tlogFile);
logger.debug("upgrading index {} file: {} size: {}", indexName, tlogFiles[0].getFileName(), size);
Directory directory = newFSDirectory(src.resolve("0").resolve("index"));
Store store = createStore(directory);
final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, src);
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexMetaData);
final Store store = createStore(indexSettings, directory);
final int iters = randomIntBetween(0, 2);
int numDocs = -1;
for (int i = 0; i < iters; i++) { // make sure we can restart on an upgraded index
try (InternalEngine engine = createEngine(store, translog)) {
try (InternalEngine engine = createEngine(indexSettings, store, translog, newMergePolicy())) {
try (Searcher searcher = engine.acquireSearcher("test")) {
if (i > 0) {
assertEquals(numDocs, searcher.reader().numDocs());
@ -2141,7 +2146,7 @@ public class InternalEngineTests extends ESTestCase {
}
}
try (InternalEngine engine = createEngine(store, translog)) {
try (InternalEngine engine = createEngine(indexSettings, store, translog, newMergePolicy())) {
if (numDocs == -1) {
try (Searcher searcher = engine.acquireSearcher("test")) {
numDocs = searcher.reader().numDocs();