Setting Durability Guarantees

To set a durability guarantee, use the Durability class. When you do this, you must provide three pieces of information:

The combination of policies that you use is driven by how sensitive your application might be to potential data loss, and by your write performance requirements.

For example, the fastest possible write performance can be achieved through a durability policy that requires:

However, this durability policy also leaves your data with the greatest risk of loss due to application or machine failure between the time the operation returns and the time when the data is written to stable storage.

On the other hand, if you want the highest possible durability guarantee, you can use:

Of course, this also results in the slowest possible write performance.

Most commonly, durability policies attempt to strike a balance between write performance and data durability guarantees. For example:

Note that you can set a default durability policy for your Store handle, but you can also override the policy on a per-operation basis for those situations where some of your data need not be as durable (or needs to be MORE durable) than the default.

For example, suppose you want an intermediate durability policy for most of your data, but sometimes you have transient or easily re-created data whose durability really is not very important. Then you would do something like this:

First, set the default durability policy for the Store handle:

var nosqldb = require('nosqldb-oraclejs');

// Create a configuration object
var configuration = new nosqldb.Configuration();
configuration.proxy.startProxy = false;
configuration.proxy.host = 'localhost:7010';
configuration.storeHelperHosts = ['localhost:5000'];
configuration.storeName = 'kvstore';
configuration.defaultDurability =
    new nosqldb.Types.Durability(
         nosqldb.Types.SyncPolicy.SYNC, //Master sync
         nosqldb.Types.ReplicaAckPolicy.SIMPLE_MAJORITY, //Ack policy
         nosqldb.Types.SyncPolicy.NO_SYNC); //Replica sync

// Open the store with the specified configuration
var store = nosqldb.createStore(configuration); 

In another part of your code, for some unusual write operations, you might then want to relax the durability guarantee so as to speed up the write performance for those specific write operations:

store.on('open', function () {
   console.log('Store opened');

   var row = {item: "Bolts",
              description: "Hex head, stainless",
              count: 5,
              percentage: 0.2173913};

    var durability = new nosqldb.Types.Durability(
                       nosqldb.Types.SyncPolicy.NO_SYNC,
                       nosqldb.Types.ReplicaAckPolicy.NONE,
                       nosqldb.Types.SyncPolicy.NO_SYNC);

    var writeOptions = new nosqldb.Types.WriteOptions(
                                    durability, 
                                    1000);

   store.put('myTable', row, writeOptions,
           function (err) {
                if (err)
                    throw err;
                else {
                    console.log("Row inserted.");
                    store.close();
                }
           });
}).on('close', function() {
    console.log('Store closed.');
}).on('error', function(error) {
    console.log(error);
});
store.open();