-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
snapshot/src/main/scala/com/evolutiongaming/kafka/journal/SnapshotSelectionCriteria.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.evolutiongaming.kafka.journal | ||
|
||
import java.time.Instant | ||
|
||
final case class SnapshotSelectionCriteria( | ||
maxSeqNr: SeqNr = SeqNr.max, | ||
maxTimestamp: Instant = Instant.MAX, | ||
minSeqNr: SeqNr = SeqNr.min, | ||
minTimestamp: Instant = Instant.MIN | ||
) | ||
|
||
object SnapshotSelectionCriteria { | ||
|
||
val All: SnapshotSelectionCriteria = SnapshotSelectionCriteria() | ||
|
||
def one(seqNr: SeqNr): SnapshotSelectionCriteria = | ||
SnapshotSelectionCriteria(maxSeqNr = seqNr, minSeqNr = seqNr) | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
snapshot/src/main/scala/com/evolutiongaming/kafka/journal/SnapshotStoreFlat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.evolutiongaming.kafka.journal | ||
|
||
import com.evolutiongaming.kafka.journal.eventual.EventualPayloadAndType | ||
|
||
/** Snapshot storage for Kafka Journal. | ||
* | ||
* Uses `Key` instead of `persistenceId`, similar to [[ReplicatedJournalFlat]] | ||
* and [[EventualJournal]]. | ||
*/ | ||
trait SnapshotStoreFlat[F[_]] { | ||
|
||
/** Save snapshot for a specific key. | ||
* | ||
* @param key | ||
* Unique identifier of a journal snapshot is done for. | ||
* @param snapshot | ||
* Journal snapshot including sequence number and some metadata. | ||
*/ | ||
def save(key: Key, snapshot: SnapshotRecord[EventualPayloadAndType]): F[Unit] | ||
|
||
/** Loads a snapshot for a given key and selection criteria. | ||
* | ||
* If several snapshots are found using a passed selection criteria for a | ||
* specific key, then the last one (i.e. with a latest `SeqNr`) is returned. | ||
* | ||
* @param key | ||
* Unique identifier of a journal snapshot was done for. | ||
* @param criteria | ||
* Criteria to use. | ||
*/ | ||
def load(key: Key, criteria: SnapshotSelectionCriteria): F[Option[SnapshotRecord[EventualPayloadAndType]]] | ||
|
||
/** Deletes all snapshots for a given key and selection criteria. | ||
* | ||
* If several snapshots are found using a passed selection criteria for a | ||
* specific key, then all of them are deleted. | ||
* | ||
* @param key | ||
* Unique identifier of a journal snapshot was done for. | ||
* @param criteria | ||
* Criteria to use. | ||
*/ | ||
def delete(key: Key, criteria: SnapshotSelectionCriteria): F[Unit] | ||
|
||
/** Deletes a snapshot for a given key and sequence number. | ||
* | ||
* The method returns the same as | ||
* `load(key, SnapshotSelectionCriteria.one(seqNr))`, | ||
* but additional optimizations might be possible. | ||
* | ||
* @param key | ||
* Unique identifier of a journal snapshot was done for. | ||
* @param seqNr | ||
* Sequence number to be deleted. | ||
*/ | ||
def delete(key: Key, seqNr: SeqNr): F[Unit] | ||
|
||
} |