objective categorical abstract machine language personal data server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add rebuild-mst subcommand

futur.blue 343e906a 5885442d

verified
+37
+16
bin/main.ml
··· 251 251 print_endline "migrating all blobs to S3" ; 252 252 S3.Blob_migration.migrate_all () 253 253 254 + let rebuild_mst ~did () = 255 + print_endline ("rebuilding MST for " ^ did) ; 256 + let%lwt repo = Repository.load did in 257 + match%lwt Repository.rebuild_mst repo with 258 + | Ok (commit_cid, commit) -> 259 + print_endline 260 + (Printf.sprintf "MST rebuilt successfully, new commit: %s (rev: %s)" 261 + (Cid.to_string commit_cid) commit.rev ) ; 262 + Lwt.return_unit 263 + | Error exn -> 264 + print_endline ("error rebuilding MST: " ^ Printexc.to_string exn) ; 265 + exit 1 266 + 254 267 let print_usage () = 255 268 print_endline 256 269 @@ String.trim ··· 262 275 create-invite [uses] create an invite code with an optional number of uses (default: 1) 263 276 migrate-blobs migrate all local blobs to S3 264 277 migrate-blobs <did> migrate blobs for a specific user to S3 278 + rebuild-mst <did> rebuild MST from records table (recovery tool) 265 279 266 280 see also: gen-keys 267 281 |} ··· 280 294 Lwt_main.run (migrate_blobs ()) 281 295 | ["migrate-blobs"; did] -> 282 296 Lwt_main.run (migrate_blobs ~did ()) 297 + | ["rebuild-mst"; did] -> 298 + Lwt_main.run (rebuild_mst ~did ()) 283 299 | ["help"] | ["--help"] | ["-h"] -> 284 300 print_usage () 285 301 | cmd :: _ ->
+21
pegasus/lib/repository.ml
··· 589 589 t.commit <- Some (root, commit) ; 590 590 Lwt.return_ok t 591 591 with exn -> Lwt.return_error exn 592 + 593 + let rebuild_mst t : (Cid.t * signed_commit, exn) Lwt_result.t = 594 + try%lwt 595 + let%lwt record_cids = User_store.get_all_record_cids t.db in 596 + let record_count = List.length record_cids in 597 + Logs.info (fun m -> m "rebuilding MST from %d records" record_count) ; 598 + let%lwt () = User_store.clear_mst t.db in 599 + Logs.info (fun m -> m "cleared existing MST blocks") ; 600 + let%lwt mst_result = Mst.of_assoc t.db record_cids in 601 + Logs.info (fun m -> 602 + m "built new MST with root %s" (Cid.to_string mst_result.root) ) ; 603 + let%lwt prev_commit = User_store.get_commit t.db in 604 + let%lwt new_commit = 605 + put_commit t mst_result.root ~previous:(Option.map snd prev_commit) 606 + in 607 + let commit_cid, commit = new_commit in 608 + Logs.info (fun m -> 609 + m "inserted new commit %s with rev %s" (Cid.to_string commit_cid) 610 + commit.rev ) ; 611 + Lwt.return_ok new_commit 612 + with exn -> Lwt.return_error exn