indexdb

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIndexDBSchemaIncompatible is returned when the index db schema is incompatible.
	ErrIndexDBSchemaIncompatible = errkind.SentinelError("index db schema is incompatible")
)

Functions

func NormalizeVirtualPath

func NormalizeVirtualPath(p string) string

NormalizeVirtualPath converts a user-provided virtual path into a stable DB key. It removes leading slashes, cleans dot segments, and returns "" for root.

func QueryStaleCount

func QueryStaleCount(mountName string, storageID string) (int64, error)

QueryStaleCount returns the number of stale (deleted=2) files for a storage. Returns 0 if the DB file does not exist.

func Reset

func Reset(mountName string) error

Reset deletes the per-mount index database so the next Open creates a fresh one.

Types

type DB

type DB struct {
	MountName string
	Path      string
	// contains filtered or unexported fields
}

DB provides access to the per-mount index database.

func Open

func Open(mountName string) (*DB, error)

Open opens (or creates) the per-mount SQLite database and applies migrations.

func (*DB) Close

func (d *DB) Close() error

Close checkpoints the WAL and closes the underlying SQL database.

TRUNCATE checkpoint flushes all committed WAL frames to the main DB file and resets the WAL to zero length. This ensures cross-process visibility in environments where WAL-index (SHM) mmap sharing is unreliable (e.g. Docker with VirtioFS bind mounts).

func (*DB) DirExists

func (d *DB) DirExists(ctx context.Context, storageID string, path string) (bool, error)

DirExists reports whether a directory exists in index DB.

func (*DB) FinalizeDelete

func (d *DB) FinalizeDelete(ctx context.Context, storageID string, p string, isDir bool) error

FinalizeDelete removes rows that were previously marked deleted=1 after physical deletion succeeded.

func (*DB) FinalizeRename

func (d *DB) FinalizeRename(ctx context.Context, storageID string, oldPath string, newPath string) error

FinalizeRename updates real_path to match the new on-disk location after physical rename succeeded.

It also ensures virtual paths (path/parent_dir/name) are at their new values. This is normally a no-op because RenamePath already set them during the FUSE operation, but acts as a safety net when the daemon's WAL commit is not yet visible to the prune process (e.g. cross-process WAL visibility lag on overlayfs).

func (*DB) FinalizeSetattr

func (d *DB) FinalizeSetattr(ctx context.Context, storageID string, p string) error

FinalizeSetattr clears file_meta overrides after they have been applied physically.

func (*DB) GetEffectiveFile

func (d *DB) GetEffectiveFile(ctx context.Context, storageID string, path string) (File, bool, error)

GetEffectiveFile returns a row merged with any file_meta overrides.

func (*DB) ListDirEntries

func (d *DB) ListDirEntries(ctx context.Context, storageID string, dirPath string) ([]DirEntry, bool, error)

ListDirEntries lists immediate children under a directory path, including subdirectories.

func (*DB) MarkDeleted

func (d *DB) MarkDeleted(ctx context.Context, storageID string, p string, isDir bool) (bool, error)

MarkDeleted soft-deletes a file or directory (optionally its subtree) by setting deleted=1. It enforces POSIX-ish semantics from the mounted view (ENOENT/ENOTEMPTY/ENOTDIR/EISDIR).

func (*DB) Ping

func (d *DB) Ping(ctx context.Context) error

Ping validates DB connectivity.

func (*DB) RenamePath

func (d *DB) RenamePath(ctx context.Context, storageID string, oldPath string, newPath string) (bool, error)

RenamePath updates virtual paths in the DB and records a pending physical rename by keeping real_path. It supports directory renames by rewriting the subtree.

func (*DB) SQL

func (d *DB) SQL() *sql.DB

SQL returns the underlying sql.DB.

func (*DB) UpsertFile

func (d *DB) UpsertFile(ctx context.Context, storageID string, p string, isDir bool, sizeBytes *int64, mtimeSec int64, mode uint32, uid uint32, gid uint32) error

UpsertFile upserts a file/dir entry while preserving last_seen_run_id for existing rows.

For new rows, it sets last_seen_run_id to the current indexer_state.current_run_id when available. It never resurrects deleted=1 tombstones; such conflicts are returned as syscall.EBUSY. It also ensures all parent directories exist as is_dir entries so the file becomes visible immediately via DB-backed lookup/readdir.

func (*DB) UpsertMeta

func (d *DB) UpsertMeta(ctx context.Context, storageID string, p string, mode *uint32, uid *uint32, gid *uint32, mtimeSec *int64) (bool, error)

UpsertMeta writes file_meta overrides for SETATTR without touching the physical filesystem. Any nil field is treated as "no change".

type DirEntry

type DirEntry struct {
	Name string
	Mode uint32
}

DirEntry describes one directory entry returned from DB-backed READDIR.

type File

type File struct {
	StorageID string
	Path      string
	RealPath  string
	IsDir     bool
	Size      int64
	MTimeSec  int64
	Mode      uint32
	UID       uint32
	GID       uint32
}

File describes one indexed filesystem entry.

type IndexerStateRow

type IndexerStateRow struct {
	StorageID      string
	CurrentRunID   int64
	LastCompleted  *int64 // unix timestamp, nil if never completed
	LastDurationMS *int64
	FileCount      *int64
	TotalBytes     *int64
}

IndexerStateRow holds summary stats from the indexer_state table.

func QueryIndexerState

func QueryIndexerState(mountName string, storageID string) (*IndexerStateRow, error)

QueryIndexerState opens the index DB read-only and returns indexer_state for a storage. Returns nil (no error) if the DB file does not exist or the storage has no row.

type InspectFileRow

type InspectFileRow struct {
	StorageID     string
	Path          string
	RealPath      string
	IsDir         bool
	Size          *int64
	MTimeSec      int64
	Mode          uint32
	UID           uint32
	GID           uint32
	Deleted       int    // 0=live, 1=pending-delete, 2=stale
	LastSeenRunID *int64 // which indexer run last saw this entry

	// file_meta overrides (nil = no override active).
	MetaMTime *int64
	MetaMode  *uint32
	MetaUID   *uint32
	MetaGID   *uint32

	// From indexer_state (for correlating last_seen_run_id).
	CurrentRunID  int64
	LastCompleted *int64 // unix timestamp of last completed index run
}

InspectFileRow holds raw and meta-overlay data for one file entry. Unlike GetEffectiveFile, it does NOT filter by deleted status and searches across all storages for a given path.

func QueryFileInspect

func QueryFileInspect(mountName string, path string) ([]InspectFileRow, error)

QueryFileInspect opens the index DB read-only and returns all rows matching the given path across ALL storages, regardless of deleted status. It joins file_meta for overrides and indexer_state for run correlation. Returns nil (no error) if the DB file does not exist.

type VirtualChildEntry

type VirtualChildEntry struct {
	Name  string
	IsDir bool
}

VirtualChildEntry describes one virtual directory child entry.

func QueryVirtualChildren

func QueryVirtualChildren(mountName string, dirPath string, namePrefix string, limit int) ([]VirtualChildEntry, error)

QueryVirtualChildren lists distinct child entries under dirPath across all storages. Returns nil (no error) if the DB file does not exist.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL