Skip to content

Latest commit

 

History

History
274 lines (222 loc) · 14.9 KB

deployment.md

File metadata and controls

274 lines (222 loc) · 14.9 KB

Deploying a cluster

This guide describes the basics of starting a cluster of Funnel nodes. Funnel provides the application, container images, and configuration documentation. Operators maintain their own provisioning scripts, deployment manifests, service definitions, upgrades, and infrastructure operations. The former bundled GCE provisioning scripts and systemd examples have been removed.

A node is a service which runs on each machine in a cluster. The node connects to the Funnel server and reports available resources. The Funnel scheduler process assigns tasks to nodes. When a task is assigned, a node will start a worker process. There is one worker process per task.

Nodes aren't always required. In some cases it makes sense to rely on an existing, external system for scheduling tasks and managing cluster resources, such as AWS Batch, HTCondor, Slurm, Grid Engine, etc. Funnel provides integration with these services without using nodes or the scheduler.

Usage

Nodes are available via the funnel node command. To start a node, run

funnel node run --config node.config.yml

When server authentication is enabled, remote nodes must use administrator credentials in RPCClient.Credential to register and update their scheduler records. Set Admin: true for the corresponding server Basic authentication credential. Ordinary task-submitter credentials cannot create, update, or delete scheduler nodes.

To activate the Funnel scheduler, use the manual backend in the config.

When upgrading to the task-claim scheduler, stop all older Funnel server instances before starting the new version. Older schedulers do not consult claims and can assign the same task to another node. Check the server logs for conflicting existing assignments before restarting task submission.

With BoltDB, PostgreSQL, and MongoDB, the scheduler records a task claim and its node reservation together. MongoDB requires a replica set or sharded cluster for these transactions. Standalone MongoDB deployments must be converted before upgrading; Funnel rejects them at startup. See the MongoDB configuration.

The available scheduler and node config:

# Activate the Funnel scheduler.
Compute: manual

Scheduler:
  # How often to run a scheduler iteration.
  ScheduleRate: 1s

  # How many tasks to schedule in one iteration.
  ScheduleChunk: 10

  # How long to wait between updates before marking a node dead.
  NodePingTimeout: 1m

  # How long to wait for a node to start, before marking the node dead.
  NodeInitTimeout: 5m


Node:
  # If empty, a node ID will be automatically generated using the hostname.
  ID: ""

  # If the node has been idle for longer than the timeout, it will shut down.
  # -1 means there is no timeout. 0 means timeout immediately after the first task.
  Timeout: -1s

  # A Node will automatically try to detect what resources are available to it. 
  # Defining Resources in the Node configuration overrides this behavior.
  Resources:
    # CPUs available.
    # Cpus: 0
    # RAM available, in GB.
    # RamGb: 0.0
    # Disk space available, in GB.
    # DiskGb: 0.0

  # For low-level tuning.
  # How often to sync with the Funnel server.
  UpdateRate: 5s

Logger:
  # Logging levels: debug, info, error
  Level: info
  # Write logs to this path. If empty, logs are written to stderr.
  OutputFile: ""

Multiple instances sharing a database

With the manual compute backend, multiple Funnel server and scheduler instances can share one PostgreSQL database or MongoDB database. MongoDB requires a replica set or sharded cluster. BoltDB is an embedded database and is not suitable for sharing between hosts.

The shared database provides one logical task queue for the connected nodes. Schedulers can select the same queued task, but a transaction commits its ownership and node capacity reservation together. Competing assignments cannot claim the same task or reserve more capacity than the node has. Workers also acquire execution permission before preparing files or starting an executor.

Nodes can run at different sites if they can reach the Funnel services and the storage their tasks require. A shared database does not automatically restrict tasks to a particular site. Configure placement constraints and access to task data and credentials for the intended worker pool. All participating servers, nodes, and workers must use the upgraded version described below.

Adding scheduler instances does not provide unlimited throughput. Instances can read overlapping queued work, and assignments to the same node still coordinate through the database. Ownership and execution admission do not guarantee exactly-once process execution or external side effects after a crash. See execution admission for recovery limits.

