Storage of an encrypted event log server in a SQL database (Effect's
eventlog/SqlEventLogServerEncrypted), on SQLite, PostgreSQL, MySQL or
SQL Server, with remote compaction.
Each identity and store has a table of batches, named by a hash of the
pair under entry_table_prefix, a table of the entry ids it holds with
the sequence each was first stored at, and a table of snapshot batches.
A batch is stored when one of its ids is new; sequences start at 1.
remote_id_table keeps the server's remote id,
<entry_table_prefix>_session_auth_bindings the signing key bound to
each public key, and <entry_table_prefix>_compaction_* the compaction
state of every store.
Up to 0.6.5 tables were named by publicKey/storeId, which two pairs
share when it holds more than one /. A pair whose key has one /
keeps its tables; any other pair whose 0.6.5 tables hold batches does not
open (its operations die with LegacyStoreNeedsMigration) until its
owner runs migrate_legacy_store once.
Re-exports#
- From
pyfect.sql.error:SqlError
Classes#
Functions#
migrate_legacy_store#
migrate_legacy_store(public_key, store_id, *, entry_table_prefix='effect_events', remote_id_table='effect_remote_id') -> Effect[bool, SqlError | LegacyStoreMigrationError, SqlClient | Digest]Gives the store of public_key and store_id the tables 0.6.5
named publicKey/storeId, as their owner: run it once for a store
whose operations die with LegacyStoreNeedsMigration, and only for
the pair that wrote them (another pair joining to the same text may
have). Succeeds with whether the store has them now; fails when another
pair was given them or the store already holds batches of its own.
| Parameter | Type | Description |
|---|---|---|
public_key | str | |
store_id | str | |
entry_table_prefix | str = 'effect_events' | |
remote_id_table | str = 'effect_remote_id' |
Returns Effect[bool, SqlError | LegacyStoreMigrationError, SqlClient | Digest]
def migrate_legacy_store(
public_key: str,
store_id: str,
*,
entry_table_prefix: str = "effect_events",
remote_id_table: str = "effect_remote_id",
) -> Effect[bool, SqlError | LegacyStoreMigrationError, SqlClient | Digest]:
"""Gives the store of ``public_key`` and ``store_id`` the tables 0.6.5
named ``publicKey/storeId``, as their owner: run it once for a store
whose operations die with ``LegacyStoreNeedsMigration``, and only for
the pair that wrote them (another pair joining to the same text may
have). Succeeds with whether the store has them now; fails when another
pair was given them or the store already holds batches of its own."""
return migrate_legacy_store_effect(
public_key,
store_id,
entry_table_prefix=entry_table_prefix,
remote_id_table=remote_id_table,
)layer_storage#
layer_storage(*, entry_table_prefix='effect_events', remote_id_table='effect_remote_id', compaction=None) -> Layer[Storage, SqlError, SqlClient | Digest]The Storage of make_storage.
| Parameter | Type | Description |
|---|---|---|
entry_table_prefix | str = 'effect_events' | |
remote_id_table | str = 'effect_remote_id' | |
compaction | CompactionOptions | None = None |
Returns Layer[Storage, SqlError, SqlClient | Digest]
def layer_storage(
*,
entry_table_prefix: str = "effect_events",
remote_id_table: str = "effect_remote_id",
compaction: CompactionOptions | None = None,
) -> Layer[Storage, SqlError, SqlClient | Digest]:
"""The ``Storage`` of ``make_storage``."""
return layer_effect(
Storage,
make_storage(
entry_table_prefix=entry_table_prefix,
remote_id_table=remote_id_table,
compaction=compaction,
),
)layer_storage_subtle#
layer_storage_subtle(*, entry_table_prefix='effect_events', remote_id_table='effect_remote_id', compaction=None) -> Layer[Storage, SqlError, SqlClient]layer_storage with the Web Crypto Digest.
| Parameter | Type | Description |
|---|---|---|
entry_table_prefix | str = 'effect_events' | |
remote_id_table | str = 'effect_remote_id' | |
compaction | CompactionOptions | None = None |
Returns Layer[Storage, SqlError, SqlClient]
def layer_storage_subtle(
*,
entry_table_prefix: str = "effect_events",
remote_id_table: str = "effect_remote_id",
compaction: CompactionOptions | None = None,
) -> Layer[Storage, SqlError, SqlClient]:
"""``layer_storage`` with the Web Crypto ``Digest``."""
return layer_storage(
entry_table_prefix=entry_table_prefix,
remote_id_table=remote_id_table,
compaction=compaction,
).pipe(layer_provide(digest_layer_web_crypto))make_storage#
make_storage(*, entry_table_prefix='effect_events', remote_id_table='effect_remote_id', compaction=None) -> Effect[StorageService, SqlError, SqlClient | Digest | Scope]Storage in the SqlClient's database, creating its tables, with
compaction and its sweep (Effect's makeStorage).
| Parameter | Type | Description |
|---|---|---|
entry_table_prefix | str = 'effect_events' | |
remote_id_table | str = 'effect_remote_id' | |
compaction | CompactionOptions | None = None |
Returns Effect[StorageService, SqlError, SqlClient | Digest | Scope]
def make_storage(
*,
entry_table_prefix: str = "effect_events",
remote_id_table: str = "effect_remote_id",
compaction: CompactionOptions | None = None,
) -> Effect[StorageService, SqlError, SqlClient | Digest | Scope]:
"""Storage in the ``SqlClient``'s database, creating its tables, with
compaction and its sweep (Effect's ``makeStorage``)."""
def build():
digest = yield from Digest()
sql = (yield from SqlClient()).without_transforms()
config = yield from make_compaction_config(compaction)
db = Db(sql, entry_table_prefix, config)
yield from create_global_tables(sql, entry_table_prefix, remote_id_table)
remote_ids = sql.identifier(remote_id_table)
rows = yield from sql("SELECT remote_id FROM {}", remote_ids)
if rows:
remote_id = RemoteId(column_bytes(rows[0]["remote_id"]))
else:
remote_id = make_remote_id_unsafe()
yield from sql("INSERT INTO {} (remote_id) VALUES ({})", remote_ids, remote_id)
resources = yield from RcMap.make(_make_lookup(db, digest), idle_time_to_live="5 minutes")
sweeper = Sweeper(db)
# A fixed schedule starts an overdue sweep straight away, so slow
# queries don't push sweeps back.
yield from fork_scoped(
sweeper.sweep.repeat(fixed(config.sweep_interval)).delay(config.sweep_interval)
)
return _SqlStorage(db, remote_id, resources)
return gen(build).with_tracer_enabled(False)