synology_apm_repo.sdk.dedup.segment_buffers module

Where BufferedExportSink keeps each segment while it is filled and flushed: a Slot of a SlotPool — one shared-memory block (SharedPool) or one sparse temporary file (Spool) holding every slot side by side, so a worker process can write into its slot directly.

class synology_apm_repo.sdk.dedup.segment_buffers.SlotPool(segment_size)

Bases: ABC

Every slot of one export side by side: slot k is the bytes [k * segment_size, (k + 1) * segment_size). Offsets below are pool-relative; a Slot adds its own base.

async create(slots)
take()

Hands out the lowest free slot; the caller checked one is free.

async close()

Releases the storage, once a cancelled create’s thread is done (the storage it made is ours to release).

abstractmethod async write_at(offset, data)
abstractmethod async write_zero(offset, length)
abstractmethod async read(offset, length)
abstractmethod async clear(offset, length)

Zeroes a whole slot again for its next segment.

abstractmethod descriptor()

How a worker process opens the pool for writing.

class synology_apm_repo.sdk.dedup.segment_buffers.Slot(pool, index)

Bases: object

Where one segment’s bytes live while it is filled and flushed. A slot reads as zero until written, and is zero again when it is handed out.

caps = SinkCaps(supports_sparse=True)
preallocated = True
async write_at(offset, data)
async write_zero(offset, length)
async read(offset, length)
worker_target()
note_worker_write()
async release()

Takes the slot back, leaving it zero for the next segment.

discard()

Takes the slot back without caring what it holds (the export is over).

class synology_apm_repo.sdk.dedup.segment_buffers.SharedMemoryDescriptor(name)

Bases: object

SinkDescriptor for a block of shared memory the parent created: a worker process attaches to it by name and writes into it directly.

name: str
open_writer()
class synology_apm_repo.sdk.dedup.segment_buffers.SharedPool(segment_size)

Bases: SlotPool

Slots in one block of shared memory, which worker processes attach to by name and write into directly.

property name: str
property buf: memoryview
async write_at(offset, data)
async write_zero(offset, length)
async read(offset, length)
async clear(offset, length)

Zeroes a whole slot again for its next segment.

descriptor()

How a worker process opens the pool for writing.

class synology_apm_repo.sdk.dedup.segment_buffers.Spool(directory, segment_size)

Bases: SlotPool

Slots in one sparse temporary file, which worker processes open by path and write into directly.

path: Path | None
async run(call, *args, **kwargs)

Runs a blocking call on the spool’s fd in a thread that close waits for, so a cancelled caller can never leave one writing to a closed (and perhaps reused) descriptor.

property fd: int
async write_at(offset, data)
async write_zero(offset, length)
async read(offset, length)
async clear(offset, length)

Zeroes a whole slot again for its next segment.

descriptor()

How a worker process opens the pool for writing.