Assignment storage upgrade

BoltDB, PostgreSQL, and MongoDB use persisted task claims as the authoritative assignment record. At first startup after this upgrade, Funnel imports active assignments from existing node records in a transaction. Conflicting owners or a claim with no reservation on an existing owner prevent startup and must be investigated. Claims whose owner node has disappeared are retained for scheduler recovery. The migration records completion and does not rescan all nodes during normal assignment.

Stop all older Funnel server and scheduler instances before upgrading. Node heartbeat requests can update node status, but cannot create assignments or remove active claims by changing task_ids. Funnel derives that list from the claims. Terminal task states remove entries from the active node index while preserving the durable ownership record.

Heartbeats, scheduling snapshots, and reservations

For all three scheduler backends, last_ping is stored separately from resource reservations. A routine heartbeat refreshes that timestamp without changing the node's configuration/reservation version. Assignment and completion do not refresh liveness. Resource, metadata, drain, and other configuration changes still check that version. Scheduler health transitions also check the observed heartbeat before marking a node dead or gone.

Each scheduling pass reads one list of candidate nodes containing scheduling fields, without expanding every node's task assignments. Successful assignments and failed reservation attempts refresh the affected candidate. The database validates current eligibility and capacity before committing an assignment. Candidates can become stale during a pass; database checks remain authoritative.

The default placement algorithm scans eligible candidates once and chooses the lowest average CPU and RAM score. Each resource score is (available + requested) / total. Equal scores retain candidate order. Queue reads fetch task IDs, creation times, states, and requested resources rather than full task payloads. PostgreSQL uses a partial queue-order index for queued tasks. Multiple schedulers can still observe the same queued work; atomic ownership checks arbitrate their reservation attempts.

An allocation records the resource quantities reserved at assignment. Terminal state writes release that allocation and update the node's resource usage in the same database transaction. Repeated terminal writes do not release it twice. Available capacity is derived from total capacity minus active usage, including when a node's reported capacity shrinks below its existing reservations.

A completed allocation cannot be reactivated by changing its task back to a nonterminal state. Submit a new task to retry it. Resource accounting follows TES terminal states, including cancellation; this does not establish that an unreachable runtime has physically stopped its process. The design does not add automatic reassignment or exactly-once process execution.

Active task IDs are reconstructed from indexed claims for worker and public node reads. Reservations and releases update a small resource budget and its version without rewriting the descriptive node record or a growing task-ID array. PostgreSQL keeps these values in dedicated columns, MongoDB updates the budget fields, and BoltDB keeps a separate budget record. The public node API continues to return task IDs and current available resources.

Startup migrations snapshot existing active allocations, reconstruct resource totals, and clear legacy task-ID arrays after importing their assignments. PostgreSQL uses transactions scoped to the task and candidate node during normal reservation/release. MongoDB uses snapshot transactions with majority writes and retries write conflicts against fresh task and node records. BoltDB retains its embedded single-writer transaction model. None of these backends requires an external event log.

Execution admission

Workers using BoltDB, PostgreSQL, or MongoDB acquire a durable execution claim before preparing files or starting any executor. The database checks the task state and records the claim with INITIALIZING in one transaction. After task preparation, the worker sets RUNNING just before it dispatches the first executor. This transition reports dispatch, not confirmation that a container has started. Only the worker that receives a successful acquisition proceeds. A second worker observes the task until it reaches a terminal state, without preparing files, running an executor, or writing task events. This prevents a duplicate batch worker from signaling successful completion while the original execution is still active. An observer exiting successfully means observation finished; the TES task state still reports whether execution completed, failed, or was canceled. A failed claim request or an unsupported claim endpoint cannot authorize a launch. Local tasks passed directly from a file or the command line do not use this distributed claim.

