use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestLeaderCache method testInitialCacheWithCallback.
@Test
public void testInitialCacheWithCallback() throws Exception {
ZooKeeper zk = getClient(0);
configure("/cache01", zk);
TestCallback cb = new TestCallback();
LeaderCache dut = new LeaderCache(zk, "/cache01", cb);
dut.start(true);
assertEquals("3 items cached.", 3, cb.m_cache.size());
assertEquals(12345678, cb.m_cache.get(0).longValue());
assertEquals(87654321, cb.m_cache.get(1).longValue());
assertEquals(11223344, cb.m_cache.get(2).longValue());
dut.shutdown();
zk.close();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestLeaderCache method testDeleteChild.
@Test
public void testDeleteChild() throws Exception {
ZooKeeper zk = getClient(0);
configure("/cache02", zk);
LeaderCache dut = new LeaderCache(zk, "/cache02");
dut.start(true);
Map<Integer, Long> cache = dut.pointInTimeCache();
assertEquals("3 items cached.", 3, cache.size());
zk.delete("/cache02/1", -1);
while (true) {
cache = dut.pointInTimeCache();
if (cache.size() == 3) {
Thread.sleep(1);
} else {
break;
}
}
assertEquals("Item removed", 2, cache.size());
assertEquals(null, cache.get(1));
assertEquals(12345678, cache.get(0).longValue());
assertEquals(11223344, cache.get(2).longValue());
dut.shutdown();
zk.close();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class RealVoltDB method onRejoinCompletion.
private void onRejoinCompletion() {
// null out the rejoin coordinator
if (m_joinCoordinator != null) {
m_joinCoordinator.close();
}
m_joinCoordinator = null;
// Mark the data transfer as done so CL can make the right decision when a truncation snapshot completes
m_rejoinDataPending = false;
try {
m_testBlockRecoveryCompletion.acquire();
} catch (InterruptedException e) {
}
final long delta = ((m_executionSiteRecoveryFinish - m_recoveryStartTime) / 1000);
final long megabytes = m_executionSiteRecoveryTransferred / (1024 * 1024);
final double megabytesPerSecond = megabytes / ((m_executionSiteRecoveryFinish - m_recoveryStartTime) / 1000.0);
deleteStagedCatalogIfNeeded();
if (m_clientInterface != null) {
m_clientInterface.mayActivateSnapshotDaemon();
try {
m_clientInterface.startAcceptingConnections();
} catch (IOException e) {
hostLog.l7dlog(Level.FATAL, LogKeys.host_VoltDB_ErrorStartAcceptingConnections.name(), e);
VoltDB.crashLocalVoltDB("Error starting client interface.", true, e);
}
// send hostUp trap
m_snmp.hostUp("Host is now a cluster member");
if (m_producerDRGateway != null && !m_producerDRGateway.isStarted()) {
// Initialize DR producer and consumer start listening on the DR ports
initializeDRProducer();
createDRConsumerIfNeeded();
prepareReplication();
}
}
startHealthMonitor();
try {
if (m_adminListener != null) {
m_adminListener.start();
}
} catch (Exception e) {
hostLog.l7dlog(Level.FATAL, LogKeys.host_VoltDB_ErrorStartHTTPListener.name(), e);
VoltDB.crashLocalVoltDB("HTTP service unable to bind to port.", true, e);
}
// Allow export datasources to start consuming their binary deques safely
// as at this juncture the initial truncation snapshot is already complete
ExportManager.instance().startPolling(m_catalogContext);
//Tell import processors that they can start ingesting data.
ImportManager.instance().readyForData(m_catalogContext, m_messenger);
if (m_config.m_startAction == StartAction.REJOIN) {
consoleLog.info("Node data recovery completed after " + delta + " seconds with " + megabytes + " megabytes transferred at a rate of " + megabytesPerSecond + " megabytes/sec");
}
try {
final ZooKeeper zk = m_messenger.getZK();
boolean logRecoveryCompleted = false;
if (getCommandLog().getClass().getName().equals("org.voltdb.CommandLogImpl")) {
String requestNode = zk.create(VoltZK.request_truncation_snapshot_node, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
if (m_rejoinTruncationReqId == null) {
m_rejoinTruncationReqId = requestNode;
}
} else {
logRecoveryCompleted = true;
}
// above to finish.
if (logRecoveryCompleted || m_joining) {
if (m_rejoining) {
CoreZK.removeRejoinNodeIndicatorForHost(m_messenger.getZK(), m_myHostId);
m_rejoining = false;
}
if (m_joining) {
CoreZK.removeJoinNodeIndicatorForHost(m_messenger.getZK(), m_myHostId);
}
String actionName = m_joining ? "join" : "rejoin";
m_joining = false;
consoleLog.info(String.format("Node %s completed", actionName));
}
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Unable to log host rejoin completion to ZK", true, e);
}
hostLog.info("Logging host rejoin completion to ZK");
m_statusTracker.setNodeState(NodeState.UP);
Object[] args = { (VoltDB.instance().getMode() == OperationMode.PAUSED) ? "PAUSED" : "NORMAL" };
consoleLog.l7dlog(Level.INFO, LogKeys.host_VoltDB_ServerOpMode.name(), args, null);
consoleLog.l7dlog(Level.INFO, LogKeys.host_VoltDB_ServerCompletedInitialization.name(), null, null);
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class RealVoltDB method validateStartAction.
private void validateStartAction() {
ZooKeeper zk = m_messenger.getZK();
boolean initCompleted = false;
List<String> children = null;
try {
initCompleted = zk.exists(VoltZK.init_completed, false) != null;
children = zk.getChildren(VoltZK.start_action, new StartActionWatcher(), null);
} catch (KeeperException e) {
hostLog.error("Failed to validate the start actions", e);
return;
} catch (InterruptedException e) {
VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
}
if (children != null && !children.isEmpty()) {
for (String child : children) {
byte[] data = null;
try {
data = zk.getData(VoltZK.start_action + "/" + child, false, null);
} catch (KeeperException excp) {
if (excp.code() == Code.NONODE) {
hostLog.debug("Failed to validate the start action as node " + VoltZK.start_action + "/" + child + " got disconnected", excp);
} else {
hostLog.error("Failed to validate the start actions ", excp);
}
return;
} catch (InterruptedException e) {
VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
}
if (data == null) {
VoltDB.crashLocalVoltDB("Couldn't find " + VoltZK.start_action + "/" + child);
}
String startAction = new String(data);
if ((startAction.equals(StartAction.JOIN.toString()) || startAction.equals(StartAction.REJOIN.toString()) || startAction.equals(StartAction.LIVE_REJOIN.toString())) && !initCompleted) {
int nodeId = VoltZK.getHostIDFromChildName(child);
if (nodeId == m_messenger.getHostId()) {
VoltDB.crashLocalVoltDB("This node was started with start action " + startAction + " during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
} else {
hostLog.warn("Node " + nodeId + " tried to " + startAction + " cluster but it is not allowed during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
}
}
}
}
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class RealVoltDB method logDebuggingInfo.
void logDebuggingInfo(int adminPort, int httpPort, String httpPortExtraLogMessage, boolean jsonEnabled) {
String startAction = m_config.m_startAction.toString();
String startActionLog = "Database start action is " + (startAction.substring(0, 1).toUpperCase() + startAction.substring(1).toLowerCase()) + ".";
if (!m_rejoining) {
hostLog.info(startActionLog);
}
// print out awesome network stuff
hostLog.info(String.format("Listening for native wire protocol clients on port %d.", m_config.m_port));
hostLog.info(String.format("Listening for admin wire protocol clients on port %d.", adminPort));
if (m_startMode == OperationMode.PAUSED) {
hostLog.info(String.format("Started in admin mode. Clients on port %d will be rejected in admin mode.", m_config.m_port));
}
if (getReplicationRole() == ReplicationRole.REPLICA) {
consoleLog.info("Started as " + getReplicationRole().toString().toLowerCase() + " cluster. " + "Clients can only call read-only procedures.");
}
if (httpPortExtraLogMessage != null) {
hostLog.info(httpPortExtraLogMessage);
}
if (httpPort != -1) {
hostLog.info(String.format("Local machine HTTP monitoring is listening on port %d.", httpPort));
} else {
hostLog.info(String.format("Local machine HTTP monitoring is disabled."));
}
if (jsonEnabled) {
hostLog.info(String.format("Json API over HTTP enabled at path /api/1.0/, listening on port %d.", httpPort));
} else {
hostLog.info("Json API disabled.");
}
// java heap size
long javamaxheapmem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();
javamaxheapmem /= (1024 * 1024);
hostLog.info(String.format("Maximum usable Java heap set to %d mb.", javamaxheapmem));
// Computed minimum heap requirement
long minRqt = computeMinimumHeapRqt(MiscUtils.isPro(), m_catalogContext.tables.size(), (m_iv2Initiators.size() - 1), m_configuredReplicationFactor);
hostLog.info("Minimum required Java heap for catalog and server config is " + minRqt + " MB.");
SortedMap<String, String> dbgMap = m_catalogContext.getDebuggingInfoFromCatalog(true);
for (String line : dbgMap.values()) {
hostLog.info(line);
}
// print out a bunch of useful system info
PlatformProperties pp = PlatformProperties.getPlatformProperties();
String[] lines = pp.toLogLines(getVersionString()).split("\n");
for (String line : lines) {
hostLog.info(line.trim());
}
if (m_catalogContext.cluster.getDrconsumerenabled() || m_catalogContext.cluster.getDrproducerenabled()) {
hostLog.info("DR initializing with Cluster Id " + m_catalogContext.cluster.getDrclusterid() + ". The DR cluster was first started at " + new Date(m_clusterCreateTime).toString() + ".");
}
final ZooKeeper zk = m_messenger.getZK();
ZKUtil.ByteArrayCallback operationModeFuture = new ZKUtil.ByteArrayCallback();
/*
* Publish our cluster metadata, and then retrieve the metadata
* for the rest of the cluster
*/
try {
zk.create(VoltZK.cluster_metadata + "/" + m_messenger.getHostId(), getLocalMetadata().getBytes("UTF-8"), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, new ZKUtil.StringCallback(), null);
zk.getData(VoltZK.operationMode, false, operationModeFuture, null);
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Error creating \"/cluster_metadata\" node in ZK", true, e);
}
Map<Integer, String> clusterMetadata = new HashMap<>(0);
/*
* Spin and attempt to retrieve cluster metadata for all nodes in the cluster.
*/
Set<Integer> metadataToRetrieve = new HashSet<>(m_messenger.getLiveHostIds());
metadataToRetrieve.remove(m_messenger.getHostId());
while (!metadataToRetrieve.isEmpty()) {
Map<Integer, ZKUtil.ByteArrayCallback> callbacks = new HashMap<>();
for (Integer hostId : metadataToRetrieve) {
ZKUtil.ByteArrayCallback cb = new ZKUtil.ByteArrayCallback();
zk.getData(VoltZK.cluster_metadata + "/" + hostId, false, cb, null);
callbacks.put(hostId, cb);
}
for (Map.Entry<Integer, ZKUtil.ByteArrayCallback> entry : callbacks.entrySet()) {
try {
ZKUtil.ByteArrayCallback cb = entry.getValue();
Integer hostId = entry.getKey();
clusterMetadata.put(hostId, new String(cb.getData(), "UTF-8"));
metadataToRetrieve.remove(hostId);
} catch (KeeperException.NoNodeException e) {
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Error retrieving cluster metadata", true, e);
}
}
}
// print out cluster membership
hostLog.info("About to list cluster interfaces for all nodes with format [ip1 ip2 ... ipN] client-port,admin-port,http-port");
for (int hostId : m_messenger.getLiveHostIds()) {
if (hostId == m_messenger.getHostId()) {
hostLog.info(String.format(" Host id: %d with interfaces: %s [SELF]", hostId, MiscUtils.formatHostMetadataFromJSON(getLocalMetadata())));
} else {
String hostMeta = clusterMetadata.get(hostId);
hostLog.info(String.format(" Host id: %d with interfaces: %s [PEER]", hostId, MiscUtils.formatHostMetadataFromJSON(hostMeta)));
}
}
try {
if (operationModeFuture.getData() != null) {
String operationModeStr = new String(operationModeFuture.getData(), "UTF-8");
m_startMode = OperationMode.valueOf(operationModeStr);
}
} catch (KeeperException.NoNodeException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations