Search in sources :

Example 1 with CreateNewSingleIndexRangeJob

use of org.graylog2.indexer.ranges.CreateNewSingleIndexRangeJob in project graylog2-server by Graylog2.

the class SetIndexReadOnlyAndCalculateRangeJob method execute.

@Override
public void execute() {
    final SystemJob setIndexReadOnlyJob = setIndexReadOnlyJobFactory.create(indexName);
    setIndexReadOnlyJob.execute();
    final SystemJob createNewSingleIndexRangeJob = createNewSingleIndexRangeJobFactory.create(indexSetRegistry.getAll(), indexName);
    createNewSingleIndexRangeJob.execute();
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob)

Example 2 with CreateNewSingleIndexRangeJob

use of org.graylog2.indexer.ranges.CreateNewSingleIndexRangeJob 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();
    }
}
Also used : CreateNewSingleIndexRangeJob(org.graylog2.indexer.ranges.CreateNewSingleIndexRangeJob) IndexRangeService(org.graylog2.indexer.ranges.IndexRangeService) Logger(org.slf4j.Logger) Cluster(org.graylog2.indexer.cluster.Cluster) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) TimeoutException(java.util.concurrent.TimeoutException) DBQuery(org.mongojack.DBQuery) Collectors(java.util.stream.Collectors) IndexRange(org.graylog2.indexer.ranges.IndexRange) Inject(javax.inject.Inject) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) IndexSet(org.graylog2.indexer.IndexSet) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) CreateNewSingleIndexRangeJob(org.graylog2.indexer.ranges.CreateNewSingleIndexRangeJob) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) IndexSet(org.graylog2.indexer.IndexSet) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 IndexSet (org.graylog2.indexer.IndexSet)1 IndexSetRegistry (org.graylog2.indexer.IndexSetRegistry)1 MongoIndexSet (org.graylog2.indexer.MongoIndexSet)1 Cluster (org.graylog2.indexer.cluster.Cluster)1 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)1 IndexSetService (org.graylog2.indexer.indexset.IndexSetService)1 TooManyAliasesException (org.graylog2.indexer.indices.TooManyAliasesException)1 CreateNewSingleIndexRangeJob (org.graylog2.indexer.ranges.CreateNewSingleIndexRangeJob)1 IndexRange (org.graylog2.indexer.ranges.IndexRange)1 IndexRangeService (org.graylog2.indexer.ranges.IndexRangeService)1 SystemJob (org.graylog2.system.jobs.SystemJob)1 DBQuery (org.mongojack.DBQuery)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1