Class ClusterNodeInfo


  • public class ClusterNodeInfo
    extends java.lang.Object
    Information about a cluster node.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BROADCAST_ID
      The broadcast id.
      static java.lang.String BROADCAST_LISTENER
      The broadcast listener (host:port).
      static boolean DEFAULT_LEASE_CHECK_DISABLED  
      static int DEFAULT_LEASE_DURATION_MILLIS  
      static int DEFAULT_LEASE_FAILURE_MARGIN_MILLIS
      OAK-3398 : default failure margin 20sec before actual lease timeout (note that OAK-3399 / MAX_RETRY_SLEEPS_BEFORE_LEASE_FAILURE eats off another few seconds from this margin, by default 5sec, so the actual default failure-margin is down to 15sec - and that is high-noon!)
      static int DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS
      OAK-3398 : default update interval 10sec
      static java.lang.String INVISIBLE
      Key for invisible flag
      static java.lang.String LAST_WRITTEN_ROOT_REV_KEY
      The key for the root-revision of the last background write (of unsaved modifications) - that is: the last root-revision written by the instance in case of a clear shutdown or via recovery of another instance in case of a crash
      static java.lang.String LEASE_END_KEY
      The end of the lease.
      static java.lang.String RECOVERY_TIME_KEY
      The time a recovery was done, if the last shutdown required a recover - not set otherwise.
      static java.lang.String REV_RECOVERY_BY
      Flag indicating which cluster node is running the recovery.
      static java.lang.String REV_RECOVERY_LOCK
      Flag to indicate whether the _lastRev recovery is in progress.
      static java.lang.String RUNTIME_ID_KEY
      Runtime UUID (generated unique ID for this instance)
      static java.lang.String START_TIME_KEY
      The start time.
      static java.lang.String STATE
      The state of the cluster.
      protected static java.lang.String WORKING_DIR
      The current working directory.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()  
      int getId()  
      static ClusterNodeInfo getInstance​(DocumentStore store, org.apache.jackrabbit.oak.plugins.document.RecoveryHandler recoveryHandler, java.lang.String machineId, java.lang.String instanceId, int configuredClusterId)
      Get or create a cluster node info instance for the store.
      static ClusterNodeInfo getInstance​(DocumentStore store, org.apache.jackrabbit.oak.plugins.document.RecoveryHandler recoveryHandler, java.lang.String machineId, java.lang.String instanceId, int configuredClusterId, boolean invisible)
      Get or create a cluster node info instance for the store.
      static ClusterNodeInfo getInstance​(DocumentStore store, org.apache.jackrabbit.oak.plugins.document.RecoveryHandler recoveryHandler, java.lang.String machineId, java.lang.String instanceId, int configuredClusterId, boolean invisible, long reuseAfterRecoveryMillis)
      Get or create a cluster node info instance for the store.
      long getLeaseEndTime()  
      long getLeaseTime()  
      static ClusterNodeInfo getReadOnlyInstance​(DocumentStore store)
      Create a cluster node info instance to be utilized for read only access to underlying store.
      protected boolean isLeaseExpired​(long time)
      Returns true if the lease for this cluster node info should be considered expired given the current time.
      void performLeaseCheck()
      Checks if the lease for this cluster node is still valid, otherwise throws a DocumentStoreException.
      boolean renewLease()
      Renew the cluster id lease.
      void setInfo​(java.util.Map<java.lang.String,​java.lang.String> info)
      Update the cluster node info.
      void setLeaseFailureHandler​(LeaseFailureHandler leaseFailureHandler)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • LEASE_END_KEY

        public static final java.lang.String LEASE_END_KEY
        The end of the lease.
        See Also:
        Constant Field Values
      • RECOVERY_TIME_KEY

        public static final java.lang.String RECOVERY_TIME_KEY
        The time a recovery was done, if the last shutdown required a recover - not set otherwise.
        See Also:
        Constant Field Values
      • START_TIME_KEY

        public static final java.lang.String START_TIME_KEY
        The start time.
        See Also:
        Constant Field Values
      • LAST_WRITTEN_ROOT_REV_KEY

        public static final java.lang.String LAST_WRITTEN_ROOT_REV_KEY
        The key for the root-revision of the last background write (of unsaved modifications) - that is: the last root-revision written by the instance in case of a clear shutdown or via recovery of another instance in case of a crash
        See Also:
        Constant Field Values
      • BROADCAST_ID

        public static final java.lang.String BROADCAST_ID
        The broadcast id. If the broadcasting cache is used, a new id is set after startup.
        See Also:
        Constant Field Values
      • BROADCAST_LISTENER

        public static final java.lang.String BROADCAST_LISTENER
        The broadcast listener (host:port). If the broadcasting cache is used, this is set after startup.
        See Also:
        Constant Field Values
      • REV_RECOVERY_BY

        public static final java.lang.String REV_RECOVERY_BY
        Flag indicating which cluster node is running the recovery.
        See Also:
        Constant Field Values
      • INVISIBLE

        public static final java.lang.String INVISIBLE
        Key for invisible flag
        See Also:
        Constant Field Values
      • RUNTIME_ID_KEY

        public static final java.lang.String RUNTIME_ID_KEY
        Runtime UUID (generated unique ID for this instance)
        See Also:
        Constant Field Values
      • WORKING_DIR

        protected static java.lang.String WORKING_DIR
        The current working directory. Note: marked protected non-final for testing purpose only.
      • DEFAULT_LEASE_DURATION_MILLIS

        public static final int DEFAULT_LEASE_DURATION_MILLIS
      • DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS

        public static final int DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS
        OAK-3398 : default update interval 10sec
        See Also:
        Constant Field Values
      • DEFAULT_LEASE_FAILURE_MARGIN_MILLIS

        public static final int DEFAULT_LEASE_FAILURE_MARGIN_MILLIS
        OAK-3398 : default failure margin 20sec before actual lease timeout (note that OAK-3399 / MAX_RETRY_SLEEPS_BEFORE_LEASE_FAILURE eats off another few seconds from this margin, by default 5sec, so the actual default failure-margin is down to 15sec - and that is high-noon!)
        See Also:
        Constant Field Values
      • DEFAULT_LEASE_CHECK_DISABLED

        public static final boolean DEFAULT_LEASE_CHECK_DISABLED
    • Method Detail

      • getId

        public int getId()
      • getReadOnlyInstance

        public static ClusterNodeInfo getReadOnlyInstance​(DocumentStore store)
        Create a cluster node info instance to be utilized for read only access to underlying store.
        Parameters:
        store - the document store.
        Returns:
        the cluster node info
      • getInstance

        public static ClusterNodeInfo getInstance​(DocumentStore store,
                                                  org.apache.jackrabbit.oak.plugins.document.RecoveryHandler recoveryHandler,
                                                  java.lang.String machineId,
                                                  java.lang.String instanceId,
                                                  int configuredClusterId)
        Get or create a cluster node info instance for the store.
        Parameters:
        store - the document store (for the lease)
        recoveryHandler - the recovery handler to call for a clusterId with an expired lease.
        machineId - the machine id (null for MAC address)
        instanceId - the instance id (null for current working directory)
        configuredClusterId - the configured cluster id (or 0 for dynamic assignment)
        Returns:
        the cluster node info
      • getInstance

        public static ClusterNodeInfo getInstance​(DocumentStore store,
                                                  org.apache.jackrabbit.oak.plugins.document.RecoveryHandler recoveryHandler,
                                                  java.lang.String machineId,
                                                  java.lang.String instanceId,
                                                  int configuredClusterId,
                                                  boolean invisible)
        Get or create a cluster node info instance for the store.
        Parameters:
        store - the document store (for the lease)
        recoveryHandler - the recovery handler to call for a clusterId with an expired lease.
        machineId - the machine id (null for MAC address)
        instanceId - the instance id (null for current working directory)
        configuredClusterId - the configured cluster id (or 0 for dynamic assignment)
        Returns:
        the cluster node info
      • getInstance

        public static ClusterNodeInfo getInstance​(DocumentStore store,
                                                  org.apache.jackrabbit.oak.plugins.document.RecoveryHandler recoveryHandler,
                                                  java.lang.String machineId,
                                                  java.lang.String instanceId,
                                                  int configuredClusterId,
                                                  boolean invisible,
                                                  long reuseAfterRecoveryMillis)
        Get or create a cluster node info instance for the store.
        Parameters:
        store - the document store (for the lease)
        recoveryHandler - the recovery handler to call for a clusterId with an expired lease.
        machineId - the machine id (null for MAC address)
        instanceId - the instance id (null for current working directory)
        configuredClusterId - the configured cluster id (or 0 for dynamic assignment)
        Returns:
        the cluster node info
      • performLeaseCheck

        public void performLeaseCheck()
                               throws DocumentStoreException
        Checks if the lease for this cluster node is still valid, otherwise throws a DocumentStoreException. Depending on the LeaseCheckMode this method will not throw the exception immediately when the lease expires. If the mode is set to LeaseCheckMode.LENIENT, then this method will give the lease update thread a last chance of 5 seconds to renew it. This allows the DocumentNodeStore to recover from an expired lease caused by a system put to sleep or a JVM in debug mode.
        Throws:
        DocumentStoreException - if the lease expired.
      • isLeaseExpired

        protected boolean isLeaseExpired​(long time)
        Returns true if the lease for this cluster node info should be considered expired given the current time. This method takes leaseFailureMargin into account and will return true even before the passed time is beyond the leaseEndTime.
        Parameters:
        time - the current time to check against the lease end.
        Returns:
        true if the lease is considered expired, false otherwise.
      • renewLease

        public boolean renewLease()
                           throws DocumentStoreException
        Renew the cluster id lease. This method needs to be called once in a while, to ensure the same cluster id is not re-used by a different instance. The lease is only renewed after 'leaseUpdateInterval' millis since last lease update - default being every 10 sec (this used to be 30sec).

        This method will not fail immediately with a DocumentStoreException if the lease expired. It will still try to renew the lease and only fail if performLeaseCheck() decided the lease expired or another cluster node initiated recover for this node.

        Returns:
        true if the lease was renewed; false otherwise.
        Throws:
        DocumentStoreException - if the operation failed or the lease expired.
      • setInfo

        public void setInfo​(java.util.Map<java.lang.String,​java.lang.String> info)
        Update the cluster node info.
        Parameters:
        info - the map of changes
      • getLeaseTime

        public long getLeaseTime()
      • getLeaseEndTime

        public long getLeaseEndTime()
      • setLeaseFailureHandler

        public void setLeaseFailureHandler​(LeaseFailureHandler leaseFailureHandler)
      • dispose

        public void dispose()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object