Table of Contents

Class Backoff

Namespace
OptunaSharp.Artifacts
Assembly
OptunaSharp.dll

An artifact store's middleware for exponential backoff. Port of optuna/artifacts/_backoff.py: Backoff.

public class Backoff : IArtifactStore
Inheritance
Backoff
Implements
Inherited Members

Examples

var artifactStore = new Backoff(new FileSystemArtifactStore("./artifacts"));

Constructors

Backoff(IArtifactStore, int, double, double, double)

Wraps an artifact store with bounded exponential retry delays.

public Backoff(IArtifactStore backend, int maxRetries = 10, double multiplier = 2, double minDelay = 0.1, double maxDelay = 30)

Parameters

backend IArtifactStore

Shared store to call; ownership remains with the caller.

maxRetries int

Maximum total attempts, including the first; must be positive.

multiplier double

Positive factor applied to the delay after each failed attempt.

minDelay double

Positive first retry delay in seconds.

maxDelay double

Delay cap in seconds; must exceed minDelay.

Remarks

Constructor preconditions are debug assertions. ArtifactNotFound is never retried, and the final provider exception is rethrown.

Methods

OpenReader(string)

Opens binary artifact content for reading.

public Stream OpenReader(string artifactId)

Parameters

artifactId string

Identifier of the artifact within the configured store.

Returns

Stream

A readable stream owned by the caller; dispose it after reading.

Exceptions

ArtifactNotFound

The artifact does not exist.

Exception

The configured store cannot retrieve the artifact.

InvalidOperationException

The attempt limit is not positive, violating the constructor precondition.

Remove(string)

Deletes the artifact identified by its store key.

public void Remove(string artifactId)

Parameters

artifactId string

Identifier of the artifact within the configured store.

Exceptions

ArtifactNotFound

The backend reports that the artifact is absent.

Exception

The backend cannot delete the artifact.

Write(string, Stream)

Copies artifact content into the store without taking ownership of the input stream.

public void Write(string artifactId, Stream contentBody)

Parameters

artifactId string

Identifier of the artifact within the configured store.

contentBody Stream

Readable content stream; ownership stays with the caller.

Remarks

Retries rewind contentBody to position zero, so the stream must be seekable when a retry occurs. A failed attempt can leave partial backend content.

Exceptions

Exception

The backend or input stream fails during the upload.

NotSupportedException

A retry attempts to rewind a non-seekable content stream.