Search in sources :

Example 21 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class MultipleIndexPopulator method newPopulatingUpdater.

@VisibleForTesting
MultipleIndexUpdater newPopulatingUpdater(NodePropertyAccessor accessor, CursorContext cursorContext) {
    Map<SchemaDescriptor, Pair<IndexPopulation, IndexUpdater>> updaters = new HashMap<>();
    forEachPopulation(population -> {
        IndexUpdater updater = population.populator.newPopulatingUpdater(accessor, cursorContext);
        updaters.put(population.schema(), Pair.of(population, updater));
    }, cursorContext);
    return new MultipleIndexUpdater(this, updaters, logProvider, cursorContext);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) HashMap(java.util.HashMap) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.internal.helpers.collection.Pair) VisibleForTesting(org.neo4j.util.VisibleForTesting)

Example 22 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexUpdaterMap method close.

@Override
public void close() throws UnderlyingStorageException {
    Set<Pair<IndexDescriptor, UnderlyingStorageException>> exceptions = null;
    for (Map.Entry<IndexDescriptor, IndexUpdater> updaterEntry : updaterMap.entrySet()) {
        IndexUpdater updater = updaterEntry.getValue();
        try {
            updater.close();
        } catch (UncheckedIOException | IndexEntryConflictException e) {
            if (null == exceptions) {
                exceptions = new HashSet<>();
            }
            exceptions.add(Pair.of(updaterEntry.getKey(), new UnderlyingStorageException(e)));
        }
    }
    clear();
    if (null != exceptions) {
        throw new MultipleUnderlyingStorageExceptions(exceptions);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) Map(java.util.Map) HashMap(java.util.HashMap) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) MultipleUnderlyingStorageExceptions(org.neo4j.kernel.impl.store.MultipleUnderlyingStorageExceptions)

Example 23 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class TransactionLogsRecoveryTest method writeSomeDataWithVersion.

private void writeSomeDataWithVersion(Path file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor, KernelVersion version) throws IOException {
    try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystem.write(file), logVersion, CURRENT_LOG_FORMAT_VERSION, file, EMPTY_ACCESSOR);
        PositionAwarePhysicalFlushableChecksumChannel writableLogChannel = new PositionAwarePhysicalFlushableChecksumChannel(versionedStoreChannel, new HeapScopedBuffer(1, KibiByte, INSTANCE))) {
        writeLogHeader(writableLogChannel, new LogHeader(logVersion, 2L, StoreId.UNKNOWN));
        writableLogChannel.beginChecksum();
        Consumer<LogPositionMarker> consumer = marker -> {
            try {
                writableLogChannel.getCurrentPosition(marker);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        };
        LogEntryWriter first = new LogEntryWriter(writableLogChannel, version);
        visitor.visit(Pair.of(first, consumer));
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) Visitor(org.neo4j.internal.helpers.collection.Visitor) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Log(org.neo4j.logging.Log) DatabaseIdFactory.from(org.neo4j.kernel.database.DatabaseIdFactory.from) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LogFilesBuilder(org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder) Config(org.neo4j.configuration.Config) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogCheckPointEvent(org.neo4j.kernel.impl.transaction.tracing.LogCheckPointEvent) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Monitors(org.neo4j.monitoring.Monitors) BASE_TX_CHECKSUM(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_CHECKSUM) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) PositionAwarePhysicalFlushableChecksumChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel) Path(java.nio.file.Path) EMPTY_CHECKER(org.neo4j.kernel.recovery.RecoveryStartupChecker.EMPTY_CHECKER) StorageEngine(org.neo4j.storageengine.api.StorageEngine) NO_RECOVERY_REQUIRED(org.neo4j.kernel.recovery.RecoveryStartInformation.NO_RECOVERY_REQUIRED) TestDirectory(org.neo4j.test.rule.TestDirectory) BASE_TX_COMMIT_TIMESTAMP(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) Instant(java.time.Instant) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Test(org.junit.jupiter.api.Test) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) TestLogEntryReader.logEntryReader(org.neo4j.kernel.impl.transaction.log.TestLogEntryReader.logEntryReader) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) Mockito.mock(org.mockito.Mockito.mock) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CsvSource(org.junit.jupiter.params.provider.CsvSource) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) ProgressReporter(org.neo4j.common.ProgressReporter) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KernelVersion(org.neo4j.kernel.KernelVersion) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) DatabaseStartupController(org.neo4j.kernel.database.DatabaseStartupController) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) EMPTY_ACCESSOR(org.neo4j.kernel.impl.transaction.log.files.ChannelNativeAccessor.EMPTY_ACCESSOR) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Inject(org.neo4j.test.extension.Inject) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) StoreId(org.neo4j.storageengine.api.StoreId) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) Files(java.nio.file.Files) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) ExceptionUtils.getRootCause(org.apache.commons.lang3.exception.ExceptionUtils.getRootCause) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CURRENT_LOG_FORMAT_VERSION(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_LOG_FORMAT_VERSION) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) UUID.randomUUID(java.util.UUID.randomUUID) Mockito.never(org.mockito.Mockito.never) CURRENT_FORMAT_LOG_HEADER_SIZE(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE) NO_MONITOR(org.neo4j.kernel.recovery.RecoveryStartInformationProvider.NO_MONITOR) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) Pair(org.neo4j.internal.helpers.collection.Pair) KibiByte(org.neo4j.io.ByteUnit.KibiByte) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PositionAwarePhysicalFlushableChecksumChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) IOException(java.io.IOException) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker)

