Add basic POSIX mirror tree support#1017
Conversation
692034b to
c21f4be
Compare
| if err := unlock(); err != nil { | ||
| panic(err) | ||
| } | ||
| m.s.mu.Unlock() |
There was a problem hiding this comment.
Same comment as the previous pull request. Immediately defer the mutex unlock after it is locked.
There was a problem hiding this comment.
d'oh, this was grandfathered in. Fixed.
|
|
||
| lh := make([][]byte, 0, maxBundles) | ||
| n := 0 | ||
| for ri := range layout.Range(from, to, sourceSize) { |
There was a problem hiding this comment.
| for ri := range layout.Range(from, to, sourceSize) { | |
| for ri := range layout.Range(from, to - from, sourceSize) { |
Lines 45 to 49 in 20980b0
There was a problem hiding this comment.
Good spot, fixed, and factored this func out to be shared with MigrationTarget too (which was also affected).
| return 0, nil, errors.New("unimplemented") | ||
| targetSize := bundleIdx * layout.EntryBundleWidth | ||
| for b := range bundles { | ||
| p := len(b.Entries) |
There was a problem hiding this comment.
If the number of entries is 0, it will be treated as a full tile writing empty bundle data to the full tile file.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This function is public, so just in case.
| // 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)) |
There was a problem hiding this comment.
Note that this preallocation would consume around 16 MiB for a full bundle.
There was a problem hiding this comment.
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.
| func (m *MirrorWriter) fetchLeafHashes(ctx context.Context, from, to, sourceSize uint64) ([][]byte, error) { | ||
| const maxBundles = 300 | ||
|
|
||
| lh := make([][]byte, 0, maxBundles) |
There was a problem hiding this comment.
There are 256 hashes in one bundle. Should this be maxBundles * layout.EntryBundleWidth instead of maxBundles?
There was a problem hiding this comment.
Good catch, updated.
7944162 to
bc70fd3
Compare
bc70fd3 to
f13ce01
Compare
| defer m.s.mu.Unlock() | ||
| unlock, err := m.s.lockFile(ctx, treeStateLock) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
If the ctx is cancelled or timed out, this will trigger the panic.
There was a problem hiding this comment.
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.
| return 0, nil, errors.New("unimplemented") | ||
| targetSize := bundleIdx * layout.EntryBundleWidth | ||
| for b := range bundles { | ||
| p := len(b.Entries) |
There was a problem hiding this comment.
This function is public, so just in case.
This PR adds a first cut at fleshing out the POSIX storage support for MTC mirrors.
Towards #945