Search in sources :

Example 1 with HealthStatus

use of org.graylog2.indexer.indices.HealthStatus in project graylog2-server by Graylog2.

the class MongoIndexSet method cycle.

@Override
public void cycle() {
    if (!getConfig().isWritable()) {
        LOG.debug("Not cycling non-writable index set <{}> ({})", getConfig().id(), getConfig().title());
        return;
    }
    int oldTargetNumber;
    try {
        oldTargetNumber = getNewestIndexNumber();
    } catch (NoTargetIndexException ex) {
        oldTargetNumber = -1;
    }
    final int newTargetNumber = oldTargetNumber + 1;
    final String newTarget = buildIndexName(newTargetNumber);
    final String oldTarget = buildIndexName(oldTargetNumber);
    if (oldTargetNumber == -1) {
        LOG.info("Cycling from <none> to <{}>.", newTarget);
    } else {
        LOG.info("Cycling from <{}> to <{}>.", oldTarget, newTarget);
    }
    // Create new index.
    LOG.info("Creating target index <{}>.", newTarget);
    if (!indices.create(newTarget, this)) {
        throw new RuntimeException("Could not create new target index <" + newTarget + ">.");
    }
    LOG.info("Waiting for allocation of index <{}>.", newTarget);
    final HealthStatus healthStatus = indices.waitForRecovery(newTarget);
    checkIfHealthy(healthStatus, (status) -> new RuntimeException("New target index did not become healthy (target index: <" + newTarget + ">)"));
    LOG.debug("Health status of index <{}>: {}", newTarget, healthStatus);
    addDeflectorIndexRange(newTarget);
    LOG.info("Index <{}> has been successfully allocated.", newTarget);
    // Point deflector to new index.
    final String indexAlias = getWriteIndexAlias();
    LOG.info("Pointing index alias <{}> to new index <{}>.", indexAlias, newTarget);
    final Activity activity = new Activity(IndexSet.class);
    if (oldTargetNumber == -1) {
        // Only pointing, not cycling.
        pointTo(newTarget);
        activity.setMessage("Cycled index alias <" + indexAlias + "> from <none> to <" + newTarget + ">.");
    } else {
        // Re-pointing from existing old index to the new one.
        LOG.debug("Switching over index alias <{}>.", indexAlias);
        pointTo(newTarget, oldTarget);
        setIndexReadOnlyAndCalculateRange(oldTarget);
        activity.setMessage("Cycled index alias <" + indexAlias + "> from <" + oldTarget + "> to <" + newTarget + ">.");
    }
    LOG.info("Successfully pointed index alias <{}> to index <{}>.", indexAlias, newTarget);
    activityWriter.write(activity);
    auditEventSender.success(AuditActor.system(nodeId), ES_WRITE_INDEX_UPDATE, ImmutableMap.of("indexName", newTarget));
}
Also used : HealthStatus(org.graylog2.indexer.indices.HealthStatus) Activity(org.graylog2.shared.system.activities.Activity)

Example 2 with HealthStatus

use of org.graylog2.indexer.indices.HealthStatus in project graylog2-server by Graylog2.

the class Cluster method elasticsearchStats.

public ElasticsearchStats elasticsearchStats() {
    final List<String> indices = Arrays.asList(indexSetRegistry.getIndexWildcards());
    final org.graylog2.system.stats.elasticsearch.ClusterStats clusterStats = clusterAdapter.clusterStats();
    final PendingTasksStats pendingTasksStats = clusterAdapter.pendingTasks();
    final ShardStats shardStats = clusterAdapter.shardStats(indices);
    final org.graylog2.system.stats.elasticsearch.ClusterHealth clusterHealth = org.graylog2.system.stats.elasticsearch.ClusterHealth.from(shardStats, pendingTasksStats);
    final HealthStatus healthStatus = clusterAdapter.health(indices).orElseThrow(() -> new IllegalStateException("Unable to retrieve cluster health."));
    return ElasticsearchStats.create(clusterStats.clusterName(), clusterStats.clusterVersion(), healthStatus, clusterHealth, clusterStats.nodesStats(), clusterStats.indicesStats());
}
Also used : ShardStats(org.graylog2.system.stats.elasticsearch.ShardStats) HealthStatus(org.graylog2.indexer.indices.HealthStatus)

Aggregations

HealthStatus (org.graylog2.indexer.indices.HealthStatus)2 Activity (org.graylog2.shared.system.activities.Activity)1 ShardStats (org.graylog2.system.stats.elasticsearch.ShardStats)1