# Configure a node

**Applies to:** development build 0.1.1. Basic networking and storage flags also exist in the public baseline; capacity protection and newer recovery controls require the development build. Check `smkv-server --help` on the actual binary.

## Configuration entry points

For packaged services, edit `/etc/default/smkv` and restart deliberately. `SMKV_ARGS` is an argument list interpreted by systemd, with no shell substitution. For a foreground process, pass the same flags to `smkv-server`. Sharded nodes also read a cluster map; security uses a separate optional file. The published baseline supports JSON, with YAML support in development sources.

```sh
SMKV_ARGS="--bind 127.0.0.1:7379 --metrics-bind 127.0.0.1:9108 --partitions 16 --workers 4 --max-entries 100000 --max-log-bytes 1073741824"
```

This example is an environment-file line, not a command that starts the server. It preserves small evaluation limits, not production sizing.

## YAML or JSON configuration

**Development sources only:** `--config` and YAML loading are not included in
published APT 0.1.0-2. Existing command-line flags continue to work.

```yaml
# /etc/smkv/server.yaml
bind: 127.0.0.1:7379
data_dir: /var/lib/smkv
workers: 4
network_workers: 2
max_connections: 1000
# Sharded nodes also set cluster_map and node_id.
```

```sh
smkv-server --config /etc/smkv/server.yaml --check-config
smkv-server --config /etc/smkv/server.yaml --workers 8
```

Explicit flags override file values; file values override built-in defaults.
Use snake_case fields corresponding to kebab-case flags. JSON uses exactly the
same fields. Repeated `--authority-seed` flags replace the entire file list.
Use `--direct-reads=false` or `--disable-capacity-protection=false` to override a
true setting; the existing bare flags still mean true.

File paths resolve relative to their containing configuration file; CLI paths
resolve relative to the working directory. Omitted settings retain their existing
defaults. Unknown fields, duplicate keys, invalid types, and conflicting final
settings are rejected. Files are limited to 1 MiB. There is no environment-variable
interpolation or automatic reload. `config` and `check_config` are CLI-only.

`--check-config` checks the combined settings, referenced maps and security files
without opening database storage, binding sockets, joining a cluster, or contacting
S3. It does not check live capacity, port availability, credentials against remote
services, or compatibility with persisted topology.

Cluster/join maps, authority peer maps, security files, and server S3 sync config
also accept `.yaml` or `.yml`. Existing JSON files remain supported. Persisted
cluster state and replication/backup formats remain unchanged. Editing a bootstrap
map does not add or remove a member; use the cluster management procedures.

For a matching development package, `/etc/default/smkv` can contain:

```sh
SMKV_ARGS="--config /etc/smkv/server.yaml"
```

The service explicitly supplies `--data-dir /var/lib/smkv`, which takes precedence
over the file. Keep that service-managed location. Ensure configuration and any
referenced security files are readable by the service user.

## Core settings

| Flag | Default | Meaning |
| --- | --- | --- |
| `--partitions` | 16 | Fixed logical partitions; cannot change when reopening data |
| `--workers` | 4 | Dedicated storage threads; may change across restarts |
| `--network-workers` | 2 | Async networking/runtime threads, independent of storage workers; range 1–64; restart required |
| `--queue-capacity` | 64 | Bounded requests per storage worker |
| `--max-connections` | 128 | Concurrent TCP connection bound |
| `--max-entries` | 100000 | Node indexed-entry budget, split across partitions |
| `--max-log-bytes` | 1073741824 | Node retained-log budget, split across partitions |
| `--segment-bytes` | 67108864 | Segment rotation target; a larger record can occupy its own segment |
| `--expiry-interval-ms` | 100 | Paced expiration maintenance; 0 disables it |
| `--metrics-bind` | Disabled unless supplied | Private HTTP Prometheus listener |

Default maximum key size is 1 KiB and value size is 1 MiB. Size your workload within the configured limits, including table/key and row-encoding overhead. Choose storage workers no greater than the partition count. Network workers are
independent: if the runtime threads saturate while the node has CPU headroom,
benchmark a higher `network_workers` value with the same workload and storage
worker count. CLI flags override JSON/YAML values. This setting changes scheduling,
not partition ownership, acknowledgment guarantees, or on-disk formats.

## Plan per-node capacity

Entry/log budgets are node totals, not per-partition settings. RF2 stores two copies across the cluster. Count owned primary and replica entries when sizing each node. Unused quota in one partition is not freely shared with another. Maps can declare different node budgets; each partition uses the smaller quota supported by its two owners.

Retained logs include old values and deletes, not just live payload bytes. Checkpoints, incoming replicas, and ownership transfers require temporary disk and memory headroom. An index estimate is not RSS; include allocator, history, networking, and copy overhead. RAM of 32–128 GB does not imply a fixed safe record count. Measure with representative keys and payloads.

## Preserve headroom

Linux development servers sample physical disk, inodes, process RSS, available host memory, and applicable cgroup-v2 memory limits. Normal puts preserve a floor plus a maintenance reserve; maintenance can use the reserve but must preserve the floor.

| Flag | Default bytes |
| --- | ---: |
| `--capacity-disk-floor-bytes` | 67108864 |
| `--capacity-disk-reserve-bytes` | 1073741824 |
| `--capacity-memory-floor-bytes` | 268435456 |
| `--capacity-memory-reserve-bytes` | 536870912 |
| `--capacity-resume-margin-bytes` | 134217728 |
| `--capacity-max-rss-bytes` | 0 (additional RSS ceiling disabled) |

`--maintenance-log-percent` reserves 5% of logical log quota by default. These are available-byte thresholds, not used-space percentages. There is no automatic eviction. Larger copies may require substantially more headroom than these defaults.

```sh
smkv-ctl --seed 10.0.0.11:7381 capacity --json
```

States are `normal`, `pressure`, and `writes_blocked`. Reads remain routable under capacity pressure. Missing or stale resource samples reject mutations. Non-Linux servers default to disabled physical sampling; startup index reconstruction is not memory-bounded by the governor.

## Apply changes deliberately

Record the existing arguments, stop the affected service, edit configuration, and restart. Check logs, readiness, replica progress, and capacity before moving to another node. Do not lower logical quotas below stored data. Do not delete manifests, locks, segments, or identity files to make a new configuration start.

## Database scope

Database-aware development builds support logical databases; published APT
0.1.0-2 does not. See [logical databases](databases.html) for client selection,
permissions, shared resource limits, backup/sync behavior and upgrade constraints.

### Experimental bounded writeback

Linux deployments using `direct_reads: true` can opt into
`writeback_buffer_bytes: 262144` (256 KiB **per partition**). Zero disables it;
nonzero values must be 65536–16777216. The equivalent flag is
`--writeback-buffer-bytes 262144`; command-line settings override the file.
The setting takes effect at restart and does not change the storage format.

This prototype batches OS writeback and serves the unclean recent-write tail
through buffered reads. Existing acknowledgment and explicit sync guarantees
remain in force. It is disabled by default pending performance qualification;
request the current bounds, caveats and validation results from
[early-access support](mailto:info@simplemagic.com) before enabling it.
