Package com.fasterxml.clustermate.api

Examples of com.fasterxml.clustermate.api.NodeDefinition


                    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 {}",
                            endpoint, totalRange);
View Full Code Here


     */
    public ClusterViewByServerImpl<K,E> bootstrap(final int thisInstancePort)
        throws IOException
    {
        // First: need the keyspace definition, to build key ranges
        NodeDefinition localDef = null;

        // Then need to know IP interface(s) host has, to find "local" entry
        Set<InetAddress> localIps = new LinkedHashSet<InetAddress>();
        ServerUtil.findLocalIPs(localIps);
        LOG.info("Local IPs: {}", localIps.toString());
        Map<IpAndPort,NodeDefinition> nodeDefs = new LinkedHashMap<IpAndPort,NodeDefinition>();

        for (NodeDefinition node : _readNodeDefs()) {
            IpAndPort ip = node.getAddress();
            LOG.info("Resolving node definitions for: "+ip.toString());
            // Entry for this instance?
            // NOTE: this call will resolve IP name to address; blocking call:
            InetAddress addr = ip.getIP();
            if (localIps.contains(addr) && ip.getPort() == thisInstancePort) {
                if (localDef != null) {
                    throw new IllegalStateException("Ambiguous definition: both "
                            +localDef.getAddress()+" and "+ip+" refer to this host");
                }
                localDef = node;
                continue;
            }
//            LOG.info("peer node: {}", node); // remove once in prod?
            nodeDefs.put(ip, node);
        }
        // Error: MUST have local node definition (until more dynamic set up is implemented)
        if (localDef == null) {
            throw new IllegalStateException("Could not find Cluster node definitions for local instance (port "
                    +thisInstancePort+")");
        }

        LOG.info("Node definition used for this host: {}, found {} configured peer nodes",
            localDef, nodeDefs.size());
       
        final NodeStateStore nodes = _stores.getNodeStore();
        // Next: load state definitions from BDB
        List<ActiveNodeState> storedStates = nodes.readAll(_keyspace);
        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
View Full Code Here

            case DYNAMIC_WITH_APPEND: // not (yet!) supported
            default:
                throw new IllegalStateException("Unsupported (as-of-yet) cluster type: "+strategy);
            }
            // we'll use same range for both passive and active ranges, with static
            defs.add(new NodeDefinition(ip, index, range, range));
        }
        return defs;
    }
View Full Code Here

       
        // Iterate over entries that have been persisted:
        for (ActiveNodeState state : storedStates) {
            IpAndPort key = state.getAddress();
            // Then: is there config for that entry? If not, skip or remove:
            NodeDefinition def = orphanDefs.remove(key);
            if (def == null) {
                long staleTimeSecs = (_startTime - state.getLastSyncAttempt()) / 1000L;
                if (staleTimeSecs < SECS_IN_24H) {
                    /* Skipping means that (a) we will leave the entry in the local DB, in case
                     * it MAY be useful via explicit info via cluster; but
                     * (b) will NOT include in current active state. Latter is
                     * useful in gracefully expiring information.
                     */
                    LOG.warn("Unrecognized persisted Node state, key {}: less than 24h old, will skip", key);
                    continue;
                }
                // If too old, delete
                if (!_stuff.isRunningTests()) {
                    LOG.warn("Unrecognized persisted Node state, key {}: more than 24h old ({} days), will DELETE",
                            key, (staleTimeSecs / SECS_IN_24H));
                }
                nodeStore.deleteEntry(key);
                continue;
            }
            // We have both config and state: merge
            state = _updatePersistentState(nodeStore, localState, def, state);
           result.put(key, state);
        }

        LOG.info("Any orphan definitions? (node without persisted state) Found {}", orphanDefs.size());
       
        // 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);
            } catch (Exception e) {
                LOG.error("Failed to update node state entry #{}, must skip. Problem ({}): {}",
View Full Code Here

                    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 {}",
                            endpoint, totalRange);
View Full Code Here

     */
    public ClusterViewByServerImpl<K,E> bootstrap(final int thisInstancePort)
        throws IOException
    {
        // First: need the keyspace definition, to build key ranges
        NodeDefinition localDef = null;

        // Then need to know IP interface(s) host has, to find "local" entry
        Set<InetAddress> localIps = new LinkedHashSet<InetAddress>();
        ServerUtil.findLocalIPs(localIps);
        LOG.info("Local IPs: {}", localIps.toString());
        Map<IpAndPort,NodeDefinition> nodeDefs = new LinkedHashMap<IpAndPort,NodeDefinition>();

        for (NodeDefinition node : _readNodeDefs()) {
            IpAndPort ip = node.getAddress();
            LOG.info("Resolving node definitions for: "+ip.toString());
            // Entry for this instance?
            // NOTE: this call will resolve IP name to address; blocking call:
            InetAddress addr = ip.getIP();
            if (localIps.contains(addr) && ip.getPort() == thisInstancePort) {
                if (localDef != null) {
                    throw new IllegalStateException("Ambiguous definition: both "
                            +localDef.getAddress()+" and "+ip+" refer to this host");
                }
                localDef = node;
                continue;
            }
//            LOG.info("peer node: {}", node); // remove once in prod?
            nodeDefs.put(ip, node);
        }
        // Error: MUST have local node definition (until more dynamic set up is implemented)
        if (localDef == null) {
            throw new IllegalStateException("Could not find Cluster node definitions for local instance (port "
                    +thisInstancePort+")");
        }

        LOG.info("Node definition used for this host: {}, found {} configured peer nodes",
            localDef, nodeDefs.size());
       
        final NodeStateStore nodes = _stores.getNodeStore();
        // Next: load state definitions from BDB
        List<ActiveNodeState> storedStates = nodes.readAll(_keyspace);
        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
View Full Code Here

            case DYNAMIC_WITH_APPEND: // not (yet!) supported
            default:
                throw new IllegalStateException("Unsupported (as-of-yet) cluster type: "+strategy);
            }
            // we'll use same range for both passive and active ranges, with static
            defs.add(new NodeDefinition(ip, index, range, range));
        }
        return defs;
    }