Claims have no expiration and do not transfer automatically. If a worker crashes after acquiring its claim, or loses the successful response, another worker cannot rerun that task ID. Kubernetes workers record their pod identity atomically with the claim. Funnel submits worker pods with restartPolicy: Never, including when a custom worker template specifies OnFailure. The Job's backoffLimit is preserved, so failures before a claim is acquired can still start a replacement pod. For worker pods with sidecars, Funnel tracks the selected worker container. If that container fails before acquiring a claim, Funnel retires the pod so the Job can retry even when a sidecar remains running.

If the worker container that owns a claim exits, or its pod is lost before the task reaches a terminal state, the Kubernetes reconciler records SYSTEM_ERROR and performs the configured resource cleanup. It checks the pod UID and controlling Job UID before treating pod termination as evidence that the claimed worker exited. A missing owner pod or a different UID at its recorded name means that the owner was lost. It does not replay the task or let a replacement worker take over its claim. A duplicate worker continues observing the task while the original worker is alive.

Claims created before this upgrade, manually launched workers without the pod identity environment, and other compute backends do not have this pod ownership information. Those tasks and duplicate observers can remain active until a user cancels the task or existing backend failure recovery records a failure. An unavailable Kubernetes API defers owner reconciliation. Failing a task after its pod is deleted does not prove that a process on an unreachable node has stopped. Inspect the original runtime before submitting replacement work with a new task ID. Changing the old task's state or retrying its claim does not grant another execution.

This protects execution admission. It does not recover running containers, stop an unreachable process, or guarantee exactly-once writes to external systems. Resource release still follows TES terminal state and does not prove that an unreachable runtime has stopped.

Stop older servers, workers, and node processes before upgrading. Older workers do not acquire execution claims and can bypass this protection. Initialize the database with the upgraded server, then start upgraded workers. An upgraded RPC worker requires an upgraded server; mixed-version rollouts do not provide this protection. Existing running and terminal tasks are treated as having consumed execution admission during the startup migration.

The claim is an internal worker operation. It does not change the TES task schema or introduce a public TES endpoint. Worker RPC authentication and task access rules also apply to acquisition. Database-backed workers using an unsupported claim implementation fail before execution rather than silently running without this guard. Datastore, DynamoDB, and Badger do not currently implement execution admission; use BoltDB, PostgreSQL, or MongoDB for remote workers with this version. Custom callers of DefaultWorker must supply an ExecutionClaimer for non-local task readers.

Container command templates

Task-provided image, name, workdir, volume paths, and environment or label entries are bound as literal runtime arguments. Quoted and unquoted scalar placeholders both preserve spaces and quotes in task values. Runtime flags belong in the administrator's template, rather than in task fields. Image identifiers cannot start with - or contain whitespace or control characters. Docker volume paths cannot contain : or NUL.

Use {{.GetEnvArgs}} and {{.GetTagArgs}} to expand environment variables and opted-in task labels. Direct range loops over Env and Tags are also supported. These maps use protected string keys; custom templates using index .Env "KEY" or index .Tags "KEY" must migrate to the helpers or a range with eq. Avoid applying string truncation or serialization to runtime argument placeholders. Task command arrays continue to be forwarded separately.

Trusted HPC submission records

Slurm, PBS, HTCondor, and Grid Engine require HPCStateDir, an absolute path to private, persistent controller storage (mode 0700). Keep it outside Worker.WorkDir, Worker.ScratchPath, and every enabled LocalStorage.AllowedDirs root. Use a bounded local-storage allowlist, or disable local storage. For example, use /var/lib/funnel/controller for HPCStateDir and /var/lib/funnel/tasks for task data.

The controller records the scheduler job ID returned by submission there. Cancellation and reconciliation use that record; provider IDs in task logs are for display. Controllers managing the same jobs must share this directory, and it must survive restarts. Do not mount it into executor containers.

Jobs submitted before this upgrade have no trusted record. Cancel those jobs with the scheduler's own command before upgrading; Funnel will refuse to use legacy task metadata as cancellation authority. Preserve the records while jobs can still be managed. Back up this directory with the task database.

Output publication copies confined task files into a private temporary snapshot before uploading. Allow local disk space and I/O for an additional copy of the outputs during publication.