Skip to content

Commit

Permalink
Merge 28eaaa5 into 7ddbcb2
Browse files Browse the repository at this point in the history
  • Loading branch information
rtar committed Feb 14, 2024
2 parents 7ddbcb2 + 28eaaa5 commit ebe25b4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
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)

}
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]

}

0 comments on commit ebe25b4

Please sign in to comment.