@@ -66,9 +66,10 @@ public class Recovery {
6666 * newest good version.
6767 *
6868 * @param fileName the database file name
69+ * @return `true` if repair successful; otherwise `false`
6970 */
70- public static void recover (String fileName ) {
71- recover (fileName , new PrintWriter (System .out ));
71+ public static boolean recover (String fileName ) {
72+ return recover (fileName , new PrintWriter (System .out ));
7273 }
7374
7475 /**
@@ -77,27 +78,29 @@ public static void recover(String fileName) {
7778 *
7879 * @param fileName the database file name
7980 * @param writer the log writer
81+ * @return `true` if repair successful; otherwise `false`
8082 */
81- public static void recover (String fileName , PrintWriter writer ) {
83+ public static boolean recover (String fileName , PrintWriter writer ) {
8284 notNull (fileName , errorMessage ("fileName can not be null" , VE_RECOVER_NULL_FILE_NAME ));
8385 notEmpty (fileName , errorMessage ("fileName can not be empty" , VE_RECOVER_EMPTY_FILE_NAME ));
8486 notNull (writer , errorMessage ("writer can not be null" , VE_RECOVER_NULL_WRITER ));
85- repair (fileName , writer );
87+ return repair (fileName , writer );
8688 }
8789
8890 /**
8991 * Repair a store by rolling back to the newest good version.
9092 *
9193 * @param fileName the file name
9294 */
93- private static void repair (String fileName , PrintWriter pw ) {
95+ private static boolean repair (String fileName , PrintWriter pw ) {
9496 long version = Long .MAX_VALUE ;
9597 OutputStream ignore = new OutputStream () {
9698 @ Override
97- public void write (int b ) throws IOException {
99+ public void write (int b ) {
98100 // ignore
99101 }
100102 };
103+ boolean repaired = false ;
101104 while (version >= 0 ) {
102105 pw .println (version == Long .MAX_VALUE ? "Trying latest version" : ("Trying version " + version ));
103106 pw .flush ();
@@ -108,6 +111,7 @@ public void write(int b) throws IOException {
108111 FilePath .get (fileName ).moveTo (FilePath .get (fileName + ".back" ), true );
109112 FilePath .get (fileName + ".temp" ).moveTo (FilePath .get (fileName ), true );
110113 pw .println ("Success" );
114+ repaired = true ;
111115 break ;
112116 }
113117 pw .println (" ... failed: " + error );
@@ -118,6 +122,7 @@ public void write(int b) throws IOException {
118122 version --;
119123 }
120124 pw .flush ();
125+ return repaired ;
121126 }
122127
123128 /**
@@ -269,7 +274,7 @@ private static String info(String fileName, Writer writer) {
269274 MVMap <String , String > meta = store .getMetaMap ();
270275 Map <String , Object > header = store .getStoreHeader ();
271276 long fileCreated = DataUtils .readHexLong (header , "created" , 0L );
272- TreeMap <Integer , Chunk > chunks = new TreeMap <Integer , Chunk >();
277+ TreeMap <Integer , Chunk > chunks = new TreeMap <>();
273278 long chunkLength = 0 ;
274279 long maxLength = 0 ;
275280 long maxLengthLive = 0 ;
0 commit comments