Search in sources :

Example 1 with ReplicatedEnvironment

use of com.sleepycat.je.rep.ReplicatedEnvironment in project qpid-broker-j by apache.

the class OrphanConfigurationRecordPurger method createEnvironment.

private Environment createEnvironment(final EnvironmentConfig config) throws Exception {
    final Environment env;
    if (_ha) {
        final ReplicationConfig repConfig = (ReplicationConfig) ReplicationConfig.DEFAULT.setNodeHostPort(_nodeHost).setGroupName(_groupName).setNodeName(_nodeName).setDesignatedPrimary(true).setElectableGroupSizeOverride(1);
        env = new ReplicatedEnvironment(new File(_storePath), repConfig, config);
    } else {
        env = new Environment(new File(_storePath), config);
    }
    return env;
}
Also used : ReplicationConfig(com.sleepycat.je.rep.ReplicationConfig) Environment(com.sleepycat.je.Environment) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment) File(java.io.File) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Example 2 with ReplicatedEnvironment

use of com.sleepycat.je.rep.ReplicatedEnvironment in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method createIntruder.

private void createIntruder(String nodeName, String node1NodeHostPort) {
    File environmentPathFile = new File(_storePath, nodeName);
    environmentPathFile.mkdirs();
    ReplicationConfig replicationConfig = new ReplicationConfig(TEST_GROUP_NAME, nodeName, node1NodeHostPort);
    replicationConfig.setHelperHosts(TEST_NODE_HOST_PORT);
    replicationConfig.setConsistencyPolicy(NoConsistencyRequiredPolicy.NO_CONSISTENCY);
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    envConfig.setDurability(TEST_DURABILITY);
    ReplicatedEnvironment intruder = null;
    try {
        intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
    } finally {
        if (intruder != null) {
            intruder.close();
        }
    }
}
Also used : ReplicationConfig(com.sleepycat.je.rep.ReplicationConfig) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) File(java.io.File) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Example 3 with ReplicatedEnvironment

use of com.sleepycat.je.rep.ReplicatedEnvironment in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeRestTest method testIntruderProtection.

public void testIntruderProtection() throws Exception {
    createHANode(NODE1, _node1HaPort, _node1HaPort);
    assertNode(NODE1, _node1HaPort, _node1HaPort, NODE1);
    Map<String, Object> nodeData = getRestTestHelper().getJsonAsMap(_baseNodeRestUrl + NODE1);
    String node1StorePath = (String) nodeData.get(BDBHAVirtualHostNode.STORE_PATH);
    long transactionId = ((Number) nodeData.get(BDBHAVirtualHostNode.LAST_KNOWN_REPLICATION_TRANSACTION_ID)).longValue();
    // add permitted node
    Map<String, Object> node3Data = createNodeAttributeMap(NODE3, _node3HaPort, _node1HaPort);
    getRestTestHelper().submitRequest(_baseNodeRestUrl + NODE3, "PUT", node3Data, HttpServletResponse.SC_CREATED);
    assertNode(NODE3, _node3HaPort, _node1HaPort, NODE1);
    assertRemoteNodes(NODE1, NODE3);
    // Ensure PINGDB is created
    // in order to exclude hanging of environment
    // when environment.close is called whilst PINGDB is created.
    // On node joining, a record is updated in PINGDB
    // if lastTransactionId is incremented then node ping task was executed
    int counter = 0;
    long newTransactionId = transactionId;
    while (newTransactionId == transactionId && counter < 50) {
        nodeData = getRestTestHelper().getJsonAsMap(_baseNodeRestUrl + NODE1);
        newTransactionId = ((Number) nodeData.get(BDBHAVirtualHostNode.LAST_KNOWN_REPLICATION_TRANSACTION_ID)).longValue();
        if (newTransactionId != transactionId) {
            break;
        }
        counter++;
        Thread.sleep(100L);
    }
    // connect intruder node
    String nodeName = NODE2;
    String nodeHostPort = "localhost:" + getNextAvailable(_node3HaPort + 1);
    File environmentPathFile = new File(node1StorePath, nodeName);
    environmentPathFile.mkdirs();
    ReplicationConfig replicationConfig = new ReplicationConfig((String) nodeData.get(BDBHAVirtualHostNode.GROUP_NAME), nodeName, nodeHostPort);
    replicationConfig.setHelperHosts((String) nodeData.get(BDBHAVirtualHostNode.ADDRESS));
    replicationConfig.setConsistencyPolicy(NoConsistencyRequiredPolicy.NO_CONSISTENCY);
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    envConfig.setDurability(Durability.parse((String) nodeData.get(BDBHAVirtualHostNode.DURABILITY)));
    ReplicatedEnvironment intruder = null;
    try {
        intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
    } finally {
        if (intruder != null) {
            intruder.close();
        }
    }
    _restTestHelper.waitForAttributeChanged(_baseNodeRestUrl + NODE1, VirtualHostNode.STATE, State.ERRORED.name());
    _restTestHelper.waitForAttributeChanged(_baseNodeRestUrl + NODE3, VirtualHostNode.STATE, State.ERRORED.name());
}
Also used : ReplicationConfig(com.sleepycat.je.rep.ReplicationConfig) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) File(java.io.File) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Example 4 with ReplicatedEnvironment