Example 24 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class CompositeIndexAccessorCompatibility method mustThrowOnIllegalCompositeQueriesAndMustNotThrowOnLegalQueries.

/* Composite query validity */
/**
 * This test verify behavior for all different index patterns on a two column composite index.
 * A composite query need to have decreasing precision among the queries.
 * This means a range or exists query can only be followed by and exists query.
 * Prefix query is also included under "range".
 * Contains or suffix queries are not allowed in a composite query at all.
 *
 * Those are all the different combinations:
 * x = exact
 * < = range (also include stringPrefix)
 * - = exists
 * ! = stringContains or stringSuffix
 * ? = any predicate
 * Index patterns
 * x x ok
 * x < ok
 * x - ok
 * < x not ok
 * < < not ok
 * < - ok
 * - x not ok
 * - < not ok
 * - - ok
 * ! ? not ok
 */
@Test
public void mustThrowOnIllegalCompositeQueriesAndMustNotThrowOnLegalQueries() throws Exception {
    Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
    // given
    Value someValue = Values.of(true);
    TextValue someString = stringValue("");
    PropertyIndexQuery firstExact = exact(100, someValue);
    PropertyIndexQuery firstRange = range(100, someValue, true, someValue, true);
    PropertyIndexQuery firstPrefix = stringPrefix(100, someString);
    PropertyIndexQuery firstExist = exists(100);
    PropertyIndexQuery firstSuffix = stringSuffix(100, someString);
    PropertyIndexQuery firstContains = stringContains(100, someString);
    PropertyIndexQuery secondExact = exact(200, someValue);
    PropertyIndexQuery secondRange = range(200, someValue, true, someValue, true);
    PropertyIndexQuery secondExist = exists(200);
    PropertyIndexQuery secondPrefix = stringPrefix(100, someString);
    PropertyIndexQuery secondSuffix = stringSuffix(100, someString);
    PropertyIndexQuery secondContains = stringContains(100, someString);
    List<Pair<PropertyIndexQuery[], Boolean>> queries = Arrays.asList(of(new PropertyIndexQuery[] { firstExact, secondExact }, true), of(new PropertyIndexQuery[] { firstExact, secondRange }, true), of(new PropertyIndexQuery[] { firstExact, secondExist }, true), of(new PropertyIndexQuery[] { firstExact, secondPrefix }, true), of(new PropertyIndexQuery[] { firstExact, secondSuffix }, false), of(new PropertyIndexQuery[] { firstExact, secondContains }, false), of(new PropertyIndexQuery[] { firstRange, secondExact }, false), of(new PropertyIndexQuery[] { firstRange, secondRange }, false), of(new PropertyIndexQuery[] { firstRange, secondExist }, true), of(new PropertyIndexQuery[] { firstRange, secondPrefix }, false), of(new PropertyIndexQuery[] { firstRange, secondSuffix }, false), of(new PropertyIndexQuery[] { firstRange, secondContains }, false), of(new PropertyIndexQuery[] { firstPrefix, secondExact }, false), of(new PropertyIndexQuery[] { firstPrefix, secondRange }, false), of(new PropertyIndexQuery[] { firstPrefix, secondExist }, true), of(new PropertyIndexQuery[] { firstPrefix, secondPrefix }, false), of(new PropertyIndexQuery[] { firstPrefix, secondSuffix }, false), of(new PropertyIndexQuery[] { firstPrefix, secondContains }, false), of(new PropertyIndexQuery[] { firstExist, secondExact }, false), of(new PropertyIndexQuery[] { firstExist, secondRange }, false), of(new PropertyIndexQuery[] { firstExist, secondExist }, true), of(new PropertyIndexQuery[] { firstExist, secondPrefix }, false), of(new PropertyIndexQuery[] { firstExist, secondSuffix }, false), of(new PropertyIndexQuery[] { firstExist, secondContains }, false), of(new PropertyIndexQuery[] { firstSuffix, secondExact }, false), of(new PropertyIndexQuery[] { firstSuffix, secondRange }, false), of(new PropertyIndexQuery[] { firstSuffix, secondExist }, false), of(new PropertyIndexQuery[] { firstSuffix, secondPrefix }, false), of(new PropertyIndexQuery[] { firstSuffix, secondSuffix }, false), of(new PropertyIndexQuery[] { firstSuffix, secondContains }, false), of(new PropertyIndexQuery[] { firstContains, secondExact }, false), of(new PropertyIndexQuery[] { firstContains, secondRange }, false), of(new PropertyIndexQuery[] { firstContains, secondExist }, false), of(new PropertyIndexQuery[] { firstContains, secondPrefix }, false), of(new PropertyIndexQuery[] { firstContains, secondSuffix }, false), of(new PropertyIndexQuery[] { firstContains, secondContains }, false));
    SimpleEntityValueClient client = new SimpleEntityValueClient();
    try (ValueIndexReader reader = accessor.newValueReader()) {
        for (Pair<PropertyIndexQuery[], Boolean> pair : queries) {
            PropertyIndexQuery[] theQuery = pair.first();
            Boolean legal = pair.other();
            if (legal) {
                // when
                reader.query(NULL_CONTEXT, client, unconstrained(), theQuery);
            // then should not throw
            } else {
                try {
                    // when
                    reader.query(NULL_CONTEXT, client, unconstrained(), theQuery);
                    fail("Expected index reader to throw for illegal composite query. Query was, " + Arrays.toString(theQuery));
                } catch (IllegalArgumentException e) {
                    // then
                    assertThat(e.getMessage()).contains("Tried to query index with illegal composite query.");
                }
            }
        }
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) TextValue(org.neo4j.values.storable.TextValue) ArrayValue(org.neo4j.values.storable.ArrayValue) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) PointValue(org.neo4j.values.storable.PointValue) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) Values.intValue(org.neo4j.values.storable.Values.intValue) Values.pointValue(org.neo4j.values.storable.Values.pointValue) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) BooleanValue(org.neo4j.values.storable.BooleanValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) DateValue(org.neo4j.values.storable.DateValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.Test)

