DockerDaemonDispatcher

Dispatches DockerDaemon instances to Runner instances for Docker operations.

Types

Link copied to clipboard
private data class ReserveQueueEntry(val runner: Runner)
Link copied to clipboard
private sealed class RunnerDispatchState
Link copied to clipboard
private object StateVerification

Namespace containing methods verifying the state of DockerDaemonDispatcher.

Properties

Link copied to clipboard

List of all available Docker daemons.

Link copied to clipboard
private const val CONNECT_DAEMON_RETRIES: Int = 5

Number of retries for waitConnection until the method will throw an exception.

Link copied to clipboard

Base wait time for waitConnection when a connection cannot be established.

Link copied to clipboard
private val DAEMON_RW_MUTEX: Mutex

Mutex for guarding availableDaemons read/write operations.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether a dispatch operation is currently progress.

Link copied to clipboard
Link copied to clipboard

Base wait time for findAvailableDaemon when a daemon cannot be found.

Link copied to clipboard
private const val FIND_DAEMON_MAX_BACKOFF: Int = 6

Maximum exponent which the backoff algorithm will increment to.

Link copied to clipboard

Map of runners which has failed to dispatch due to an exception being thrown while being dispatched or bound to a daemon.

Link copied to clipboard
private val logger: Logger
Link copied to clipboard

Mapping of all managed runners to its internal state.

Link copied to clipboard
private val QUEUE_RW_MUTEX: Mutex

Mutex for guarding reserveQueue read/write operations.

Link copied to clipboard

Frequency of reserve queue dispatch task.

Link copied to clipboard

Reserve queue for runners awaiting dispatch to a Docker daemon.

Link copied to clipboard

Time of latest reserve queue dispatch task.

Link copied to clipboard
private const val TRACE_LOG_MUTEX: Boolean = false

Whether to enable trace logging when any Mutex is acquired or released via withLoggingLock.

Functions

Link copied to clipboard
suspend fun addDaemon(hostname: String, isMainHost: Boolean)

Adds a daemon to the list of available DockerDaemon for dispatch.

Link copied to clipboard
suspend fun bind(runner: Runner): DockerDaemon?

Binds a DockerDaemon to a Runner instance.

Link copied to clipboard

Finds an available daemon which can serve a runner with the given resource limit.

Link copied to clipboard
suspend fun getAllocatedGpu(runner: Runner): GpuDevice?
Link copied to clipboard
suspend fun getBoundDaemon(runner: Runner): DockerDaemon

Returns the DockerDaemon allocated to a Runner instance.

Link copied to clipboard
private suspend fun getDaemon(runner: Runner): DockerDaemon?

Helper method to get the DockerDaemon instance bound to a Runner, and check that the DockerDaemon is still connected to the Docker engine.

Link copied to clipboard
suspend fun getDaemonBlocking(runner: Runner, backoff: Duration = Duration.ofSeconds(1)): DockerDaemon

Returns a DockerDaemon allocated to a Runner instance, blocking until a daemon is bound to the runner instance.

Link copied to clipboard
private suspend fun getDaemonByRunner(runner: Runner): DaemonHost?
Link copied to clipboard
Link copied to clipboard

Retrieves an unbounded daemon.

Link copied to clipboard
suspend fun hasAnyDaemon(): Boolean
Link copied to clipboard
suspend fun removeDaemon(hostname: String)

Removes a daemon from the list of available DockerDaemon for dispatch.

Link copied to clipboard
private fun Runner.toDebugString(): String
Link copied to clipboard
suspend fun tryAllocDaemon(runner: Runner): DockerDaemon?
private suspend fun tryAllocDaemon(runner: Runner, triggeredByWrite: Boolean): DockerDaemon?

Attempts to allocate a daemon to the runner, and returns the DockerDaemon if one is allocated.

Link copied to clipboard
private suspend fun tryBindSingle(triggeringRunner: Runner?): DaemonHost?
Link copied to clipboard
private suspend fun tryBindToRunners(triggeringRunner: Runner?, triggeredByWrite: Boolean)

Traverses through the reserveQueue, and sequentially binds runners to a Docker daemon if possible.

Link copied to clipboard
private suspend fun tryBindToRunnersLocked(triggeredByWrite: Boolean)
Link copied to clipboard
suspend fun unbind(runner: Runner)

Unbinds a DockerDaemon from a Runner instance.

Link copied to clipboard
private suspend fun unbindImpl(runner: Runner): Boolean

Internal implementation for unbinding a DockerDaemon from a Runner instance.

Link copied to clipboard
private fun unbindLocked(runner: Runner, daemon: DaemonHost)

Unbinds a runner from its daemon, provided that DAEMON_RW_MUTEX is locked by the caller of this method.

Link copied to clipboard
private suspend fun waitConnection(daemon: DaemonHost): DaemonHost

Waits for the daemon to be connected.

Link copied to clipboard
private inline suspend fun <T> withDaemonMutex(lockSource: String, owner: Any? = null, action: MutableList<DaemonHost>.() -> T): T
Link copied to clipboard
private inline suspend fun <T, R> T.withLoggingLock(mutex: Mutex, lockName: String, lockSource: String, owner: Any? = null, action: T.() -> R): R
Link copied to clipboard
private inline suspend fun <T> withQueueMutex(lockSource: String, owner: Any? = null, action: MutableList<DockerDaemonDispatcher.ReserveQueueEntry>.() -> T): T