use of com.sleepycat.je.rep.ReplicatedEnvironment in project qpid-broker-j by apache.

the class MultiNodeTest method testClusterCannotStartWithIntruder.

public void testClusterCannotStartWithIntruder() throws Exception {
    // set property explicitly as test requires broker to start to enable check for ERRORED nodes
    setSystemProperty(Broker.BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD, String.valueOf(Boolean.FALSE));
    int intruderPort = getNextAvailable(Collections.max(_groupCreator.getBdbPortNumbers()) + 1);
    String nodeName = "intruder";
    String nodeHostPort = _groupCreator.getIpAddressOfBrokerHost() + ":" + intruderPort;
    File environmentPathFile = Files.createTempDirectory("qpid-work-intruder").toFile();
    try {
        environmentPathFile.mkdirs();
        ReplicationConfig replicationConfig = new ReplicationConfig(_groupCreator.getGroupName(), nodeName, nodeHostPort);
        replicationConfig.setHelperHosts(_groupCreator.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);
        }
        for (int port : _groupCreator.getBrokerPortNumbersForNodes()) {
            _groupCreator.awaitNodeToAttainAttributeValue(port, port, BDBHAVirtualHostNode.STATE, State.ERRORED.name());
        }
        _groupCreator.stopCluster();
        _groupCreator.startCluster();
        for (int port : _groupCreator.getBrokerPortNumbersForNodes()) {
            _groupCreator.awaitNodeToAttainAttributeValue(port, port, BDBHAVirtualHostNode.STATE, State.ERRORED.name());
        }
    } finally {
        FileUtils.delete(environmentPathFile, true);
    }
}
Also used : ReplicationConfig(com.sleepycat.je.rep.ReplicationConfig) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Durability(com.sleepycat.je.Durability) File(java.io.File) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Example 5 with ReplicatedEnvironment

use of com.sleepycat.je.rep.ReplicatedEnvironment in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method joinIntruder.

private void joinIntruder(final int nodePortNumber, final String nodeName, final String groupName, final String helperAddress, final Durability durability, final File environmentPathFile) {
    environmentPathFile.mkdirs();
    ReplicationConfig replicationConfig = new ReplicationConfig(groupName, nodeName, "localhost:" + nodePortNumber);
    replicationConfig.setNodePriority(0);
    replicationConfig.setHelperHosts(helperAddress);
    replicationConfig.setConsistencyPolicy(NoConsistencyRequiredPolicy.NO_CONSISTENCY);
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    envConfig.setDurability(durability);
    ReplicatedEnvironment intruder = null;
    String originalThreadName = Thread.currentThread().getName();
    try {
        intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
    } finally {
        try {
            if (intruder != null) {
                intruder.close();
            }
        } finally {
            Thread.currentThread().setName(originalThreadName);
        }
    }
}
Also used : ReplicationConfig(com.sleepycat.je.rep.ReplicationConfig) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Aggregations

ReplicatedEnvironment (com.sleepycat.je.rep.ReplicatedEnvironment)5 ReplicationConfig (com.sleepycat.je.rep.ReplicationConfig)5 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)4 File (java.io.File)4 Durability (com.sleepycat.je.Durability)1 Environment (com.sleepycat.je.Environment)1