Example 25 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class DurationValueTest method shouldGetSameInstantWhenAddingDurationBetweenToInstant.

@Test
void shouldGetSameInstantWhenAddingDurationBetweenToInstant() {
    // given
    @SuppressWarnings("unchecked") Pair<Temporal, Temporal>[] input = new Pair[] { pair(datetime(date(2017, 3, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 3, 26), localTime(19, 40, 0, 0), ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 3, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 3, 26), localTime(11, 40, 0, 0), ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 10, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 10, 29), localTime(19, 40, 0, 0), ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 10, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 10, 29), localTime(11, 40, 0, 0), ZoneId.of("Europe/Stockholm"))) };
    for (Pair<Temporal, Temporal> pair : input) {
        Temporal a = pair.first(), b = pair.other();
        // when
        DurationValue diffAB = durationBetween(a, b);
        DurationValue diffBA = durationBetween(b, a);
        DurationValue diffABs = between(SECONDS, a, b);
        DurationValue diffBAs = between(SECONDS, b, a);
        // then
        assertEquals(b, a.plus(diffAB), diffAB.prettyPrint());
        assertEquals(a, b.plus(diffBA), diffBA.prettyPrint());
        assertEquals(b, a.plus(diffABs), diffABs.prettyPrint());
        assertEquals(a, b.plus(diffBAs), diffBAs.prettyPrint());
    }
}
Also used : Temporal(java.time.temporal.Temporal) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.jupiter.api.Test)

Aggregations

Pair (org.neo4j.internal.helpers.collection.Pair)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)22 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)12 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)11 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 TextValue (org.neo4j.values.storable.TextValue)9 PointValue (org.neo4j.values.storable.PointValue)8 Value (org.neo4j.values.storable.Value)8 Values.stringValue (org.neo4j.values.storable.Values.stringValue)8 Values.pointValue (org.neo4j.values.storable.Values.pointValue)7 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 Label (org.neo4j.graphdb.Label)5 Path (java.nio.file.Path)4 Transaction (org.neo4j.graphdb.Transaction)4 Map (java.util.Map)3