Class SqlIndexingStateStorage
- All Implemented Interfaces:
IndexingStateStorage
IndexingStateStorage.
Manages the persistence and retrieval of CompactionState (AKA IndexingState) objects in the metadata storage.
Indexing states are uniquely identified by their fingerprints, which are SHA-256 hashes of their content.
This implementation is designed to be called from a single thread and relies on database constraints and the retry mechanism to handle any conflicts. Operations are idempotent - concurrent upserts for the same fingerprint will either succeed or fail with a constraint violation that is safely ignored.
-
Constructor Summary
ConstructorsConstructorDescriptionSqlIndexingStateStorage(MetadataStorageTablesConfig dbTables, com.fasterxml.jackson.databind.ObjectMapper jsonMapper, SQLMetadataConnector connector) -
Method Summary
Modifier and TypeMethodDescriptionintdeletePendingIndexingStatesOlderThan(long timestamp) Deletes pending indexing states older than the given timestamp.intdeleteUnusedIndexingStatesOlderThan(long timestamp) Deletes unused indexing states older than the given timestamp.Finds all indexing state fingerprints which have been marked as unused but are still referenced by some used segments.isIndexingStatePending(String fingerprint) Checks if the indexing state for the given fingerprint is pending.intmarkIndexingStatesAsActive(List<String> stateFingerprints) Marks indexing states as activeintmarkIndexingStatesAsUsed(List<String> stateFingerprints) Marks indexing states as used.intMarks indexing states as unused if they are not referenced by any used segments.voidupsertIndexingState(@NotEmpty String dataSource, @NotEmpty String fingerprint, CompactionState indexingState, org.joda.time.DateTime updateTime) Upserts an indexing state to storage.
-
Constructor Details
-
SqlIndexingStateStorage
@Inject public SqlIndexingStateStorage(MetadataStorageTablesConfig dbTables, com.fasterxml.jackson.databind.ObjectMapper jsonMapper, SQLMetadataConnector connector)
-
-
Method Details
-
upsertIndexingState
public void upsertIndexingState(@NotEmpty @NotEmpty String dataSource, @NotEmpty @NotEmpty String fingerprint, @Nonnull CompactionState indexingState, @Nonnull org.joda.time.DateTime updateTime) Description copied from interface:IndexingStateStorageUpserts an indexing state to storage.If a fingerprint already exists, update to reflect proper used state and timestamp. If a fingerprint doesn't exist, inserts a new row with the full state payload.
- Specified by:
upsertIndexingStatein interfaceIndexingStateStorage- Parameters:
dataSource- The datasource namefingerprint- The fingerprint of the indexing stateindexingState- The indexing state to upsertupdateTime- The timestamp for this update
-
markUnreferencedIndexingStatesAsUnused
public int markUnreferencedIndexingStatesAsUnused()Description copied from interface:IndexingStateStorageMarks indexing states as unused if they are not referenced by any used segments.This is used for cleanup operations.
- Specified by:
markUnreferencedIndexingStatesAsUnusedin interfaceIndexingStateStorage- Returns:
- Number of rows updated, or 0 if not applicable
-
findReferencedIndexingStateMarkedAsUnused
Description copied from interface:IndexingStateStorageFinds all indexing state fingerprints which have been marked as unused but are still referenced by some used segments. This is used for validation/reconciliation. Implementations may return an empty list if not applicable.- Specified by:
findReferencedIndexingStateMarkedAsUnusedin interfaceIndexingStateStorage- Returns:
- List of fingerprints, or empty list
-
markIndexingStatesAsUsed
Description copied from interface:IndexingStateStorageMarks indexing states as used.This is used for reconciliation operations to avoid deleting states that are still in use.
- Specified by:
markIndexingStatesAsUsedin interfaceIndexingStateStorage- Parameters:
stateFingerprints- List of fingerprints to mark as used- Returns:
- Number of rows updated, or 0 if not applicable
-
markIndexingStatesAsActive
Description copied from interface:IndexingStateStorageMarks indexing states as active- Specified by:
markIndexingStatesAsActivein interfaceIndexingStateStorage- Parameters:
stateFingerprints- List of fingerprints to mark as active- Returns:
- Number of rows updated, or 0 if not applicable
-
deleteUnusedIndexingStatesOlderThan
public int deleteUnusedIndexingStatesOlderThan(long timestamp) Description copied from interface:IndexingStateStorageDeletes unused indexing states older than the given timestamp.This is used for cleanup operations.
- Specified by:
deleteUnusedIndexingStatesOlderThanin interfaceIndexingStateStorage- Parameters:
timestamp- The cutoff timestamp in milliseconds- Returns:
- Number of rows deleted, or 0 if not applicable
-
deletePendingIndexingStatesOlderThan
public int deletePendingIndexingStatesOlderThan(long timestamp) Description copied from interface:IndexingStateStorageDeletes pending indexing states older than the given timestamp.- Specified by:
deletePendingIndexingStatesOlderThanin interfaceIndexingStateStorage- Parameters:
timestamp- The cutoff timestamp in milliseconds- Returns:
- Number of rows deleted, or 0 if not applicable
-
isIndexingStatePending
Checks if the indexing state for the given fingerprint is pending.Useful for testing purposes to verify the pending status of an indexing state.
-