Skip to content

Commit

Permalink
Track searchable snapshot usage (elastic#77597)
Browse files Browse the repository at this point in the history
This commit adds usage tracking to searchable snapshots. It works by
inspecting all indices metadata in cluster state every 15 minutes to see
if any searchable snapshot stores exist, and if any do, then triggering
feature usage tracking on the license state.
  • Loading branch information
rjernst authored Sep 15, 2021
1 parent 6243c72 commit b71af8e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ public Collection<Object> createComponents(
} else {
PersistentCache.cleanUp(settings, nodeEnvironment);
}

if (DiscoveryNode.isMasterNode(environment.settings())) {
// Tracking usage of searchable snapshots is too costly to do on each individually mounted snapshot.
// Instead, we periodically look through the indices and identify if any are searchable snapshots,
// then marking the feature as used. We do this on each master node so that if one master fails, the
// continue reporting usage state.
var usageTracker = new SearchableSnapshotsUsageTracker(getLicenseState(), clusterService::state);
threadPool.scheduleWithFixedDelay(usageTracker, TimeValue.timeValueMinutes(15), ThreadPool.Names.GENERIC);
}

this.allocator.set(new SearchableSnapshotAllocator(client, clusterService.getRerouteService(), frozenCacheInfoService));
components.add(new FrozenCacheServiceSupplier(frozenCacheService.get()));
components.add(new CacheServiceSupplier(cacheService.get()));
Expand Down Expand Up @@ -748,4 +758,5 @@ public void clusterChanged(ClusterChangedEvent event) {
assert knownUuids.equals(newUuids) : knownUuids + " vs " + newUuids;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.searchablesnapshots;

import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;

import java.util.function.Supplier;

import static org.elasticsearch.xpack.core.searchablesnapshots.SearchableSnapshotsConstants.SEARCHABLE_SNAPSHOT_FEATURE;

final class SearchableSnapshotsUsageTracker implements Runnable {

private final XPackLicenseState licenseState;
private final Supplier<ClusterState> clusterStateSupplier;

SearchableSnapshotsUsageTracker(XPackLicenseState licenseState, Supplier<ClusterState> clusterStateSupplier) {
this.clusterStateSupplier = clusterStateSupplier;
this.licenseState = licenseState;
}

@Override
public void run() {
if (hasSearchableSnapshotsIndices(clusterStateSupplier.get())) {
SEARCHABLE_SNAPSHOT_FEATURE.check(licenseState);
}
}

private static boolean hasSearchableSnapshotsIndices(ClusterState state) {
for (IndexMetadata indexMetadata : state.metadata()) {
if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings())) {
return true;
}
}
return false;
}
}

0 comments on commit b71af8e

Please sign in to comment.