View Full Code Here

       
        // Iterate over entries that have been persisted:
        for (ActiveNodeState state : storedStates) {
            IpAndPort key = state.getAddress();
            // Then: is there config for that entry? If not, skip or remove:
            NodeDefinition def = orphanDefs.remove(key);
            if (def == null) {
                long staleTimeSecs = (_startTime - state.getLastSyncAttempt()) / 1000L;
                if (staleTimeSecs < SECS_IN_24H) {
                    /* Skipping means that (a) we will leave the entry in the local DB, in case
                     * it MAY be useful via explicit info via cluster; but
                     * (b) will NOT include in current active state. Latter is
                     * useful in gracefully expiring information.
                     */
                    LOG.warn("Unrecognized persisted Node state, key {}: less than 24h old, will skip", key);
                    continue;
                }
                // If too old, delete
                if (!_stuff.isRunningTests()) {
                    LOG.warn("Unrecognized persisted Node state, key {}: more than 24h old ({} days), will DELETE",
                            key, (staleTimeSecs / SECS_IN_24H));
                }
                nodeStore.deleteEntry(key);
                continue;
            }
            // We have both config and state: merge
            state = _updatePersistentState(nodeStore, localState, def, state);
           result.put(key, state);
        }

        LOG.info("Any orphan definitions? (node without persisted state) Found {}", orphanDefs.size());
       
        // 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);
            } catch (Exception e) {
                LOG.error("Failed to update node state entry #{}, must skip. Problem ({}): {}",
View Full Code Here

     */
    public ClusterViewByServerImpl<K,E> bootstrap(final int thisInstancePort)
        throws IOException
    {
        // First: need the keyspace definition, to build key ranges
        NodeDefinition localDef = null;

        // Then need to know IP interface(s) host has, to find "local" entry
        Set<InetAddress> localIps = new LinkedHashSet<InetAddress>();
        ServerUtil.findLocalIPs(localIps);
        LOG.info("Local IPs: {}", localIps.toString());
        Map<IpAndPort,NodeDefinition> nodeDefs = new LinkedHashMap<IpAndPort,NodeDefinition>();

        for (NodeDefinition node : _readNodeDefs()) {
            IpAndPort ip = node.getAddress();
            LOG.info("Resolving node definitions for: "+ip.toString());
            // Entry for this instance?
            // NOTE: this call will resolve IP name to address; blocking call:
            InetAddress addr = ip.getIP();
            if (localIps.contains(addr) && ip.getPort() == thisInstancePort) {
                if (localDef != null) {
                    throw new IllegalStateException("Ambiguous definition: both "
                            +localDef.getAddress()+" and "+ip+" refer to this host");
                }
                localDef = node;
                continue;
            }
//            LOG.info("peer node: {}", node); // remove once in prod?
            nodeDefs.put(ip, node);
        }
        // Error: MUST have local node definition (until more dynamic set up is implemented)
        if (localDef == null) {
            throw new IllegalStateException("Could not find Cluster node definitions for local instance (port "
                    +thisInstancePort+")");
        }

        LOG.info("Node definition used for this host: {}, found {} configured peer nodes",
            localDef, nodeDefs.size());
       
        final NodeStateStore nodes = _stores.getNodeStore();
        // Next: load state definitions from BDB
        List<ActiveNodeState> storedStates = nodes.readAll(_keyspace);
        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
View Full Code Here

            case DYNAMIC_WITH_APPEND: // not (yet!) supported
            default:
                throw new IllegalStateException("Unsupported (as-of-yet) cluster type: "+strategy);
            }
            // we'll use same range for both passive and active ranges, with static
            defs.add(new NodeDefinition(ip, index, range, range));
        }
        return defs;
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.clustermate.api.NodeDefinition

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.