mirror of
https://github.com/urbit/ares.git
synced 2024-12-23 05:12:15 +03:00
Merge pull request #226 from urbit/barter-simsum/pma-record-node-partitions-in-flist-on-restore
pma: fix memory corruption restoration bug
This commit is contained in:
commit
34c4d036bd
@ -318,7 +318,7 @@ int main(int argc, char *argv[])
|
||||
assert(SUCC(bt_state_open(state4, "./pmatest4", 0, 0644)));
|
||||
|
||||
assert(state4->file_size_p == PMA_INITIAL_SIZE_p + PMA_GROW_SIZE_p * 2);
|
||||
assert(state4->flist->next->hi == state4->file_size_p);
|
||||
assert(state4->flist->hi == state4->file_size_p);
|
||||
|
||||
for (size_t i = 0; i < PMA_GROW_SIZE_b * 2; i++)
|
||||
assert(t4a_copy[i] == t4a[i]);
|
||||
|
@ -1689,7 +1689,6 @@ _flist_grow(BT_state *state, size_t pages)
|
||||
static int
|
||||
_flist_new(BT_state *state, size_t size_p)
|
||||
#define FLIST_PG_START (BT_META_SECTION_WIDTH / BT_PAGESIZE)
|
||||
/* #define FLIST_PG_START ((BT_META_SECTION_WIDTH + BLK_BASE_LEN0_b) / BT_PAGESIZE) */
|
||||
{
|
||||
BT_flistnode *head = calloc(1, sizeof *head);
|
||||
head->next = 0;
|
||||
@ -2407,6 +2406,22 @@ _freelist_restore2(BT_state *state, BT_page *node,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_flist_restore_partitions(BT_state *state)
|
||||
{
|
||||
BT_meta *meta = state->meta_pages[state->which];
|
||||
assert(meta->blk_base[0] == BT_NUMMETAS);
|
||||
|
||||
for (size_t i = 0
|
||||
; i < BT_NUMPARTS && meta->blk_base[i] != 0
|
||||
; i++) {
|
||||
pgno_t partoff_p = meta->blk_base[i];
|
||||
size_t partlen_p = BLK_BASE_LENS_b[i] / BT_PAGESIZE;
|
||||
|
||||
_flist_record_alloc(state, partoff_p, partoff_p + partlen_p);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_freelist_restore(BT_state *state)
|
||||
/* restores the mlist, nlist, and mlist */
|
||||
@ -2416,7 +2431,11 @@ _freelist_restore(BT_state *state)
|
||||
assert(SUCC(_flist_new(state, state->file_size_p)));
|
||||
assert(SUCC(_nlist_load(state)));
|
||||
assert(SUCC(_mlist_new(state)));
|
||||
/* first record root's allocation */
|
||||
|
||||
/* record node partitions in flist */
|
||||
_flist_restore_partitions(state);
|
||||
|
||||
/* record root's allocation and then handle subtree */
|
||||
_nlist_record_alloc(state, root);
|
||||
_freelist_restore2(state, root, 1, meta->depth);
|
||||
}
|
||||
@ -2515,7 +2534,6 @@ _bt_state_load(BT_state *state)
|
||||
/* map the node segment */
|
||||
_bt_state_map_node_segment(state);
|
||||
|
||||
/* new db, so populate metadata */
|
||||
if (new) {
|
||||
assert(SUCC(_flist_new(state, PMA_GROW_SIZE_p)));
|
||||
assert(SUCC(_nlist_new(state)));
|
||||
|
Loading…
Reference in New Issue
Block a user