The embedded metadata store

The embedded metadata store

How nodes run oxia themselves, from founding the five keyspaces to raising replication, draining a departing node's copies, and splitting hot shards.

By default, Nova's nodes run the metadata store themselves, as embedded oxia. Three rules keep it safe to grow and shrink. A keyspace's shard IDs never move once it is founded. A keyspace's replication factor rises to 3 and never falls. A node's data server leaves only after oxia has moved every copy it held to other servers. Metadata keyspaces covers what the store holds; this page covers how the nodes run it.

Where it lives

CodeWhat it owns
internal/kv/oxia/embedded/embedded.goThe roles, the five namespace names, the founding shard counts, and the standalone shape
internal/kv/oxia/embedded/cluster.goThe cluster shape: starting the data server and the coordinator, registering, founding the keyspaces, removing a data server, and splitting a shard
internal/kv/oxia/embedded/tender.goThe tender on the leading peer: raising replication, forgetting drained servers, and the hot-shard alarm
internal/kv/oxia/embedded/tender_drain.goThe watch over data servers that oxia is draining
internal/kv/oxia/embedded/heatThe split arithmetic: merging load histograms and choosing a split point

A node has one of three roles, which it logs at start as role=:

RoleRunsWhen
standaloneOne data server, with no coordinator and no replication--oxia-server-peers is empty
peerA data server and a coordinatorThe node's oxia address is in --oxia-server-peers
memberA data serverAny other node of a cluster

The coordinators keep their control state in a raft group across the peers, or in ConfigMaps on Kubernetes. The first address in --oxia-server-peers founds the raft group when its directory holds no raft state. The data server's files live under <dir>/metadata.

Founding the keyspaces

The store holds five keyspaces, each an oxia namespace. Shard IDs are dealt in a fixed order, and each keyspace starts with a floor of shards that --oxia-server-shards can raise:

OrderKeyspaceKey orderFounding shards
1streamshierarchical4
2queueshierarchical4
3sessionshierarchical8
4registrynatural1
5dispatchhierarchical4

Dispatch comes last, so a store founded before it existed gains it without moving a shard it already holds. Oxia splits shards but never merges them, so the floors are kept small.

