Documentation
¶
Index ¶
- type DiffFile
- type PendingDiff
- type PendingFileRef
- type SeqState
- type Snapshot
- type Storage
- func (s *Storage) AppendTransactionLog(entry *TransactionLogEntry) error
- func (s *Storage) CurrentSeqState() (*SeqState, error)
- func (s *Storage) DeletePending(virtualPath string, txSeq int64) error
- func (s *Storage) DeleteSnapshot(virtualPath string, commitCount int64) error
- func (s *Storage) DeleteTransactionState(transactionID string) error
- func (s *Storage) EnsurePathDir(virtualPath string) error
- func (s *Storage) FilesystemToPath(fsPath string) string
- func (s *Storage) FindNearestSnapshot(virtualPath string, targetCommitCount int64) (int64, error)
- func (s *Storage) ListDiffs(virtualPath string) ([]struct{ ... }, error)
- func (s *Storage) ListSnapshots(virtualPath string) ([]int64, error)
- func (s *Storage) NextCommitCount() (int64, error)
- func (s *Storage) NextTxSeq() (int64, error)
- func (s *Storage) PathToFilesystem(virtualPath string) string
- func (s *Storage) ReadDiff(virtualPath string, commitCount, txSeq int64, pending bool) (*DiffFile, error)
- func (s *Storage) ReadSnapshot(virtualPath string, commitCount int64) (*Snapshot, error)
- func (s *Storage) ReadTransactionLog(minCommitCount *int64) ([]*TransactionLogEntry, error)
- func (s *Storage) ReadTransactionState(transactionID string) (*TransactionState, error)
- func (s *Storage) RecoverTransactions() error
- func (s *Storage) RenamePendingToDiff(virtualPath string, newCommitCount, txSeq int64) error
- func (s *Storage) Root() string
- func (s *Storage) UpdateTransactionState(transactionID string, updateFn func(*TransactionState)) error
- func (s *Storage) WriteDiff(virtualPath string, commitCount, txSeq int64, timestamp string, diff *ir.Node, ...) error
- func (s *Storage) WriteDiffAtomically(virtualPath string, timestamp string, diff *ir.Node, pending bool) (commitCount, txSeq int64, err error)
- func (s *Storage) WriteSnapshot(virtualPath string, commitCount int64, state *ir.Node) error
- func (s *Storage) WriteTransactionState(state *TransactionState) error
- type TransactionLogEntry
- type TransactionState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiffFile ¶
type DiffFile struct {
Seq int64
Path string
Timestamp string
Diff *ir.Node
Pending bool // true for .pending files, false for .diff files
}
DiffFile represents a diff file on disk.
type PendingDiff ¶
type PendingDiff struct {
Path string
DiffFile string // Full filesystem path to the .pending file
WrittenAt string // RFC3339 timestamp
}
PendingDiff represents a pending diff in a transaction.
type PendingFileRef ¶
PendingFileRef references a pending file that needs to be renamed.
type SeqState ¶
type SeqState struct {
CommitCount int64 // Monotonic commit count
TxSeq int64 // Transaction sequence number
}
SeqState represents the sequence number state.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage provides filesystem-based storage for logd.
func Open ¶
Open opens or creates a Storage instance with the given root directory. The root directory will be created if it doesn't exist. umask is applied to directory permissions (e.g., 022 for 0755 -> 0755). If logger is nil, slog.Default() will be used.
func (*Storage) AppendTransactionLog ¶
func (s *Storage) AppendTransactionLog(entry *TransactionLogEntry) error
AppendTransactionLog appends a transaction commit log entry atomically.
func (*Storage) CurrentSeqState ¶
CurrentSeqState returns the current sequence state without incrementing.
func (*Storage) DeletePending ¶
DeletePending deletes a .pending file.
func (*Storage) DeleteSnapshot ¶
DeleteSnapshot deletes a snapshot file.
func (*Storage) DeleteTransactionState ¶
DeleteTransactionState deletes a transaction state file.
func (*Storage) EnsurePathDir ¶
EnsurePathDir ensures the directory for a virtual path exists.
func (*Storage) FilesystemToPath ¶
FilesystemToPath converts a filesystem directory path back to a virtual document path. Example: "/logd/paths/proc/processes" -> "/proc/processes"
func (*Storage) FindNearestSnapshot ¶
FindNearestSnapshot finds the nearest snapshot with commit count <= targetCommitCount. Returns 0 if no snapshot exists.
func (*Storage) ListDiffs ¶
ListDiffs lists all committed diff files for a path, ordered by commit count. Only returns .diff files, not .pending files. Returns a slice of (commitCount, txSeq) pairs.
func (*Storage) ListSnapshots ¶
ListSnapshots lists all snapshot commit counts for a path, ordered by commit count.
func (*Storage) NextCommitCount ¶
NextCommitCount atomically increments and returns the next commit count.
func (*Storage) NextTxSeq ¶
NextTxSeq atomically increments and returns the next transaction sequence number.
func (*Storage) PathToFilesystem ¶
PathToFilesystem converts a virtual document path to a filesystem directory path. Example: "/proc/processes" -> "/logd/paths/proc/processes"
func (*Storage) ReadDiff ¶
func (s *Storage) ReadDiff(virtualPath string, commitCount, txSeq int64, pending bool) (*DiffFile, error)
ReadDiff reads a diff file from disk. For pending files, commitCount is ignored (can be 0).
func (*Storage) ReadSnapshot ¶
ReadSnapshot reads a snapshot file from disk.
func (*Storage) ReadTransactionLog ¶
func (s *Storage) ReadTransactionLog(minCommitCount *int64) ([]*TransactionLogEntry, error)
ReadTransactionLog reads transaction log entries. If minCommitCount is nil, reads all entries. If minCommitCount is provided, uses binary search to find entries at or after that commit count.
func (*Storage) ReadTransactionState ¶
func (s *Storage) ReadTransactionState(transactionID string) (*TransactionState, error)
ReadTransactionState reads a transaction state file from disk.
func (*Storage) RecoverTransactions ¶
RecoverTransactions replays the transaction log to complete any partial commits.
func (*Storage) RenamePendingToDiff ¶
RenamePendingToDiff atomically renames a .pending file to .diff file with new commit count.
func (*Storage) UpdateTransactionState ¶
func (s *Storage) UpdateTransactionState(transactionID string, updateFn func(*TransactionState)) error
UpdateTransactionState updates an existing transaction state file.
func (*Storage) WriteDiff ¶
func (s *Storage) WriteDiff(virtualPath string, commitCount, txSeq int64, timestamp string, diff *ir.Node, pending bool) error
WriteDiff writes a diff file. For atomic sequence allocation and file writing, use WriteDiffAtomically instead.
func (*Storage) WriteDiffAtomically ¶
func (s *Storage) WriteDiffAtomically(virtualPath string, timestamp string, diff *ir.Node, pending bool) (commitCount, txSeq int64, err error)
WriteDiff writes a diff file to disk. commitCount should be 0 for pending files, and the actual commit count for committed files. If pending is true, writes as .pending file; otherwise writes as .diff file. WriteDiffAtomically atomically allocates sequence numbers and writes the diff file. This ensures that files are written in the order that sequence numbers are allocated, preventing race conditions where a later sequence number is written before an earlier one.
func (*Storage) WriteSnapshot ¶
WriteSnapshot writes a snapshot file atomically.
func (*Storage) WriteTransactionState ¶
func (s *Storage) WriteTransactionState(state *TransactionState) error
WriteTransactionState writes a transaction state file to disk.
type TransactionLogEntry ¶
type TransactionLogEntry struct {
CommitCount int64 // Commit count assigned to this transaction
TransactionID string
Timestamp string // RFC3339 timestamp
PendingFiles []PendingFileRef
}
TransactionLogEntry represents a transaction commit log entry.
func NewTransactionLogEntry ¶
func NewTransactionLogEntry(commitCount int64, transactionID string, pendingFiles []PendingFileRef) *TransactionLogEntry
NewTransactionLogEntry creates a new TransactionLogEntry.
type TransactionState ¶
type TransactionState struct {
TransactionID string
ParticipantCount int
ParticipantsReceived int
Status string // "pending", "committed", "aborted"
CreatedAt string // RFC3339 timestamp
Diffs []PendingDiff
}
TransactionState represents the state of a transaction.
func NewTransactionState ¶
func NewTransactionState(transactionID string, participantCount int) *TransactionState
NewTransactionState creates a new TransactionState with the given transaction ID and participant count.