mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-24 23:27:25 -04:00
more cleanups
This commit is contained in:
parent
c0eca94a04
commit
d2e3e8cc7b
9 changed files with 27 additions and 111 deletions
|
@ -260,6 +260,9 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
throw new IllegalStateException("Can't create shard [" + index.name() + "][" + sShardId + "], closed");
|
throw new IllegalStateException("Can't create shard [" + index.name() + "][" + sShardId + "], closed");
|
||||||
}
|
}
|
||||||
|
if (indexSettings.get("index.translog.type") != null) { // TODO remove?
|
||||||
|
throw new IllegalStateException("a custom translog type is no longer supported. got [" + indexSettings.get("index.translog.type") + "]");
|
||||||
|
}
|
||||||
final ShardId shardId = new ShardId(index, sShardId);
|
final ShardId shardId = new ShardId(index, sShardId);
|
||||||
ShardLock lock = null;
|
ShardLock lock = null;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
@ -313,7 +316,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
||||||
(primary && IndexMetaData.isOnSharedFilesystem(indexSettings));
|
(primary && IndexMetaData.isOnSharedFilesystem(indexSettings));
|
||||||
IndexStore indexStore = injector.getInstance(IndexStore.class);
|
IndexStore indexStore = injector.getInstance(IndexStore.class);
|
||||||
store = new Store(shardId, indexSettings, indexStore.newDirectoryService(path), lock, new StoreCloseListener(shardId, canDeleteShardContent, () -> injector.getInstance(IndicesQueryCache.class).onClose(shardId)));
|
store = new Store(shardId, indexSettings, indexStore.newDirectoryService(path), lock, new StoreCloseListener(shardId, canDeleteShardContent, () -> injector.getInstance(IndicesQueryCache.class).onClose(shardId)));
|
||||||
if (primary && IndexMetaData.isIndexUsingShadowReplicas(indexSettings)) {
|
if (useShadowEngine(primary, indexSettings)) {
|
||||||
indexShard = new ShadowIndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class));
|
indexShard = new ShadowIndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class));
|
||||||
} else {
|
} else {
|
||||||
indexShard = new IndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class));
|
indexShard = new IndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class));
|
||||||
|
@ -338,6 +341,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean useShadowEngine(boolean primary, Settings indexSettings) {
|
||||||
|
return primary == false && IndexMetaData.isIndexUsingShadowReplicas(indexSettings);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void removeShard(int shardId, String reason) {
|
public synchronized void removeShard(int shardId, String reason) {
|
||||||
final ShardId sId = new ShardId(index, shardId);
|
final ShardId sId = new ShardId(index, shardId);
|
||||||
final Injector shardInjector;
|
final Injector shardInjector;
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to Elasticsearch under one or more contributor
|
|
||||||
* license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright
|
|
||||||
* ownership. Elasticsearch licenses this file to you under
|
|
||||||
* the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.elasticsearch.index.shard;
|
|
||||||
|
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
||||||
import org.elasticsearch.common.inject.AbstractModule;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@code IndexShardModule} module is responsible for binding the correct
|
|
||||||
* shard id, index shard, engine factory, and warming service for a newly
|
|
||||||
* created shard.
|
|
||||||
*/
|
|
||||||
public class IndexShardModule extends AbstractModule {
|
|
||||||
|
|
||||||
private final ShardId shardId;
|
|
||||||
private final Settings settings;
|
|
||||||
private final boolean primary;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IndexShardModule(ShardId shardId, boolean primary, Settings settings) {
|
|
||||||
this.settings = settings;
|
|
||||||
this.shardId = shardId;
|
|
||||||
this.primary = primary;
|
|
||||||
if (settings.get("index.translog.type") != null) {
|
|
||||||
throw new IllegalStateException("a custom translog type is no longer supported. got [" + settings.get("index.translog.type") + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true if a shadow engine should be used */
|
|
||||||
protected boolean useShadowEngine() {
|
|
||||||
return primary == false && IndexMetaData.isIndexUsingShadowReplicas(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(ShardId.class).toInstance(shardId);
|
|
||||||
if (useShadowEngine()) {
|
|
||||||
bind(IndexShard.class).to(ShadowIndexShard.class).asEagerSingleton();
|
|
||||||
} else {
|
|
||||||
bind(IndexShard.class).asEagerSingleton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -116,5 +116,4 @@ public class IndexStore extends AbstractIndexComponent implements Closeable {
|
||||||
public DirectoryService newDirectoryService(ShardPath path) {
|
public DirectoryService newDirectoryService(ShardPath path) {
|
||||||
return new FsDirectoryService(indexSettings, this, path);
|
return new FsDirectoryService(indexSettings, this, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,13 +73,6 @@ public abstract class Plugin {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Per index shard service that will be automatically closed.
|
|
||||||
*/
|
|
||||||
public Collection<Class<? extends Closeable>> shardServices() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be
|
* Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be
|
||||||
* overwritten with the additional settings. These settings added if they don't exist.
|
* overwritten with the additional settings. These settings added if they don't exist.
|
||||||
|
|
|
@ -250,14 +250,6 @@ public class PluginsService extends AbstractComponent {
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Class<? extends Closeable>> shardServices() {
|
|
||||||
List<Class<? extends Closeable>> services = new ArrayList<>();
|
|
||||||
for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
||||||
services.addAll(plugin.v2().shardServices());
|
|
||||||
}
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about plugins (jvm and site plugins).
|
* Get information about plugins (jvm and site plugins).
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,19 +17,19 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.index.shard;
|
package org.elasticsearch.index;
|
||||||
|
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.index.shard.ShardId;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/** Unit test(s) for IndexShardModule */
|
/** Unit test(s) for IndexService */
|
||||||
public class IndexShardModuleTests extends ESTestCase {
|
public class IndexServiceTests extends ESTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetermineShadowEngineShouldBeUsed() {
|
public void testDetermineShadowEngineShouldBeUsed() {
|
||||||
ShardId shardId = new ShardId("myindex", 0);
|
|
||||||
Settings regularSettings = Settings.builder()
|
Settings regularSettings = Settings.builder()
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2)
|
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2)
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
||||||
|
@ -41,14 +41,9 @@ public class IndexShardModuleTests extends ESTestCase {
|
||||||
.put(IndexMetaData.SETTING_SHADOW_REPLICAS, true)
|
.put(IndexMetaData.SETTING_SHADOW_REPLICAS, true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
IndexShardModule ism1 = new IndexShardModule(shardId, true, regularSettings);
|
assertFalse("no shadow replicas for normal settings", IndexService.useShadowEngine(true, regularSettings));
|
||||||
IndexShardModule ism2 = new IndexShardModule(shardId, false, regularSettings);
|
assertFalse("no shadow replicas for normal settings", IndexService.useShadowEngine(false, regularSettings));
|
||||||
IndexShardModule ism3 = new IndexShardModule(shardId, true, shadowSettings);
|
assertFalse("no shadow replicas for primary shard with shadow settings", IndexService.useShadowEngine(true, shadowSettings));
|
||||||
IndexShardModule ism4 = new IndexShardModule(shardId, false, shadowSettings);
|
assertTrue("shadow replicas for replica shards with shadow settings",IndexService.useShadowEngine(false, shadowSettings));
|
||||||
|
|
||||||
assertFalse("no shadow replicas for normal settings", ism1.useShadowEngine());
|
|
||||||
assertFalse("no shadow replicas for normal settings", ism2.useShadowEngine());
|
|
||||||
assertFalse("no shadow replicas for primary shard with shadow settings", ism3.useShadowEngine());
|
|
||||||
assertTrue("shadow replicas for replica shards with shadow settings", ism4.useShadowEngine());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -66,24 +66,10 @@ public class JvmExamplePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Module> indexModules(Settings indexSettings) {
|
public Collection<Module> indexModules(Settings indexSettings) { return Collections.emptyList();}
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends Closeable>> indexServices() {
|
public Collection<Class<? extends Closeable>> indexServices() { return Collections.emptyList();}
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Module> shardModules(Settings indexSettings) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Class<? extends Closeable>> shardServices() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Settings additionalSettings() {
|
public Settings additionalSettings() {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
import org.elasticsearch.index.settings.IndexSettingsService;
|
import org.elasticsearch.index.settings.IndexSettingsService;
|
||||||
|
import org.elasticsearch.index.shard.ShardPath;
|
||||||
import org.elasticsearch.index.store.DirectoryService;
|
import org.elasticsearch.index.store.DirectoryService;
|
||||||
import org.elasticsearch.index.store.IndexStore;
|
import org.elasticsearch.index.store.IndexStore;
|
||||||
import org.elasticsearch.indices.store.IndicesStore;
|
import org.elasticsearch.indices.store.IndicesStore;
|
||||||
|
@ -37,7 +38,7 @@ public class SmbMmapFsIndexStore extends IndexStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends DirectoryService> shardDirectory() {
|
public DirectoryService newDirectoryService(ShardPath path) {
|
||||||
return SmbMmapFsDirectoryService.class;
|
return new SmbMmapFsDirectoryService(indexSettings(), this, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
import org.elasticsearch.index.settings.IndexSettingsService;
|
import org.elasticsearch.index.settings.IndexSettingsService;
|
||||||
|
import org.elasticsearch.index.shard.ShardPath;
|
||||||
import org.elasticsearch.index.store.DirectoryService;
|
import org.elasticsearch.index.store.DirectoryService;
|
||||||
import org.elasticsearch.index.store.IndexStore;
|
import org.elasticsearch.index.store.IndexStore;
|
||||||
import org.elasticsearch.indices.store.IndicesStore;
|
import org.elasticsearch.indices.store.IndicesStore;
|
||||||
|
@ -36,9 +37,13 @@ public class SmbSimpleFsIndexStore extends IndexStore {
|
||||||
super(index, indexSettings, indexSettingsService, indicesStore);
|
super(index, indexSettings, indexSettingsService, indicesStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends DirectoryService> shardDirectory() {
|
public Class<? extends DirectoryService> shardDirectory() {
|
||||||
return SmbSimpleFsDirectoryService.class;
|
return SmbSimpleFsDirectoryService.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DirectoryService newDirectoryService(ShardPath path) {
|
||||||
|
return new SmbSimpleFsDirectoryService(indexSettings(), this, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue