Made btree commit track bids correctly during recursion
This doesn't have that big an impact at the moment, but limiting the bids/rids to well intentioned values helps development and debugging. As we tail-recurse up the btree, the current bid always indicates the left-most/least id in the current rbyd. This contrasts with pid, which is the right-most id in the current rbyd. Before this the bid was somewhat arbitrary after the first leaf, which risks confusion later. This also implies bid=0 when we reach the root, which is a useful debug assertion.
This commit is contained in:
@@ -3916,6 +3916,7 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
|
|
||||||
// done?
|
// done?
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
|
LFS_ASSERT(bid == 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3928,6 +3929,7 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
//
|
//
|
||||||
// note that since we defer merges to compaction time, we can
|
// note that since we defer merges to compaction time, we can
|
||||||
// end up removing an rbyd here
|
// end up removing an rbyd here
|
||||||
|
bid -= pid - (pweight-1);
|
||||||
if (rbyd->weight == 0) {
|
if (rbyd->weight == 0) {
|
||||||
scratch_attrs[0] = LFSR_ATTR(
|
scratch_attrs[0] = LFSR_ATTR(
|
||||||
bid+pid, RM, +rbyd->weight-pweight,
|
bid+pid, RM, +rbyd->weight-pweight,
|
||||||
@@ -4010,6 +4012,7 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
|
|
||||||
// done?
|
// done?
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
|
LFS_ASSERT(bid == 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4022,6 +4025,7 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
//
|
//
|
||||||
// note that since we defer merges to compaction time, we can
|
// note that since we defer merges to compaction time, we can
|
||||||
// end up removing an rbyd here
|
// end up removing an rbyd here
|
||||||
|
bid -= pid - (pweight-1);
|
||||||
if (rbyd->weight == 0) {
|
if (rbyd->weight == 0) {
|
||||||
scratch_attrs[0] = LFSR_ATTR(
|
scratch_attrs[0] = LFSR_ATTR(
|
||||||
bid+pid, RM, +rbyd->weight-pweight,
|
bid+pid, RM, +rbyd->weight-pweight,
|
||||||
@@ -4144,20 +4148,21 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepare commit to parent, tail recursing upwards
|
// prepare commit to parent, tail recursing upwards
|
||||||
|
LFS_ASSERT(bid == 0);
|
||||||
scratch_attrs[0] = LFSR_ATTR(
|
scratch_attrs[0] = LFSR_ATTR(
|
||||||
bid, BRANCH, +rbyd_.weight,
|
0, BRANCH, +rbyd_.weight,
|
||||||
BUF(scratch1_buf, scratch1_dsize));
|
BUF(scratch1_buf, scratch1_dsize));
|
||||||
scratch_attrs[1] = (lfsr_tag_suptype(stag) == LFSR_TAG_NAME
|
scratch_attrs[1] = (lfsr_tag_suptype(stag) == LFSR_TAG_NAME
|
||||||
? LFSR_ATTR(
|
? LFSR_ATTR(
|
||||||
bid+rbyd_.weight, BNAME, +sibling.weight,
|
rbyd_.weight, BNAME, +sibling.weight,
|
||||||
DATA(sdata))
|
DATA(sdata))
|
||||||
: LFSR_ATTR_NOOP);
|
: LFSR_ATTR_NOOP);
|
||||||
scratch_attrs[2] = (lfsr_tag_suptype(stag) == LFSR_TAG_NAME
|
scratch_attrs[2] = (lfsr_tag_suptype(stag) == LFSR_TAG_NAME
|
||||||
? LFSR_ATTR(
|
? LFSR_ATTR(
|
||||||
bid+rbyd_.weight+sibling.weight-1, BRANCH, 0,
|
rbyd_.weight+sibling.weight-1, BRANCH, 0,
|
||||||
BUF(scratch2_buf, scratch2_dsize))
|
BUF(scratch2_buf, scratch2_dsize))
|
||||||
: LFSR_ATTR(
|
: LFSR_ATTR(
|
||||||
bid+rbyd_.weight, BRANCH, +sibling.weight,
|
rbyd_.weight, BRANCH, +sibling.weight,
|
||||||
BUF(scratch2_buf, scratch2_dsize)));
|
BUF(scratch2_buf, scratch2_dsize)));
|
||||||
attrs = scratch_attrs;
|
attrs = scratch_attrs;
|
||||||
attr_count = 3;
|
attr_count = 3;
|
||||||
@@ -4165,6 +4170,7 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
// yes parent? push up split
|
// yes parent? push up split
|
||||||
} else {
|
} else {
|
||||||
// prepare commit to parent, tail recursing upwards
|
// prepare commit to parent, tail recursing upwards
|
||||||
|
bid -= pid - (pweight-1);
|
||||||
scratch_attrs[0] = LFSR_ATTR(
|
scratch_attrs[0] = LFSR_ATTR(
|
||||||
bid+pid, GROW(RM), +rbyd_.weight-pweight, NULL);
|
bid+pid, GROW(RM), +rbyd_.weight-pweight, NULL);
|
||||||
scratch_attrs[1] = LFSR_ATTR(
|
scratch_attrs[1] = LFSR_ATTR(
|
||||||
@@ -4371,6 +4377,9 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// prepare commit to parent, tail recursing upwards
|
||||||
|
bid -= pid - (pweight-1);
|
||||||
|
|
||||||
// make pid the lower child so the following math is easier
|
// make pid the lower child so the following math is easier
|
||||||
if (pid > sid) {
|
if (pid > sid) {
|
||||||
lfs_sswap32(&pid, &sid);
|
lfs_sswap32(&pid, &sid);
|
||||||
@@ -4383,7 +4392,6 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
return scratch_dsize;
|
return scratch_dsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare commit to parent, tail recursing upwards
|
|
||||||
scratch_attrs[0] = LFSR_ATTR(
|
scratch_attrs[0] = LFSR_ATTR(
|
||||||
bid+sid, RM, -sweight, NULL);
|
bid+sid, RM, -sweight, NULL);
|
||||||
scratch_attrs[1] = LFSR_ATTR(
|
scratch_attrs[1] = LFSR_ATTR(
|
||||||
|
|||||||
Reference in New Issue
Block a user