Skip to main content
Version: v3.9.0

Store

The Store module owns the on-disk SQLite database (edgelet.db) under the configured disk directory. It provides typed accessors for Controller cache, local deploy state, service account tokens, runtime container references, and agent credentials. Migrations are embedded and applied idempotently at open.

Code: internal/store/

Operator backup/wipe guidance: Persistence. This document focuses on schema and module boundaries.

Purpose​

  • Single-writer SQLite with WAL mode for daemon durability
  • Versioned schema via embedded SQL migrations
  • CRUD for controller-sourced and locally deployed entities
  • Integrity check on open; WAL checkpoint on close

Dependencies​

Depends onReason
Filesystem{diskDirectory}/edgelet.db
modernc.org/sqlitePure Go SQLite driver
Used byReason
supervisorOpens/closes DB around module lifetime
fieldagentController cache, credentials, Edge Guard
processmanagerLocal workloads, runtime refs, control plane row
runtimeapi / EdgeletAPIDeploy apply, auth tokens, provision, models
modelmanagerLocal model rows and prune refs
edgeguardAttestation signature row
serviceaccountProjected token persistence

Lifecycle​

Open​

store.GetInstance().Open(dir). Called once at Supervisor start:

  1. MkdirAll disk directory (0700)
  2. Open SQLite with _journal_mode=WAL, _foreign_keys=ON
  3. SetMaxOpenConns(1). Single writer
  4. migrate(). Apply pending embedded migrations
  5. PRAGMA integrity_check

Close​

Close(). WAL checkpoint TRUNCATE, then connection close. Invoked last in Supervisor shutdown.

Schema v1​

Baseline migration: migrations/001_edgelet_schema_v1.sql. schema_versions tracks applied version; wipe-only upgrades from pre-v1 agents. No in-place legacy migration.

Controller cache (Field Agent writers)​

TablePurpose
controller_microservicesDesired MS from Controller
controller_registriesRegistry auth
controller_volume_mountsSecrets/configmaps

Agent identity​

TablePurpose
agent_credentialsSingleton Ed25519 private key (id=1)
agent_edgeguard_signatureLast Edge Guard attestation JWT

Local operator state (EdgeletAPI writers)​

TablePurpose
local_workloadsCLI/applied Microservice manifests
local_registriesLocal registry credentials
local_runtime_classesApplied RuntimeClass handler map (source local | managed)
system_control_planeSingleton ControlPlane deployment
local_service_account_tokensIssued SA JWT metadata

Runtime linkage​

TablePurpose
runtime_container_refsMaps MS UUID + scope → containerd workload/sandbox IDs

Schema v2​

In-place migration migrations/002_edgelet_schema_v2.sql (v1 → v2). No wipe.

Table / columnPurpose
local_registries.type, ca_b64, insecureRegistry kind (oci | hf) and TLS
controller_registries.type, ca_b64, insecureSame on controller snapshot
local_modelsLocal Model deploy + pull state
controller_modelsController model snapshot
controller_runtime_classesFleet RuntimeClass snapshot (name PK + handler, replace-all)
local_runtime_classes.sourceApplied class provenance local | managed
model_refsKeep-alive refs for dangling prune

Operator backup of {diskDirectory}/models/: Persistence, Models.

Schema v3​

In-place migration migrations/003_edgelet_schema_v3.sql (v2 → v3). No wipe.

Table / columnPurpose
persistent_volumesOwnership ledger for persistent VOLUME claims (scope private | shared, kind workload | controlplane). Local and controller consumers share this table.

Operator backup of {diskDirectory}/volumes/data/ and {diskDirectory}/volumes/shared/: Persistence, Volumes.

Schema v4​

In-place migration migrations/004_edgelet_schema_v4.sql (v3 → v4). No wipe.

Table / columnPurpose
local_knowledgeLocal Knowledge deploy + pull state (source local | managed)
controller_knowledgeController Knowledge snapshot (uuid PK, unique name)
knowledge_refsKeep-alive refs for dangling prune
controller_microservices.knowledgeCatalog JSON (bindPath, permissions, items[].name)

Operator backup of {diskDirectory}/knowledge/: Persistence, Knowledge.

Access patterns​

Store exposes methods on *DB split by domain file:

FileOperations
microservices.goSave/load/clear controller microservices
registries.goController registries
volumes.goVolume mount upsert/replace
persistent_volumes.goPersistent VOLUME ledger
local_deployed_microservices.goLocal workload CRUD
local_registries.goLocal registry CRUD
local_models.goLocal model CRUD
local_knowledge.goLocal Knowledge CRUD
controller_models.goController model rows
controller_knowledge.goController Knowledge rows
knowledge_refs.goKnowledge catalog bind refs
controller_runtime_classes.goFleet RuntimeClass replace-all
local_runtime_classes.goApplied RuntimeClass CRUD
control_plane_deployments.goControlPlane singleton
service_account_tokens.goSA token upsert/revoke/list
edgeguard_credentials.goEdge Guard signature
runtime_container_refs (in schema)Accessed from processmanager/runtime paths

Handlers should not use Conn() directly except in tests; prefer typed store methods to keep SQL centralized.

Configuration​

KeyEffect
diskDirectoryDirectory containing edgelet.db (default under /var/lib/edgelet/)

External APIs​

No network surface. Data reaches operators via EdgeletAPI (GET /v1/ms, deploy list routes) and CLI.

Observability​

  • Log module name: "SQLite Store"
  • Migration apply logs at INFO per version
  • Integrity failure fails daemon start loudly

Failure modes​

SymptomTypical cause
Daemon won't startMigration error, integrity check failure
Empty MS list after provisionField Agent not synced; check controller tables
Duplicate local MS nameUnique index on (application_name, microservice_name)
Token revoke ineffectiveRow still active until revoked_at set

Restore procedure: Persistence.

Code map​

FileRole
db.goSingleton, open/close, integrity
schema.goMigration runner
migrations/*.sqlEmbedded DDL (v1, v2, v3)
*_test.go, schema_v1_contract_test.go, schema_v2_test.go, persistent_volumes_test.goContract tests

Related: Field agent, Process manager, Edgelet API module.

Group 3See anything wrong with the document? Help us improve it!