swh.objstorage.backends.winery.sharedbase module#
- class swh.objstorage.backends.winery.sharedbase.ShardState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
- STANDBY = 'standby'#
- WRITING = 'writing'#
- FULL = 'full'#
- PACKING = 'packing'#
- PACKED = 'packed'#
- CLEANING = 'cleaning'#
- READONLY = 'readonly'#
- property locked#
- property image_available#
- property readonly#
- class swh.objstorage.backends.winery.sharedbase.SignatureState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
- INFLIGHT = 'inflight'#
- PRESENT = 'present'#
- DELETED = 'deleted'#
- class swh.objstorage.backends.winery.sharedbase.TemporaryShardLocker(base: SharedBase, current_state: ShardState, new_state: ShardState, min_mapped_hosts: int = 0)[source]#
Bases:
object
Opportunistically lock a shard, and provide a context manager to unlock the shard if an operation fails.
Use this through the
SharedBase.maybe_lock_one_shard()
method.
- class swh.objstorage.backends.winery.sharedbase.SharedBase(base_dsn: str, application_name: str = 'SWH Winery SharedBase', **kwargs)[source]#
Bases:
Database
- lock_one_shard(current_state: ShardState, new_state: ShardState, min_mapped_hosts: int = 0) → Tuple[str, int] | None[source]#
Lock one shard in current_state, putting it into new_state. Only lock a shard if it has more than min_mapped_hosts hosts that have registered as having mapped the shard.
- maybe_lock_one_shard(current_state: ShardState, new_state: ShardState, min_mapped_hosts: int = 0) → TemporaryShardLocker[source]#
Opportunistically lock a shard, and, if a shard was locked, provide a context manager to rollback the locking on failure.
Example:
locked = base.maybe_lock_one_shard( current_state=ShardState.FULL, new_state=ShardState.PACKING, ) if not locked: wait_a_minute() return with locked: do_something_with_locked_shard(locked.name)
If
do_something_with_locked_shard
fails, the shard will be moved back to thecurrent_state
on exit.
- set_shard_state(new_state: ShardState, set_locker: bool = False, check_locker: bool = False, name: str | None = None, db: Connection | None = None)[source]#
- get_shard_state(name: str) → ShardState | None[source]#