static inline int si_noderecover(sinode *n, sr *r) { /* recover branches */ sriter i; sr_iterinit(sd_recover, &i, r); sr_iteropen(sd_recover, &i, &n->file); int first = 1; int rc; while (sr_iteratorhas(&i)) { sdindexheader *h = sr_iteratorof(&i); sibranch *b; if (first) { b = &n->self; } else { b = si_branchnew(r); if (srunlikely(b == NULL)) goto error; } sdindex index; sd_indexinit(&index); rc = sd_indexcopy(&index, r, h); if (srunlikely(rc == -1)) goto error; si_branchset(b, &index); b->next = n->branch; n->branch = b; n->branch_count++; first = 0; sr_iteratornext(&i); } rc = sd_recover_complete(&i); if (srunlikely(rc == -1)) goto error; sr_iteratorclose(&i); return 0; error: sr_iteratorclose(&i); return -1; }
srfile f; sr_fileinit(&f, &a); t( sr_filenew(&f, "./0000.db") == 0 ); t( sd_commit(&b, &r, &index, &f) == 0 ); srmap map; t( sr_mapfile(&map, &f, 1) == 0 ); sdindex i; sd_indexinit(&i); i.h = (sdindexheader*)(map.p); sriter it; sr_iterinit(sd_iter, &it, &r); sr_iteropen(sd_iter, &it, &i, map.p, 1, 0, NULL); t( sr_iteratorhas(&it) == 1 ); sv *v = sr_iteratorof(&it); t( *(int*)sv_key(v, &r, 0) == 7); sr_iteratornext(&it); v = sr_iteratorof(&it); t( *(int*)sv_key(v, &r, 0) == 8); sr_iteratornext(&it); v = sr_iteratorof(&it); t( *(int*)sv_key(v, &r, 0) == 9); sr_iteratornext(&it); t( sr_iteratorhas(&it) == 0 ); sr_iteratorclose(&it); sr_fileclose(&f); t( sr_mapunmap(&map) == 0 );