Package com.fasterxml.clustermate.service.state

Examples of com.fasterxml.clustermate.service.state.ActiveNodeState


                /* How interesting! Someone who we don't even know seems to be joining...
                 * Two possible cases, then; (a) We are seeing something for which we do
                 * have data in local DB, just not in config file, or (b) New entry for
                 * which no data exists.
                 */
                ActiveNodeState oldState = _stores.getNodeStore().findEntry(endpoint);
                // If such data found, assume it's accurate; we'll be updated soon if not
                if (oldState != null) {
                    peer = _createPeer(oldState);
                    LOG.warn("Request from node {} for which we have info in Local DB, restoring", endpoint);
                } else {
                    // But if not found need minimal bootstrapping
                    ActiveNodeState initialStatus = new ActiveNodeState(_localState,
                            new NodeDefinition(endpoint, NodeDefinition.INDEX_UNKNOWN,
                                    totalRange, totalRange),
                            _timeMaster.currentTimeMillis());
                    peer = _createPeer(initialStatus);
                    LOG.warn("Request from node {} for which we have no information, bootstrap with range of {}",
View Full Code Here


                    LOG.warn("Status for new node {} received: must create a peer", endpoint);
                    // node: should not ever occur for node itself... but...
                    _updateMissingPeer(nodeStatus, byNodeItself);
                } else { // more common, just update...
                    // But first, see that information is more up-to-date
                    ActiveNodeState currentState = peer.getSyncState();
                    if (currentState.getLastUpdated() >= nodeStatus.getLastUpdated()) {
                        return false;
                    }
                    return _updateExistingPeer(nodeStatus, byNodeItself, peer);
                }
            }
