Remove unused index store in directory service

With this commit we remove the unused field `indexStore` from all
implementations of `FsDirectoryService`.

Relates #37097
This commit is contained in:
Daniel Mitterdorfer 2019-01-14 13:44:32 +01:00 committed by GitHub
parent 07dc8c7eee
commit abe35fb99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 16 additions and 24 deletions

View File

@ -25,7 +25,6 @@ import org.apache.lucene.store.MMapDirectory;
import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.FsDirectoryService; import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.SmbDirectoryWrapper; import org.elasticsearch.index.store.SmbDirectoryWrapper;
import java.io.IOException; import java.io.IOException;
@ -33,8 +32,8 @@ import java.nio.file.Path;
public class SmbMmapFsDirectoryService extends FsDirectoryService { public class SmbMmapFsDirectoryService extends FsDirectoryService {
public SmbMmapFsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) { public SmbMmapFsDirectoryService(IndexSettings indexSettings, ShardPath path) {
super(indexSettings, indexStore, path); super(indexSettings, path);
} }
@Override @Override

View File

@ -32,6 +32,6 @@ public class SmbMmapFsIndexStore extends IndexStore {
@Override @Override
public DirectoryService newDirectoryService(ShardPath path) { public DirectoryService newDirectoryService(ShardPath path) {
return new SmbMmapFsDirectoryService(indexSettings, this, path); return new SmbMmapFsDirectoryService(indexSettings, path);
} }
} }

View File

@ -25,7 +25,6 @@ import org.apache.lucene.store.SimpleFSDirectory;
import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.FsDirectoryService; import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.SmbDirectoryWrapper; import org.elasticsearch.index.store.SmbDirectoryWrapper;
import java.io.IOException; import java.io.IOException;
@ -33,8 +32,8 @@ import java.nio.file.Path;
public class SmbSimpleFsDirectoryService extends FsDirectoryService { public class SmbSimpleFsDirectoryService extends FsDirectoryService {
public SmbSimpleFsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) { public SmbSimpleFsDirectoryService(IndexSettings indexSettings, ShardPath path) {
super(indexSettings, indexStore, path); super(indexSettings, path);
} }
@Override @Override

View File

@ -32,7 +32,7 @@ public class SmbSimpleFsIndexStore extends IndexStore {
@Override @Override
public DirectoryService newDirectoryService(ShardPath path) { public DirectoryService newDirectoryService(ShardPath path) {
return new SmbSimpleFsDirectoryService(indexSettings, this, path); return new SmbSimpleFsDirectoryService(indexSettings, path);
} }
} }

View File

