use of com.sleepycat.je.EnvironmentConfig 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();
}
}
}
use of com.sleepycat.je.EnvironmentConfig in project qpid-broker-j by apache.
the class MultiNodeTest method testClusterCannotStartWithIntruder.
@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);
}
}
use of com.sleepycat.je.EnvironmentConfig in project qpid-broker-j by apache.
the class AbstractUpgradeTestCase method createEnvironment.
protected Environment createEnvironment(File storeLocation) {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setConfigParam("je.lock.nLockTables", "7");
envConfig.setReadOnly(false);
envConfig.setSharedCache(false);
envConfig.setCacheSize(0);
return new Environment(storeLocation, envConfig);
}
use of com.sleepycat.je.EnvironmentConfig in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method createEnvironment.
private void createEnvironment(boolean createEnvironmentInSeparateThread, Runnable postCreationAction) {
String groupName = _configuration.getGroupName();
String helperHostPort = _configuration.getHelperHostPort();
String hostPort = _configuration.getHostPort();
boolean designatedPrimary = _configuration.isDesignatedPrimary();
int priority = _configuration.getPriority();
int quorumOverride = _configuration.getQuorumOverride();
String nodeName = _configuration.getName();
String helperNodeName = _configuration.getHelperNodeName();
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Creating environment");
LOGGER.info("Environment path " + _environmentDirectory.getAbsolutePath());
LOGGER.info("Group name " + groupName);
LOGGER.info("Node name " + nodeName);
LOGGER.info("Node host port " + hostPort);
LOGGER.info("Helper host port " + helperHostPort);
LOGGER.info("Helper node name " + helperNodeName);
LOGGER.info("Durability " + _defaultDurability);
LOGGER.info("Designated primary (applicable to 2 node case only) " + designatedPrimary);
LOGGER.info("Node priority " + priority);
LOGGER.info("Quorum override " + quorumOverride);
LOGGER.info("Permitted node list " + _permittedNodes);
}
Map<String, String> replicationEnvironmentParameters = new HashMap<>(ReplicatedEnvironmentFacade.REPCONFIG_DEFAULTS);
replicationEnvironmentParameters.putAll(_configuration.getReplicationParameters());
ReplicationConfig replicationConfig = new ReplicationConfig(groupName, nodeName, hostPort);
replicationConfig.setHelperHosts(helperHostPort);
replicationConfig.setDesignatedPrimary(designatedPrimary);
replicationConfig.setNodePriority(priority);
replicationConfig.setElectableGroupSizeOverride(quorumOverride);
for (Map.Entry<String, String> configItem : replicationEnvironmentParameters.entrySet()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Setting ReplicationConfig key " + configItem.getKey() + " to '" + configItem.getValue() + "'");
}
replicationConfig.setConfigParam(configItem.getKey(), configItem.getValue());
}
Map<String, String> environmentParameters = new HashMap<>(EnvironmentFacade.ENVCONFIG_DEFAULTS);
environmentParameters.putAll(_configuration.getParameters());
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setExceptionListener(new ExceptionListener());
envConfig.setDurability(_defaultDurability);
envConfig.setCacheMode(_configuration.getCacheMode());
envConfig.setLoggingHandler(new Slf4jLoggingHandler(_configuration));
LOGGER.info("Cache mode {}", envConfig.getCacheMode());
for (Map.Entry<String, String> configItem : environmentParameters.entrySet()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Setting EnvironmentConfig key " + configItem.getKey() + " to '" + configItem.getValue() + "'");
}
envConfig.setConfigParam(configItem.getKey(), configItem.getValue());
}
DbInternal.setLoadPropertyFile(envConfig, false);
File propsFile = new File(_environmentDirectory, "je.properties");
if (propsFile.exists()) {
LOGGER.warn("The BDB configuration file at '" + _environmentDirectory + File.separator + "je.properties' will NOT be loaded. Configure BDB using Qpid context variables instead.");
}
if (createEnvironmentInSeparateThread) {
createEnvironmentInSeparateThread(_environmentDirectory, envConfig, replicationConfig, postCreationAction);
} else {
createEnvironment(_environmentDirectory, envConfig, replicationConfig, postCreationAction);
}
}
use of com.sleepycat.je.EnvironmentConfig in project sessdb by ppdai.
the class BdbBenchmark method open.
@Override
public void open() {
try {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setCachePercent(90);
File file = new File(databaseDir_);
if (!file.exists()) {
file.mkdirs();
}
env_ = new Environment(file, envConfig);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
bdb_ = env_.openDatabase(null, BdbBenchmark.DATABASE_NAME, dbConfig);
} catch (DatabaseException e) {
e.printStackTrace();
}
}
Aggregations