use of jetbrains.exodus.env.EnvironmentImpl 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.EnvironmentImpl in project meghanada-server by mopemope.
the class ProjectDatabase method close.
private synchronized void close() {
if (nonNull(this.entityStore)) {
try {
EnvironmentImpl environment = (EnvironmentImpl) this.entityStore.getEnvironment();
environment.flushAndSync();
this.entityStore.close();
} catch (ExodusException e) {
// wait transaction
try {
Thread.sleep(1000 * 3);
} catch (InterruptedException e1) {
log.catching(e1);
}
this.entityStore.close();
}
this.entityStore = null;
}
if (nonNull(this.environment)) {
this.environment.close();
this.environment = null;
}
}
use of jetbrains.exodus.env.EnvironmentImpl in project meghanada-server by mopemope.
the class ProjectDatabase method reset.
public static void reset() {
if (projectDatabase != null) {
if (nonNull(projectDatabase.entityStore)) {
try {
EnvironmentImpl environment = (EnvironmentImpl) projectDatabase.entityStore.getEnvironment();
environment.flushAndSync();
projectDatabase.entityStore.close();
} catch (ExodusException e) {
// wait transaction
try {
Thread.sleep(1000 * 3);
} catch (InterruptedException e1) {
log.catching(e1);
}
projectDatabase.entityStore.close();
}
projectDatabase.entityStore = null;
}
if (nonNull(projectDatabase.environment)) {
projectDatabase.environment.close();
projectDatabase.environment = null;
}
projectDatabase.open();
}
}
use of jetbrains.exodus.env.EnvironmentImpl in project xodus by JetBrains.
the class EntitySnapshotTests method testConcurrentPutJetPassLike.
public void testConcurrentPutJetPassLike() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
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(new JobProcessorExceptionHandler() {
@Override
public void handle(JobProcessor processor, Job job, Throwable 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() throws Throwable {
getEntityStore().executeInTransaction(new StoreTransactionalExecutable() {
@Override
public void execute(@NotNull final StoreTransaction txn) {
final Entity ticket = txn.newEntity("CASTicket");
ticket.setProperty("id", id);
}
});
}
});
}
processor.waitForJobs(100);
processor.finish();
getEntityStore().executeInTransaction(new StoreTransactionalExecutable() {
@Override
public void execute(@NotNull final StoreTransaction 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);
}
}
});
}
use of jetbrains.exodus.env.EnvironmentImpl in project xodus by JetBrains.
the class BackgroundCleaningJob method doCleanLog.
private void doCleanLog(@NotNull final Log log, @NotNull final GarbageCollector gc) {
GarbageCollector.loggingInfo("Starting background cleaner loop for " + log.getLocation());
final EnvironmentImpl env = gc.getEnvironment();
final UtilizationProfile up = gc.getUtilizationProfile();
final long highFile = log.getHighFileAddress();
final long loopStart = System.currentTimeMillis();
final int gcRunPeriod = env.getEnvironmentConfig().getGcRunPeriod();
try {
do {
final Iterator<Long> fragmentedFiles = up.getFilesSortedByUtilization(highFile);
if (!fragmentedFiles.hasNext()) {
return;
}
if (cleanFiles(gc, fragmentedFiles)) {
break;
}
Thread.yield();
} while (canContinue() && loopStart + gcRunPeriod > System.currentTimeMillis());
gc.setUseRegularTxn(true);
try {
while (canContinue() && loopStart + gcRunPeriod > System.currentTimeMillis()) {
final Iterator<Long> fragmentedFiles = up.getFilesSortedByUtilization(highFile);
if (!fragmentedFiles.hasNext() || !cleanFiles(gc, fragmentedFiles)) {
break;
}
}
} finally {
gc.setUseRegularTxn(false);
}
} finally {
gc.resetNewFiles();
up.estimateTotalBytes();
up.setDirty(true);
GarbageCollector.loggingInfo("Finished background cleaner loop for " + log.getLocation());
}
}
Aggregations