system.stores.MVCC module

Multi-version concurrency control transactional key-value store with journaling.

exception system.stores.MVCC.TransactionAbortedException[source]

Bases: Exception

An exception that is raised when a transaction is aborted by the store.

class system.stores.MVCC.JournalEntry(*, TA_id: int)[source]

Bases: ABC, BaseModel

An abstract class for journal entries.

TA_id: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class system.stores.MVCC.Begin(*, TA_id: int)[source]

Bases: JournalEntry

A journal entry marking the start of a transaction.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class system.stores.MVCC.Commit(*, TA_id: int, commit_timestamp: int)[source]

Bases: JournalEntry

A journal entry marking the commit of a transaction, recording its commit timestamp.

commit_timestamp: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class system.stores.MVCC.Abort(*, TA_id: int)[source]

Bases: JournalEntry

A journal entry marking the abort of a transaction.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class system.stores.MVCC.Update(*, TA_id: int, object_id: Key, nev_value: Value)[source]

Bases: JournalEntry, Generic

A journal entry for an update operation.

object_id: Key
nev_value: Value
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class system.stores.MVCC.Delete(*, TA_id: int, object_id: Key)[source]

Bases: JournalEntry, Generic

A journal entry for a delete operation.

object_id: Key
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class system.stores.MVCC.TransactionalKeyValueStore(use_brute_force_validation: bool = False, persistence_layer: KeyValueStore = None)[source]

Bases: VersionedKeyValueStore, ACIDStore

A fully transactional versioned key value store (formerly known as MVCCStore).

Notice that this store goes far beyond the typical key value store, which typically is only transactional per SINGLE key update/insert/delete. In contrast, this store is FULLY transaction, i.e. it allows for multiple keys to be updated within a single transaction. Those changes are SERIALIZABLE. The write skew anomaly is detected and avoided.

class TDEntry(read_clauses: set[HashableDict[str, Clause | int]], write_set: set[str], committed_timestamp: int | None, last_committed_TA_index_in_TA_trace: int | None)[source]

Bases: object

Entries used for the transaction dictionary.

read_clauses: set[HashableDict[str, Clause | int]]
write_set: set[str]
committed_timestamp: int | None
last_committed_TA_index_in_TA_trace: int | None
read_objects(TA_id: int, where: Clause = None, collect_read_clause: bool = True) → list[tuple[str, object]][source]

Returns a list with all objects that match the WHERE_clause. If the store uses brute force validation, the checksum of the returned list is also computed.

In any case, the where clause (and checksum) are added to the read set of TA <TA_id>.

Parameters:
  • TA_id – the transaction id reading the data, required for snapshot isolation

  • where – a where clause expression that is evaluated against the actual data (not the object ids)

  • collect_read_clause – if set to True, the where clause is not added to the read set of TA <TA_id>

Returns:

a list over the object ids that match the given conditions

update_object(object_id: str, updated_object: object, TA_id: int) → None[source]

See ACIDStore.update_object().

Also supports inserts (a missing object_id creates a new entry) and must be executed atomically in a concurrent environment. Aborts the transaction and raises TransactionAbortedException if another transaction currently holds a work-in-progress version of the object. Writes an Update journal entry, stores a deep copy of the value as an append-only work-in-progress version, and records the object_id in the transaction’s write set.

delete_object(object_id: str, TA_id: int) → None[source]

See ACIDStore.delete_object().

Must be executed atomically in a concurrent environment. Raises if another transaction currently holds a work-in-progress version of the object. Writes a Delete journal entry, adds a delete-marker work-in-progress version, and records the object_id in the transaction’s write set.

show_transaction_dictionary() → None[source]

Shows the transaction dictionary (self.TD).

begin_transaction() → int[source]

See ACIDStore.begin_transaction().

Additionally appends a Begin entry to the journal.

commit_transaction(TA_id: int) → None[source]

See ACIDStore.commit_transaction().

Runs the validation phase first: on a conflict the transaction is aborted and TransactionAbortedException is raised. On success, a Commit journal entry is written and flushed, and the transaction’s work-in-progress versions become visible by moving them from wip to the committed list under the commit timestamp.

abort_transaction(TA_id: int) → None[source]

See ACIDStore.abort_transaction().

Writes an Abort journal entry, removes every work-in-progress version created by the transaction, and deletes the transaction from the transaction dictionary.