Class HeapMemorySegmentMetadataCache
java.lang.Object
org.apache.druid.metadata.segment.cache.HeapMemorySegmentMetadataCache
- All Implemented Interfaces:
SegmentMetadataCache
@ThreadSafe
public class HeapMemorySegmentMetadataCache
extends Object
implements SegmentMetadataCache
In-memory implementation of
SegmentMetadataCache.
Only used segments (excluding num_rows and schema_fingerprint) and pending segments are cached. Unused segments are not cached.
Non-leader Overlords also keep polling the metadata store to keep the cache up-to-date in case leadership changes.
For cache usage modes, see SegmentMetadataCache.UsageMode.
The map datasourceToSegmentCache contains the cache for each datasource.
If the cache for a datasource is empty, the sync thread removes it from the map.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.druid.metadata.segment.cache.SegmentMetadataCache
SegmentMetadataCache.Action<T>, SegmentMetadataCache.UsageMode -
Constructor Summary
ConstructorsConstructorDescriptionHeapMemorySegmentMetadataCache(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, com.google.common.base.Supplier<SegmentsMetadataManagerConfig> config, com.google.common.base.Supplier<MetadataStorageTablesConfig> tablesConfig, SegmentSchemaCache segmentSchemaCache, SQLMetadataConnector connector, ScheduledExecutorFactory executorFactory, ServiceEmitter emitter) -
Method Summary
Modifier and TypeMethodDescriptionvoidawaitNextSync(long timeoutMillis) Waits until the cache finishes the next sync with the metadata store or until the timeout elapses, whichever is sooner.voidRefreshes the cache once the service is elected leader.booleanboolean<T> TreadCacheForDataSource(String dataSource, SegmentMetadataCache.Action<T> readAction) Performs a thread-safe read action on the cache for the given datasource.voidstart()Starts the cache on service start.voidstop()Stops the cache on service stop.voidNotifies the cache that the service has lost leadership.<T> TwriteCacheForDataSource(String dataSource, SegmentMetadataCache.Action<T> writeAction) Performs a thread-safe write action on the cache for the given datasource.
-
Constructor Details
-
HeapMemorySegmentMetadataCache
@Inject public HeapMemorySegmentMetadataCache(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, com.google.common.base.Supplier<SegmentsMetadataManagerConfig> config, com.google.common.base.Supplier<MetadataStorageTablesConfig> tablesConfig, SegmentSchemaCache segmentSchemaCache, SQLMetadataConnector connector, ScheduledExecutorFactory executorFactory, ServiceEmitter emitter)
-
-
Method Details
-
start
public void start()Description copied from interface:SegmentMetadataCacheStarts the cache on service start.- Specified by:
startin interfaceSegmentMetadataCache
-
stop
public void stop()Description copied from interface:SegmentMetadataCacheStops the cache on service stop.- Specified by:
stopin interfaceSegmentMetadataCache
-
becomeLeader
public void becomeLeader()Description copied from interface:SegmentMetadataCacheRefreshes the cache once the service is elected leader.- Specified by:
becomeLeaderin interfaceSegmentMetadataCache
-
stopBeingLeader
public void stopBeingLeader()Description copied from interface:SegmentMetadataCacheNotifies the cache that the service has lost leadership.- Specified by:
stopBeingLeaderin interfaceSegmentMetadataCache
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabledin interfaceSegmentMetadataCache- Returns:
- true if the cache is enabled
-
isSyncedForRead
public boolean isSyncedForRead()- Specified by:
isSyncedForReadin interfaceSegmentMetadataCache- Returns:
- true if the cache is enabled and synced with the metadata store. Reads can be done from the cache only if it is synced but writes can happen even before the sync has finished.
-
getDataSourcesSnapshot
- Specified by:
getDataSourcesSnapshotin interfaceSegmentMetadataCache- Returns:
- Latest snapshot of the datasources with all their used segments.
-
awaitNextSync
public void awaitNextSync(long timeoutMillis) Description copied from interface:SegmentMetadataCacheWaits until the cache finishes the next sync with the metadata store or until the timeout elapses, whichever is sooner.- Specified by:
awaitNextSyncin interfaceSegmentMetadataCache
-
readCacheForDataSource
Description copied from interface:SegmentMetadataCachePerforms a thread-safe read action on the cache for the given datasource. Read actions can be concurrent with other reads but are mutually exclusive from other write actions on the same datasource.- Specified by:
readCacheForDataSourcein interfaceSegmentMetadataCache
-
writeCacheForDataSource
Description copied from interface:SegmentMetadataCachePerforms a thread-safe write action on the cache for the given datasource. Write actions are mutually exclusive from other writes or reads on the same datasource.- Specified by:
writeCacheForDataSourcein interfaceSegmentMetadataCache
-