Search in sources :

Example 1 with EnvironmentConfig

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();
    }
}
Also used : Log(jetbrains.exodus.log.Log) EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) EnvironmentImpl(jetbrains.exodus.env.EnvironmentImpl)

Example 2 with EnvironmentConfig

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");
    }
}
Also used : Instant(java.time.Instant) EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) Store(jetbrains.exodus.env.Store)

Example 3 with EnvironmentConfig

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;
}
Also used : EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) InvalidSettingException(jetbrains.exodus.InvalidSettingException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with 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();
}
Also used : EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig)

Example 5 with EnvironmentConfig

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);
        }
    });
}
Also used : MultiThreadDelegatingJobProcessor(jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor) EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) Job(jetbrains.exodus.core.execution.Job) EnvironmentImpl(jetbrains.exodus.env.EnvironmentImpl) JobProcessor(jetbrains.exodus.core.execution.JobProcessor) Assert(org.junit.Assert) EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) MultiThreadDelegatingJobProcessor(jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor) JobProcessor(jetbrains.exodus.core.execution.JobProcessor) MultiThreadDelegatingJobProcessor(jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor) EnvironmentImpl(jetbrains.exodus.env.EnvironmentImpl) Job(jetbrains.exodus.core.execution.Job)

Aggregations

EnvironmentConfig (jetbrains.exodus.env.EnvironmentConfig)5 EnvironmentImpl (jetbrains.exodus.env.EnvironmentImpl)2 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 InvalidSettingException (jetbrains.exodus.InvalidSettingException)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 MultiThreadDelegatingJobProcessor (jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor)1 Store (jetbrains.exodus.env.Store)1 Log (jetbrains.exodus.log.Log)1 Assert (org.junit.Assert)1