@@ -67,16 +67,20 @@ public Integer call() throws Exception {
67
67
.errorText ("Specify at least one exit database: --db dbName." ));
68
68
return 404 ;
69
69
}
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." ));
74
77
}
75
78
spec .commandLine ().getOut ().println ("root task done." );
76
- return 0 ;
79
+ return code ;
77
80
}
78
81
79
- private void calcMerkleRoot (String name ) {
82
+ private Ret calcMerkleRoot (String name ) {
83
+ Ret info = new Ret ();
80
84
try (DBInterface database = DbTool .getDB (this .db , name )) {
81
85
DBIterator iterator = database .iterator ();
82
86
iterator .seekToFirst ();
@@ -85,15 +89,33 @@ private void calcMerkleRoot(String name) {
85
89
.collect (Collectors .toCollection (ArrayList ::new ));
86
90
Sha256Hash root = MerkleRoot .root (ids );
87
91
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 );
90
94
} catch (RocksDBException | IOException e ) {
91
95
logger .error ("calc db {} fail" , name , e );
96
+ info .code = 1 ;
97
+ info .msg = String .format ("db: %s,fail: %s" ,
98
+ name , e .getMessage ());
92
99
}
100
+ return info ;
93
101
}
94
102
95
103
private Sha256Hash getHash (Map .Entry <byte [], byte []> entry ) {
96
104
return Sha256Hash .of (true ,
97
105
Bytes .concat (entry .getKey (), entry .getValue ()));
98
106
}
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
+ }
99
121
}
0 commit comments