From 055ae27d66cf13de6f0fcffcf3f0f57045cb9f64 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Thu, 24 Jan 2019 23:59:02 -0800 Subject: [PATCH 1/5] replay one event at a time --- vere/sist.c | 377 ++++++++++++++++++++-------------------------------- 1 file changed, 141 insertions(+), 236 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index 7b3266fe7..4ed454712 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -15,10 +15,14 @@ c3_d u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) { u3_ulog* lug_u = &u3Z->lug_u; + c3_d hed_d; + c3_d ven_d; c3_d tar_d; u3_ular lar_u; - tar_d = lug_u->len_d + len_w; + hed_d = lug_u->len_d; + ven_d = hed_d + c3_wiseof(c3_w); + tar_d = ven_d + (c3_d)len_w; lar_u.tem_w = tem_w; lar_u.typ_w = typ_w; @@ -30,6 +34,8 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) u3A->ent_d++; lar_u.len_w = len_w; + // write trailer + // if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) { uL(fprintf(uH, "sist: seek failed, lseek: %s\n", strerror(errno))); c3_assert(0); @@ -38,7 +44,19 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) uL(fprintf(uH, "sist: write failed, write: %s\n", strerror(errno))); c3_assert(0); } - if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) { + // write header (just a size) + // + if ( -1 == lseek64(lug_u->fid_i, 4ULL * hed_d, SEEK_SET) ) { + uL(fprintf(uH, "sist: seek failed, lseek: %s\n", strerror(errno))); + c3_assert(0); + } + if ( sizeof(c3_w) != write(lug_u->fid_i, &len_w, sizeof(c3_w)) ) { + uL(fprintf(uH, "sist: write failed, write: %s\n", strerror(errno))); + c3_assert(0); + } + // write the event in between the header and trailer + // + if ( -1 == lseek64(lug_u->fid_i, 4ULL * ven_d, SEEK_SET) ) { uL(fprintf(uH, "sist: seek failed, lseek: %s\n", strerror(errno))); c3_assert(0); } @@ -54,7 +72,7 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) uL(fprintf(uH, "sist: write failed, write: %s\n", strerror(errno))); c3_assert(0); } - lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u)); + lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u) + c3_wiseof(c3_w)); free(bob_w); // Sync. Or, what goes by sync. @@ -242,7 +260,7 @@ _sist_sing(u3_noun ovo) if ( c3__init == u3h(fav) ) { u3A->own = u3k(u3t(fav)); - u3A->fak = ( c3__fake == u3h(tag) ) ? c3y : c3n; + u3A->fak = ( c3__fake == u3h(dat) ) ? c3y : c3n; } vir = u3t(vir); @@ -554,7 +572,7 @@ _sist_zest() { u3_uled led_u; - led_u.mag_l = u3r_mug('g'); + led_u.mag_l = u3r_mug('h'); led_u.kno_w = 163; if ( 0 == u3A->key ) { @@ -581,144 +599,6 @@ _sist_zest() u3_raft_play(); } -/* _sist_rest_nuu(): upgrade log from previous format. -*/ -static void -_sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) -{ - c3_c nuu_c[2048]; - u3_noun roe = u3_nul; - c3_i fid_i = lug_u->fid_i; - c3_i fud_i; - c3_i ret_i; - c3_d end_d = lug_u->len_d; - - uL(fprintf(uH, "rest: converting log from prior format\n")); - - c3_assert(led_u.mag_l == u3r_mug('f')); - - if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "rest: rest_nuu failed (a), lseek64: %s\n", strerror(errno))); - u3_lo_bail(); - } - - while ( end_d != c3_wiseof(u3_uled) ) { - c3_d tar_d; - u3_olar lar_u; - c3_w* img_w; - u3_noun ron; - - tar_d = (end_d - (c3_d)c3_wiseof(u3_olar)); - - if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (b), lseek64: %s\n", strerror(errno))); - u3_lo_bail(); - } - if ( sizeof(u3_olar) != read(fid_i, &lar_u, sizeof(u3_olar)) ) { - uL(fprintf(uH, "rest_nuu failed (c), read: %s\n", strerror(errno))); - u3_lo_bail(); - } - - if ( lar_u.syn_w != u3r_mug_chub(tar_d) ) { - uL(fprintf(uH, "rest_nuu failed (d)\n")); - u3_lo_bail(); - } - - img_w = c3_malloc(4 * lar_u.len_w); - end_d = (tar_d - (c3_d)lar_u.len_w); - - if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (e), lseek64: %s\n", strerror(errno))); - u3_lo_bail(); - } - if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { - uL(fprintf(uH, "rest_nuu failed (f), read: %s\n", strerror(errno))); - u3_lo_bail(); - } - - ron = u3i_words(lar_u.len_w, img_w); - free(img_w); - - if ( lar_u.mug_w != u3r_mug(ron) ) { - uL(fprintf(uH, "rest_nuu failed (g)\n")); - u3_lo_bail(); - } - - roe = u3nc(ron, roe); - } - - if ( 0 != close(fid_i) ) { - uL(fprintf(uH, "rest: could not close, close: %s\n", strerror(errno))); - u3_lo_bail(); - } - - ret_i = snprintf(nuu_c, 2048, "%s/.urb/ham.hope", u3_Host.dir_c); - c3_assert(ret_i < 2048); - - if ( (fud_i = open(nuu_c, O_CREAT | O_TRUNC | O_RDWR, 0600)) < 0 ) { - uL(fprintf(uH, "rest: can't open record (%s), open: %s\n", nuu_c, - strerror(errno))); - u3_lo_bail(); - } - - led_u.mag_l = u3r_mug('g'); - if ( (sizeof(led_u) != write(fud_i, &led_u, sizeof(led_u))) ) { - uL(fprintf(uH, "rest: can't write header, write: %s\n", strerror(errno))); - u3_lo_bail(); - } - - { - c3_d ent_d = 1; - - c3_assert(end_d == c3_wiseof(u3_uled)); - while ( u3_nul != roe ) { - u3_noun ovo = u3k(u3h(roe)); - u3_noun nex = u3k(u3t(roe)); - u3_ular lar_u; - c3_w* img_w; - c3_d tar_d; - - lar_u.len_w = u3r_met(5, ovo); - tar_d = end_d + lar_u.len_w; - lar_u.syn_w = u3r_mug(tar_d); - lar_u.ent_d = ent_d; - lar_u.tem_w = 0; - lar_u.typ_w = c3__ov; - - u3_noun moo = u3nt(u3k(ovo), u3_nul, c3__ov); - lar_u.mug_w = u3r_mug(moo); - u3z(moo); - - img_w = c3_malloc(lar_u.len_w << 2); - u3r_words(0, lar_u.len_w, img_w, ovo); - u3z(ovo); - - if ( (lar_u.len_w << 2) != write(fud_i, img_w, lar_u.len_w << 2) ) { - uL(fprintf(uH, "rest_nuu failed (h), write: %s\n", strerror(errno))); - u3_lo_bail(); - } - if ( sizeof(u3_ular) != write(fud_i, &lar_u, sizeof(u3_ular)) ) { - uL(fprintf(uH, "rest_nuu failed (i), write: %s\n", strerror(errno))); - u3_lo_bail(); - } - - ent_d++; - end_d = tar_d + c3_wiseof(u3_ular); - u3z(roe); roe = nex; - } - } - if ( 0 != rename(nuu_c, old_c) ) { - uL(fprintf(uH, "rest_nuu failed (k), rename: %s\n", strerror(errno))); - u3_lo_bail(); - } - if ( -1 == lseek64(fud_i, sizeof(u3_uled), SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (l), lseek64: %s\n", strerror(errno))); - u3_lo_bail(); - } - lug_u->fid_i = fud_i; - lug_u->len_d = end_d; -} - /* _sist_rest(): restore from record, or exit. */ static void @@ -727,11 +607,12 @@ _sist_rest() struct stat buf_b; c3_i fid_i; c3_c ful_c[2048]; + c3_d cur_d; c3_d old_d = u3A->ent_d; c3_d las_d = 0; - u3_noun roe = u3_nul; u3_noun sev_l, key_l, sal_l; u3_noun ohh = c3n; + u3_ular lar_u; if ( 0 != u3A->ent_d ) { u3_noun ent; @@ -779,11 +660,7 @@ _sist_rest() u3_lo_bail(); } - if ( u3r_mug('f') == led_u.mag_l ) { - _sist_rest_nuu(&u3Z->lug_u, led_u, ful_c); - fid_i = u3Z->lug_u.fid_i; - } - else if (u3r_mug('g') != led_u.mag_l ) { + if (u3r_mug('h') != led_u.mag_l ) { uL(fprintf(uH, "record (%s) is obsolete (or corrupt)\n", ful_c)); u3_lo_bail(); } @@ -841,26 +718,22 @@ _sist_rest() // Read in the fscking events. These are probably corrupt as well. { c3_d ent_d; - c3_d end_d; u3_noun rup = c3n; - end_d = u3Z->lug_u.len_d; + cur_d = u3Z->lug_u.len_d; ent_d = 0; - if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "end_d %" PRIu64 ", lseek64: %s\n", end_d, + if ( -1 == lseek64(fid_i, 4ULL * cur_d, SEEK_SET) ) { + uL(fprintf(uH, "cur_d %" PRIu64 ", lseek64: %s\n", cur_d, strerror(errno))); uL(fprintf(uH, "rest: record (%s) is corrupt (c)\n", ful_c)); u3_lo_bail(); } - while ( end_d != c3_wiseof(u3_uled) ) { - c3_d tar_d = (end_d - (c3_d)c3_wiseof(u3_ular)); - u3_ular lar_u; - c3_w* img_w; - u3_noun ron; + while ( cur_d != (c3_d)c3_wiseof(u3_uled) ) { + c3_d tar_d = (cur_d - (c3_d)c3_wiseof(u3_ular)); - // uL(fprintf(uH, "rest: reading event at %" PRIx64 "\n", end_d)); + // uL(fprintf(uH, "rest: reading event at %" PRIx64 "\n", cur_d)); if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); @@ -877,7 +750,7 @@ _sist_rest() rup = c3y; } uL(fprintf(uH, "lar:%x mug:%x\n", lar_u.syn_w, u3r_mug_chub(tar_d))); - end_d--; u3Z->lug_u.len_d--; + cur_d--; u3Z->lug_u.len_d--; continue; } else if ( c3y == rup ) { @@ -897,7 +770,7 @@ _sist_rest() lar_u.len_w, lar_u.mug_w)); #endif - if ( end_d == u3Z->lug_u.len_d ) { + if ( cur_d == u3Z->lug_u.len_d ) { ent_d = las_d = lar_u.ent_d; } else { @@ -908,27 +781,13 @@ _sist_rest() } ent_d -= 1ULL; } - end_d = (tar_d - (c3_d)lar_u.len_w); + cur_d = tar_d - (c3_d)(lar_u.len_w + c3_wiseof(c3_w)); if ( ent_d < old_d ) { /* change to continue to check all events */ break; } - img_w = c3_malloc(4 * lar_u.len_w); - - if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (h)\n", ful_c)); - u3_lo_bail(); - } - if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (i)\n", ful_c)); - u3_lo_bail(); - } - - ron = u3i_words(lar_u.len_w, img_w); - free(img_w); - // this validation is disabled, as it broke when mug // was switched from FNV to Murmur3 // event-log encryption is enabled, so any actual corruption @@ -944,32 +803,11 @@ _sist_rest() u3_lo_bail(); } #endif - - if ( c3__ov != lar_u.typ_w ) { - u3z(ron); - continue; - } - - if ( u3A->key ) { - u3_noun dep; - - dep = u3dc("de:crub:crypto", u3k(u3A->key), ron); - if ( c3n == u3du(dep) ) { - uL(fprintf(uH, "record (%s) is corrupt (k)\n", ful_c)); - u3_lo_bail(); - } - else { - ron = u3k(u3t(dep)); - u3z(dep); - } - } - - roe = u3nc(u3ke_cue(ron), roe); } u3A->ent_d = c3_max(las_d + 1ULL, old_d); } - if ( u3_nul == roe ) { + if ( cur_d == u3Z->lug_u.len_d ) { // Nothing in the log that was not also in the checkpoint. // c3_assert(u3A->ent_d == old_d); @@ -982,45 +820,112 @@ _sist_rest() u3_lo_bail(); } } - else { - u3_noun rou = roe; - c3_w xno_w; - // Execute the fscking things. This is pretty much certain to crash. + + // Read and execute the fscking things. This is pretty much certain to crash. + // + uL(fprintf(uH, "rest: replaying through event %" PRIu64 "\n", las_d)); + fprintf(uH, "---------------- playback starting----------------\n"); + + c3_w xno_w = 0; + while ( cur_d != u3Z->lug_u.len_d ) { + u3_noun ven; + u3_noun now, ovo; + c3_d tar_d; + c3_w* img_w; + c3_w len_w; + + // read the size // - uL(fprintf(uH, "rest: replaying through event %" PRIu64 "\n", las_d)); - fprintf(uH, "---------------- playback starting----------------\n"); + if ( -1 == lseek64(fid_i, 4ULL * cur_d, SEEK_SET) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); + u3_lo_bail(); + } + if ( sizeof(len_w) != read(fid_i, &len_w, sizeof(len_w)) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); + u3_lo_bail(); + } - xno_w = 0; - while ( u3_nul != roe ) { - u3_noun i_roe = u3h(roe); - u3_noun t_roe = u3t(roe); - u3_noun now = u3h(i_roe); - u3_noun ovo = u3t(i_roe); + tar_d = cur_d + c3_wiseof(len_w) + len_w; - u3v_time(u3k(now)); - if ( (c3y == u3_Host.ops_u.vno) && - ( (c3__veer == u3h(u3t(ovo)) || - (c3__vega == u3h(u3t(ovo)))) ) ) - { - fprintf(stderr, "replay: skipped veer\n"); + // read the trailer + // + if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); + u3_lo_bail(); + } + if ( sizeof(u3_ular) != read(fid_i, &lar_u, sizeof(u3_ular)) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); + u3_lo_bail(); + } + + img_w = c3_malloc(4 * lar_u.len_w); + + // read the event + // + if ( -1 == lseek64(fid_i, 4ULL * (cur_d + c3_wiseof(c3_w)), SEEK_SET) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (h)\n", ful_c)); + u3_lo_bail(); + } + if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (i)\n", ful_c)); + u3_lo_bail(); + } + + ven = u3i_words(lar_u.len_w, img_w); + free(img_w); + + if ( c3__ov != lar_u.typ_w ) { + u3z(ven); + continue; + } + + // decrypt the event + // + if ( u3A->key ) { + u3_noun dep; + + dep = u3dc("de:crub:crypto", u3k(u3A->key), ven); + if ( c3n == u3du(dep) ) { + uL(fprintf(uH, "record (%s) is corrupt (k)\n", ful_c)); + u3_lo_bail(); } else { - _sist_sing(u3k(ovo)); - fputc('.', stderr); - } - - // fprintf(stderr, "playback: sing: %d\n", xno_w)); - - roe = t_roe; - xno_w++; - - if ( 0 == (xno_w % 1000) ) { - uL(fprintf(uH, "{%d}\n", xno_w)); - // u3_lo_grab("rest", rou, u3_none); + ven = u3k(u3t(dep)); + u3z(dep); } } - u3z(rou); + + // run the event + // + ven = u3ke_cue(ven); + now = u3h(ven); + ovo = u3t(ven); + + u3v_time(u3k(now)); + + if ( (c3y == u3_Host.ops_u.vno) && + ( (c3__veer == u3h(u3t(ovo)) || + (c3__vega == u3h(u3t(ovo)))) ) ) + { + fprintf(stderr, "replay: skipped veer\n"); + } + else { + _sist_sing(u3k(ovo)); + fputc('.', stderr); + } + + // fprintf(stderr, "playback: sing: %d\n", xno_w)); + + xno_w++; + + if ( 0 == (xno_w % 1000) ) { + uL(fprintf(uH, "{%d}\n", xno_w)); + // u3_lo_grab("rest", rou, u3_none); + } + + u3z(ven); + cur_d += c3_wiseof(len_w) + len_w + c3_wiseof(lar_u); } uL(fprintf(stderr, "\n---------------- playback complete----------------\r\n")); @@ -1062,13 +967,13 @@ _sist_rest() if ( c3y == ohh ) { uL(fprintf(uH, "rest: bumping ent_d\n")); u3_ular lar_u; - c3_d end_d; + c3_d cur_d; c3_d tar_d; u3A->ent_d++; - end_d = u3Z->lug_u.len_d; - while ( end_d != c3_wiseof(u3_uled) ) { - tar_d = end_d - c3_wiseof(u3_ular); + cur_d = u3Z->lug_u.len_d; + while ( cur_d != c3_wiseof(u3_uled) ) { + tar_d = cur_d - c3_wiseof(u3_ular); if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { uL(fprintf(uH, "bumping sequence numbers failed (a)\n")); u3_lo_bail(); @@ -1086,7 +991,7 @@ _sist_rest() uL(fprintf(uH, "bumping sequence numbers failed (d)\n")); u3_lo_bail(); } - end_d = tar_d - lar_u.len_w; + cur_d = tar_d - (c3_d)(lar_u.len_w + c3_wiseof(c3_w)); } } @@ -1094,11 +999,11 @@ _sist_rest() { u3_uled led_u; - led_u.mag_l = u3r_mug('g'); + led_u.mag_l = u3r_mug('h'); led_u.sal_l = sal_l; led_u.sev_l = u3A->sev_l; led_u.key_l = u3A->key ? u3r_mug(u3A->key) : 0; - led_u.kno_w = 163; // may need actual translation! + led_u.kno_w = 163; // XX very wrong led_u.tno_l = 1; if ( (-1 == lseek64(fid_i, 0, SEEK_SET)) || From 079b87cbd683ca69759cb8b26904da6fb5a8b5c3 Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Mon, 28 Jan 2019 15:08:53 -0800 Subject: [PATCH 2/5] added _sist_rest_nuu for g -> h log format conversion --- vere/sist.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/vere/sist.c b/vere/sist.c index 4ed454712..c6988aebd 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -599,6 +599,151 @@ _sist_zest() u3_raft_play(); } +/* _sist_rest_nuu(): upgrade log from previous format. +*/ +static void +_sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) +{ + c3_c nuu_c[2048]; + u3_noun roe = u3_nul; + c3_i fid_i = lug_u->fid_i; + c3_i fud_i; + c3_i ret_i; + c3_d end_d = lug_u->len_d; + + uL(fprintf(uH, "rest: converting log from prior format\n")); + + c3_assert(led_u.mag_l == u3r_mug('g')); + + ret_i = snprintf(nuu_c, 2048, "%s/.urb/ham.hope", u3_Host.dir_c); + c3_assert(ret_i < 2048); + + if ( (fud_i = open(nuu_c, O_CREAT | O_TRUNC | O_RDWR, 0600)) < 0 ) { + uL(fprintf(uH, "rest: can't open record (%s), open: %s\n", nuu_c, + strerror(errno))); + u3_lo_bail(); + } + + led_u.mag_l = u3r_mug('h'); + if ( (sizeof(led_u) != write(fud_i, &led_u, sizeof(led_u))) ) { + uL(fprintf(uH, "rest: can't write header, write: %s\n", strerror(errno))); + u3_lo_bail(); + } + + c3_o fir_o = c3y; + c3_d pos_d; + + while ( end_d != c3_wiseof(u3_uled) ) { + c3_d tar_d; + u3_ular lar_u; + c3_w* img_w; + u3_noun ron; + + // read trailer + // + tar_d = (end_d - (c3_d)c3_wiseof(u3_ular)); + + if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { + uL(fprintf(uH, "rest_nuu failed (b), lseek64: %s\n", strerror(errno))); + u3_lo_bail(); + } + if ( sizeof(u3_ular) != read(fid_i, &lar_u, sizeof(u3_ular)) ) { + uL(fprintf(uH, "rest_nuu failed (c), read: %s\n", strerror(errno))); + u3_lo_bail(); + } + + if ( lar_u.syn_w != u3r_mug_chub(tar_d) ) { + uL(fprintf(uH, "rest_nuu failed (d)\n")); + u3_lo_bail(); + } + + // calculate new log size + // + if (c3y == fir_o) { + pos_d = (end_d + lar_u.ent_d + 1); + fir_o = c3n; + } + + // read event + // + img_w = c3_malloc(4 * lar_u.len_w); + end_d = (tar_d - (c3_d)lar_u.len_w); + + if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { + uL(fprintf(uH, "rest_nuu failed (e), lseek64: %s\n", strerror(errno))); + u3_lo_bail(); + } + if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { + uL(fprintf(uH, "rest_nuu failed (f), read: %s\n", strerror(errno))); + u3_lo_bail(); + } + + // write event trailer + // + pos_d -= (c3_d)c3_wiseof(lar_u); + lar_u.syn_w = u3r_mug_chub(pos_d); + + if ( -1 == lseek64(fud_i, (4ULL * pos_d), SEEK_SET) ) { + uL(fprintf(uH, "rest_nuu failed (g), lseek64: %s\n", strerror(errno))); + u3_lo_bail(); + } + + if ( sizeof(u3_ular) != write(fud_i, &lar_u, sizeof(u3_ular)) ) { + uL(fprintf(uH, "rest_nuu failed (h), read: %s\n", strerror(errno))); + u3_lo_bail(); + } + + // write event + // + pos_d -= (c3_d)lar_u.len_w; + + if ( -1 == lseek64(fud_i, (4ULL * pos_d), SEEK_SET) ) { + uL(fprintf(uH, "rest_nuu failed (i), lseek64: %s\n", strerror(errno))); + u3_lo_bail(); + } + + if ( (4 * lar_u.len_w) != write(fud_i, img_w, (4 * lar_u.len_w)) ) { + uL(fprintf(uH, "rest_nuu failed (j), read: %s\n", strerror(errno))); + u3_lo_bail(); + } + + // write event header + // + pos_d -= 1ULL; + if ( -1 == lseek64(fud_i, (4ULL * pos_d), SEEK_SET) ) { + uL(fprintf(uH, "rest_nuu failed (k), lseek64: %s\n", strerror(errno))); + u3_lo_bail(); + } + + if ( 4ULL != write(fud_i, &lar_u.len_w, 4ULL) ) { + uL(fprintf(uH, "rest_nuu failed (l), read: %s\n", strerror(errno))); + u3_lo_bail(); + } + + free(img_w); + + if ( lar_u.ent_d % 100000 == 0 ) { + printf("ent_d: %d\n", lar_u.ent_d); + } + } + + if ( 0 != close(fid_i) ) { + uL(fprintf(uH, "rest: could not close, close: %s\n", strerror(errno))); + u3_lo_bail(); + } + + if ( 0 != rename(nuu_c, old_c) ) { + uL(fprintf(uH, "rest_nuu failed (k), rename: %s\n", strerror(errno))); + u3_lo_bail(); + } + if ( -1 == lseek64(fud_i, sizeof(u3_uled), SEEK_SET) ) { + uL(fprintf(uH, "rest_nuu failed (l), lseek64: %s\n", strerror(errno))); + u3_lo_bail(); + } + lug_u->fid_i = fud_i; + lug_u->len_d = end_d; +} + /* _sist_rest(): restore from record, or exit. */ static void @@ -660,7 +805,10 @@ _sist_rest() u3_lo_bail(); } - if (u3r_mug('h') != led_u.mag_l ) { + if ( u3r_mug('g') == led_u.mag_l ) { + _sist_rest_nuu(&u3Z->lug_u, led_u, ful_c); + fid_i = u3Z->lug_u.fid_i; + } else if (u3r_mug('h') != led_u.mag_l ) { uL(fprintf(uH, "record (%s) is obsolete (or corrupt)\n", ful_c)); u3_lo_bail(); } From bb258a5b66ebc98b20a57e3053827aae1b3e11d1 Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Mon, 28 Jan 2019 17:20:14 -0800 Subject: [PATCH 3/5] - stuck event playback in else block - store new event log size correctly - minor code cleanup --- vere/sist.c | 213 ++++++++++++++++++++++++++-------------------------- 1 file changed, 105 insertions(+), 108 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index c6988aebd..58ba47e0d 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -632,12 +632,12 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) c3_o fir_o = c3y; c3_d pos_d; + c3_d new_d = c3_wiseof(u3_uled); while ( end_d != c3_wiseof(u3_uled) ) { c3_d tar_d; u3_ular lar_u; c3_w* img_w; - u3_noun ron; // read trailer // @@ -661,6 +661,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) // if (c3y == fir_o) { pos_d = (end_d + lar_u.ent_d + 1); + new_d = (end_d + lar_u.ent_d + 1); fir_o = c3n; } @@ -681,6 +682,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) // write event trailer // pos_d -= (c3_d)c3_wiseof(lar_u); + lar_u.syn_w = u3r_mug_chub(pos_d); if ( -1 == lseek64(fud_i, (4ULL * pos_d), SEEK_SET) ) { @@ -709,7 +711,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) // write event header // - pos_d -= 1ULL; + pos_d -= (4ULL * c3_wiseof(c3_w)); if ( -1 == lseek64(fud_i, (4ULL * pos_d), SEEK_SET) ) { uL(fprintf(uH, "rest_nuu failed (k), lseek64: %s\n", strerror(errno))); u3_lo_bail(); @@ -721,10 +723,6 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) } free(img_w); - - if ( lar_u.ent_d % 100000 == 0 ) { - printf("ent_d: %d\n", lar_u.ent_d); - } } if ( 0 != close(fid_i) ) { @@ -741,7 +739,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) u3_lo_bail(); } lug_u->fid_i = fud_i; - lug_u->len_d = end_d; + lug_u->len_d = new_d; } /* _sist_rest(): restore from record, or exit. @@ -967,115 +965,114 @@ _sist_rest() "and do not delete your pier!\n")); u3_lo_bail(); } - } - - - // Read and execute the fscking things. This is pretty much certain to crash. - // - uL(fprintf(uH, "rest: replaying through event %" PRIu64 "\n", las_d)); - fprintf(uH, "---------------- playback starting----------------\n"); - - c3_w xno_w = 0; - while ( cur_d != u3Z->lug_u.len_d ) { - u3_noun ven; - u3_noun now, ovo; - c3_d tar_d; - c3_w* img_w; - c3_w len_w; - - // read the size + } else { + // Read and execute the fscking things. This is pretty much certain to crash. // - if ( -1 == lseek64(fid_i, 4ULL * cur_d, SEEK_SET) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); - u3_lo_bail(); - } - if ( sizeof(len_w) != read(fid_i, &len_w, sizeof(len_w)) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); - u3_lo_bail(); - } + uL(fprintf(uH, "rest: replaying through event %" PRIu64 "\n", las_d)); + fprintf(uH, "---------------- playback starting----------------\n"); - tar_d = cur_d + c3_wiseof(len_w) + len_w; + c3_w xno_w = 0; + while ( cur_d != u3Z->lug_u.len_d ) { + u3_noun ven; + u3_noun now, ovo; + c3_d tar_d; + c3_w* img_w; + c3_w len_w; - // read the trailer - // - if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); - u3_lo_bail(); - } - if ( sizeof(u3_ular) != read(fid_i, &lar_u, sizeof(u3_ular)) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); - u3_lo_bail(); - } - - img_w = c3_malloc(4 * lar_u.len_w); - - // read the event - // - if ( -1 == lseek64(fid_i, 4ULL * (cur_d + c3_wiseof(c3_w)), SEEK_SET) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (h)\n", ful_c)); - u3_lo_bail(); - } - if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { - uL(fprintf(uH, "rest: record (%s) is corrupt (i)\n", ful_c)); - u3_lo_bail(); - } - - ven = u3i_words(lar_u.len_w, img_w); - free(img_w); - - if ( c3__ov != lar_u.typ_w ) { - u3z(ven); - continue; - } - - // decrypt the event - // - if ( u3A->key ) { - u3_noun dep; - - dep = u3dc("de:crub:crypto", u3k(u3A->key), ven); - if ( c3n == u3du(dep) ) { - uL(fprintf(uH, "record (%s) is corrupt (k)\n", ful_c)); + // read the size + // + if ( -1 == lseek64(fid_i, 4ULL * cur_d, SEEK_SET) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); u3_lo_bail(); } - else { - ven = u3k(u3t(dep)); - u3z(dep); + if ( sizeof(len_w) != read(fid_i, &len_w, sizeof(len_w)) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); + u3_lo_bail(); } + + tar_d = cur_d + c3_wiseof(len_w) + len_w; + + // read the trailer + // + if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); + u3_lo_bail(); + } + if ( sizeof(u3_ular) != read(fid_i, &lar_u, sizeof(u3_ular)) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); + u3_lo_bail(); + } + + img_w = c3_malloc(4 * lar_u.len_w); + + // read the event + // + if ( -1 == lseek64(fid_i, 4ULL * (cur_d + c3_wiseof(c3_w)), SEEK_SET) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (h)\n", ful_c)); + u3_lo_bail(); + } + if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { + uL(fprintf(uH, "rest: record (%s) is corrupt (i)\n", ful_c)); + u3_lo_bail(); + } + + ven = u3i_words(lar_u.len_w, img_w); + free(img_w); + + if ( c3__ov != lar_u.typ_w ) { + u3z(ven); + continue; + } + + // decrypt the event + // + if ( u3A->key ) { + u3_noun dep; + + dep = u3dc("de:crub:crypto", u3k(u3A->key), ven); + if ( c3n == u3du(dep) ) { + uL(fprintf(uH, "record (%s) is corrupt (k)\n", ful_c)); + u3_lo_bail(); + } + else { + ven = u3k(u3t(dep)); + u3z(dep); + } + } + + // run the event + // + ven = u3ke_cue(ven); + now = u3h(ven); + ovo = u3t(ven); + + u3v_time(u3k(now)); + + if ( (c3y == u3_Host.ops_u.vno) && + ( (c3__veer == u3h(u3t(ovo)) || + (c3__vega == u3h(u3t(ovo)))) ) ) + { + fprintf(stderr, "replay: skipped veer\n"); + } + else { + _sist_sing(u3k(ovo)); + fputc('.', stderr); + } + + // fprintf(stderr, "playback: sing: %d\n", xno_w)); + + xno_w++; + + if ( 0 == (xno_w % 1000) ) { + uL(fprintf(uH, "{%d}\n", xno_w)); + // u3_lo_grab("rest", rou, u3_none); + } + + u3z(ven); + cur_d += c3_wiseof(len_w) + len_w + c3_wiseof(lar_u); } - - // run the event - // - ven = u3ke_cue(ven); - now = u3h(ven); - ovo = u3t(ven); - - u3v_time(u3k(now)); - - if ( (c3y == u3_Host.ops_u.vno) && - ( (c3__veer == u3h(u3t(ovo)) || - (c3__vega == u3h(u3t(ovo)))) ) ) - { - fprintf(stderr, "replay: skipped veer\n"); - } - else { - _sist_sing(u3k(ovo)); - fputc('.', stderr); - } - - // fprintf(stderr, "playback: sing: %d\n", xno_w)); - - xno_w++; - - if ( 0 == (xno_w % 1000) ) { - uL(fprintf(uH, "{%d}\n", xno_w)); - // u3_lo_grab("rest", rou, u3_none); - } - - u3z(ven); - cur_d += c3_wiseof(len_w) + len_w + c3_wiseof(lar_u); + uL(fprintf(stderr, "\n---------------- playback complete----------------\r\n")); } - uL(fprintf(stderr, "\n---------------- playback complete----------------\r\n")); #if 0 // If you see this error, your record is totally fscking broken! From 7dcfbfd55ffdb26f832f40031478a6eadef3211e Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Mon, 28 Jan 2019 18:49:55 -0800 Subject: [PATCH 4/5] fixed bug with event header size --- vere/sist.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index 58ba47e0d..1600382c7 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -631,8 +631,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) } c3_o fir_o = c3y; - c3_d pos_d; - c3_d new_d = c3_wiseof(u3_uled); + c3_d pos_d, new_d; while ( end_d != c3_wiseof(u3_uled) ) { c3_d tar_d; @@ -661,7 +660,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) // if (c3y == fir_o) { pos_d = (end_d + lar_u.ent_d + 1); - new_d = (end_d + lar_u.ent_d + 1); + new_d = pos_d; fir_o = c3n; } @@ -711,7 +710,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) // write event header // - pos_d -= (4ULL * c3_wiseof(c3_w)); + pos_d -= c3_wiseof(c3_w); if ( -1 == lseek64(fud_i, (4ULL * pos_d), SEEK_SET) ) { uL(fprintf(uH, "rest_nuu failed (k), lseek64: %s\n", strerror(errno))); u3_lo_bail(); From 56049e22467d03713df2491ca07f39fc94d8bceb Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 29 Jan 2019 00:05:23 -0800 Subject: [PATCH 5/5] @joemfb review comments --- include/vere/vere.h | 9 --------- vere/sist.c | 8 +++++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/include/vere/vere.h b/include/vere/vere.h index e19d7af5c..712086403 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -326,15 +326,6 @@ c3_l tno_l; // terminal count in host } u3_uled; - /* u3_olar: event log trailer, old version. - */ - typedef struct { - c3_w syn_w; // must equal mug of address - c3_w ent_w; // event sequence number - c3_w len_w; // word length of this event - c3_w mug_w; // mug of entry - } u3_olar; - /* u3_ular: event log trailer. */ typedef struct { diff --git a/vere/sist.c b/vere/sist.c index 1600382c7..3d893ea40 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -658,7 +658,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) // calculate new log size // - if (c3y == fir_o) { + if ( c3y == fir_o ) { pos_d = (end_d + lar_u.ent_d + 1); new_d = pos_d; fir_o = c3n; @@ -805,7 +805,8 @@ _sist_rest() if ( u3r_mug('g') == led_u.mag_l ) { _sist_rest_nuu(&u3Z->lug_u, led_u, ful_c); fid_i = u3Z->lug_u.fid_i; - } else if (u3r_mug('h') != led_u.mag_l ) { + } + else if (u3r_mug('h') != led_u.mag_l ) { uL(fprintf(uH, "record (%s) is obsolete (or corrupt)\n", ful_c)); u3_lo_bail(); } @@ -964,7 +965,8 @@ _sist_rest() "and do not delete your pier!\n")); u3_lo_bail(); } - } else { + } + else { // Read and execute the fscking things. This is pretty much certain to crash. // uL(fprintf(uH, "rest: replaying through event %" PRIu64 "\n", las_d));