Skip to content

Commit

Permalink
Do not run SetIndexReadOnlyAndCalculateRangeJob if index is closed (#…
Browse files Browse the repository at this point in the history
…3931)

Also add that check to other jobs that could fail if an index is already
closed.

Fixes #3909
  • Loading branch information
bernd authored and joschi committed Jun 27, 2017
1 parent 6d98f00 commit 2ee401b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Expand Up @@ -62,6 +62,11 @@ public SetIndexReadOnlyJob(Indices indices,

@Override
public void execute() {
if (indices.isClosed(index)) {
log.debug("Not running job for closed index <{}>", index);
return;
}

final Optional<IndexSet> indexSet = indexSetRegistry.getForIndex(index);

if (!indexSet.isPresent()) {
Expand Down
Expand Up @@ -515,6 +515,10 @@ public Set<String> getClosedIndices(final IndexSet indexSet) {
return getClosedIndices(Collections.singleton(indexSet.getIndexWildcard()));
}

public boolean isClosed(final String indexName) {
return getClosedIndices(Collections.singleton(indexName)).contains(indexName);
}

/**
* Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices</a> request from Elasticsearch.
*
Expand Down
Expand Up @@ -59,6 +59,11 @@ public OptimizeIndexJob(Indices indices,

@Override
public void execute() {
if (indices.isClosed(index)) {
LOG.debug("Not running job for closed index <{}>", index);
return;
}

String msg = "Optimizing index <" + index + ">.";
activityWriter.write(new Activity(msg, OptimizeIndexJob.class));
LOG.info(msg);
Expand Down
Expand Up @@ -19,34 +19,46 @@
import com.google.inject.assistedinject.Assisted;
import org.graylog2.indexer.IndexSetRegistry;
import org.graylog2.indexer.SetIndexReadOnlyJob;
import org.graylog2.indexer.indices.Indices;
import org.graylog2.indexer.ranges.CreateNewSingleIndexRangeJob;
import org.graylog2.system.jobs.SystemJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;

public class SetIndexReadOnlyAndCalculateRangeJob extends SystemJob {
private static final Logger LOG = LoggerFactory.getLogger(SetIndexReadOnlyAndCalculateRangeJob.class);

public interface Factory {
SetIndexReadOnlyAndCalculateRangeJob create(String indexName);
}

private final SetIndexReadOnlyJob.Factory setIndexReadOnlyJobFactory;
private final CreateNewSingleIndexRangeJob.Factory createNewSingleIndexRangeJobFactory;
private final IndexSetRegistry indexSetRegistry;
private final Indices indices;
private final String indexName;

@Inject
public SetIndexReadOnlyAndCalculateRangeJob(SetIndexReadOnlyJob.Factory setIndexReadOnlyJobFactory,
CreateNewSingleIndexRangeJob.Factory createNewSingleIndexRangeJobFactory,
IndexSetRegistry indexSetRegistry,
Indices indices,
@Assisted String indexName) {
this.setIndexReadOnlyJobFactory = setIndexReadOnlyJobFactory;
this.createNewSingleIndexRangeJobFactory = createNewSingleIndexRangeJobFactory;
this.indexSetRegistry = indexSetRegistry;
this.indices = indices;
this.indexName = indexName;
}

@Override
public void execute() {
if (indices.isClosed(indexName)) {
LOG.debug("Not running job for closed index <{}>", indexName);
return;
}
final SystemJob setIndexReadOnlyJob = setIndexReadOnlyJobFactory.create(indexName);
setIndexReadOnlyJob.execute();
final SystemJob createNewSingleIndexRangeJob = createNewSingleIndexRangeJobFactory.create(indexSetRegistry.getAll(), indexName);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import org.graylog2.indexer.IndexSet;
import org.graylog2.indexer.indices.Indices;
import org.graylog2.shared.system.activities.ActivityWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,6 +31,7 @@
public class CreateNewSingleIndexRangeJob extends RebuildIndexRangesJob {
private static final Logger LOG = LoggerFactory.getLogger(CreateNewSingleIndexRangeJob.class);
private final String indexName;
private final Indices indices;

public interface Factory {
CreateNewSingleIndexRangeJob create(Set<IndexSet> indexSets, String indexName);
Expand All @@ -39,9 +41,11 @@ public interface Factory {
public CreateNewSingleIndexRangeJob(@Assisted Set<IndexSet> indexSets,
@Assisted String indexName,
ActivityWriter activityWriter,
Indices indices,
IndexRangeService indexRangeService) {
super(indexSets, activityWriter, indexRangeService);
this.indexName = checkNotNull(indexName);
this.indices = indices;
}

@Override
Expand All @@ -56,6 +60,10 @@ public String getInfo() {

@Override
public void execute() {
if (indices.isClosed(indexName)) {
LOG.debug("Not running job for closed index <{}>", indexName);
return;
}
LOG.info("Calculating ranges for index {}.", indexName);
try {
final IndexRange indexRange = indexRangeService.calculateRange(indexName);
Expand Down

0 comments on commit 2ee401b

Please sign in to comment.