Repository navigation
Conversation
The record log port now lives in internal/recordlog, as ADR-0091 decides: the Log port, its Reader and Stats, the Holding state whose zero value is unknown, the segment and manifest types, and the port's refusals. The package imports no file-system package. internal/segmentlog is the segments kind behind it: Open and Inspect take a recordlog.Config, refuse the zero kind, and read lines back through the directory handle the writer holds, failing the log on any mismatch. internal/trailfile names the kind in one place and reads export, cursors and reindex through the Reader; an unknown holding state is an error, never free. trail segments prints from Stats and says unknown where another process cannot see the writer's bounds. Conformance cases 10 to 13 join the port's suite, each with its negative control. Signed-off-by: Konrad Karauda <konrad@karauda.com>
…sees A segment others may write now fails a read-back in segmentlog and refuses a repeat in trailfile; both tests kill the mutant that swaps the checked open for a plain one. The import check drops a case that could only ever be an import cycle. Reader.Stats says which numbers are the writer's and unknown to a reader, never a measured zero. Signed-off-by: Konrad Karauda <konrad@karauda.com>
A reader asked only the directory's lock file whether a writer held the log. With `segments.lock` unlinked under a running collector, `trail` and `trail export` read its partial line as unheld and reported a `partial_tail` gap, where they had asked the live file's own lock before. Holding now asks both: held when either is held, free only when each is free or absent, unknown when either cannot be asked. It also answers unknown when the directory at the log's path is no longer the one the view inspected, and HeldByWriter is ErrNoLock where the platform has no file lock, so a lock it cannot ask is never read as free. Signed-off-by: Konrad Karauda <konrad@karauda.com>
…ocks ADR-0091 is accepted. The changelog names the read-back's file checks, the line `trail segments` adds, the lock a holding is asked of and the `recordlog:` refusals. The watch guide, the glossary, the status rows, the export contract and B14's acceptance say what the port is, what a reader sees and what stays open; two pages cover internal/recordlog. Signed-off-by: Konrad Karauda <konrad@karauda.com>
Holding asks segments.lock first and the live segment's lock beside it: held when either is held, unknown when the directory's lock cannot be asked or the directory at the log's path is no longer the one inspected. OpenLive's contract now says the live file is locked, so a second writer is refused even with the directory's lock file unlinked. Signed-off-by: Konrad Karauda <konrad@karauda.com>
Signed-off-by: Konrad Karauda <konrad@karauda.com>
Signed-off-by: Konrad Karauda <konrad@karauda.com> # Conflicts: # CHANGELOG.md # site/docs/changelog.html
A writer takes an exclusive lock on the log directory itself, through the directory it judged, before segments.lock, and holds it until it closes. No unlink or replace of a name in the directory drops it, so a second writer, a prune beside a running collector included, is refused whether or not a live segment exists. Holding asks that lock first, through the directory it inspected, then segments.lock and the live segment's lock: held when any is held, free only when every lock asked is free. Once OpenLive returns, the log opens the live file again and refuses it unless a writer holds its lock (ErrLiveUnlocked): an open is refused, an append fails the log. The package's test opener locks, so the conformance suite no longer passes an opener that does not. Signed-off-by: Konrad Karauda <konrad@karauda.com>
…directory check A live file whose lock the check cannot ask is refused with that error, not as unlocked, so an append does not fail the log for good on a passing open failure. A test pins that a copy of the log put at its path reads as unknown to a reader that inspected the original. Signed-off-by: Konrad Karauda <konrad@karauda.com>
…e upgrade order Signed-off-by: Konrad Karauda <konrad@karauda.com>
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
Signed-off-by: Konrad Karauda <konrad@karauda.com> # Conflicts: # CHANGELOG.md # site/docs/changelog.html
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed, and why
The record log port moves to its consumers in new package
internal/recordlog.Logappends, seals, prunes, reads back written lines and countsStats.Readerreads the manifest, opens segments without a lock and reports whether a writer holds the log as held, free or unknown (never read as free). A test usesgo list -depsto verify no file, OS or kind package imports on linux, darwin and windows.internal/segmentlogis its sole kind,segments.internal/trailfilewrites and reads only through the port, reading no segment file by name. Manifest0.1bytes, the export, cursors, flags and exit codes are unchanged.scripts/ports.txtgains therecord-logrow; conformance cases 10 to 13 intestdata/ports/record-logeach include a negative control.A writer of a directory of segments now holds an exclusive lock on the log directory itself, taken through the directory it judged before
segments.lockand held until it closes, so a second writer (prunebeside a runningcollect) is refused withsegmentlog: the directory is held by another writereven withsegments.lockunlinked or replaced and no live segment. Before, such aprunecould open beside the collector, and the collector's next seal left a log that refused to open.segments.lockstays for readers and writers of earlier builds; stop everycollectandpruneof an earlier version before running this one on the same directory. A file system on which a directory cannot be locked refuses the writer.Whether a writer holds the log is asked of the directory's own lock,
segments.lockand the live segment's lock, in that order. Any held lock answers held; the answer is free only if every lock asked is free, a missing live segment counting as free, and unknown otherwise, including when the path no longer names the inspected directory.trail segmentsexits 1 on unknown;trailandtrail exportrefuse the same way when the live segment ends in a partial line.Options.OpenLivemust lock the live file it returns, as trailfile's does; the kind opens the file again and asks its lock, and refuses an unlocked one withsegmentlog: the live file was opened and not locked(an open is refused; at an append, the log fails).collectreads resent records back through its open directory, judging each segment file as on write (regular file, not a link, owner, mode). A segment file another account could write fails the log on resend;collectrefuses that record and later appends until reopened.trail segmentsprints a third line,kind=segments max_line_bytes=786432 segment_bytes=unknown max_bytes=unknown budget_refusals=unknown. Byte bounds and budget refusals belong to the collector and another process cannot see them, so they printunknown, never 0. Shared log refusals startrecordlog:; kind-only ones keepsegmentlog:.Invariant or record
ADR-0091 is accepted, resolving ADR-0072's "interface beside the kind". Invariants 4 and 5: unknown holding refuses, never reads as free.
How it was tested
internal/recordlog,internal/segmentlog,internal/trailfile,internal/docscheckandcmd/guardana-gateway. New tests:TestASecondWriterIsRefusedWithTheLockFileUnlinkedAndNoLiveFile,TestAPruneBesideAnOpenWriterIsRefused,TestAReplacedLockFileWithNoLiveFileReadsHeld,TestAReplacedLockAndLiveFileReadHeld,TestAnOpenerThatDoesNotLockTheLiveFileIsRefused,TestACopyOfTheLogAtItsPathIsUnknown,TestAWriterHoldsTheLogThroughEitherLock,TestAHeldDirectoryLockIsHeldWhateverTheLiveFile,TestAHoldingThatCannotBeAskedIsUnknown,TestAReadBackOfASegmentOthersMayWriteFailsTheLogand trailfile'sTestAnUnlinkedDirectoryLockLeavesALiveWritersTailHeld.osimported ininternal/recordlog, directory identity check dropped, the writer's directory lock not taken, holding not asking it, the live-file lock check off. Each new one-writer test was red on the commit before the directory lock.internal/segmentlogandinternal/trailfilepassed, including the directory lock's tests; flock on a directory descriptor was checked on darwin and linux before building on it. The other failures there lack thegobinary orgo.mod. The last change (an unaskable live lock reported as it is, and the directory-copy test) was not run on Linux.go vet.make vet,go vet -tags twoaccounts,golangci-lintdarwin andGOOS=linux,gofmt,make check-sizes,scripts/check-brand.shandmake docs-checkpassed.make qualitywas not verified; CI'smake qualityon this pull request is the gate.Documentation
Updated ADR-0091 (accepted),
docs/contracts.md(port, the three locks),docs/status.md(trail-collector details),docs/guides/watch-a-plane-without-a-collector.md,docs/reference/cli.md(third line; covers),docs/concepts/glossary.md,docs/backlog.md(B14 item removed), CHANGELOG Security, Changed and Fixed entries; ADR-0091 states the directory lock, the OpenLive check and the upgrade order. Gateway pages listed bymake docs-impactwere read; none states locks, the third line or refusal text.