synology_apm_repo.sdk.storage.smb module

SmbStore — an ObjectStore implementation for a repository reached over SMB2/3 rather than a locally-mounted share.

smbclient is imported lazily and has no async API, so the four read methods run its synchronous calls on a thread pool of the store’s own, bounded (_THREAD_POOL_SIZE): a timed-out call’s thread cannot be stopped, and on the loop’s default executor a stalled server would starve every other to_thread() user (LocalFsStore, chunk decode). Each slot keeps its own connection_cache instead of smbclient’s process-wide session table, so closing one SmbStore never tears down a sibling’s connection.

Requests are routed through a pool of independent sessions (_DEFAULT_CONNECTION_POOL_SIZE) because an SMB2 connection’s credit window starts at 1, and two in-flight requests on one connection would race for it.

Each session keeps the files it read open for reuse (_SLOT_OPEN_HANDLES, closed after _HANDLE_IDLE seconds unused), so a repeated read of a bucket or composition file costs one round trip instead of open, read and close. A cached handle reads the file as it was opened: an open repository is read as a snapshot, so a file written to or replaced meanwhile need not show the change. One whose read fails (the server closed it) gives way to a fresh open.

Unlike S3Store/AzureStore, a share has real directories, so listdir on a missing path raises NotFoundError (as LocalFsStore does). smbprotocol has no timeout or retry after the initial connect, so this module adds both (NETWORK_READ_TIMEOUT/_DEFAULT_MAX_ATTEMPTS); its connect timeout is capped to NETWORK_CONNECT_TIMEOUT.

synology_apm_repo.sdk.storage.smb.DEFAULT_SMB_PORT = 445

The SMB server port used unless one is given.

class synology_apm_repo.sdk.storage.smb.SmbStoreDescriptor(share, server, port, username, password)

Bases: object

Picklable recipe for rebuilding an equivalent SmbStore.

share: str
server: str
port: int
username: str | None
password: str | None
build()
class synology_apm_repo.sdk.storage.smb.SmbStore(share, *, server, port=445, username=None, password=None)

Bases: AsyncClosing

One SMB share, addressed by "/"-separated paths relative to the share root (the equivalent of S3Store’s bucket).

username accepts DOMAIN\username or user@domain; leaving username/password unset attempts an anonymous/guest session.

Backed by a pool of SMB sessions created lazily (see module docstring). A call checks out a free slot, preferring an already connected one (LIFO), and holds it until the call, including retries, finishes.

descriptor()

How a worker process rebuilds this store.

async close()

Tear down every pooled SMB session of this instance (not a sibling’s) once in-flight calls finish; the store stays usable afterward. Safe to call more than once.

async read(path, offset=0, length=None)
async size(path)
async exists(path)
async listdir(path)