Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental migration support for POSIX #441

Merged
merged 16 commits into from
Jan 14, 2025
Prev Previous commit
Next Next commit
fixes
AlCutter committed Jan 14, 2025
commit 21a5ca26ecf46dfd89fdb5d58f1aa2655a2acb9a
54 changes: 26 additions & 28 deletions api/layout/paths.go
Original file line number Diff line number Diff line change
@@ -63,9 +63,9 @@ func Range(from, N, treeSize uint64) (iter.Seq[RangeInfo], error) {

r := rangeIterator{
startIndex: from / EntryBundleWidth,
startFirst: int(from % EntryBundleWidth),
startFirst: uint(from % EntryBundleWidth),
endIndex: endInc / EntryBundleWidth,
endN: int((endInc)%EntryBundleWidth) + 1,
endN: uint((endInc)%EntryBundleWidth) + 1,
}
if r.startIndex == r.endIndex {
r.endN = r.endN - r.startFirst
@@ -89,20 +89,19 @@ type rangeIterator struct {
startIndex uint64
// startPartial is the expected size of the bundle found at StartIndex.
// If zero, a full bundle is expected to be present.
//
startPartial uint8
// startFirst is the index of the first entry in the `startIndex` bundle to be used.
//
// Once the bundle at `startIndex[.p/startPartial]` has been fetched, the leading
// `startFirst` entries should be discarded.
startFirst int
startFirst uint

// endIndex is the index of the final entry bundle containing part of the range.
endIndex uint64
// endPartial is non-zero if the bundle at endIndex is expected to be partial.
endPartial uint8
// endN is the number of entries from the endIndex bundle to be used. Zero means "all".
endN int
endN uint
}

// iterate returns an iterator over parameters for the bundle(s) in the underlying range:
@@ -118,30 +117,29 @@ type rangeIterator struct {
// indicated, but not found, the caller should attempt to fetch the full bundle instead.
func (r rangeIterator) iterate(yield func(RangeInfo) bool) {
for idx := r.startIndex; idx <= r.endIndex; idx++ {
if !yield(r.at(idx)) {
return
ri := RangeInfo{
Index: idx,
N: EntryBundleWidth,
}
}
}

func (r *rangeIterator) at(idx uint64) RangeInfo {
if idx > r.endIndex {
panic(fmt.Sprintf("RangeInfo called, but all data has been returned."))
}
ret := RangeInfo{
Index: idx,
N: EntryBundleWidth,
}
switch ret.Index {
case r.startIndex:
ret.Partial, ret.First = r.startPartial, r.startFirst
if ret.Index == r.endIndex {
ret.N = r.endN
switch ri.Index {
case r.startIndex:
ri.Partial, ri.First = r.startPartial, r.startFirst
if ri.Index == r.endIndex {
ri.N = r.endN
} else if ri.First > 0 {
w := uint(ri.Partial)
if w == 0 {
w = EntryBundleWidth
}
ri.N = uint(w - ri.First)
}
case r.endIndex:
ri.Partial, ri.N = r.endPartial, r.endN
}
if !yield(ri) {
return
}
case r.endIndex:
ret.Partial, ret.N = r.endPartial, r.endN
}
return ret
}

// RangeInfo describes a specific range of elements within a particular bundle/tile.
@@ -151,9 +149,9 @@ type RangeInfo struct {
// Partial is the partial size of the bundle/tile, or zero if a full bundle/tile is expected.
Partial uint8
// First is the offset into the entries contained by the bundle/tile at which the range starts.
First int
First uint
// N is the number of entries, starting at First, which are covered by the range.
N int
N uint
}

// NWithSuffix returns a tiles-spec "N" path, with a partial suffix if p > 0.
8 changes: 5 additions & 3 deletions api/layout/paths_test.go
Original file line number Diff line number Diff line change
@@ -339,7 +339,7 @@ func TestRange(t *testing.T) {
from: 0,
N: 256,
treeSize: 257,
want: []RangeInfo{},
want: []RangeInfo{{N: 256}},
}, {
desc: "ok: entire single (partial) bundle",
from: 20,
@@ -374,7 +374,7 @@ func TestRange(t *testing.T) {
{Index: 1, Partial: 0, First: 0, N: 256},
{Index: 2, Partial: 0, First: 0, N: 256},
{Index: 3, Partial: 0, First: 0, N: 256},
{Index: 4, Partial: 0, First: 0, N: 4},
{Index: 4, Partial: 0, First: 0, N: 6},
},
}, {
desc: "ok: offset and trucated from single bundle in middle of tree",
@@ -392,10 +392,12 @@ func TestRange(t *testing.T) {
return
}

for i, gotInfo := range gotI {
i := 0
for gotInfo := range gotI {
if d := cmp.Diff(test.want[i], gotInfo); d != "" {
t.Fatalf("got results[%d] with diff:\n%s", i, d)
}
i++
}
})
}