com.sleepycat.je.rep.ReplicatedEnvironment Java Examples
The following examples show how to use
com.sleepycat.je.rep.ReplicatedEnvironment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BDBHAVirtualHostNodeImpl.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private void doStateChange(StateChangeEvent stateChangeEvent) { com.sleepycat.je.rep.ReplicatedEnvironment.State state = stateChangeEvent.getState(); NodeRole previousRole = getRole(); LOGGER.info("Received BDB event indicating transition from state {} to {} for {}", previousRole, state, getName()); try { switch (state) { case MASTER: onMaster(); break; case REPLICA: onReplica(); break; case DETACHED: closeVirtualHostIfExist().get(); break; case UNKNOWN: closeVirtualHostIfExist().get(); break; default: LOGGER.error("Unexpected state change: " + state); } } catch (InterruptedException | ExecutionException e) { throw new ServerScopedRuntimeException(e); } finally { NodeRole newRole = NodeRole.fromJeState(state); _lastRole.set(newRole); attributeSet(ROLE, _role, newRole); getEventLogger().message(getGroupLogSubject(), HighAvailabilityMessages.ROLE_CHANGED(getName(), getAddress(), previousRole.name(), newRole.name())); } }
Example #2
Source File: MultiNodeTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Test public void testClusterCannotStartWithIntruder() throws Exception { int intruderPort = new PortHelper().getNextAvailable(Arrays.stream(getBrokerAdmin().getBdbPorts()).max().getAsInt() + 1); String nodeName = "intruder"; String nodeHostPort = getBrokerAdmin().getHost() + ":" + intruderPort; File environmentPathFile = Files.createTempDirectory("qpid-work-intruder").toFile(); try { environmentPathFile.mkdirs(); ReplicationConfig replicationConfig = new ReplicationConfig("test", nodeName, nodeHostPort); replicationConfig.setHelperHosts(getBrokerAdmin().getHelperHostPort()); EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); envConfig.setDurability(new Durability(Durability.SyncPolicy.SYNC, Durability.SyncPolicy.WRITE_NO_SYNC, Durability.ReplicaAckPolicy.SIMPLE_MAJORITY)); final String currentThreadName = Thread.currentThread().getName(); try (ReplicatedEnvironment intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig)) { LOGGER.debug("Intruder started"); } finally { Thread.currentThread().setName(currentThreadName); } Set<Integer> ports = Arrays.stream(getBrokerAdmin().getGroupAmqpPorts()).boxed().collect(Collectors.toSet()); for (int port : ports) { getBrokerAdmin().awaitNodeToAttainAttributeValue(port, BDBHAVirtualHostNode.STATE, State.ERRORED.name()); } getBrokerAdmin().stop(); try { getBrokerAdmin().start(); fail("Cluster cannot start with an intruder node"); } catch (Exception e) { // pass } } finally { FileUtils.delete(environmentPathFile, true); } }
Example #3
Source File: BDBHAVirtualHostNodeImpl.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private void processNodeState(ReplicationNode node, NodeState nodeState) { BDBHARemoteReplicationNodeImpl remoteNode = getChildByName(BDBHARemoteReplicationNodeImpl.class, node.getName()); if (remoteNode != null) { final NodeRole previousRole = remoteNode.getRole(); final NodeRole newRole; if (nodeState == null) { newRole = NodeRole.UNREACHABLE; remoteNode.setRole(newRole); remoteNode.setLastTransactionId(-1); if (previousRole != NodeRole.UNREACHABLE) { getEventLogger().message(getGroupLogSubject(), HighAvailabilityMessages.LEFT(remoteNode.getName(), remoteNode.getAddress())); } } else { LOGGER.debug("Node {} processing state update. Node state {} joinTime {} currentTxnEndVLSN {}", remoteNode.getName(), nodeState.getNodeState(), nodeState.getJoinTime(), nodeState.getCurrentTxnEndVLSN()); remoteNode.setJoinTime(nodeState.getJoinTime()); remoteNode.setLastTransactionId(nodeState.getCurrentTxnEndVLSN()); ReplicatedEnvironment.State state = nodeState.getNodeState(); newRole = NodeRole.fromJeState(state); remoteNode.setRole(newRole); if (previousRole == NodeRole.UNREACHABLE) { getEventLogger().message(getGroupLogSubject(), HighAvailabilityMessages.JOINED(remoteNode.getName(), remoteNode.getAddress())); } if (NodeRole.MASTER == newRole) { byte[] applicationState = nodeState.getAppState(); if (applicationState != null) { Set<String> permittedNodes = ReplicatedEnvironmentFacade.convertApplicationStateBytesToPermittedNodeList(applicationState); if (_permittedNodes.size() != permittedNodes.size() || !_permittedNodes.containsAll(permittedNodes)) { if (_permittedNodes.contains(remoteNode.getAddress())) { setAttributes(Collections.<String, Object>singletonMap(PERMITTED_NODES, new ArrayList<>(permittedNodes))); } else { LOGGER.warn("Cannot accept the new permitted node list from the master as the master '" + remoteNode.getName() + "' (" + remoteNode.getAddress() + ") was not in previous permitted list " + _permittedNodes); } } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Application state returned by JE was 'null' so skipping permitted node handling: %s", nodeState)); } } } } if (newRole != previousRole) { getEventLogger().message(getGroupLogSubject(), HighAvailabilityMessages.ROLE_CHANGED(remoteNode.getName(), remoteNode.getAddress(), previousRole.name(), newRole.name())); } } }
Example #4
Source File: JE_HA_Repository.java From tddl5 with Apache License 2.0 | 4 votes |
@Override public boolean isWriteAble() { return ((ReplicatedEnvironment) env).getState().isMaster(); }
Example #5
Source File: JE_HA_Repository.java From tddl with Apache License 2.0 | 4 votes |
@Override public boolean isWriteAble() { return ((ReplicatedEnvironment) env).getState().isMaster(); }