1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 /**
9  * The WAL Recover Mode
10  */
11 public enum WALRecoveryMode {
12 
13   /**
14    * Original levelDB recovery
15    *
16    * We tolerate incomplete record in trailing data on all logs
17    * Use case : This is legacy behavior (default)
18    */
19   TolerateCorruptedTailRecords((byte)0x00),
20 
21   /**
22    * Recover from clean shutdown
23    *
24    * We don't expect to find any corruption in the WAL
25    * Use case : This is ideal for unit tests and rare applications that
26    * can require high consistency guarantee
27    */
28   AbsoluteConsistency((byte)0x01),
29 
30   /**
31    * Recover to point-in-time consistency
32    * We stop the WAL playback on discovering WAL inconsistency
33    * Use case : Ideal for systems that have disk controller cache like
34    * hard disk, SSD without super capacitor that store related data
35    */
36   PointInTimeRecovery((byte)0x02),
37 
38   /**
39    * Recovery after a disaster
40    * We ignore any corruption in the WAL and try to salvage as much data as
41    * possible
42    * Use case : Ideal for last ditch effort to recover data or systems that
43    * operate with low grade unrelated data
44    */
45   SkipAnyCorruptedRecords((byte)0x03);
46 
47   private byte value;
48 
WALRecoveryMode(final byte value)49   WALRecoveryMode(final byte value) {
50     this.value = value;
51   }
52 
53   /**
54    * <p>Returns the byte value of the enumerations value.</p>
55    *
56    * @return byte representation
57    */
getValue()58   public byte getValue() {
59     return value;
60   }
61 
62   /**
63    * <p>Get the WALRecoveryMode enumeration value by
64    * passing the byte identifier to this method.</p>
65    *
66    * @param byteIdentifier of WALRecoveryMode.
67    *
68    * @return WALRecoveryMode instance.
69    *
70    * @throws IllegalArgumentException If WALRecoveryMode cannot be found for the
71    *   provided byteIdentifier
72    */
getWALRecoveryMode(final byte byteIdentifier)73   public static WALRecoveryMode getWALRecoveryMode(final byte byteIdentifier) {
74     for (final WALRecoveryMode walRecoveryMode : WALRecoveryMode.values()) {
75       if (walRecoveryMode.getValue() == byteIdentifier) {
76         return walRecoveryMode;
77       }
78     }
79 
80     throw new IllegalArgumentException(
81         "Illegal value provided for WALRecoveryMode.");
82   }
83 }
84