@ -45,7 +45,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class FsDirectoryService extends DirectoryService { public class FsDirectoryService extends DirectoryService {
protected final IndexStore indexStore;
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> { public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
switch (s) { switch (s) {
case "native": case "native":
@ -60,10 +59,9 @@ public class FsDirectoryService extends DirectoryService {
private final ShardPath path; private final ShardPath path;
@Inject @Inject
public FsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) { public FsDirectoryService(IndexSettings indexSettings, ShardPath path) {
super(path.getShardId(), indexSettings); super(path.getShardId(), indexSettings);
this.path = path; this.path = path;
this.indexStore = indexStore;
} }
@Override @Override

View File

@ -33,7 +33,7 @@ public class IndexStore extends AbstractIndexComponent {
* The shard store class that should be used for each shard. * The shard store class that should be used for each shard.
*/ */
public DirectoryService newDirectoryService(ShardPath path) { public DirectoryService newDirectoryService(ShardPath path) {
return new FsDirectoryService(indexSettings, this, path); return new FsDirectoryService(indexSettings, path);
} }
} }

View File

@ -49,11 +49,10 @@ public class FsDirectoryServiceTests extends ESTestCase {
.putList(IndexModule.INDEX_STORE_PRE_LOAD_SETTING.getKey(), preload) .putList(IndexModule.INDEX_STORE_PRE_LOAD_SETTING.getKey(), preload)
.build(); .build();
IndexSettings settings = IndexSettingsModule.newIndexSettings("foo", build); IndexSettings settings = IndexSettingsModule.newIndexSettings("foo", build);
IndexStore store = new IndexStore(settings);
Path tempDir = createTempDir().resolve(settings.getUUID()).resolve("0"); Path tempDir = createTempDir().resolve(settings.getUUID()).resolve("0");
Files.createDirectories(tempDir); Files.createDirectories(tempDir);
ShardPath path = new ShardPath(false, tempDir, tempDir, new ShardId(settings.getIndex(), 0)); ShardPath path = new ShardPath(false, tempDir, tempDir, new ShardId(settings.getIndex(), 0));
FsDirectoryService fsDirectoryService = new FsDirectoryService(settings, store, path); FsDirectoryService fsDirectoryService = new FsDirectoryService(settings, path);
Directory directory = fsDirectoryService.newDirectory(); Directory directory = fsDirectoryService.newDirectory();
assertFalse(directory instanceof SleepingLockWrapper); assertFalse(directory instanceof SleepingLockWrapper);
if (preload.length == 0) { if (preload.length == 0) {

View File

@ -60,8 +60,7 @@ public class IndexStoreTests extends ESTestCase {
} }
Settings settings = settingsBuilder.build(); Settings settings = settingsBuilder.build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
FsDirectoryService service = new FsDirectoryService(indexSettings, null, FsDirectoryService service = new FsDirectoryService(indexSettings, new ShardPath(false, tempDir, tempDir, new ShardId(index, 0)));
new ShardPath(false, tempDir, tempDir, new ShardId(index, 0)));
try (Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) { try (Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) {
switch (type) { switch (type) {
case HYBRIDFS: case HYBRIDFS:

View File

@ -43,7 +43,6 @@ import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.FsDirectoryService; import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.Store; import org.elasticsearch.index.store.Store;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
@ -74,8 +73,8 @@ public class MockFSDirectoryService extends FsDirectoryService {
private final boolean crashIndex; private final boolean crashIndex;
@Inject @Inject
public MockFSDirectoryService(IndexSettings idxSettings, IndexStore indexStore, final ShardPath path) { public MockFSDirectoryService(IndexSettings idxSettings, final ShardPath path) {
super(idxSettings, indexStore, path); super(idxSettings, path);
Settings indexSettings = idxSettings.getSettings(); Settings indexSettings = idxSettings.getSettings();
final long seed = idxSettings.getValue(ESIntegTestCase.INDEX_TEST_SEED_SETTING); final long seed = idxSettings.getValue(ESIntegTestCase.INDEX_TEST_SEED_SETTING);
this.random = new Random(seed); this.random = new Random(seed);
@ -90,7 +89,7 @@ public class MockFSDirectoryService extends FsDirectoryService {
logger.debug("Using MockDirWrapper with seed [{}] throttle: [{}] crashIndex: [{}]", SeedUtils.formatSeed(seed), logger.debug("Using MockDirWrapper with seed [{}] throttle: [{}] crashIndex: [{}]", SeedUtils.formatSeed(seed),
throttle, crashIndex); throttle, crashIndex);
} }
delegateService = randomDirectoryService(indexStore, path); delegateService = randomDirectoryService(idxSettings, path);
} }
@ -152,8 +151,7 @@ public class MockFSDirectoryService extends FsDirectoryService {
return w; return w;
} }
private FsDirectoryService randomDirectoryService(IndexStore indexStore, ShardPath path) { private FsDirectoryService randomDirectoryService(IndexSettings indexSettings, ShardPath path) {
final IndexSettings indexSettings = indexStore.getIndexSettings();
final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()) final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData())
.settings(Settings.builder() .settings(Settings.builder()
// don't use the settings from indexSettings#getSettings() they are merged with node settings and might contain // don't use the settings from indexSettings#getSettings() they are merged with node settings and might contain
@ -163,7 +161,7 @@ public class MockFSDirectoryService extends FsDirectoryService {
RandomPicks.randomFrom(random, IndexModule.Type.values()).getSettingsKey())) RandomPicks.randomFrom(random, IndexModule.Type.values()).getSettingsKey()))
.build(); .build();
final IndexSettings newIndexSettings = new IndexSettings(build, indexSettings.getNodeSettings()); final IndexSettings newIndexSettings = new IndexSettings(build, indexSettings.getNodeSettings());
return new FsDirectoryService(newIndexSettings, indexStore, path); return new FsDirectoryService(newIndexSettings, path);
} }
public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper { public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper {

View File

@ -86,7 +86,7 @@ public class MockFSIndexStore extends IndexStore {
@Override @Override
public DirectoryService newDirectoryService(ShardPath path) { public DirectoryService newDirectoryService(ShardPath path) {
return new MockFSDirectoryService(indexSettings, this, path); return new MockFSDirectoryService(indexSettings, path);
} }
private static final EnumSet<IndexShardState> validCheckIndexStates = EnumSet.of( private static final EnumSet<IndexShardState> validCheckIndexStates = EnumSet.of(