@@ -67,16 +67,20 @@ public Integer call() throws Exception {
6767 .errorText ("Specify at least one exit database: --db dbName." ));
6868 return 404 ;
6969 }
70- if (dbs .size () > 1 ) {
71- ProgressBar .wrap (dbs .stream (), "root task" ).parallel ().forEach (this ::calcMerkleRoot );
72- } else {
73- calcMerkleRoot (dbs .get (0 ));
70+ List <Ret > task = ProgressBar .wrap (dbs .stream (), "root task" ).parallel ()
71+ .map (this ::calcMerkleRoot ).collect (Collectors .toList ());
72+ task .forEach (this ::printInfo );
73+ int code = (int ) task .stream ().filter (r -> r .code == 1 ).count ();
74+ if (code > 0 ) {
75+ spec .commandLine ().getErr ().println (spec .commandLine ().getColorScheme ()
76+ .errorText ("There are some errors, please check toolkit.log for detail." ));
7477 }
7578 spec .commandLine ().getOut ().println ("root task done." );
76- return 0 ;
79+ return code ;
7780 }
7881
79- private void calcMerkleRoot (String name ) {
82+ private Ret calcMerkleRoot (String name ) {
83+ Ret info = new Ret ();
8084 try (DBInterface database = DbTool .getDB (this .db , name )) {
8185 DBIterator iterator = database .iterator ();
8286 iterator .seekToFirst ();
@@ -85,15 +89,33 @@ private void calcMerkleRoot(String name) {
8589 .collect (Collectors .toCollection (ArrayList ::new ));
8690 Sha256Hash root = MerkleRoot .root (ids );
8791 logger .info ("db: {},root: {}" , database .getName (), root );
88- spec . commandLine (). getOut (). println ( String . format ( "db: %s,root: %s" ,
89- database .getName (), root ) );
92+ info . code = 0 ;
93+ info . msg = String . format ( "db: %s,root: %s" , database .getName (), root );
9094 } catch (RocksDBException | IOException e ) {
9195 logger .error ("calc db {} fail" , name , e );
96+ info .code = 1 ;
97+ info .msg = String .format ("db: %s,fail: %s" ,
98+ name , e .getMessage ());
9299 }
100+ return info ;
93101 }
94102
95103 private Sha256Hash getHash (Map .Entry <byte [], byte []> entry ) {
96104 return Sha256Hash .of (true ,
97105 Bytes .concat (entry .getKey (), entry .getValue ()));
98106 }
107+
108+ private void printInfo (Ret ret ) {
109+ if (ret .code == 0 ) {
110+ spec .commandLine ().getOut ().println (ret .msg );
111+ } else {
112+ spec .commandLine ().getErr ().println (spec .commandLine ().getColorScheme ()
113+ .errorText (ret .msg ));
114+ }
115+ }
116+
117+ private static class Ret {
118+ private int code ;
119+ private String msg ;
120+ }
99121}
0 commit comments