Skip to content

Add basic POSIX mirror tree support#1017

Merged
AlCutter merged 2 commits into
transparency-dev:mainfrom
AlCutter:posix_mirror_tree_support
Jun 25, 2026
Merged

Add basic POSIX mirror tree support#1017
AlCutter merged 2 commits into
transparency-dev:mainfrom
AlCutter:posix_mirror_tree_support

Conversation

@AlCutter

@AlCutter AlCutter commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This PR adds a first cut at fleshing out the POSIX storage support for MTC mirrors.

Towards #945

@AlCutter AlCutter requested a review from roger2hk June 23, 2026 11:20
@AlCutter AlCutter force-pushed the posix_mirror_tree_support branch 4 times, most recently from 692034b to c21f4be Compare June 24, 2026 11:56
@AlCutter AlCutter changed the title Add POSIX mirror tree support Add basic POSIX mirror tree support Jun 24, 2026
@AlCutter AlCutter marked this pull request as ready for review June 24, 2026 12:16
@AlCutter AlCutter requested a review from a team as a code owner June 24, 2026 12:16
Comment thread storage/posix/files.go Outdated
if err := unlock(); err != nil {
panic(err)
}
m.s.mu.Unlock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as the previous pull request. Immediately defer the mutex unlock after it is locked.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh, this was grandfathered in. Fixed.

Comment thread storage/posix/files.go Outdated

lh := make([][]byte, 0, maxBundles)
n := 0
for ri := range layout.Range(from, to, sourceSize) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ri := range layout.Range(from, to, sourceSize) {
for ri := range layout.Range(from, to - from, sourceSize) {

// Range returns an iterator over a list of RangeInfo structs which describe the bundles/tiles
// necessary to cover the specified range of individual entries/hashes `[from, min(from+N, treeSize) )`.
//
// If from >= treeSize or N == 0, the returned iterator will yield no elements.
func Range(from, N, treeSize uint64) iter.Seq[RangeInfo] {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, fixed, and factored this func out to be shared with MigrationTarget too (which was also affected).

Comment thread storage/posix/files.go
return 0, nil, errors.New("unimplemented")
targetSize := bundleIdx * layout.EntryBundleWidth
for b := range bundles {
p := len(b.Entries)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the number of entries is 0, it will be treated as a full tile writing empty bundle data to the full tile file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this could happen in a valid request, but added a check to be defensive.
Also added a check that we can't get partial sized bundles mid-stream.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is public, so just in case.

Comment thread storage/posix/files.go
// marshalTlogEntryBundle returns a tlog-tiles compatible serialization of the provided entrybundle.
func marshalTlogEntryBundle(b api.EntryBundle) ([]byte, error) {
// Max size we could possibly write out.
data := make([]byte, 0, len(b.Entries)*(2+1<<16))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this preallocation would consume around 16 MiB for a full bundle.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct - I went back and forth on this for a bit, in the end I went with this since it's "only" 16MB, and there should only really ever ~one "live" alloc of this per mirror.

Left a comment about it in case we want to go back in the future and change to a more conservative default and let Go's slice reallocator sort it out.

Comment thread storage/posix/files.go Outdated
func (m *MirrorWriter) fetchLeafHashes(ctx context.Context, from, to, sourceSize uint64) ([][]byte, error) {
const maxBundles = 300

lh := make([][]byte, 0, maxBundles)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 256 hashes in one bundle. Should this be maxBundles * layout.EntryBundleWidth instead of maxBundles?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated.

@AlCutter AlCutter force-pushed the posix_mirror_tree_support branch from 7944162 to bc70fd3 Compare June 25, 2026 11:25
@AlCutter AlCutter force-pushed the posix_mirror_tree_support branch from bc70fd3 to f13ce01 Compare June 25, 2026 15:12
Comment thread storage/posix/files.go
defer m.s.mu.Unlock()
unlock, err := m.s.lockFile(ctx, treeStateLock)
if err != nil {
panic(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the ctx is cancelled or timed out, this will trigger the panic.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the comment on the other PR, I'll leave these consistent as panics for now, and we can decide what to do about them in a separate PR.

Comment thread storage/posix/files.go
return 0, nil, errors.New("unimplemented")
targetSize := bundleIdx * layout.EntryBundleWidth
for b := range bundles {
p := len(b.Entries)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is public, so just in case.

@AlCutter AlCutter merged commit 577ff18 into transparency-dev:main Jun 25, 2026
20 checks passed
@AlCutter AlCutter deleted the posix_mirror_tree_support branch June 25, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants