Skip to content

Commit 9e56123

Browse files
committed
Clean up Archive CLI a bit
1 parent 87966c4 commit 9e56123

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/app/archive/cli/archive_cli.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ let command_run =
4242
~doc:
4343
"int The number of accounts to insert from the database in one \
4444
transaction, when processing genesis ledger. This is to prevent \
45-
Postgres Out of Memory errors \n\
46-
\ when handling very big genesis file. Default is 100."
45+
Postgres Out of Memory errors when handling very big genesis file. \
46+
Default is 100."
4747
(optional_with_default 100 int)
4848
in
4949
let runtime_config_opt =
@@ -94,16 +94,17 @@ let command_prune =
9494
Format: 2000-00-00 12:00:00+0100"
9595
and postgres = Flag.Uri.Archive.postgres in
9696
fun () ->
97+
let logger = Logger.create () in
9798
let timestamp =
9899
timestamp
99100
|> Option.map ~f:Block_time.of_time
100101
|> Option.map ~f:Block_time.to_int64
101102
in
102-
let go () =
103+
let execute () =
103104
let open Deferred.Result.Let_syntax in
104105
let%bind ((module Conn) as conn) = Mina_caqti.connect postgres.value in
105106
let%bind () = Conn.start () in
106-
match%bind.Async.Deferred
107+
match%bind.Deferred
107108
let%bind () =
108109
Archive_lib.Processor.Block.delete_if_older_than ?height
109110
?num_blocks ?timestamp conn
@@ -112,11 +113,13 @@ let command_prune =
112113
with
113114
| Ok () ->
114115
return ()
115-
| Error err ->
116-
let%bind.Async.Deferred _ = Conn.rollback () in
117-
Deferred.Result.fail err
116+
| Error txn_error ->
117+
let%map.Deferred rollback_result = Conn.rollback () in
118+
Result.iter_error rollback_result ~f:(fun err ->
119+
[%log error] "Failed to rollback txn on failure"
120+
~metadata:[ ("error", `String (Caqti_error.show err)) ] ) ;
121+
Error txn_error
118122
in
119-
let logger = Logger.create () in
120123
let cmd_metadata =
121124
List.filter_opt
122125
[ Option.map height ~f:(fun v -> ("height", `Int v))
@@ -125,7 +128,7 @@ let command_prune =
125128
("timestamp", `String (Int64.to_string v)) )
126129
]
127130
in
128-
match%map.Async.Deferred go () with
131+
match%map.Async.Deferred execute () with
129132
| Ok () ->
130133
[%log info] "Successfully purged blocks." ~metadata:cmd_metadata
131134
| Error err ->

0 commit comments

Comments
 (0)