Skip to content

Avoid passing Lucene version to Store#createEmpty. #65861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private void internalRecoverFromStore(IndexShard indexShard) throws IndexShardRe
}
index.setFileDetailsComplete();
} else {
store.createEmpty(indexShard.indexSettings().getIndexVersionCreated().luceneVersion);
store.createEmpty();
final String translogUUID = Translog.createEmptyTranslog(
indexShard.shardPath().resolveTranslog(), SequenceNumbers.NO_OPS_PERFORMED, shardId,
indexShard.getPendingPrimaryTerm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,8 @@ public void accept(ShardLock Lock) {
/**
* creates an empty lucene index and a corresponding empty translog. Any existing data will be deleted.
*/
public void createEmpty(Version luceneVersion) throws IOException {
public void createEmpty() throws IOException {
Version luceneVersion = indexSettings.getIndexVersionCreated().luceneVersion;
metadataLock.writeLock().lock();
try (IndexWriter writer = newEmptyIndexWriter(directory, luceneVersion)) {
final Map<String, String> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,7 @@ public void testCurrentTranslogUUIIDIsCommitted() throws IOException {

// create
{
store.createEmpty(Version.CURRENT.luceneVersion);
store.createEmpty();
final String translogUUID =
Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(),
SequenceNumbers.NO_OPS_PERFORMED, shardId, primaryTerm.get());
Expand Down Expand Up @@ -3051,7 +3051,7 @@ public void testTranslogCleanUpPostCommitCrash() throws Exception {
final Path translogPath = createTempDir();
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
final LongSupplier globalCheckpointSupplier = () -> globalCheckpoint.get();
store.createEmpty(Version.CURRENT.luceneVersion);
store.createEmpty();
final String translogUUID = Translog.createEmptyTranslog(translogPath, globalCheckpoint.get(), shardId, primaryTerm.get());
store.associateIndexWithNewTranslog(translogUUID);
try (InternalEngine engine =
Expand Down Expand Up @@ -4930,7 +4930,7 @@ public void testKeepTranslogAfterGlobalCheckpoint() throws Exception {
final Path translogPath = createTempDir();
store = createStore();
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
store.createEmpty(Version.CURRENT.luceneVersion);
store.createEmpty();
final String translogUUID = Translog.createEmptyTranslog(translogPath, globalCheckpoint.get(), shardId, primaryTerm.get());
store.associateIndexWithNewTranslog(translogUUID);

Expand Down Expand Up @@ -5869,7 +5869,7 @@ public void testStoreHonorsLuceneVersion() throws IOException {
.put(indexSettings())
.put(IndexMetadata.SETTING_VERSION_CREATED, createdVersion).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings);
try (Store store = createStore();
try (Store store = createStore(indexSettings, newDirectory());
InternalEngine engine = createEngine(config(indexSettings, store, createTempDir(), NoMergePolicy.INSTANCE, null))) {
ParsedDocument doc = testParsedDocument("1", null, new Document(),
new BytesArray("{}".getBytes("UTF-8")), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.core.internal.io.IOUtils;
Expand Down Expand Up @@ -184,7 +183,7 @@ public void testReadOnly() 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);
store.createEmpty(Version.CURRENT.luceneVersion);
store.createEmpty();
try (ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine(config, null , new TranslogStats(), true, Function.identity(), true)) {
Class<? extends Throwable> expectedException = LuceneTestCase.TEST_ASSERTS_ENABLED ? AssertionError.class :
UnsupportedOperationException.class;
Expand All @@ -205,7 +204,7 @@ public void testVerifyShardBeforeIndexClosingIsNoOp() 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);
store.createEmpty(Version.CURRENT.luceneVersion);
store.createEmpty();
try (ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine(config, null , new TranslogStats(), true, Function.identity(), true)) {
globalCheckpoint.set(randomNonNegativeLong());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.bytes.BytesArray;
Expand Down Expand Up @@ -121,7 +120,7 @@ public void onFailedEngine(String reason, @Nullable Exception e) {
// we don't need to notify anybody in this test
}
};
store.createEmpty(Version.CURRENT.luceneVersion);
store.createEmpty();
final long primaryTerm = randomNonNegativeLong();
final String translogUUID =
Translog.createEmptyTranslog(translogConfig.getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId, primaryTerm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ public void testEnsureIndexHasHistoryUUID() throws IOException {
final ShardId shardId = new ShardId("index", "_na_", 1);
try (Store store = new Store(shardId, INDEX_SETTINGS, StoreTests.newDirectory(random()), new DummyShardLock(shardId))) {

store.createEmpty(Version.LATEST);
store.createEmpty();

// remove the history uuid
IndexWriterConfig iwc = new IndexWriterConfig(null)
Expand Down Expand Up @@ -1042,7 +1042,7 @@ public void testHistoryUUIDCanBeForced() throws IOException {
final ShardId shardId = new ShardId("index", "_na_", 1);
try (Store store = new Store(shardId, INDEX_SETTINGS, StoreTests.newDirectory(random()), new DummyShardLock(shardId))) {

store.createEmpty(Version.LATEST);
store.createEmpty();

SegmentInfos segmentInfos = Lucene.readSegmentInfos(store.directory());
assertThat(segmentInfos.getUserData(), hasKey(Engine.HISTORY_UUID_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ protected InternalEngine createEngine(@Nullable IndexWriterFactory indexWriterFa
final Store store = config.getStore();
final Directory directory = store.directory();
if (Lucene.indexExists(directory) == false) {
store.createEmpty(config.getIndexSettings().getIndexVersionCreated().luceneVersion);
store.createEmpty();
final String translogUuid = Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(),
SequenceNumbers.NO_OPS_PERFORMED, shardId, primaryTerm.get());
store.associateIndexWithNewTranslog(translogUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void restoreShard(Store store, SnapshotId snapshotId, IndexId indexId, Sh
private void createEmptyStore(Store store) {
store.incRef();
try {
store.createEmpty(store.indexSettings().getIndexVersionCreated().luceneVersion);
store.createEmpty();
} catch (final EngineException | IOException e) {
throw new IndexShardRecoveryException(store.shardId(), "failed to create empty store", e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static Store createStore(
}

private FollowingEngine createEngine(Store store, EngineConfig config) throws IOException {
store.createEmpty(config.getIndexSettings().getIndexVersionCreated().luceneVersion);
store.createEmpty();
final String translogUuid = Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(),
SequenceNumbers.NO_OPS_PERFORMED, shardId, 1L);
store.associateIndexWithNewTranslog(translogUuid);
Expand Down Expand Up @@ -492,7 +492,7 @@ private void runFollowTest(CheckedBiConsumer<InternalEngine, FollowingEngine, Ex
IndexMetadata leaderIndexMetadata = IndexMetadata.builder(index.getName()).settings(leaderSettings).build();
IndexSettings leaderIndexSettings = new IndexSettings(leaderIndexMetadata, leaderSettings);
try (Store leaderStore = createStore(shardId, leaderIndexSettings, newDirectory())) {
leaderStore.createEmpty(leaderIndexMetadata.getCreationVersion().luceneVersion);
leaderStore.createEmpty();
EngineConfig leaderConfig = engineConfig(shardId, leaderIndexSettings, threadPool, leaderStore, logger, xContentRegistry());
leaderStore.associateIndexWithNewTranslog(Translog.createEmptyTranslog(
leaderConfig.getTranslogConfig().getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId, 1L));
Expand Down