use of org.graylog2.indexer.indices.TooManyAliasesException in project graylog2-server by Graylog2.
the class V20161130141500_DefaultStreamRecalcIndexRanges method upgrade.
@Override
public void upgrade() {
IndexSet indexSet;
try {
indexSet = indexSetRegistry.getDefault();
} catch (IllegalStateException e) {
// Try to find the default index set manually if the index set registry cannot find it.
// This is needed if you run this migration with a 2.2.0-beta.2 state before commit 460cac6af.
final IndexSetConfig indexSetConfig = indexSetService.findOne(DBQuery.is("default", true)).orElseThrow(() -> new IllegalStateException("No default index set configured! This is a bug!"));
indexSet = indexSetFactory.create(indexSetConfig);
}
final IndexSet defaultIndexSet = indexSet;
if (!cluster.isConnected()) {
LOG.info("Cluster not connected yet, delaying migration until it is reachable.");
while (true) {
try {
cluster.waitForConnectedAndDeflectorHealthy();
break;
} catch (InterruptedException | TimeoutException e) {
LOG.warn("Interrupted or timed out waiting for Elasticsearch cluster, checking again.");
}
}
}
final Set<String> indexRangesWithoutStreams = indexRangeService.findAll().stream().filter(indexRange -> defaultIndexSet.isManagedIndex(indexRange.indexName())).filter(indexRange -> indexRange.streamIds() == null).map(IndexRange::indexName).collect(Collectors.toSet());
if (indexRangesWithoutStreams.size() == 0) {
// all ranges have a stream list, even if it is empty, nothing more to do
return;
}
final String currentWriteTarget;
try {
currentWriteTarget = defaultIndexSet.getActiveWriteIndex();
} catch (TooManyAliasesException e) {
LOG.error("Multiple write targets found for write alias. Cannot continue to assign streams to older indices", e);
return;
}
for (String indexName : defaultIndexSet.getManagedIndices()) {
if (indexName.equals(currentWriteTarget)) {
// do not recalculate for current write target
continue;
}
if (!indexRangesWithoutStreams.contains(indexName)) {
// already computed streams for this index
continue;
}
LOG.info("Recalculating streams in index {}", indexName);
final CreateNewSingleIndexRangeJob createNewSingleIndexRangeJob = rebuildIndexRangeJobFactory.create(indexSetRegistry.getAll(), indexName);
createNewSingleIndexRangeJob.execute();
}
}
use of org.graylog2.indexer.indices.TooManyAliasesException in project graylog2-server by Graylog2.
the class IndexFieldTypePollerPeriodical method poll.
private void poll(IndexSetConfig indexSetConfig) {
final String indexSetTitle = indexSetConfig.title();
final String indexSetId = indexSetConfig.id();
scheduler.submit(() -> {
try {
final MongoIndexSet indexSet = mongoIndexSetFactory.create(indexSetConfig);
// Only check the active write index on a regular basis, the others don't change anymore
final String activeWriteIndex = indexSet.getActiveWriteIndex();
if (activeWriteIndex != null) {
LOG.debug("Updating index field types for active write index <{}> in index set <{}/{}>", activeWriteIndex, indexSetTitle, indexSetId);
poller.pollIndex(activeWriteIndex, indexSetId).ifPresent(dbService::upsert);
} else {
LOG.warn("Active write index for index set \"{}\" ({}) doesn't exist yet", indexSetTitle, indexSetId);
}
} catch (TooManyAliasesException e) {
LOG.error("Couldn't get active write index", e);
} catch (Exception e) {
LOG.error("Couldn't update field types for index set <{}/{}>", indexSetTitle, indexSetId, e);
} finally {
lastPoll.put(indexSetId, Instant.now());
}
});
}
use of org.graylog2.indexer.indices.TooManyAliasesException in project graylog2-server by Graylog2.
the class RebuildIndexRangesJob method execute.
@Override
public void execute() {
info("Recalculating index ranges.");
// for each index set we know about
final ListMultimap<IndexSet, String> indexSets = MultimapBuilder.hashKeys().arrayListValues().build();
for (IndexSet indexSet : this.indexSets) {
final String[] managedIndicesNames = indexSet.getManagedIndices();
for (String name : managedIndicesNames) {
indexSets.put(indexSet, name);
}
}
if (indexSets.size() == 0) {
info("No indices, nothing to calculate.");
return;
}
indicesToCalculate = indexSets.values().size();
Stopwatch sw = Stopwatch.createStarted();
for (IndexSet indexSet : indexSets.keySet()) {
LOG.info("Recalculating index ranges for index set {} ({}): {} indices affected.", indexSet.getConfig().title(), indexSet.getIndexWildcard(), indexSets.get(indexSet).size());
for (String index : indexSets.get(indexSet)) {
try {
if (index.equals(indexSet.getActiveWriteIndex())) {
LOG.debug("{} is current write target, do not calculate index range for it", index);
final IndexRange emptyRange = indexRangeService.createUnknownRange(index);
try {
final IndexRange indexRange = indexRangeService.get(index);
if (indexRange.begin().getMillis() != 0 || indexRange.end().getMillis() != 0) {
LOG.info("Invalid date ranges for write index {}, resetting it.", index);
indexRangeService.save(emptyRange);
}
} catch (NotFoundException e) {
LOG.info("No index range found for write index {}, recreating it.", index);
indexRangeService.save(emptyRange);
}
indicesCalculated.incrementAndGet();
continue;
}
} catch (TooManyAliasesException e) {
LOG.error("Multiple write alias targets found, this is a bug.");
indicesCalculated.incrementAndGet();
continue;
}
if (cancelRequested) {
info("Stop requested. Not calculating next index range, not updating ranges.");
sw.stop();
return;
}
try {
final IndexRange indexRange = indexRangeService.calculateRange(index);
indexRangeService.save(indexRange);
LOG.info("Created ranges for index {}: {}", index, indexRange);
} catch (Exception e) {
LOG.info("Could not calculate range of index [" + index + "]. Skipping.", e);
} finally {
indicesCalculated.incrementAndGet();
}
}
}
info("Done calculating index ranges for " + indicesToCalculate + " indices. Took " + sw.stop().elapsed(TimeUnit.MILLISECONDS) + "ms.");
}
use of org.graylog2.indexer.indices.TooManyAliasesException in project graylog2-server by Graylog2.
the class IndexRotationThread method checkAndRepair.
protected void checkAndRepair(IndexSet indexSet) {
if (!indexSet.isUp()) {
if (indices.exists(indexSet.getWriteIndexAlias())) {
// Publish a notification if there is an *index* called graylog2_deflector
Notification notification = notificationService.buildNow().addType(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX).addSeverity(Notification.Severity.URGENT);
final boolean published = notificationService.publishIfFirst(notification);
if (published) {
LOG.warn("There is an index called [" + indexSet.getWriteIndexAlias() + "]. Cannot fix this automatically and published a notification.");
}
} else {
indexSet.setUp();
}
} else {
try {
String currentTarget;
try {
currentTarget = indexSet.getActiveWriteIndex();
} catch (TooManyAliasesException e) {
// If we get this exception, there are multiple indices which have the deflector alias set.
// We try to cleanup the alias and try again. This should not happen, but might under certain
// circumstances.
indexSet.cleanupAliases(e.getIndices());
try {
currentTarget = indexSet.getActiveWriteIndex();
} catch (TooManyAliasesException e1) {
throw new IllegalStateException(e1);
}
}
String shouldBeTarget = indexSet.getNewestIndex();
if (!shouldBeTarget.equals(currentTarget)) {
String msg = "Deflector is pointing to [" + currentTarget + "], not the newest one: [" + shouldBeTarget + "]. Re-pointing.";
LOG.warn(msg);
activityWriter.write(new Activity(msg, IndexRotationThread.class));
if (indices.waitForRecovery(shouldBeTarget) == HealthStatus.Red) {
LOG.error("New target index for deflector didn't get healthy within timeout. Skipping deflector update.");
} else {
indexSet.pointTo(shouldBeTarget, currentTarget);
}
}
} catch (NoTargetIndexException e) {
LOG.warn("Deflector is not up. Not trying to point to another index.");
}
}
}
use of org.graylog2.indexer.indices.TooManyAliasesException in project graylog2-server by Graylog2.
the class IndexerOverviewResource method getIndexerOverview.
private IndexerOverview getIndexerOverview(IndexSet indexSet) throws TooManyAliasesException {
final String indexSetId = indexSet.getConfig().id();
final DeflectorSummary deflectorSummary = deflectorResource.deflector(indexSetId);
final List<IndexRangeSummary> indexRanges = indexRangesResource.list().ranges();
final JsonNode indexStats = indices.getIndexStats(indexSet);
final List<String> indexNames = new ArrayList<>();
indexStats.fieldNames().forEachRemaining(indexNames::add);
final Map<String, Boolean> areReopened = indices.areReopened(indexNames);
final Map<String, IndexSummary> indicesSummaries = buildIndexSummaries(deflectorSummary, indexSet, indexRanges, indexStats, areReopened);
return IndexerOverview.create(deflectorSummary, IndexerClusterOverview.create(indexerClusterResource.clusterHealth(), indexerClusterResource.clusterName().name()), MessageCountResponse.create(counts.total(indexSet)), indicesSummaries);
}
Aggregations