Search in sources :

Example 21 with LongPredicate

use of java.util.function.LongPredicate in project bboxdb by jnidzwetzki.

the class SSTableCheckpointRunnable method isCheckpointNeeded.

/**
 * Decide if a new checkpoint is needed
 * @return
 */
protected boolean isCheckpointNeeded(final TupleStoreManager ssTableManager) {
    final List<ReadOnlyTupleStore> inMemoryStores = ssTableManager.getAllInMemoryStorages();
    if (inMemoryStores.isEmpty()) {
        return false;
    }
    final long currentTime = System.currentTimeMillis();
    // The checkpoint predicate
    final LongPredicate checkpointPredicate = m -> {
        final long checkpointThreshold = TimeUnit.MICROSECONDS.toMillis(m) + maxUncheckpointedMiliseconds;
        return checkpointThreshold < currentTime;
    };
    final boolean checkpointNeeded = inMemoryStores.stream().filter(Objects::nonNull).mapToLong(m -> m.getOldestTupleVersionTimestamp()).anyMatch(checkpointPredicate);
    logger.debug("Checkpoint for {} needed {}", ssTableManager.getTupleStoreName().getFullname(), checkpointNeeded);
    return checkpointNeeded;
}
Also used : Logger(org.slf4j.Logger) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) LoggerFactory(org.slf4j.LoggerFactory) Const(org.bboxdb.misc.Const) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) SystemInfo(org.bboxdb.commons.SystemInfo) List(java.util.List) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) LongPredicate(java.util.function.LongPredicate) StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) Objects(java.util.Objects) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) LongPredicate(java.util.function.LongPredicate)

Aggregations

LongPredicate (java.util.function.LongPredicate)21 Predicate (java.util.function.Predicate)14 Test (org.junit.Test)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 LongPredicateAssert (org.assertj.core.api.LongPredicateAssert)10 LongPredicateAssertBaseTest (org.assertj.core.api.LongPredicateAssertBaseTest)10 PredicateDescription (org.assertj.core.presentation.PredicateDescription)10 FailureMessages.actualIsNull (org.assertj.core.util.FailureMessages.actualIsNull)10 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)10 Mockito.verify (org.mockito.Mockito.verify)10 List (java.util.List)9 File (java.io.File)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 OptionalDouble (java.util.OptionalDouble)4 OptionalLong (java.util.OptionalLong)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 DoublePredicate (java.util.function.DoublePredicate)4 IntPredicate (java.util.function.IntPredicate)4 Collectors (java.util.stream.Collectors)4