Durability Policy

Durability in databases is the property that ensures transactions are saved permanently and do not accidentally disappear or get erased, even during a database crash. This is usually achieved by saving all transactions to a non-volatile storage medium.

In Oracle NoSQL, durability may be specified for every API call that performs a write operation. A durability policy can be thought of as your level of confidence in the survival of a piece of data in the event of catastrophic failures of hardware or software.

In real life example let us choose e-mail system in which the e-mail content of one e-mail in the Inbox for a user using the strictest durability policy is available and then it is printed back to the console. The following code illustrates that :

public class Emails {

public static void main(String[] args) {

final KVStore store;
String storeName = “kvstore”;
String hostName = “localhost”;
String hostPort = “5000”;

store = KVStoreFactory.getStore
(new KVStoreConfig(storeName, hostName + “:” + hostPort));

ArrayList<String> majorList = new ArrayList<String>();
ArrayList<String> inboxList = new ArrayList<String>();

majorList.add(“users”);
majorList.add(“12345”);
majorList.add(“folders”);

inboxList.add(“inbox”);
inboxList.add(“20090213”);
inboxList.add(“174510”);
inboxList.add(“From:Tanya”);
inboxList.add(“To:Jennifer”);

Key inboxKey = Key.createKey(majorList, inboxList);
String st = “Hi Jennifer, Happy Birthday”;
Value emailText = Value.createValue(st.getBytes());

Durability dur = new Durability(Durability.SyncPolicy.SYNC, Durability.SyncPolicy.NO_SYNC,
Durability.ReplicaAckPolicy.ALL);
try {
store.put(inboxKey,  emailText, null, dur, 0, null);
} catch (DurabilityException de) {
de.printStackTrace();
} catch (RequestTimeoutException re) {
re.printStackTrace();
}

ValueVersion vv = store.get(inboxKey, Consistency.ABSOLUTE, 0, null);
System.out.println(“The e-mail content for 1st email is ” + inboxKey.toString() + ” is ” +
new String(vv.getValue().getValue()));
}
}

 

The output for above is displayed as:

durability

Leave A Reply

Your email address will not be published. Required fields are marked *