Dropped mroot bit, rely on context to determine mroots

This greatly simplifies mid handling at the cost of increased subtlety
around determining if a given mdir is an mroot.

Fortunately it turns out we can rely on context to determine if an mdir
is an mroot or not:

1. If an mdir's mid.bid == -1, it's an mroot. This is always true for
   fake mroots, since they can't hold any inlined mids.

2. If the mtree is inlined (mtree.weight == 0), all mdirs are mroots.
   This lets us use mid.bid=0 for inlined mids. We just need to check
   if the mtree is inlined before deciding if the mdir is an mroot or
   not.

The makes it so that for any non-mroot mdir, mid.bid=-1 is always a
reserved value. Which is very useful for compressed mids.
This commit is contained in:
Christopher Haster
2023-08-29 02:08:06 -05:00
parent dbf6d4579d
commit 19f2b24161
2 changed files with 55 additions and 52 deletions
+6 -6
View File
@@ -1289,7 +1289,7 @@ code = '''
lfsr_mtree_lookup(&lfs, LFSR_MID(0*lfsr_mbidweight(&lfs), -1), &mdir) => 0;
// drop should make sure we never have empty mdirs
assert(lfsr_mdir_ismroot(&mdir) || mdir.u.m.weight > 0);
assert(lfsr_mtree_isinlined(&lfs) || mdir.u.m.weight > 0);
// force a compaction?
if (FORCE_COMPACTION) {
@@ -1409,7 +1409,7 @@ code = '''
lfsr_mtree_lookup(&lfs, LFSR_MID(0*lfsr_mbidweight(&lfs), -1), &mdir) => 0;
// drop should make sure we never have empty mdirs
assert(lfsr_mdir_ismroot(&mdir) || mdir.u.m.weight > 0);
assert(lfsr_mtree_isinlined(&lfs) || mdir.u.m.weight > 0);
// force a compaction?
if (FORCE_COMPACTION) {
@@ -1511,7 +1511,7 @@ code = '''
lfsr_mtree_lookup(&lfs, LFSR_MID(mid, -1), &mdir) => 0;
// drop should make sure we never have empty mdirs
assert(lfsr_mdir_ismroot(&mdir) || mdir.u.m.weight > 0);
assert(lfsr_mtree_isinlined(&lfs) || mdir.u.m.weight > 0);
for (mdir.mid.rid = 0;
mdir.mid.rid < (lfs_ssize_t)mdir.u.m.weight;
@@ -1544,7 +1544,7 @@ code = '''
lfsr_mtree_lookup(&lfs, LFSR_MID(mid, -1), &mdir) => 0;
// drop should make sure we never have empty mdirs
assert(lfsr_mdir_ismroot(&mdir) || mdir.u.m.weight > 0);
assert(lfsr_mtree_isinlined(&lfs) || mdir.u.m.weight > 0);
for (mdir.mid.rid = 0;
mdir.mid.rid < (lfs_ssize_t)mdir.u.m.weight;
@@ -2600,7 +2600,7 @@ code = '''
lfsr_mtree_lookup(&lfs, LFSR_MID(mid, -1), &mdir) => 0;
// drop should make sure we never have empty mdirs
assert(lfsr_mdir_ismroot(&mdir) || mdir.u.m.weight > 0);
assert(lfsr_mtree_isinlined(&lfs) || mdir.u.m.weight > 0);
for (mdir.mid.rid = 0;
mdir.mid.rid < (lfs_ssize_t)mdir.u.m.weight;
@@ -2633,7 +2633,7 @@ code = '''
lfsr_mtree_lookup(&lfs, LFSR_MID(mid, -1), &mdir) => 0;
// drop should make sure we never have empty mdirs
assert(lfsr_mdir_ismroot(&mdir) || mdir.u.m.weight > 0);
assert(lfsr_mtree_isinlined(&lfs) || mdir.u.m.weight > 0);
for (mdir.mid.rid = 0;
mdir.mid.rid < (lfs_ssize_t)mdir.u.m.weight;