Some btree progress, implementing rbyd-tag-weight changes
This commit is contained in:
@@ -1410,12 +1410,14 @@ static int lfsr_rbyd_fetch(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adjust any pending finds
|
// adjust any pending finds
|
||||||
if (find && find->predicted_id >= id) {
|
if (find && find->predicted_id >= id-lfs_smax32(delta-1, 0)+(delta < 0 ? 1 : 0)) {
|
||||||
// pending find removed?
|
// pending find removed?
|
||||||
if (delta < 0 && find->predicted_id < id-delta) {
|
if (delta < 0 && find->predicted_id <= id+lfs_smin32(delta+1, 0)) {
|
||||||
|
printf("%x: a %d v %d+%d\n", off, find->predicted_id, id-(delta-1), delta);
|
||||||
find->predicted_tag = 0;
|
find->predicted_tag = 0;
|
||||||
find->predicted_id = id-1;
|
find->predicted_id = id-1;
|
||||||
} else {
|
} else {
|
||||||
|
printf("%x: b %d v %d+%d\n", off, find->predicted_id, id-(delta-1), delta);
|
||||||
find->predicted_id += delta;
|
find->predicted_id += delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2016,15 +2018,15 @@ static int lfsr_rbyd_append(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
|
|
||||||
id_ = id - lfs_smax32(-delta, 0);
|
id_ = id - lfs_smax32(-delta, 0);
|
||||||
other_id_ = id;
|
other_id_ = id;
|
||||||
tag_ = tag & ~0x2;
|
tag_ = lfsr_tag_key(tag);
|
||||||
other_tag_ = (tag & ~0x2) + 0x10;
|
other_tag_ = lfsr_tag_key(tag) + 0x10;
|
||||||
} else {
|
} else {
|
||||||
LFS_ASSERT(id < rbyd->weight);
|
LFS_ASSERT(id < rbyd->weight);
|
||||||
|
|
||||||
id_ = id - lfs_smax32(-delta, 0);
|
id_ = id - lfs_smax32(-delta, 0);
|
||||||
other_id_ = id;
|
other_id_ = id;
|
||||||
tag_ = tag;
|
tag_ = lfsr_tag_key(tag);
|
||||||
other_tag_ = tag;
|
other_tag_ = lfsr_tag_key(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep track of bounds as we descend down the tree
|
// keep track of bounds as we descend down the tree
|
||||||
@@ -3087,19 +3089,18 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO can we combine weight changes with normal tag updates?
|
// note that since we defer merges to compaction time, we can
|
||||||
// maybe this should be looked at again
|
// end up removing an rbyd here
|
||||||
scratch_attrs[0] = *LFSR_ATTR(
|
if (rbyd->weight == 0) {
|
||||||
BRANCH, rid, scratch_buf1, delta,
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
&scratch_attrs[1]);
|
MKUNR, rid, +rbyd->weight-rweight, scratch_buf1, delta,
|
||||||
// note grow/shrink with 0 is treated as a noop in rbyd
|
|
||||||
if (rbyd->weight >= rweight) {
|
|
||||||
scratch_attrs[1] = *LFSR_ATTR(
|
|
||||||
GROW, rid-(rweight-1), NULL, rbyd->weight-rweight,
|
|
||||||
NULL);
|
NULL);
|
||||||
} else {
|
} else {
|
||||||
scratch_attrs[1] = *LFSR_ATTR(
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
SHRINK, rid-(rweight-1), NULL, rweight-rbyd->weight,
|
BRANCH, rid, 0, scratch_buf1, delta,
|
||||||
|
&scratch_attrs[1]);
|
||||||
|
scratch_attrs[1] = *LFSD_ATTR(
|
||||||
|
UNR, rid, +rbyd->weight-rweight, NULL, 0,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3124,9 +3125,8 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
while (true) {
|
while (true) {
|
||||||
lfs_off_t off;
|
lfs_off_t off;
|
||||||
lfs_size_t size;
|
lfs_size_t size;
|
||||||
lfs_size_t weight;
|
|
||||||
err = lfsr_rbyd_lookup(lfs, rbyd, lfsr_tag_next(tag), id,
|
err = lfsr_rbyd_lookup(lfs, rbyd, lfsr_tag_next(tag), id,
|
||||||
&tag, &id, &weight, &off, &size);
|
&tag, &id, NULL, &off, &size);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3134,18 +3134,18 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is really wasteful and throws off our predicted
|
// // TODO this is really wasteful and throws off our predicted
|
||||||
// size, can we combine grows into the tag append in the rbyd
|
// // size, can we combine grows into the tag append in the rbyd
|
||||||
// somehow?
|
// // somehow?
|
||||||
// create grows as necessary
|
// // create grows as necessary
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
// err = lfsr_rbyd_append_(lfs, &rbyd_,
|
||||||
LFSR_TAG_GROW,
|
// LFSR_TAG_GROW,
|
||||||
id - (weight-1),
|
// id - (weight-1),
|
||||||
// TODO also this is a weird way to use lfsr_data_t
|
// // TODO also this is a weird way to use lfsr_data_t
|
||||||
LFSR_DATA_BUF(NULL, weight));
|
// LFSR_DATA_BUF(NULL, weight));
|
||||||
if (err) {
|
// if (err) {
|
||||||
return err;
|
// return err;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Because it makes a lot of the split-sensitive cross-id operations
|
// Because it makes a lot of the split-sensitive cross-id operations
|
||||||
// easier, we can end up with an occasional "vestigial" name tag on
|
// easier, we can end up with an occasional "vestigial" name tag on
|
||||||
@@ -3155,13 +3155,20 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
//
|
//
|
||||||
// Discarding these during compaction is easy and prevents any
|
// Discarding these during compaction is easy and prevents any
|
||||||
// real storage cost.
|
// real storage cost.
|
||||||
if (lfsr_tag_suptype(tag) == LFSR_TAG_NAME && id-(weight-1) == 0) {
|
if (lfsr_tag_suptype(tag) == LFSR_TAG_NAME && rbyd_.weight == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// note we need to account for the missing weight of vestigial name
|
||||||
|
// tags in the following branch tag, which is why we calculate
|
||||||
|
// weight like this
|
||||||
|
lfs_size_t weight = id+1 - rbyd_.weight;
|
||||||
|
|
||||||
// append the attr
|
// append the attr
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
tag, id, LFSR_DATA_DISK(rbyd->block, off, size));
|
lfsr_tag_setmk(tag),
|
||||||
|
id-lfs_smax32(weight-1, 0), +weight,
|
||||||
|
LFSR_DATA_DISK(rbyd->block, off, size));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3176,8 +3183,8 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
// append any pending attrs, it's up to upper
|
// append any pending attrs, it's up to upper
|
||||||
// layers to make sure these always fit
|
// layers to make sure these always fit
|
||||||
for (const struct lfsr_attr *attr = attrs; attr; attr = attr->next) {
|
for (const struct lfsr_attr *attr = attrs; attr; attr = attr->next) {
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
attr->tag, attr->id, attr->data);
|
attr->tag, attr->id, attr->delta, attr->data);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3214,19 +3221,18 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO can we combine weight changes with normal tag updates?
|
// note that since we defer merges to compaction time, we can
|
||||||
// maybe this should be looked at again
|
// end up removing an rbyd here
|
||||||
scratch_attrs[0] = *LFSR_ATTR(
|
if (rbyd_.weight == 0) {
|
||||||
BRANCH, rid, scratch_buf1, delta,
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
&scratch_attrs[1]);
|
MKUNR, rid, +rbyd_.weight-rweight, scratch_buf1, delta,
|
||||||
// note grow/shrink with 0 is treated as a noop in rbyd
|
|
||||||
if (rbyd_.weight >= rweight) {
|
|
||||||
scratch_attrs[1] = *LFSR_ATTR(
|
|
||||||
GROW, rid-(rweight-1), NULL, rbyd_.weight-rweight,
|
|
||||||
NULL);
|
NULL);
|
||||||
} else {
|
} else {
|
||||||
scratch_attrs[1] = *LFSR_ATTR(
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
SHRINK, rid-(rweight-1), NULL, rweight-rbyd_.weight,
|
BRANCH, rid, 0, scratch_buf1, delta,
|
||||||
|
&scratch_attrs[1]);
|
||||||
|
scratch_attrs[1] = *LFSD_ATTR(
|
||||||
|
UNR, rid, +rbyd_.weight-rweight, NULL, 0,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3235,6 +3241,7 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
split:;
|
split:;
|
||||||
|
printf("B SPLIT %x %d\n", rbyd_.block, rbyd_.weight);
|
||||||
// find out which id we need to split around
|
// find out which id we need to split around
|
||||||
lfs_ssize_t bisect = lfsr_rbyd_bisect(lfs, rbyd);
|
lfs_ssize_t bisect = lfsr_rbyd_bisect(lfs, rbyd);
|
||||||
if (bisect < 0) {
|
if (bisect < 0) {
|
||||||
@@ -3246,10 +3253,9 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
// TODO does this work if we're removing nothing/oob?
|
// TODO does this work if we're removing nothing/oob?
|
||||||
// add an rbyd and btree test?
|
// add an rbyd and btree test?
|
||||||
if ((lfs_size_t)bisect < rbyd_.weight) {
|
if ((lfs_size_t)bisect < rbyd_.weight) {
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
LFSR_TAG_SHRINK,
|
LFSR_TAG_MKUNR, rbyd_.weight-1, -(rbyd_.weight-bisect),
|
||||||
bisect,
|
LFSR_DATA_NULL);
|
||||||
LFSR_DATA_BUF(NULL, rbyd_.weight-bisect));
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3262,8 +3268,8 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
lfs_ssize_t bisect_ = bisect;
|
lfs_ssize_t bisect_ = bisect;
|
||||||
for (const struct lfsr_attr *attr = attrs; attr; attr = attr->next) {
|
for (const struct lfsr_attr *attr = attrs; attr; attr = attr->next) {
|
||||||
if (attr->id < bisect_) {
|
if (attr->id < bisect_) {
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
attr->tag, attr->id, attr->data);
|
attr->tag, attr->id, attr->delta, attr->data);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3271,11 +3277,13 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
|
|
||||||
// we need to make sure we keep bisect updated with weight changes
|
// we need to make sure we keep bisect updated with weight changes
|
||||||
if (attr->id < bisect_) {
|
if (attr->id < bisect_) {
|
||||||
if (attr->tag == LFSR_TAG_GROW) {
|
// TODO do we need to check for mk?
|
||||||
bisect_ += attr->data.len;
|
bisect_ += attr->delta;
|
||||||
} else if (attr->tag == LFSR_TAG_SHRINK) {
|
// if (attr->tag == LFSR_TAG_GROW) {
|
||||||
bisect_ -= attr->data.len;
|
// bisect_ += attr->data.len;
|
||||||
}
|
// } else if (attr->tag == LFSR_TAG_SHRINK) {
|
||||||
|
// bisect_ -= attr->data.len;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3310,22 +3318,23 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is really wasteful and throws off our predicted
|
// // TODO this is really wasteful and throws off our predicted
|
||||||
// size, can we combine grows into the tag append in the rbyd
|
// // size, can we combine grows into the tag append in the rbyd
|
||||||
// somehow?
|
// // somehow?
|
||||||
// create grows as necessary
|
// // create grows as necessary
|
||||||
err = lfsr_rbyd_append_(lfs, &sibling,
|
// err = lfsr_rbyd_append_(lfs, &sibling,
|
||||||
LFSR_TAG_GROW,
|
// LFSR_TAG_GROW,
|
||||||
id - bisect - (weight-1),
|
// id - bisect - (weight-1),
|
||||||
// TODO also this is a weird way to use lfsr_data_t
|
// // TODO also this is a weird way to use lfsr_data_t
|
||||||
LFSR_DATA_BUF(NULL, weight));
|
// LFSR_DATA_BUF(NULL, weight));
|
||||||
if (err) {
|
// if (err) {
|
||||||
return err;
|
// return err;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// append the attr
|
// append the attr
|
||||||
err = lfsr_rbyd_append_(lfs, &sibling,
|
err = lfsr_rbyd_append(lfs, &sibling,
|
||||||
tag, id - bisect,
|
lfsr_tag_setmk(tag),
|
||||||
|
id-bisect-lfs_smax32(weight-1, 0), +weight,
|
||||||
LFSR_DATA_DISK(rbyd->block, off, size));
|
LFSR_DATA_DISK(rbyd->block, off, size));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -3338,8 +3347,8 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
bisect_ = bisect;
|
bisect_ = bisect;
|
||||||
for (const struct lfsr_attr *attr = attrs; attr; attr = attr->next) {
|
for (const struct lfsr_attr *attr = attrs; attr; attr = attr->next) {
|
||||||
if (attr->id >= bisect_) {
|
if (attr->id >= bisect_) {
|
||||||
err = lfsr_rbyd_append_(lfs, &sibling,
|
err = lfsr_rbyd_append(lfs, &sibling,
|
||||||
attr->tag, attr->id-bisect_, attr->data);
|
attr->tag, attr->id-bisect_, attr->delta, attr->data);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3347,11 +3356,13 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
|
|
||||||
// we need to make sure we keep bisect updated with weight changes
|
// we need to make sure we keep bisect updated with weight changes
|
||||||
if (attr->id < bisect_) {
|
if (attr->id < bisect_) {
|
||||||
if (attr->tag == LFSR_TAG_GROW) {
|
// TODO do we need to check for mk?
|
||||||
bisect_ += attr->data.len;
|
bisect_ += attr->delta;
|
||||||
} else if (attr->tag == LFSR_TAG_SHRINK) {
|
// if (attr->tag == LFSR_TAG_GROW) {
|
||||||
bisect_ -= attr->data.len;
|
// bisect_ += attr->data.len;
|
||||||
}
|
// } else if (attr->tag == LFSR_TAG_SHRINK) {
|
||||||
|
// bisect_ -= attr->data.len;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3399,28 +3410,25 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
return delta2;
|
return delta2;
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch_attrs[0] = *LFSR_ATTR(
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
GROW, 0,
|
MKBRANCH, 0, +rbyd_.weight, scratch_buf1, delta1,
|
||||||
NULL, rbyd_.weight,
|
|
||||||
&scratch_attrs[1]);
|
&scratch_attrs[1]);
|
||||||
scratch_attrs[1] = *LFSR_ATTR(
|
|
||||||
BRANCH, 0+rbyd_.weight-1,
|
|
||||||
scratch_buf1, delta1,
|
|
||||||
&scratch_attrs[2]);
|
|
||||||
|
|
||||||
scratch_attrs[2] = *LFSR_ATTR(
|
if (lfsr_tag_suptype(stag) == LFSR_TAG_NAME) {
|
||||||
GROW, 0+rbyd_.weight,
|
scratch_attrs[1] = *LFSD_ATTR_DISK(
|
||||||
NULL, sibling.weight,
|
MKBNAME, rbyd_.weight, +sibling.weight,
|
||||||
&scratch_attrs[3]);
|
sibling.block, soff, ssize,
|
||||||
scratch_attrs[3] = *LFSR_ATTR_DISK_IF(
|
&scratch_attrs[2]);
|
||||||
lfsr_tag_suptype(stag) == LFSR_TAG_NAME,
|
scratch_attrs[2] = *LFSD_ATTR(
|
||||||
BNAME, 0+rbyd_.weight+sibling.weight-1,
|
BRANCH, 0+rbyd_.weight+sibling.weight-1, 0,
|
||||||
sibling.block, soff, ssize,
|
scratch_buf2, delta2,
|
||||||
&scratch_attrs[4]);
|
NULL);
|
||||||
scratch_attrs[4] = *LFSR_ATTR(
|
} else {
|
||||||
BRANCH, 0+rbyd_.weight+sibling.weight-1,
|
scratch_attrs[1] = *LFSD_ATTR(
|
||||||
scratch_buf2, delta2,
|
MKBRANCH, 0+rbyd_.weight, +sibling.weight,
|
||||||
NULL);
|
scratch_buf2, delta2,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// yes parent? push up split
|
// yes parent? push up split
|
||||||
} else {
|
} else {
|
||||||
@@ -3440,41 +3448,39 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
return delta2;
|
return delta2;
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch_attrs[0] = *LFSR_ATTR_(
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
(rbyd_.weight > rweight) ? LFSR_TAG_GROW : LFSR_TAG_SHRINK,
|
UNR, rid, +rbyd_.weight-rweight, NULL, 0,
|
||||||
rid-(rweight-1),
|
|
||||||
NULL,
|
|
||||||
(rbyd_.weight > rweight)
|
|
||||||
? rbyd_.weight - rweight
|
|
||||||
: rweight - rbyd_.weight,
|
|
||||||
&scratch_attrs[1]);
|
&scratch_attrs[1]);
|
||||||
scratch_attrs[1] = *LFSR_ATTR(
|
scratch_attrs[1] = *LFSD_ATTR(
|
||||||
BRANCH, rid-(rweight-1)+rbyd_.weight-1,
|
BRANCH, rid-(rweight-1)+rbyd_.weight-1, 0,
|
||||||
scratch_buf1, delta1,
|
scratch_buf1, delta1,
|
||||||
&scratch_attrs[2]);
|
&scratch_attrs[2]);
|
||||||
|
|
||||||
scratch_attrs[2] = *LFSR_ATTR(
|
if (lfsr_tag_suptype(stag) == LFSR_TAG_NAME) {
|
||||||
GROW, rid-(rweight-1)+rbyd_.weight,
|
scratch_attrs[2] = *LFSD_ATTR_DISK(
|
||||||
NULL, sibling.weight,
|
MKBNAME, rid-(rweight-1)+rbyd_.weight,
|
||||||
&scratch_attrs[3]);
|
+sibling.weight,
|
||||||
scratch_attrs[3] = *LFSR_ATTR_DISK_IF(
|
sibling.block, soff, ssize,
|
||||||
lfsr_tag_suptype(stag) == LFSR_TAG_NAME,
|
&scratch_attrs[3]);
|
||||||
BNAME, rid-(rweight-1)+rbyd_.weight
|
scratch_attrs[3] = *LFSD_ATTR(
|
||||||
+sibling.weight-1,
|
BRANCH, rid-(rweight-1)+rbyd_.weight+sibling.weight-1,
|
||||||
sibling.block, soff, ssize,
|
0,
|
||||||
&scratch_attrs[4]);
|
scratch_buf2, delta2,
|
||||||
scratch_attrs[4] = *LFSR_ATTR(
|
NULL);
|
||||||
BRANCH, rid-(rweight-1)+rbyd_.weight
|
} else {
|
||||||
+sibling.weight-1,
|
scratch_attrs[2] = *LFSD_ATTR(
|
||||||
scratch_buf2, delta2,
|
MKBRANCH, rid-(rweight-1)+rbyd_.weight,
|
||||||
NULL);
|
+sibling.weight,
|
||||||
|
scratch_buf2, delta2,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*rbyd = parent;
|
*rbyd = parent;
|
||||||
attrs = scratch_attrs;
|
attrs = scratch_attrs;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
merge:;
|
merge:;
|
||||||
|
printf("B MERGE %x %d\n", rbyd_.block, rbyd_.weight);
|
||||||
// last child? try the left sibling
|
// last child? try the left sibling
|
||||||
// lfs_ssize_t sid;
|
// lfs_ssize_t sid;
|
||||||
lfs_ssize_t sdelta;
|
lfs_ssize_t sdelta;
|
||||||
@@ -3549,22 +3555,24 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is really wasteful and throws off our predicted
|
// // TODO this is really wasteful and throws off our predicted
|
||||||
// size, can we combine grows into the tag append in the rbyd
|
// // size, can we combine grows into the tag append in the rbyd
|
||||||
// somehow?
|
// // somehow?
|
||||||
// create grows as necessary
|
// // create grows as necessary
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
// err = lfsr_rbyd_append_(lfs, &rbyd_,
|
||||||
LFSR_TAG_GROW,
|
// LFSR_TAG_GROW,
|
||||||
sdelta + id - (weight-1),
|
// sdelta + id - (weight-1),
|
||||||
// TODO also this is a weird way to use lfsr_data_t
|
// // TODO also this is a weird way to use lfsr_data_t
|
||||||
LFSR_DATA_BUF(NULL, weight));
|
// LFSR_DATA_BUF(NULL, weight));
|
||||||
if (err) {
|
// if (err) {
|
||||||
return err;
|
// return err;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// append the attr
|
// append the attr
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
tag, sdelta + id, LFSR_DATA_DISK(sibling.block, off, size));
|
lfsr_tag_setmk(tag),
|
||||||
|
sdelta+id-lfs_smax32(weight-1, 0), +weight,
|
||||||
|
LFSR_DATA_DISK(sibling.block, off, size));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3572,11 +3580,10 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
// if we exceed our compaction threshold our merge has
|
// if we exceed our compaction threshold our merge has
|
||||||
// failed, clean up ids and merge_abort
|
// failed, clean up ids and merge_abort
|
||||||
if (rbyd_.off > lfs->cfg->block_size/2) {
|
if (rbyd_.off > lfs->cfg->block_size/2) {
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
LFSR_TAG_SHRINK,
|
LFSR_TAG_MKUNR, sdelta+(rbyd_.weight-rweight_)-1,
|
||||||
sdelta,
|
-(rbyd_.weight-rweight_),
|
||||||
// TODO also this is a weird way to use lfsr_data_t
|
LFSR_DATA_NULL);
|
||||||
LFSR_DATA_BUF(NULL, rbyd_.weight - rweight_));
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3607,8 +3614,8 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = lfsr_rbyd_append_(lfs, &rbyd_,
|
err = lfsr_rbyd_append(lfs, &rbyd_,
|
||||||
LFSR_TAG_BNAME, split_id,
|
LFSR_TAG_BNAME, split_id, 0,
|
||||||
LFSR_DATA_DISK(parent.block, split_off, split_size));
|
LFSR_DATA_DISK(parent.block, split_off, split_size));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -3646,22 +3653,11 @@ static int lfsr_btree_commit(lfs_t *lfs,
|
|||||||
lfs_swap32(&rweight, &sweight);
|
lfs_swap32(&rweight, &sweight);
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch_attrs[0] = *LFSR_ATTR(
|
scratch_attrs[0] = *LFSD_ATTR(
|
||||||
SHRINK, sid-(sweight-1),
|
MKUNR, sid, -sweight, NULL, 0,
|
||||||
NULL, sweight,
|
|
||||||
&scratch_attrs[1]);
|
&scratch_attrs[1]);
|
||||||
|
scratch_attrs[1] = *LFSD_ATTR(
|
||||||
scratch_attrs[1] = *LFSR_ATTR_(
|
BRANCH, rid, +rbyd_.weight-rweight, scratch_buf1, delta1,
|
||||||
(rbyd_.weight > rweight) ? LFSR_TAG_GROW : LFSR_TAG_SHRINK,
|
|
||||||
rid-(rweight-1),
|
|
||||||
NULL,
|
|
||||||
(rbyd_.weight > rweight)
|
|
||||||
? rbyd_.weight - rweight
|
|
||||||
: rweight - rbyd_.weight,
|
|
||||||
&scratch_attrs[2]);
|
|
||||||
scratch_attrs[2] = *LFSR_ATTR(
|
|
||||||
BRANCH, rid-(rweight-1)+rbyd_.weight-1,
|
|
||||||
scratch_buf1, delta1,
|
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3704,13 +3700,13 @@ static int lfsr_btree_push(lfs_t *lfs, lfsr_btree_t *btree,
|
|||||||
|
|
||||||
// commit our entries
|
// commit our entries
|
||||||
err = lfsr_rbyd_commit(lfs, &rbyd,
|
err = lfsr_rbyd_commit(lfs, &rbyd,
|
||||||
LFSR_ATTR(GROW, 0, NULL, btree->weight,
|
LFSD_ATTR_(
|
||||||
LFSR_ATTR_(btree->tag, 0+btree->weight-1,
|
lfsr_tag_setmk(btree->tag), 0, +btree->weight,
|
||||||
btree->u.inlined.buf, btree->u.inlined.size,
|
btree->u.inlined.buf, btree->u.inlined.size,
|
||||||
LFSR_ATTR(GROW, id, NULL, weight,
|
LFSD_ATTR_(
|
||||||
LFSR_ATTR_(tag, id+weight-1,
|
lfsr_tag_setmk(tag), id, +weight,
|
||||||
buffer, size,
|
buffer, size,
|
||||||
NULL)))));
|
NULL)));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3744,10 +3740,9 @@ static int lfsr_btree_push(lfs_t *lfs, lfsr_btree_t *btree,
|
|||||||
// commit our id into the tree, letting lfsr_btree_commit take care
|
// commit our id into the tree, letting lfsr_btree_commit take care
|
||||||
// of the rest
|
// of the rest
|
||||||
return lfsr_btree_commit(lfs, btree,
|
return lfsr_btree_commit(lfs, btree,
|
||||||
lfs_min32(id, btree->weight-1), &rbyd,
|
lfs_min32(id, btree->weight-1), &rbyd,
|
||||||
LFSR_ATTR(GROW, rid, NULL, weight,
|
LFSD_ATTR_(lfsr_tag_setmk(tag), rid, +weight, buffer, size,
|
||||||
LFSR_ATTR_(tag, rid+weight-1, buffer, size,
|
NULL));
|
||||||
NULL)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3784,15 +3779,11 @@ static int lfsr_btree_update(lfs_t *lfs, lfsr_btree_t *btree,
|
|||||||
// commit our id into the tree, letting lfsr_btree_commit take care
|
// commit our id into the tree, letting lfsr_btree_commit take care
|
||||||
// of the rest
|
// of the rest
|
||||||
return lfsr_btree_commit(lfs, btree, id, &rbyd,
|
return lfsr_btree_commit(lfs, btree, id, &rbyd,
|
||||||
LFSR_ATTR_IF_(tag != rtag,
|
LFSD_ATTR_IF_(tag != rtag,
|
||||||
lfsr_tag_setrm(rtag), rid, NULL, 0,
|
lfsr_tag_setrm(rtag), rid, 0, NULL, 0,
|
||||||
LFSR_ATTR_(tag, rid, buffer, size,
|
LFSD_ATTR_(tag, rid, +weight-rweight,
|
||||||
LFSR_ATTR_(
|
buffer, size,
|
||||||
weight >= rweight ? LFSR_TAG_GROW : LFSR_TAG_SHRINK,
|
NULL)));
|
||||||
rid-(rweight-1),
|
|
||||||
NULL,
|
|
||||||
weight >= rweight ? weight - rweight : rweight - weight,
|
|
||||||
NULL))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3879,7 +3870,7 @@ static int lfsr_btree_pop(lfs_t *lfs, lfsr_btree_t *btree, lfs_size_t id) {
|
|||||||
// remove our id, letting lfsr_btree_commit take care
|
// remove our id, letting lfsr_btree_commit take care
|
||||||
// of the rest
|
// of the rest
|
||||||
return lfsr_btree_commit(lfs, btree, id, &rbyd,
|
return lfsr_btree_commit(lfs, btree, id, &rbyd,
|
||||||
LFSR_ATTR(SHRINK, rid-(rweight-1), NULL, rweight,
|
LFSD_ATTR(MKUNR, rid, -rweight, NULL, 0,
|
||||||
NULL));
|
NULL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3909,15 +3900,13 @@ static int lfsr_btree_split(lfs_t *lfs, lfsr_btree_t *btree,
|
|||||||
|
|
||||||
// commit our entries
|
// commit our entries
|
||||||
err = lfsr_rbyd_commit(lfs, &rbyd,
|
err = lfsr_rbyd_commit(lfs, &rbyd,
|
||||||
LFSR_ATTR(GROW, 0, NULL, weight1,
|
LFSD_ATTR_(lfsr_tag_setmk(tag1), 0, +weight1,
|
||||||
LFSR_ATTR_(tag1, 0+weight1-1,
|
|
||||||
buffer1, size1,
|
buffer1, size1,
|
||||||
LFSR_ATTR(GROW, weight1, NULL, weight2,
|
LFSD_ATTR(MKBNAME, weight1, +weight2,
|
||||||
LFSR_ATTR(BNAME, weight1+weight2-1,
|
|
||||||
name, name_len,
|
name, name_len,
|
||||||
LFSR_ATTR_(tag2, weight1+weight2-1,
|
LFSD_ATTR_(tag2, weight1+weight2-1, 0,
|
||||||
buffer2, size2,
|
buffer2, size2,
|
||||||
NULL))))));
|
NULL))));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -3953,20 +3942,15 @@ static int lfsr_btree_split(lfs_t *lfs, lfsr_btree_t *btree,
|
|||||||
// commit our id into the tree, letting lfsr_btree_commit take care
|
// commit our id into the tree, letting lfsr_btree_commit take care
|
||||||
// of the rest
|
// of the rest
|
||||||
return lfsr_btree_commit(lfs, btree, id, &rbyd,
|
return lfsr_btree_commit(lfs, btree, id, &rbyd,
|
||||||
// TODO can we avoid conditions like this?
|
LFSD_ATTR(UNR, rid, +weight1-rweight, NULL, 0,
|
||||||
LFSR_ATTR_(
|
LFSD_ATTR_(tag1, rid-(rweight-1)+weight1-1, 0,
|
||||||
(weight1 > rweight) ? LFSR_TAG_GROW : LFSR_TAG_SHRINK,
|
|
||||||
rid-(rweight-1),
|
|
||||||
NULL,
|
|
||||||
(weight1 > rweight) ? weight1-rweight : rweight-weight1,
|
|
||||||
LFSR_ATTR_(tag1, rid-(rweight-1)+weight1-1,
|
|
||||||
buffer1, size1,
|
buffer1, size1,
|
||||||
LFSR_ATTR(GROW, rid-(rweight-1)+weight1, NULL, weight2,
|
// TODO should we always be making name entries?
|
||||||
LFSR_ATTR(BNAME, rid-(rweight-1)+weight1+weight2-1,
|
LFSD_ATTR(MKBNAME, rid-(rweight-1)+weight1, +weight2,
|
||||||
name, name_len,
|
name, name_len,
|
||||||
LFSR_ATTR_(tag2, rid-(rweight-1)+weight1+weight2-1,
|
LFSD_ATTR_(tag2, rid-(rweight-1)+weight1+weight2-1, 0,
|
||||||
buffer2, size2,
|
buffer2, size2,
|
||||||
NULL))))));
|
NULL)))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -275,7 +275,7 @@ def show_log(block_size, data, rev, off, *,
|
|||||||
# note we ignore out-of-bounds here for debugging
|
# note we ignore out-of-bounds here for debugging
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
# grow lifetimes
|
# grow lifetimes
|
||||||
i, id_ = index(weights, lower_)
|
i, id_ = index(weights, id-(delta-1))
|
||||||
if id_ > 0:
|
if id_ > 0:
|
||||||
weights[i:i+1] = [id_, delta, weights[i]-id_]
|
weights[i:i+1] = [id_, delta, weights[i]-id_]
|
||||||
lifetimes[i:i+1] = [
|
lifetimes[i:i+1] = [
|
||||||
@@ -288,7 +288,7 @@ def show_log(block_size, data, rev, off, *,
|
|||||||
|
|
||||||
elif delta < 0:
|
elif delta < 0:
|
||||||
# shrink lifetimes
|
# shrink lifetimes
|
||||||
i, id_ = index(weights, lower_)
|
i, id_ = index(weights, id+1)
|
||||||
delta_ = -delta
|
delta_ = -delta
|
||||||
weights_ = weights.copy()
|
weights_ = weights.copy()
|
||||||
lifetimes_ = lifetimes.copy()
|
lifetimes_ = lifetimes.copy()
|
||||||
|
|||||||
Reference in New Issue
Block a user