Package io.camunda.zeebe.snapshots.impl
Class FileBasedSnapshotStore
java.lang.Object
io.camunda.zeebe.scheduler.Actor
io.camunda.zeebe.snapshots.impl.FileBasedSnapshotStore
- All Implemented Interfaces:
AsyncClosable,ConcurrencyControl,BootstrapSnapshotStore,ConstructableSnapshotStore,PersistedSnapshotStore,ReceivableSnapshotStore,RestorableSnapshotStore,CloseableSilently,AutoCloseable,Executor
public final class FileBasedSnapshotStore
extends Actor
implements ConstructableSnapshotStore, ReceivableSnapshotStore, RestorableSnapshotStore, BootstrapSnapshotStore
-
Nested Class Summary
Nested classes/interfaces inherited from class io.camunda.zeebe.scheduler.Actor
Actor.ActorBuilder -
Field Summary
Fields inherited from class io.camunda.zeebe.scheduler.Actor
actor, ACTOR_PROP_NAME, ACTOR_PROP_PARTITION_ID -
Constructor Summary
ConstructorsConstructorDescriptionFileBasedSnapshotStore(int brokerId, int partitionId, Path root, CRC32CChecksumProvider checksumProvider, io.micrometer.core.instrument.MeterRegistry meterRegistry) -
Method Summary
Modifier and TypeMethodDescriptionPurges all ongoing pending/transient/volatile snapshots.addSnapshotListener(PersistedSnapshotListener listener) Adds anPersistedSnapshotListenerto the store, which is notified when a newPersistedSnapshotis persisted at this store.copyForBootstrap(PersistedSnapshot persistedSnapshot, BiConsumer<Path, Path> copySnapshot) Makes a copy of the given snapshot to the given destination folder, keeping only the columns needed for the bootstrap process of a new partition.delete()Deletes aPersistedSnapshotStorefrom disk.Returns a set of all available snapshots.Returns the lowest compaction bound of all available snapshots.longgetName()getPath()booleanhasSnapshotId(String id) Returns true if the given identifier is equal to the snapshot id of the current persisted snapshot, false otherwise.newReceivedSnapshot(String snapshotId) Starts a new received volatile snapshot which can be persisted later.newTransientSnapshot(long index, long term, long processedPosition, long exportedPosition, boolean forceSnapshot) Starts a new transient snapshot which can be persisted after the snapshot was taken.protected voidprotected voidRemoves an registeredPersistedSnapshotListenerfrom the store.restore(PersistedSnapshot snapshot) Restore a PersistedSnapshot using the actor context in order to be thread safevoidRestores the snapshot by moving the snapshotFiles to the snapshotDirectory.toString()Methods inherited from class io.camunda.zeebe.scheduler.Actor
buildActorName, call, close, closeAsync, getContext, handleFailure, isActorClosed, newActor, onActorClosed, onActorCloseRequested, onActorFailed, onActorStarted, run, runOnCompletion, runOnCompletion, schedule, wrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.camunda.zeebe.util.CloseableSilently
closeMethods inherited from interface io.camunda.zeebe.scheduler.ConcurrencyControl
createCompletedFuture, createFuture, execute
-
Constructor Details
-
FileBasedSnapshotStore
public FileBasedSnapshotStore(int brokerId, int partitionId, Path root, CRC32CChecksumProvider checksumProvider, io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
-
Method Details
-
createContext
- Overrides:
createContextin classActor
-
getName
-
onActorStarting
protected void onActorStarting()- Overrides:
onActorStartingin classActor
-
onActorClosing
protected void onActorClosing()- Overrides:
onActorClosingin classActor
-
hasSnapshotId
Description copied from interface:PersistedSnapshotStoreReturns true if the given identifier is equal to the snapshot id of the current persisted snapshot, false otherwise.- Specified by:
hasSnapshotIdin interfacePersistedSnapshotStore- Parameters:
id- the snapshot Id to look for- Returns:
- true if the current snapshot has the equal Id, false otherwise
- See Also:
-
getLatestSnapshot
- Specified by:
getLatestSnapshotin interfacePersistedSnapshotStore- Returns:
- the latest
PersistedSnapshotif exists
-
getAvailableSnapshots
Description copied from interface:PersistedSnapshotStoreReturns a set of all available snapshots.- Specified by:
getAvailableSnapshotsin interfacePersistedSnapshotStore
-
getCompactionBound
Description copied from interface:PersistedSnapshotStoreReturns the lowest compaction bound of all available snapshots.- Specified by:
getCompactionBoundin interfacePersistedSnapshotStore
-
abortPendingSnapshots
Description copied from interface:PersistedSnapshotStorePurges all ongoing pending/transient/volatile snapshots.- Specified by:
abortPendingSnapshotsin interfacePersistedSnapshotStore- Returns:
- future which will be completed when all pending snapshots are deleted
-
addSnapshotListener
Description copied from interface:PersistedSnapshotStoreAdds anPersistedSnapshotListenerto the store, which is notified when a newPersistedSnapshotis persisted at this store.- Specified by:
addSnapshotListenerin interfacePersistedSnapshotStore- Parameters:
listener- the listener which should be added and notified later
-
removeSnapshotListener
Description copied from interface:PersistedSnapshotStoreRemoves an registeredPersistedSnapshotListenerfrom the store. The listener will no longer called when a newPersistedSnapshotis persisted at this store.- Specified by:
removeSnapshotListenerin interfacePersistedSnapshotStore- Parameters:
listener- the listener which should be removed
-
getCurrentSnapshotIndex
public long getCurrentSnapshotIndex()- Specified by:
getCurrentSnapshotIndexin interfacePersistedSnapshotStore- Returns:
- the snapshot index of the latest
PersistedSnapshot - See Also:
-
delete
Description copied from interface:PersistedSnapshotStoreDeletes aPersistedSnapshotStorefrom disk.The snapshot store will be deleted by simply reading
snapshotfile names from disk and deleting snapshot files directly. Deleting the snapshot store does not involve reading any snapshot files into memory.- Specified by:
deletein interfacePersistedSnapshotStore
-
getPath
- Specified by:
getPathin interfacePersistedSnapshotStore
-
newReceivedSnapshot
Description copied from interface:ReceivableSnapshotStoreStarts a new received volatile snapshot which can be persisted later.- Specified by:
newReceivedSnapshotin interfaceReceivableSnapshotStore- Parameters:
snapshotId- the snapshot id which is defined asindex-term-timestamp-processedposition-exportedposition- Returns:
- the new volatile received snapshot
-
newTransientSnapshot
public Either<SnapshotException,TransientSnapshot> newTransientSnapshot(long index, long term, long processedPosition, long exportedPosition, boolean forceSnapshot) Description copied from interface:ConstructableSnapshotStoreStarts a new transient snapshot which can be persisted after the snapshot was taken.- Specified by:
newTransientSnapshotin interfaceConstructableSnapshotStore- Parameters:
index- the index to which the snapshot corresponds toterm- the term to which the snapshots corresponds toprocessedPosition- the processed position in the snapshotexportedPosition- the exported position in the snapshot- Returns:
- either an exception or transientSnapshot, if it was taken successfully.
-
getBootstrapSnapshot
- Specified by:
getBootstrapSnapshotin interfaceBootstrapSnapshotStore- Returns:
- the latest snapshot that was copied if present.
-
copyForBootstrap
public ActorFuture<PersistedSnapshot> copyForBootstrap(PersistedSnapshot persistedSnapshot, BiConsumer<Path, Path> copySnapshot) Description copied from interface:BootstrapSnapshotStoreMakes a copy of the given snapshot to the given destination folder, keeping only the columns needed for the bootstrap process of a new partition. Any raft related data is removed.Only one snapshot for bootstrap can be taken at a time. It will be located into the "bootstrap-snapshots" folder.
- Specified by:
copyForBootstrapin interfaceBootstrapSnapshotStore- Parameters:
persistedSnapshot- the persisted snapshot to copycopySnapshot- the consumer which copies the snapshot to the destination folder. The first argument is the path of the source snapshot and the second argument is the destination folder
-
deleteBootstrapSnapshots
- Specified by:
deleteBootstrapSnapshotsin interfaceBootstrapSnapshotStore- Returns:
- an ActorFuture which completes when all bootstrap snapshots have been deleted
-
restore
Description copied from interface:RestorableSnapshotStoreRestores the snapshot by moving the snapshotFiles to the snapshotDirectory.WARN. Implementation of this method can be not thread safe.
- Specified by:
restorein interfaceRestorableSnapshotStore- Parameters:
snapshotId-snapshotFiles-- Throws:
IOException
-
restore
Description copied from interface:RestorableSnapshotStoreRestore a PersistedSnapshot using the actor context in order to be thread safe- Specified by:
restorein interfaceRestorableSnapshotStore
-
getSnapshotMetrics
-
toString
-