Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.jackrabbit.oak.plugins.document;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Represents the document stored in the settings collection containing a
* 'cluster view'.
*
* A 'cluster view' is the state of the membership of instances that are or have
* all been connected to the same oak repository. The 'cluster view' is
* maintained by all instances in the cluster concurrently - the faster one
* wins. Its information is derived from the clusterNodes collection. From there
* the following three states are derived and instances are grouped into these:
*
*
Active: an instance is active and has no recoveryLock is currently
* acquired. The lease timeout is ignored. When the lease times out, this is
* noticed by one of the instances at some point and a recovery is started, at
* which point the instance transitions from 'Active' to 'Recovering'.
*
Recovering: an instance that was active but currently has the
* recoveryLock acquired by one of the instances.
*
Inactive: an instance is not set to active (in which case the
* recoveryLock is never set)
*
*
* Note that the states managed in this ClusterViewDocument differs from the one
* from ClusterView - since ClusterView also manages the fact that after a
* recovery of a crashed instance there could be a 'backlog' of changes which it
* doesn't yet see until a background read is performed.
*/
class ClusterViewDocument {
private static final Logger logger = LoggerFactory.getLogger(ClusterViewDocument.class);
/** the id of this document is always 'clusterView' **/
private static final String CLUSTERVIEW_DOC_ID = "clusterView";
// keys that we store in the root document - and in the history
/**
* document key that stores the monotonically incrementing sequence number
* of the cluster view. Any update will increase this by 1
**/
static final String VIEW_SEQ_NUM_KEY = "seqNum";
/**
* document key that stores the comma-separated list of active instance ids
**/
static final String ACTIVE_KEY = "active";
/**
* document key that stores the comma-separated list of inactive instance
* ids (they might still have a backlog, that is handled in ClusterView
* though, never persisted
*/
static final String INACTIVE_KEY = "inactive";
/**
* document key that stores the comma-separated list of recovering instance
* ids
**/
static final String RECOVERING_KEY = "recovering";
/**
* document key that stores the date and time when this view was created -
* for debugging purpose only
**/
private static final String CREATED_KEY = "created";
/**
* document key that stores the id of the instance that created this view -
* for debugging purpose only
**/
private static final String CREATOR_KEY = "creator";
/**
* document key that stores the date and time when this was was retired -
* for debugging purpose only
**/
private static final String RETIRED_KEY = "retired";
/**
* document key that stores the id of the instance that retired this view -
* for debugging purpose only
**/
private static final String RETIRER_KEY = "retirer";
/**
* document key that stores a short, limited history of previous cluster
* views - for debugging purpose only
**/
private static final String CLUSTER_VIEW_HISTORY_KEY = "clusterViewHistory";
/** the format used when storing date+time **/
private static final DateFormat standardDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
/** number of elements kept in the CLUSTERVIEW_HISTORY_KEY field **/
static final int HISTORY_LIMIT = 10;
/** the monotonically incrementing sequence number of this cluster view **/
private final long viewSeqNum;
/** the ids of instances that are active at this moment **/
private final Integer[] activeIds;
/**
* the ids of instances that are recovering (lastRev-recovery) at this
* moment
**/
private final Integer[] recoveringIds;
/** the ids of instances that are inactive at this moment **/
private final Integer[] inactiveIds;
/**
* the short, limited history of previous cluster views, for debugging only
**/
private final Map