Documentation
¶
Index ¶
Constants ¶
const LockFileName = ".oddk.lock"
LockFileName is the advisory lock guarding a data directory. Both the daemon and 'snapshot apply' take it, so the two can never operate on the same deployment concurrently.
Variables ¶
This section is empty.
Functions ¶
func OpenAuthOnly ¶
OpenAuthOnly opens an EXISTING oddk database for the narrow purpose of managing CLI auth tokens from a separate process (the `oddk auth` commands). Unlike NewStore it runs no migrations and no startup writes - those belong to the daemon and would race (and MustExec-panic) against a running daemon. A busy_timeout lets the single token INSERT wait out the daemon's writer lock rather than failing immediately. The caller must Close the returned *sqlx.DB.
Types ¶
type DataDirLock ¶ added in v0.1.59
type DataDirLock struct {
// contains filtered or unexported fields
}
DataDirLock is an exclusive advisory lock on a data directory.
func AcquireDataDirLock ¶ added in v0.1.59
func AcquireDataDirLock(dataDir string) (*DataDirLock, error)
AcquireDataDirLock takes an exclusive, non-blocking flock on <dataDir>/.oddk.lock.
This is what actually prevents two writers. A point-in-time port probe cannot: the systemd unit sets Restart=always/RestartSec=5, so a daemon that is killed rather than stopped returns within seconds — possibly mid-apply, at which point both processes drive Docker and write oddk.db, and the daemon's startup sweep force-removes the helper containers the restore is using.
flock is released by the kernel when the process exits or the fd closes, so unlike a lock row in SQLite it cannot be left stale by a crash or a SIGKILL.
func (*DataDirLock) Release ¶ added in v0.1.59
func (l *DataDirLock) Release()
Release drops the lock. Safe to call more than once.
type Store ¶
type Store struct {
Sqlx *sqlx.DB
Auth *auth.AuthStore
Instances *instances.InstanceStore
Backup *backup.BackupStore
Cron *cron.CronStore
Notifications *notifications.NotificationStore
Parameters *parameters.ParameterStore
Health *health.HealthStore
KV *kvstore.KVStore
Offsite *offsite.OffsiteStore
Snapshot *snapshot.SnapshotStore
}
func NewStore ¶
NewStore opens (creating if needed) the ODDK database and migrates it.
masterKey is the 32-byte key from {dataDir}/master.key. It is required, not optional: the notification store encrypts its `config` column with it, and a store built without one could only fall back to writing those credentials in cleartext — the failure this parameter exists to make impossible.
func (*Store) AppliedMigrations ¶ added in v0.1.59
AppliedMigrations returns the names of migrations applied to this store, in application order. A snapshot records these so a restore can reason about schema compatibility more precisely than a version string allows.
func (*Store) VacuumInto ¶ added in v0.1.59
VacuumInto writes a consistent copy of the store to path using SQLite's VACUUM INTO. It is safe against a live database — SQLite serialises it with other work — so a snapshot can be taken without stopping the daemon. The destination must not already exist.
The copy is also compacted, which matters because a snapshot embeds it.