Skip to content

Commit

Permalink
* Only return deflector indices in Deflector#getAllDeflectorIndices()…
Browse files Browse the repository at this point in the history
…Unbreaks count based index retention (again).Also rename #getAllDeflectorIndexNames() to #getAllGraylogIndexNames() forclarity.

* Only return deflector indices in Deflector#getAllGraylogDeflectorIndices(): Unbreaks count based index retention (again).
* Rename #getAllDeflectorIndexNames() to #getAllGraylogIndexNames() for clarity.
  • Loading branch information
bernd authored and joschi committed Apr 18, 2016
1 parent 3a1fcc0 commit 7d2c0ca
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 14 deletions.
16 changes: 13 additions & 3 deletions graylog2-server/src/main/java/org/graylog2/indexer/Deflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ public int getNewestTargetNumber() throws NoTargetIndexException {
return Collections.max(indexNumbers);
}

public String[] getAllDeflectorIndexNames() {
/**
* Returns a list of all Graylog managed indices.
*
* @return list of managed indices
*/
public String[] getAllGraylogIndexNames() {
final Map<String, IndexStats> indices = this.indices.getAll();
final List<String> result = Lists.newArrayListWithExpectedSize(indices.size());
for (String indexName : indices.keySet()) {
Expand All @@ -219,12 +224,17 @@ public String[] getAllDeflectorIndexNames() {
return result.toArray(new String[result.size()]);
}

public Map<String, IndexStats> getAllDeflectorIndices() {
/**
* Returns all Graylog deflector indices.
*
* @return index name and index stats
*/
public Map<String, IndexStats> getAllGraylogDeflectorIndices() {
final ImmutableMap.Builder<String, IndexStats> result = ImmutableMap.builder();
for (Map.Entry<String, IndexStats> e : indices.getAll().entrySet()) {
final String name = e.getKey();

if (isGraylogIndex(name)) {
if (isGraylogDeflectorIndex(name)) {
result.put(name, e.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Counts(Client client, Deflector deflector) {
}

public long total() {
final SearchRequest request = c.prepareSearch(deflector.getAllDeflectorIndexNames())
final SearchRequest request = c.prepareSearch(deflector.getAllGraylogIndexNames())
.setSize(0)
.request();
return c.search(request).actionGet().getHits().totalHits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public SortedSet<IndexRange> find(DateTime begin, DateTime end) {
@Override
public SortedSet<IndexRange> findAll() {
final ImmutableSortedSet.Builder<IndexRange> indexRanges = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR);
for (String index : deflector.getAllDeflectorIndexNames()) {
for (String index : deflector.getAllGraylogIndexNames()) {
try {
indexRanges.add(cache.get(index));
} catch (ExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public String getDescription() {
public void execute() {
info("Re-calculating index ranges.");

String[] indices = deflector.getAllDeflectorIndexNames();
String[] indices = deflector.getAllGraylogIndexNames();
if (indices == null || indices.length == 0) {
info("No indices, nothing to calculate.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AbstractIndexCountBasedRetentionStrategy(Deflector deflector, Indices ind

@Override
public void retain() {
final Map<String, IndexStats> deflectorIndices = deflector.getAllDeflectorIndices();
final Map<String, IndexStats> deflectorIndices = deflector.getAllGraylogDeflectorIndices();
final int indexCount = deflectorIndices.size();
final Optional<Integer> maxIndices = getMaxNumberOfIndices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void doRun() {
return;
}

final Set<String> indexNames = ImmutableSet.copyOf(deflector.getAllDeflectorIndexNames());
final Set<String> indexNames = ImmutableSet.copyOf(deflector.getAllGraylogIndexNames());
final SortedSet<IndexRange> indexRanges = indexRangeService.findAll();

final Set<String> removedIndices = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Uninterruptibles;
import org.graylog2.indexer.Deflector;
import org.graylog2.indexer.cluster.Cluster;
Expand Down Expand Up @@ -89,7 +87,7 @@ public void doRun() {
Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
}

final Set<String> indexNames = ImmutableSet.copyOf(deflector.getAllDeflectorIndexNames());
final Set<String> indexNames = ImmutableSet.copyOf(deflector.getAllGraylogIndexNames());

// Migrate old MongoDB index ranges
final SortedSet<IndexRange> mongoIndexRanges = legacyMongoIndexRangeService.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public void testBuildDeflectorNameWithCustomIndexPrefix() {

@Test
public void nullIndexerDoesNotThrow() {
final Map<String, IndexStats> deflectorIndices = deflector.getAllDeflectorIndices();
final Map<String, IndexStats> deflectorIndices = deflector.getAllGraylogDeflectorIndices();
assertNotNull(deflectorIndices);
assertEquals(0, deflectorIndices.size());
}

@Test
public void nullIndexerDoesNotThrowOnIndexName() {
final String[] deflectorIndices = deflector.getAllDeflectorIndexNames();
final String[] deflectorIndices = deflector.getAllGraylogIndexNames();
assertNotNull(deflectorIndices);
assertEquals(0, deflectorIndices.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void setUp() throws Exception {
.get();
assumeTrue(clusterHealthResponse.getStatus() == ClusterHealthStatus.GREEN);

when(deflector.getAllDeflectorIndexNames()).thenReturn(new String[]{INDEX_NAME});
when(deflector.getAllGraylogIndexNames()).thenReturn(new String[]{INDEX_NAME});

counts = new Counts(client, deflector);
}
Expand Down

0 comments on commit 7d2c0ca

Please sign in to comment.