Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je.rep;
  
 
A consistency policy which ensures that the environment on a Replica node is at least as current as denoted by the specified com.sleepycat.je.CommitToken. This token represents a point in the serialized transaction schedule created by the master. In other words, this token is like a bookmark, representing a particular transaction commit in the replication stream. The Replica ensures that the commit identified by the com.sleepycat.je.CommitToken has been executed on this node before allowing the application's com.sleepycat.je.Environment.beginTransaction(com.sleepycat.je.Transaction,com.sleepycat.je.TransactionConfig) operation on the Replica to proceed.

For example, suppose the application is a web application where a replicated group is implemented within a load balanced web server group. Each request to the web server consists of an update operation followed by read operations (say from the same client), The read operations naturally expect to see the data from the updates executed by the same request. However, the read operations might have been routed to a node that did not execute the update.

In such a case, the update request would generate a com.sleepycat.je.CommitToken, which would be resubmitted by the browser, along with subsequent read requests. The read request could be directed at any one of the available web servers by a load balancer. The node which executes the read request would create a CommitPointConsistencyPolicy with that com.sleepycat.je.CommitToken and use it at transaction begin. If the environment at the web server was already current (wrt the commit token), it could immediately execute the transaction and satisfy the request. If not, the "transaction begin" would stall until the Replica replay had caught up and the change was available at that web server.

Consistency policies are specified at either a per-transaction level through com.sleepycat.je.TransactionConfig.setConsistencyPolicy(com.sleepycat.je.ReplicaConsistencyPolicy) or as an replication node wide default through ReplicationConfig.setConsistencyPolicy(com.sleepycat.je.ReplicaConsistencyPolicy)

See also:
com.sleepycat.je.CommitToken
Managing Consistency
 
 public class CommitPointConsistencyPolicy implements ReplicaConsistencyPolicy {

    
The name: associated with this policy. The name can be used when constructing policy property values for use in je.properties files.
 
     public static final String NAME = "CommitPointConsistencyPolicy";
 
     /*
      * Identifies the commit of interest in a serialized transaction schedule.
      */
     private final CommitToken commitToken;
 
     /*
      * Amount of time (in milliseconds) to wait for consistency to be
      * reached.
      */
     private final int timeout;

    
Defines how current a Replica needs to be in terms of a specific transaction that was committed on the Master. A transaction on the Replica that uses this consistency policy is allowed to start only after the transaction identified by the commitToken has been committed on the Replica. The com.sleepycat.je.Environment.beginTransaction(com.sleepycat.je.Transaction,com.sleepycat.je.TransactionConfig) will wait for at most timeout for the Replica to catch up. If the Replica has not caught up in this period, the beginTransaction() method will throw a ReplicaConsistencyException.

Parameters:
commitToken the token identifying the transaction
timeout the maximum amount of time that the transaction start will wait to allow the Replica to catch up.
timeoutUnit the TimeUnit for the timeout parameter.
Throws:
java.lang.IllegalArgumentException if the commitToken or timeoutUnit is null.
    public CommitPointConsistencyPolicy(CommitToken commitToken,
                                        long timeout,
                                        TimeUnit timeoutUnit) {
        if (commitToken == null) {
            throw new IllegalArgumentException("commitToken must not be null");
        }
        this. = commitToken;
        this. = PropUtil.durationToMillis(timeouttimeoutUnit);
    }

    
Returns the name: NAME, associated with this policy.

See also:
NAME
    public String getName() {
        return ;
    }

    

Hidden:
For internal use only. Ensures that the replica has replayed the replication stream to the point identified by the commit token or past it. If it has not, the method waits until the constraint is satisfied, or the timeout period has expired, whichever event takes place first.
    public void ensureConsistency(EnvironmentImpl envImpl)
        throws InterruptedException,
               ReplicaConsistencyException {
        /*
         * Cast is done to preserve replication/non replication code
         * boundaries.
         */
        RepImpl repImpl = (RepImplenvImpl;
        if (!.getRepenvUUID().equals
                (repImpl.getRepNode().getUUID())) {
            throw new IllegalArgumentException
                ("Replication environment mismatch. " +
                 "The UUID associated with the commit token is: " +
                 .getRepenvUUID() +
                 " but this replica environment has the UUID: " +
                 repImpl.getRepNode().getUUID());
        }
        Replica replica = repImpl.getRepNode().replica();
        replica.getConsistencyTracker().awaitVLSN
            (.getVLSN(), this);
    }

    
Return the CommitToken used to create this consistency policy.

Returns:
the CommitToken used to create this consistency policy.
    public CommitToken getCommitToken() {
        return ;
    }

    
Return the timeout specified when creating this consistency policy.

Parameters:
unit the TimeUnit of the returned value.
Returns:
the timeout specified when creating this consistency policy
    public long getTimeout(TimeUnit unit) {
        return PropUtil.millisToDuration(unit);
    }

    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + (( == null) ? 0 : .hashCode());
        result = prime * result + ;
        return result;
    }

    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof CommitPointConsistencyPolicy)) {
            return false;
        }
        CommitPointConsistencyPolicy other =
            (CommitPointConsistencyPolicyobj;
        if ( == null) {
            if (other.commitToken != null) {
                return false;
            }
        } else if (!.equals(other.commitToken)) {
            return false;
        }
        if ( != other.timeout) {
            return false;
        }
        return true;
    }
    @Override
    public String toString() {
        return getName() + " commitToken=" + ;
    }
New to GrepCode? Check out our FAQ X