Library Version 12.1.3.0

Chapter 11. Consistency Guarantees
Prev |  | Next

## Chapter 11. Consistency Guarantees

The KV store is built from some number of computers (generically referred to as nodes) that are working together using a network. All data in your store is first written to a master node. The master node then copies that data to other nodes in the store. Nodes which are not master nodes are referred to as replicas.

Because of the relatively slow performance of distributed systems, there can be a possibility that, at any given moment, a write operation that was performed on the master node will not yet have been performed on some other node in the store.

Consistency, then, is the policy describing whether it is possible for a record on Node A to be different from the same record on Node B.

When there is a high likelihood that a record stored on one node is identical to the same record stored on another node, we say that we have a high consistency guarantee. Likewise, a low consistency guarantee means that there is a good possibility that a record on one node differs in some way from the same record stored on another node.

You can control how high you want your consistency guarantee to be. Note that the trade-off in setting a high consistency guarantee is that your store's read performance might not be as high as if you use a low consistency guarantee.

There are several different forms of consistency guarantees that you can use. They are described in the following sections.

Note that by default, Oracle NoSQL Database uses the lowest consistency guarantee possible.

## Specifying Consistency Policies

To specify a consistency policy, you use one of the static instances of the `Consistency` class, or one of its nested classes.

Once you have selected a consistency policy, you can put it to use in one of two ways. First, you can use it to define a default consistency policy using the `KVStoreConfig.setConsistency()` method. Use of this method means that all store operations will use that policy, unless they are overridden on an operation by operation basis.

The second way to use a consistency policy is to override the default policy using the `Consistency` parameter on the `KVStore` method using a `ReadOption` class instance you provide to the `TableAPI` method that you are using to perform the store operation.

The following example shows how to set a default consistency policy for the store. We will show the per-operation usage of the `Consistency` class in the following sections.

    package kvstore.basicExample;

    import oracle.kv.Consistency;
    import oracle.kv.KVStore;
    import oracle.kv.KVStoreConfig;
    import oracle.kv.KVStoreFactory;

    ...

    KVStoreConfig kconfig = new KVStoreConfig("exampleStore",
        "node1.example.org:5088, node2.example.org:4129");

    kconfig.setConsistency(Consistency.NONE_REQUIRED);

    KVStore kvstore = KVStoreFactory.getStore(kconfig);

Prev |  | Next
Chapter 10. Using Versions | Home | Using Predefined Consistency