alt [missing] loop [each keyspace, in founding order] start its own data server register the data server GetNamespace CreateNamespace (replication factor 1, or the streams keyspace's) place its shards on the registered servers wait until every shard has a leader the tender raises replication to 3 once three servers exist Starting node Leading coordinator Data servers

On a cluster start, each node does three things in order:

  1. Registers its data server with whichever peer's coordinator leads.
  2. Ensures the keyspaces. Through the leading peer, it creates each namespace that does not exist yet, in founding order. A new store starts at replication factor 1. A keyspace added to an existing store starts at the replication factor the streams keyspace has reached, so it is no less durable than the keyspaces beside it.
  3. Waits for every shard to have a leader, because a client call to a shard with no leader goes nowhere.
internal/kv/oxia/embedded/cluster.go
func (c *cluster) start(oxiaCtx, startCtx context.Context, dir string, role Role) error {
	if err := c.startServer(oxiaCtx, dir); err != nil {
		return err
	}
	// ...
	if err := c.register(startCtx, identity); err != nil {
		return err
	}

	if err := c.ensureNamespaces(startCtx); err != nil {
		return err
	}

	return c.awaitAssignments(startCtx)
}

The founding peer logs embedded: initialising metadata with the shard plan, embedded: namespace created for each keyspace, and embedded: metadata initialisation complete with how long it took.

Replication

The tender runs on the peer whose coordinator leads, every 2 seconds. Once three data servers exist, it raises every keyspace below a replication factor of 3 to 3, and logs embedded: replication factor raised. It skips 2 on purpose: oxia's majority of two copies is two, so a two-copy shard needs both for every write and gains no availability. It never lowers the factor, because a server that leaves is a failure or a decommission, not a request for less durability. A data server that oxia is draining or has drained does not count toward the three.

Removing a data server

nova node decommission removes the node's data server through the leading coordinator, which starts oxia's drain: the coordinator moves the server's copies to other servers. The removal returns at once, so the command reads the server's state:

  • DRAINED, or no longer listed once oxia would call it drained: the removal is done.
  • Anything else: ErrStillDraining, with how many copies are left. nova node decommission exits 3, or asks again every 5 seconds with --wait.
  • A removal that would leave fewer servers than the replication factor is refused with ErrBelowReplication.

A detached star, one leaving embedded oxia during a move to external oxia, removes its own data server the same way. It asks every 5 seconds until oxia has drained the server, and logs embedded: oxia refuses to release this star's data server until more servers are attached once if the removal is refused.

The tender then forgets drained servers, at most 8 a pass. A server that stays draining for 30 minutes most likely holds a copy oxia cannot move, such as the only copy of a shard. The tender logs embedded: data server draining past the bound once for it. The nova.oxia.server.draining gauge counts the servers oxia is draining, and nova.oxia.server.draining.age gives the oldest one's age.

Splitting shards by measured load

Oxia splits a shard forever, so splits follow measured load. Every star and auditor counts its metadata operations in a histogram of 4,096 buckets over oxia's 32-bit hash ring, by the hash of each operation's locality key. Nodes publish the histograms in their stats records. The split arithmetic in internal/kv/oxia/embedded/heat merges them, slices the load by shard, and splits a hot shard at its load-weighted median. A streams shard is hot when it stays above 60% of 2,000 operations per second for 10 minutes.

When one histogram bucket carries more than half a shard's load, a median cut cannot divide it. The bucket is isolated on a shard of its own instead. Continued heat there points to one hot stream that no further split can fix.

A shard hot past the window raises one Warn line, embedded: shard hot past the window, and the nova.oxia.server.hot_shards gauge until it cools. On Kubernetes the controller cuts the shard. On machines a person does, with nova oxia hot and nova oxia split.

Crash points

Every founding step checks before it acts, so a node that restarts runs the same steps again and converges.

Crash afterState left behindWhat the re-run does
The data server registeredNo keyspacesRegisters again and creates all five in order
Some keyspaces createdThe first keyspaces, with their shard IDsFinds those, and creates the rest in the same order, so no shard ID moves
Every keyspace createdShards that may still lack a leaderWaits again until every shard has one
A removal asked forA data server drainingAsks again; a server already out of the configuration answers not found, and the command reads the drain afresh

Concurrency

Several nodes may start at once. Each goes through the leading coordinator, and a create that finds its namespace already made is accepted, so racing nodes agree on one founding. Only the leading peer runs the tender, so replication changes and forgets come from one place.

Oxia places a new namespace's shards across every data server registered at that moment. That matters when a standalone node grows into a cluster. Its directory already holds the founding shard IDs. If the other nodes register before the founding is placed on the old node, shards land on servers with no data and are elected empty. Their records are lost. The growth is safe when the other nodes start only after the first one is serving again, or after a one-peer restart. Grow a standalone node into a cluster gives the steps.

To move the metadata to an external oxia, an operator first attaches the external data servers with nova oxia attach; Moving the metadata store out gives the procedure.

Bounds and signals

BoundValue
Founding shardsstreams 4, queues 4, sessions 8, registry 1, dispatch 4; --oxia-server-shards raises them
Replication factor1 at founding, then 3 once three data servers exist; never 2, never lowered
Tender passEvery 2 seconds, on the leading peer
Drained servers forgottenAt most 8 a pass
Draining alarmAfter 30 minutes
Hot shardAbove 60% of 2,000 operations per second for 10 minutes
Load histogram4,096 buckets over the 32-bit hash ring; a bucket above half a shard's load is isolated
SignalShows
embedded: initialising metadata, metadata initialisation completeA node founding or joining, with its role and shard plan
embedded: coordinator leading, coordinator leadership lostWhich peer runs the tender
embedded: replication factor raisedThe tender raising a keyspace to 3
embedded: shard hot past the window, shard split, shard cooledHeat and splits
nova.oxia.server.hot_shardsStreams shards hot past the window
nova.oxia.server.draining, nova.oxia.server.draining.ageData servers oxia is draining, and the oldest one's age

Tests

  • embedded_test.go: TestMetadataInitializationReportsShardsAndCompletion, TestStandaloneOxiaSurvivesRestart.
  • cluster_test.go: TestReplicationFactorRisesAtTheThirdStar, TestRemoveTakesAStarOutOfOxia, TestRemoveRefusesToFallBelowTheReplicationFactor, TestSplitShardDividesAStreamsShard, TestHotShardsAndTheChosenSplitPoint.
  • drain_internal_test.go: TestRemovalIsDoneOnlyOnceOxiaDrainedTheServer, TestAStillDrainingRemovalCountsTheReplicasLeft.
  • tender_test.go and tender_internal_test.go: TestTenderRaisesTheAlarmForAShardHotPastTheWindow, TestTenderForgetsABoundedBatchAPass, TestTenderRaisesTheAlarmOnAServerDrainingPastTheBound.
  • upgrade_test.go: TestStandaloneDirectoryUpgradesToClusterModeInPlace. stages_test.go: TestDetachedStarsLeaveTheirDataToAttachedServers, TestStageTwoMovesTheCoordinatorToExternalPeers.
  • heat/heat_test.go: TestSplitPointDividesLoad, TestSplitPointBracketsConcentration.

See also

On this page