View Full Code Here

        /* Ok: let's also see if we have old state information in the
         * local DB. If we do, we may be able to avoid syncing from
         * the beginning of time; and/or obtain actual key range.
         */
        NodeStateStore<IpAndPort, ActiveNodeState> stateStore = _stores.getNodeStore();
        ActiveNodeState initialStatus = new ActiveNodeState(_localState, nodeStatus,
                _timeMaster.currentTimeMillis());
        // TODO: should perhaps also find by index + range?
        ActiveNodeState oldState = stateStore.findEntry(endpoint);

        ClusterPeerImpl<K,E> peer = null;
        // First common case: info was persisted earlier; we just "unthaw it"
        if (oldState != null) {
            if (oldState.equals(initialStatus)) {
                peer = _createPeer(oldState);
                _peers.put(endpoint, peer);
                LOG.info("Restoring node {} from persisted data: no change", endpoint);
            } else {
                // Some changes; but is the sync range unaffected?
View Full Code Here

    public void markDisabled(long timestamp, boolean isDisabled)
    {
        if (timestamp <= 0L) { // optional
            timestamp = _syncState.getDisabledUpdated();
        }
        ActiveNodeState state = _syncState.withDisabled(timestamp, isDisabled);
        if (state != _syncState) {
            _syncState = state;
            try {
                _stateStore.upsertEntry(state.getAddress(), state);
            } catch (Exception e) {
                LOG.error("Failed to update node state (disabled to {}) for {}. Problem ({}): {}",
                        isDisabled, _syncState, e.getClass().getName(), e.getMessage());
            }
        }
View Full Code Here

     * @param syncStartTime Timestamp of when sync attempt was done
     * @param lastSeen
     */
    private void _updatePersistentState(long syncStartTime, long lastSeen)
    {
        ActiveNodeState orig = _syncState;
        _syncState = _syncState.withLastSyncAttempt(syncStartTime);
        if (lastSeen > _syncState.getSyncedUpTo()) {
            _syncState = _syncState.withSyncedUpTo(lastSeen);
        }
        if (_syncState != orig) {
View Full Code Here

         * 60 seconds).
         */

        for (RemoteClusterNode peer : cluster.getRemotePeers()) {
            // Lazy-load synced-up-to as needed
            ActiveNodeState pstate = peer.persisted();

            if (pstate == null) {
                try {
                    pstate = _stores.getRemoteNodeStore().findEntry(peer.getAddress());
                    if (pstate == null) {
                        pstate = new ActiveNodeState(_localState, peer.asNodeState(_localState),
                                _stuff.currentTimeMillis());
                    }
                    peer.setPersisted(pstate);
                } catch (Exception e) {
                    LOG.warn("Failed to load Remote Node State for {}; must skip node", peer);
                    continue;
                }
            }
            // Let's try initial call with relatively high timeout; if it succeeds,
            // we'll consider matching peer to be live and do actual sync
            try {
                final long startTime = System.currentTimeMillis(); // real time since it's displayed
                SyncListResponse<?> fetchRemoteSyncList = _syncListAccessor
                        .fetchRemoteSyncList(_localState, peer.getAddress(),
                                pstate.getSyncedUpTo(), TIMEOUT_FOR_INITIAL_SYNCLIST_MSECS);
                // Returns null if call fails
                if (fetchRemoteSyncList != null) {
                    return _syncPull(startTime, peer, fetchRemoteSyncList);
                }
            } catch (InterruptedException e) { // presumably should bail out
View Full Code Here

    protected long _syncPull(final long startTime, RemoteClusterNode peer, SyncListResponse<?> listResponse)
        throws InterruptedException, IOException
    {
        final long processUntil = _stuff.currentTimeMillis() + MAX_TIME_FOR_SYNCPULL_MSECS;
        long total = 0L;
        ActiveNodeState savedState = null;
        int listCalls = 0;

        ActiveNodeState pstate = peer.persisted();

        // Let's try to limit damage from infinite loops by second check
        // (ideally shouldn't need such ad hoc limit but...)
        while (_running.get() && ++listCalls < 1000) {
            final int count = listResponse.size();
            total += count;
            if (count == 0) {
                break;
            }

            List<SyncListResponseEntry> newEntries = listResponse.entries;
            /*int tombstoneCount =*/ _handleTombstones(newEntries);
            // then filter out entries that we already have:
            _filterSeen(newEntries);
            if (!_running.get()) { // short-circuit during shutdown
                break;
            }
            if (!newEntries.isEmpty()) {
                int newCount = newEntries.size();
                AtomicInteger rounds = new AtomicInteger(0);
                /*long lastProcessed =*/ _fetchMissing(peer.getAddress(), newEntries, rounds);
                int fetched = newCount - newEntries.size();

                double secs = (_stuff.currentTimeMillis() - startTime) / 1000.0;
                String timeDesc = String.format("%.2f", secs);
                LOG.info("Fetched {}/{} missing entries ({} listed) from {} in {} seconds ({} rounds)",
                        new Object[] { fetched, newCount, count, peer.getAddress(), timeDesc, rounds.get()});
            }

            // One safety thing: let's persist synced-up-to after first round;
            // this to reduce likelihood of 'poison pills' from blocking sync pipeline
            long lastSeenTimestamp = listResponse.lastSeen();
            if (lastSeenTimestamp > 0L) {
                pstate = pstate.withSyncedUpTo(lastSeenTimestamp);
            } else {
                LOG.warn("Missing lastSeenTimestamp from sync-list to {}", peer.getAddress());
            }
            peer.setPersisted(pstate);
            if (_stuff.currentTimeMillis() >= processUntil) {
                // we use negative values to indicate time out... old-skool
                total = -total;
                break;
            }
            if (savedState == null) {
                savedState = pstate;
                _stores.getRemoteNodeStore().upsertEntry(peer.getAddress(), pstate);
            }
            // And then get more stuff...
            /* Except for one more thing: if we seem to be running out of entries,
             * let's not wait for trickles; inefficient to request stuff by ones and twos.
             * Instead, let stuff aggregate and we ought to get more.
             *
             * ... would be good to be able to verify it has an effect too. But for now
             * just need to assume it does.
             */
            if (count < 50) {
                if (listResponse.clientWait > 0L) {
                    break;
                }
            }

            listResponse = _syncListAccessor
                    .fetchRemoteSyncList(_localState, peer.getAddress(),
                            pstate.getSyncedUpTo(), TIMEOUT_FOR_INITIAL_SYNCLIST_MSECS);
            lastSeenTimestamp = listResponse.lastSeen();
        }

        // Also make sure to update this timestamp
        if (savedState != pstate) {
View Full Code Here

        // Next: load state definitions from local node DB
        List<ActiveNodeState> storedStates = nodes.readAll();
        LOG.info("Read {} persisted node entries from local store", storedStates.size());

        // First things first: find and update node for local node
        ActiveNodeState localAct = _remove(storedStates, localDef.getAddress());
        if (localAct == null) { // need to create?
            if (!_stuff.isRunningTests()) {
                LOG.warn("No persisted entry for local node: will create and store one");
            }
            localAct = new ActiveNodeState(localDef, _startTime);
        } else {
            // index may have changed; if so, override
            if (localAct.getIndex() != localDef.getIndex()) {
                LOG.warn("Node index of current node changed from {} to {} -- may change key range!",
                        localAct.getIndex(), localDef.getIndex());
                localAct = localAct.withIndex(localDef.getIndex());
            }
        }
        // one more thing: force dummy update on restart as well (official startup time too)
        localAct = localAct.withLastUpdated(_startTime);
        // Either way, need to update persisted version
        nodes.upsertEntry(localAct.getAddress(), localAct);
       
        // then merge entries; create/delete orphans
        Map<IpAndPort,ActiveNodeState> activeState = _mergeStates(nodes,
                localAct, nodeDefs, storedStates);
View Full Code Here

       
        // And then reverse check: any config entries for which we have no state?
        // If we do, need to initialize state
        int i = 0;
        for (NodeDefinition def : orphanDefs.values()) {
            ActiveNodeState state = new ActiveNodeState(def, _startTime);
            state = state.withSyncRange(localState);
            if (!_stuff.isRunningTests()) {
                LOG.warn("Configuration entry without state, key {}: will need to (re)create state (sync range {})",
                        def.getAddress(), state.getRangeSync());
            }
            try {
                nodeStore.upsertEntry(state.getAddress(), state);
            } catch (Exception e) {
                LOG.error("Failed to update node state entry #{}, must skip. Problem ({}): {}",
                        i, e.getClass().getName(), e.getMessage());
            }
            result.put(state.getAddress(), state);
            ++i;
        }
        return result;
    }
View Full Code Here

    private ActiveNodeState _remove(Collection<ActiveNodeState> nodes, IpAndPort key)
    {
        Iterator<ActiveNodeState> it = nodes.iterator();
        while (it.hasNext()) {
            ActiveNodeState curr = it.next();
            if (key.equals(curr.getAddress())) {
                it.remove();
                return curr;
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of com.fasterxml.clustermate.service.state.ActiveNodeState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.