Skip to content

Commit

Permalink
allow to enabled/disable gc deletes internally
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Dec 8, 2011
1 parent df9f333 commit ba29160
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
*/
TimeValue defaultRefreshInterval();

void enableGcDeletes(boolean enableGcDeletes);

void updateIndexingBufferSize(ByteSizeValue indexingBufferSize);

void addFailedEngineListener(FailedEngineListener listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {

private long gcDeletesInMillis;

private volatile boolean enableGcDeletes = true;

private final ThreadPool threadPool;

private final IndexSettingsService indexSettingsService;
Expand Down Expand Up @@ -286,6 +288,11 @@ public TimeValue defaultRefreshInterval() {
return new TimeValue(1, TimeUnit.SECONDS);
}

@Override
public void enableGcDeletes(boolean enableGcDeletes) {
this.enableGcDeletes = enableGcDeletes;
}

public GetResult get(Get get) throws EngineException {
rwl.readLock().lock();
try {
Expand Down Expand Up @@ -386,7 +393,7 @@ private void innerCreate(Create create, IndexWriter writer) throws IOException {
if (versionValue == null) {
currentVersion = loadCurrentVersionFromIndex(create.uid());
} else {
if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
if (enableGcDeletes && versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
currentVersion = -1; // deleted, and GC
} else {
currentVersion = versionValue.version();
Expand Down Expand Up @@ -510,7 +517,7 @@ private void innerIndex(Index index, IndexWriter writer) throws IOException {
if (versionValue == null) {
currentVersion = loadCurrentVersionFromIndex(index.uid());
} else {
if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
if (enableGcDeletes && versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
currentVersion = -1; // deleted, and GC
} else {
currentVersion = versionValue.version();
Expand Down Expand Up @@ -625,7 +632,7 @@ private void innerDelete(Delete delete, IndexWriter writer) throws IOException {
if (versionValue == null) {
currentVersion = loadCurrentVersionFromIndex(delete.uid());
} else {
if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
if (enableGcDeletes && versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
currentVersion = -1; // deleted, and GC
} else {
currentVersion = versionValue.version();
Expand Down Expand Up @@ -940,7 +947,7 @@ private void refreshVersioningTable(long time) {
continue; // its a newer value, from after/during we refreshed, don't clear it
}
if (versionValue.delete()) {
if ((time - versionValue.time()) > gcDeletesInMillis) {
if (enableGcDeletes && (time - versionValue.time()) > gcDeletesInMillis) {
versionMap.remove(id);
}
} else {
Expand Down

0 comments on commit ba29160

Please sign in to comment.