*/
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<IpAndPort, ActiveNodeState> nodes = _stores.getNodeStore();
// Next: load state definitions from BDB
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