Documentation
¶
Overview ¶
Package sync provides cross-machine observation sync via PostgreSQL.
Index ¶
- func ApplyMutation(ctx context.Context, engramAPI string, m RemoteMutation) error
- func ConnectPG(ctx context.Context, dsn string) (*pgx.Conn, error)
- func Pull(ctx context.Context, pgConn *pgx.Conn, cfg *config.Config, logger *slog.Logger) (applied int, cursor int64, err error)
- func Push(ctx context.Context, sqliteDB *sql.DB, pgConn *pgx.Conn, cfg *config.Config, ...) (pushed int, highWater int64, err error)
- func PushCursorFile() string
- func ReadCursor(ctx context.Context, pgConn *pgx.Conn, machineID string) (int64, error)
- func ReadPushCursor(path string) (int64, error)
- func SDNotify(state string) bool
- func UpdateCursor(ctx context.Context, pgConn *pgx.Conn, machineID string, seq int64) error
- func WatchdogLoop(ctx context.Context)
- func WritePushCursor(path string, seq int64) error
- type Daemon
- type Mutation
- type RemoteMutation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyMutation ¶
func ApplyMutation(ctx context.Context, engramAPI string, m RemoteMutation) error
ApplyMutation applies a single mutation to the local engram instance via its HTTP API.
func Pull ¶
func Pull(ctx context.Context, pgConn *pgx.Conn, cfg *config.Config, logger *slog.Logger) (applied int, cursor int64, err error)
Pull fetches new mutations from PG in batches and applies them to the local engram instance. Returns the total number of mutations applied and the final cursor.
func Push ¶
func Push(ctx context.Context, sqliteDB *sql.DB, pgConn *pgx.Conn, cfg *config.Config, logger *slog.Logger) (pushed int, highWater int64, err error)
Push reads new mutations from local SQLite and inserts them into PostgreSQL. Returns the number of mutations pushed and the new high-water mark.
func PushCursorFile ¶
func PushCursorFile() string
PushCursorFile returns the path to the local push cursor file.
func ReadCursor ¶
ReadCursor reads this machine's pull cursor from PostgreSQL.
func ReadPushCursor ¶
ReadPushCursor reads the last pushed seq from the local cursor file.
func SDNotify ¶
SDNotify sends a message to systemd's notification socket. Returns false if NOTIFY_SOCKET is not set (not running under systemd).
func UpdateCursor ¶
UpdateCursor updates this machine's pull cursor in PostgreSQL.
func WatchdogLoop ¶
WatchdogLoop sends WATCHDOG=1 heartbeats to systemd at half the configured WatchdogSec interval. If WATCHDOG_USEC is not set, this is a no-op. Blocks until ctx is canceled.
func WritePushCursor ¶
WritePushCursor writes the push cursor to the local file.
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon runs the sync loop: pushes local mutations to PG and pulls remote mutations via LISTEN/NOTIFY with polling fallback.
type Mutation ¶
type Mutation struct {
Seq int64
TargetKey string
Entity string
EntityKey string
Op string
Payload string
Source string
Project string
OccurredAt string
}
Mutation represents a row from engram's sync_mutations table.