allow to enabled/disable gc deletes internally

This commit is contained in:
Shay Banon 2011-12-08 12:07:55 +02:00
parent df9f333a27
commit ba29160562
2 changed files with 13 additions and 4 deletions

View File

@ -56,6 +56,8 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
*/ */
TimeValue defaultRefreshInterval(); TimeValue defaultRefreshInterval();
void enableGcDeletes(boolean enableGcDeletes);
void updateIndexingBufferSize(ByteSizeValue indexingBufferSize); void updateIndexingBufferSize(ByteSizeValue indexingBufferSize);
void addFailedEngineListener(FailedEngineListener listener); void addFailedEngineListener(FailedEngineListener listener);

View File

@ -92,6 +92,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
private long gcDeletesInMillis; private long gcDeletesInMillis;
private volatile boolean enableGcDeletes = true;
private final ThreadPool threadPool; private final ThreadPool threadPool;
private final IndexSettingsService indexSettingsService; private final IndexSettingsService indexSettingsService;
@ -286,6 +288,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
return new TimeValue(1, TimeUnit.SECONDS); return new TimeValue(1, TimeUnit.SECONDS);
} }
@Override
public void enableGcDeletes(boolean enableGcDeletes) {
this.enableGcDeletes = enableGcDeletes;
}
public GetResult get(Get get) throws EngineException { public GetResult get(Get get) throws EngineException {
rwl.readLock().lock(); rwl.readLock().lock();
try { try {
@ -386,7 +393,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
if (versionValue == null) { if (versionValue == null) {
currentVersion = loadCurrentVersionFromIndex(create.uid()); currentVersion = loadCurrentVersionFromIndex(create.uid());
} else { } else {
if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) { if (enableGcDeletes && versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
currentVersion = -1; // deleted, and GC currentVersion = -1; // deleted, and GC
} else { } else {
currentVersion = versionValue.version(); currentVersion = versionValue.version();
@ -510,7 +517,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
if (versionValue == null) { if (versionValue == null) {
currentVersion = loadCurrentVersionFromIndex(index.uid()); currentVersion = loadCurrentVersionFromIndex(index.uid());
} else { } else {
if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) { if (enableGcDeletes && versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
currentVersion = -1; // deleted, and GC currentVersion = -1; // deleted, and GC
} else { } else {
currentVersion = versionValue.version(); currentVersion = versionValue.version();
@ -625,7 +632,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
if (versionValue == null) { if (versionValue == null) {
currentVersion = loadCurrentVersionFromIndex(delete.uid()); currentVersion = loadCurrentVersionFromIndex(delete.uid());
} else { } else {
if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) { if (enableGcDeletes && versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
currentVersion = -1; // deleted, and GC currentVersion = -1; // deleted, and GC
} else { } else {
currentVersion = versionValue.version(); currentVersion = versionValue.version();
@ -940,7 +947,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
continue; // its a newer value, from after/during we refreshed, don't clear it continue; // its a newer value, from after/during we refreshed, don't clear it
} }
if (versionValue.delete()) { if (versionValue.delete()) {
if ((time - versionValue.time()) > gcDeletesInMillis) { if (enableGcDeletes && (time - versionValue.time()) > gcDeletesInMillis) {
versionMap.remove(id); versionMap.remove(id);
} }
} else { } else {