use of jetbrains.exodus.env.EnvironmentConfig in project xodus by JetBrains.
the class BackgroundCleaningJob method execute.
@Override
protected void execute() throws Throwable {
final GarbageCollector gc = this.gc;
if (gc == null) {
return;
}
final BackgroundCleaner cleaner = gc.getCleaner();
if (!cleaner.isCurrentThread()) {
return;
}
try {
if (canContinue()) {
final long minTimeToInvokeCleaner = gc.getStartTime();
if (minTimeToInvokeCleaner > System.currentTimeMillis()) {
gc.wakeAt(minTimeToInvokeCleaner);
return;
}
final EnvironmentImpl env = gc.getEnvironment();
final EnvironmentConfig ec = env.getEnvironmentConfig();
final Log log = env.getLog();
if (gc.getMinFileAge() < log.getNumberOfFiles()) {
cleaner.setCleaning(true);
try {
doCleanLog(log, gc);
if (gc.isTooMuchFreeSpace()) {
final int gcRunPeriod = ec.getGcRunPeriod();
if (gcRunPeriod > 0) {
gc.wakeAt(System.currentTimeMillis() + gcRunPeriod);
}
}
} finally {
cleaner.setCleaning(false);
}
}
}
} finally {
gc.deletePendingFiles();
}
}
use of jetbrains.exodus.env.EnvironmentConfig in project pwm by pwm-project.
the class XodusLocalDB method init.
@Override
public void init(final File dbDirectory, final Map<String, String> initParameters, final Map<Parameter, String> parameters) throws LocalDBException {
this.fileLocation = dbDirectory;
LOGGER.trace("begin environment open");
final Instant startTime = Instant.now();
final EnvironmentConfig environmentConfig = makeEnvironmentConfig(initParameters);
{
final boolean compressionEnabled = initParameters.containsKey(Property.Compression_Enabled.getKeyName()) ? Boolean.parseBoolean(initParameters.get(Property.Compression_Enabled.getKeyName())) : BindMachine.DEFAULT_ENABLE_COMPRESSION;
final int compressionMinLength = initParameters.containsKey(Property.Compression_MinLength.getKeyName()) ? Integer.parseInt(initParameters.get(Property.Compression_MinLength.getKeyName())) : BindMachine.DEFAULT_MIN_COMPRESSION_LENGTH;
bindMachine = new BindMachine(compressionEnabled, compressionMinLength);
}
readOnly = parameters.containsKey(Parameter.readOnly) && Boolean.parseBoolean(parameters.get(Parameter.readOnly));
LOGGER.trace("preparing to open with configuration " + JsonUtil.serializeMap(environmentConfig.getSettings()));
environment = Environments.newInstance(dbDirectory.getAbsolutePath() + File.separator + "xodus", environmentConfig);
LOGGER.trace("environment open (" + TimeDuration.fromCurrent(startTime).asCompactString() + ")");
environment.executeInTransaction(txn -> {
for (final LocalDB.DB db : LocalDB.DB.values()) {
final Store store = initStore(db, txn);
cachedStoreObjects.put(db, store);
}
});
status = LocalDB.Status.OPEN;
for (final LocalDB.DB db : LocalDB.DB.values()) {
LOGGER.trace("opened " + db + " with " + this.size(db) + " records");
}
}
use of jetbrains.exodus.env.EnvironmentConfig in project pwm by pwm-project.
the class XodusLocalDB method makeEnvironmentConfig.
private EnvironmentConfig makeEnvironmentConfig(final Map<String, String> initParameters) {
final EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setEnvCloseForcedly(true);
environmentConfig.setMemoryUsage(50 * 1024 * 1024);
environmentConfig.setEnvGatherStatistics(true);
for (final Map.Entry<String, String> entry : initParameters.entrySet()) {
final String key = entry.getKey();
final String value = entry.getValue();
final Map<String, String> singleMap = Collections.singletonMap(key, value);
try {
environmentConfig.setSettings(singleMap);
LOGGER.trace("set env setting from appProperty: " + key + "=" + value);
} catch (InvalidSettingException e) {
LOGGER.warn("problem setting configured env settings: " + e.getMessage());
}
}
return environmentConfig;
}
use of jetbrains.exodus.env.EnvironmentConfig in project xodus by JetBrains.
the class BackgroundCleaningJob method canContinue.
private boolean canContinue() {
final GarbageCollector gc = this.gc;
if (gc == null) {
return false;
}
final BackgroundCleaner cleaner = gc.getCleaner();
if (cleaner.isSuspended() || cleaner.isFinished()) {
return false;
}
final EnvironmentConfig ec = gc.getEnvironment().getEnvironmentConfig();
return ec.isGcEnabled() && !ec.getEnvIsReadonly() && gc.isTooMuchFreeSpace();
}
use of jetbrains.exodus.env.EnvironmentConfig in project xodus by JetBrains.
the class EntitySnapshotTests method testConcurrentPutJetPassLike.
public void testConcurrentPutJetPassLike() {
getEntityStore().getConfig().setCachingDisabled(true);
final EnvironmentImpl environment = (EnvironmentImpl) getEntityStore().getEnvironment();
final EnvironmentConfig config = environment.getEnvironmentConfig();
// disable GC
config.setGcEnabled(false);
final JobProcessor processor = new MultiThreadDelegatingJobProcessor("ConcurrentPutProcessor", 8) {
};
processor.setExceptionHandler((processor1, job, t) -> logger.error("Background exception", t));
processor.start();
final int count = 30000;
for (int i = 0; i < count; ++i) {
final int id = i;
processor.queue(new Job() {
@Override
protected void execute() {
getEntityStore().executeInTransaction(txn -> {
final Entity ticket = txn.newEntity("CASTicket");
ticket.setProperty("id", id);
});
}
});
}
processor.waitForJobs(100);
processor.finish();
getEntityStore().executeInTransaction(txn -> {
// System.out.println("Structure id: " + executeMethod(environment, "getLastStructureId"));
Assert.assertEquals(count, (int) txn.getAll("CASTicket").size());
final EntityIterable sorted = txn.sort("CASTicket", "id", true);
Assert.assertEquals(count, (int) sorted.size());
int i = 0;
for (final Entity ticket : sorted) {
final Comparable id = ticket.getProperty("id");
Assert.assertNotNull(id);
Assert.assertEquals(i++, id);
}
});
}
Aggregations