mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Failed to acquire lock, closes #193.
This commit is contained in:
parent
463910da45
commit
26364afd7e
@ -116,6 +116,20 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine,
|
||||
this.mergeScheduler = mergeScheduler;
|
||||
this.analysisService = analysisService;
|
||||
this.similarityService = similarityService;
|
||||
|
||||
// clear the index dir by creating a new index
|
||||
try {
|
||||
// release locks when started
|
||||
if (IndexWriter.isLocked(store.directory())) {
|
||||
logger.trace("Shard is locked, releasing lock");
|
||||
store.directory().clearLock(IndexWriter.WRITE_LOCK_NAME);
|
||||
}
|
||||
IndexWriter writer = new IndexWriter(store.directory(), analysisService.defaultIndexAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
|
||||
writer.commit();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to clean the index", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void start() throws EngineException {
|
||||
|
@ -19,9 +19,7 @@
|
||||
|
||||
package org.elasticsearch.index.store.fs;
|
||||
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.MMapDirectory;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.LocalNodeId;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
@ -53,12 +51,19 @@ public class MmapFsStore extends AbstractFsStore<Directory> {
|
||||
super(shardId, indexSettings);
|
||||
// by default, we don't need to sync to disk, since we use the gateway
|
||||
this.syncToDisk = componentSettings.getAsBoolean("sync_to_disk", false);
|
||||
this.fsDirectory = new CustomMMapDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), syncToDisk);
|
||||
String fsLock = componentSettings.get("use_fs_lock", "none");
|
||||
LockFactory lockFactory = new NoLockFactory();
|
||||
if (fsLock.equals("native")) {
|
||||
lockFactory = new NativeFSLockFactory();
|
||||
} else if (fsLock.equals("simple")) {
|
||||
lockFactory = new SimpleFSLockFactory();
|
||||
}
|
||||
this.fsDirectory = new CustomMMapDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), lockFactory, syncToDisk);
|
||||
|
||||
SwitchDirectory switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory);
|
||||
if (switchDirectory != null) {
|
||||
suggestUseCompoundFile = false;
|
||||
logger.debug("Using [mmap_fs] Store with path [{}], cache [true] with extensions [{}]", new Object[]{fsDirectory.getFile(), switchDirectory.primaryExtensions()});
|
||||
logger.debug("Using [mmap_fs] Store with path [{}], cache [true] with extensions [{}]", fsDirectory.getFile(), switchDirectory.primaryExtensions());
|
||||
directory = switchDirectory;
|
||||
} else {
|
||||
suggestUseCompoundFile = true;
|
||||
@ -83,8 +88,8 @@ public class MmapFsStore extends AbstractFsStore<Directory> {
|
||||
|
||||
private final boolean syncToDisk;
|
||||
|
||||
private CustomMMapDirectory(File path, boolean syncToDisk) throws IOException {
|
||||
super(path);
|
||||
private CustomMMapDirectory(File path, LockFactory lockFactory, boolean syncToDisk) throws IOException {
|
||||
super(path, lockFactory);
|
||||
this.syncToDisk = syncToDisk;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,7 @@
|
||||
|
||||
package org.elasticsearch.index.store.fs;
|
||||
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.NIOFSDirectory;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.LocalNodeId;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
@ -53,12 +51,19 @@ public class NioFsStore extends AbstractFsStore<Directory> {
|
||||
super(shardId, indexSettings);
|
||||
// by default, we don't need to sync to disk, since we use the gateway
|
||||
this.syncToDisk = componentSettings.getAsBoolean("sync_to_disk", false);
|
||||
this.fsDirectory = new CustomNioFSDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), syncToDisk);
|
||||
String fsLock = componentSettings.get("use_fs_lock", "none");
|
||||
LockFactory lockFactory = new NoLockFactory();
|
||||
if (fsLock.equals("native")) {
|
||||
lockFactory = new NativeFSLockFactory();
|
||||
} else if (fsLock.equals("simple")) {
|
||||
lockFactory = new SimpleFSLockFactory();
|
||||
}
|
||||
this.fsDirectory = new CustomNioFSDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), lockFactory, syncToDisk);
|
||||
|
||||
SwitchDirectory switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory);
|
||||
if (switchDirectory != null) {
|
||||
suggestUseCompoundFile = false;
|
||||
logger.debug("Using [nio_fs] Store with path [{}], cache [true] with extensions [{}]", new Object[]{fsDirectory.getFile(), switchDirectory.primaryExtensions()});
|
||||
logger.debug("Using [nio_fs] Store with path [{}], cache [true] with extensions [{}]", fsDirectory.getFile(), switchDirectory.primaryExtensions());
|
||||
directory = switchDirectory;
|
||||
} else {
|
||||
suggestUseCompoundFile = true;
|
||||
@ -83,8 +88,8 @@ public class NioFsStore extends AbstractFsStore<Directory> {
|
||||
|
||||
private final boolean syncToDisk;
|
||||
|
||||
private CustomNioFSDirectory(File path, boolean syncToDisk) throws IOException {
|
||||
super(path);
|
||||
private CustomNioFSDirectory(File path, LockFactory lockFactory, boolean syncToDisk) throws IOException {
|
||||
super(path, lockFactory);
|
||||
this.syncToDisk = syncToDisk;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,7 @@
|
||||
|
||||
package org.elasticsearch.index.store.fs;
|
||||
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.SimpleFSDirectory;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.LocalNodeId;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
@ -53,12 +51,19 @@ public class SimpleFsStore extends AbstractFsStore<Directory> {
|
||||
super(shardId, indexSettings);
|
||||
// by default, we don't need to sync to disk, since we use the gateway
|
||||
this.syncToDisk = componentSettings.getAsBoolean("sync_to_disk", false);
|
||||
this.fsDirectory = new CustomSimpleFSDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), syncToDisk);
|
||||
String fsLock = componentSettings.get("use_fs_lock", "none");
|
||||
LockFactory lockFactory = new NoLockFactory();
|
||||
if (fsLock.equals("native")) {
|
||||
lockFactory = new NativeFSLockFactory();
|
||||
} else if (fsLock.equals("simple")) {
|
||||
lockFactory = new SimpleFSLockFactory();
|
||||
}
|
||||
this.fsDirectory = new CustomSimpleFSDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), lockFactory, syncToDisk);
|
||||
|
||||
SwitchDirectory switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory);
|
||||
if (switchDirectory != null) {
|
||||
suggestUseCompoundFile = false;
|
||||
logger.debug("Using [simple_fs] Store with path [{}], cache [true] with extensions [{}]", new Object[]{fsDirectory.getFile(), switchDirectory.primaryExtensions()});
|
||||
logger.debug("Using [simple_fs] Store with path [{}], cache [true] with extensions [{}]", fsDirectory.getFile(), switchDirectory.primaryExtensions());
|
||||
directory = switchDirectory;
|
||||
} else {
|
||||
suggestUseCompoundFile = true;
|
||||
@ -83,8 +88,8 @@ public class SimpleFsStore extends AbstractFsStore<Directory> {
|
||||
|
||||
private final boolean syncToDisk;
|
||||
|
||||
private CustomSimpleFSDirectory(File path, boolean syncToDisk) throws IOException {
|
||||
super(path);
|
||||
private CustomSimpleFSDirectory(File path, LockFactory lockFactory, boolean syncToDisk) throws IOException {
|
||||
super(path, lockFactory);
|
||||
this.syncToDisk = syncToDisk;
|
||||
}
|
||||
|
||||
|
@ -212,18 +212,6 @@ public abstract class AbstractSimpleEngineTests {
|
||||
searchResult.release();
|
||||
|
||||
engine.close();
|
||||
|
||||
// TODO check that operations on engine will throw an EngineAlreadyClosed exception (and while you are at it, create the exception as well)
|
||||
|
||||
// now create a new engine, it should see the flushed changes
|
||||
engine = createEngine(store);
|
||||
engine.start();
|
||||
|
||||
searchResult = engine.searcher();
|
||||
assertThat(searchResult, engineSearcherTotalHits(1));
|
||||
assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0));
|
||||
assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 1));
|
||||
searchResult.release();
|
||||
}
|
||||
|
||||
@Test public void testSearchResultRelease() throws Exception {
|
||||
|
Loading…
x
Reference in New Issue
Block a user