Class IndexingStateCache

java.lang.Object
org.apache.druid.segment.metadata.IndexingStateCache
Direct Known Subclasses:
NoopIndexingStateCache

public class IndexingStateCache extends Object
In-memory cache of indexing states used by HeapMemorySegmentMetadataCache.

This cache stores indexing states for published segments polled from the metadata store. It is the primary way to read indexing states in production.

The cache is populated during segment metadata cache sync operations and provides fast lookups without hitting the database.

  • Constructor Details

    • IndexingStateCache

      public IndexingStateCache()
  • Method Details

    • isEnabled

      public boolean isEnabled()
    • resetIndexingStatesForPublishedSegments

      public void resetIndexingStatesForPublishedSegments(Map<String,CompactionState> fingerprintToStateMap)
      Resets the cache with indexing states polled from the metadata store. Called after each successful poll in HeapMemorySegmentMetadataCache.
      Parameters:
      fingerprintToStateMap - Complete fp:state map of all active indexing state fingerprints
    • getIndexingStateByFingerprint

      public Optional<CompactionState> getIndexingStateByFingerprint(String fingerprint)
      Retrieves an indexing state by its fingerprint. This is the indexing method for reading indexing states.
      Parameters:
      fingerprint - The fingerprint to look up
      Returns:
      The cached indexing state, or Optional.empty() if not cached
    • addIndexingState

      public void addIndexingState(String fingerprint, CompactionState state)
      Adds or updates a single indexing state in the cache.

      This is called when a new indexing state is persisted to the database via upsertIndexingState to ensure the cache is immediately consistent without waiting for the next sync.

      This method checks if the state is already cached before performing the atomic update.

      Parameters:
      fingerprint - The fingerprint key
      state - The indexing state to cache
    • getPublishedIndexingStateMap

      public Map<String,CompactionState> getPublishedIndexingStateMap()
      Gets the full cached map (immutable copy). Used by HeapMemorySegmentMetadataCache for delta sync calculations.
    • clear

      public void clear()
      Clears the cache. Called when node stops being leader.
    • getAndResetStats

      public Map<String,Integer> getAndResetStats()
      Returns:
      Summary stats for metric emission