Search in sources :

Example 1 with PrimitiveLongLongMap

use of org.neo4j.collection.primitive.PrimitiveLongLongMap in project neo4j by neo4j.

the class CheckTxLogs method validateCheckPoints.

boolean validateCheckPoints(PhysicalLogFiles logFiles, InconsistenciesHandler handler) throws IOException {
    final long lowestLogVersion = logFiles.getLowestLogVersion();
    final long highestLogVersion = logFiles.getHighestLogVersion();
    boolean success = true;
    try (PrimitiveLongLongMap logFileSizes = Primitive.offHeapLongLongMap()) {
        for (long i = lowestLogVersion; i <= highestLogVersion; i++) {
            logFileSizes.put(i, fs.getFileSize(logFiles.getLogFileForVersion(i)));
        }
        LogEntryCursor logEntryCursor = LogTestUtils.openLogs(fs, logFiles);
        while (logEntryCursor.next()) {
            LogEntry logEntry = logEntryCursor.get();
            if (logEntry instanceof CheckPoint) {
                LogPosition logPosition = logEntry.<CheckPoint>as().getLogPosition();
                // if the file has been pruned we cannot validate the check point
                if (logPosition.getLogVersion() >= lowestLogVersion) {
                    long size = logFileSizes.get(logPosition.getLogVersion());
                    if (logPosition.getByteOffset() < 0 || size < 0 || logPosition.getByteOffset() > size) {
                        long currentLogVersion = logEntryCursor.getCurrentLogVersion();
                        handler.reportInconsistentCheckPoint(currentLogVersion, logPosition, size);
                        success = false;
                    }
                }
            }
        }
    }
    return success;
}
Also used : PrimitiveLongLongMap(org.neo4j.collection.primitive.PrimitiveLongLongMap) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 2 with PrimitiveLongLongMap

use of org.neo4j.collection.primitive.PrimitiveLongLongMap in project neo4j by neo4j.

the class PrimitiveLongMapTest method longLongEntryVisitorShouldSeeAllEntriesIfItDoesNotBreakOut.

@SuppressWarnings("unchecked")
@Test
public void longLongEntryVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() {
    // GIVEN
    PrimitiveLongLongVisitor<RuntimeException> visitor;
    try (PrimitiveLongLongMap map = Primitive.offHeapLongLongMap()) {
        map.put(1, 100);
        map.put(2, 200);
        map.put(3, 300);
        visitor = mock(PrimitiveLongLongVisitor.class);
        // WHEN
        map.visitEntries(visitor);
    }
    // THEN
    verify(visitor).visited(1, 100);
    verify(visitor).visited(2, 200);
    verify(visitor).visited(3, 300);
    verifyNoMoreInteractions(visitor);
}
Also used : PrimitiveLongLongVisitor(org.neo4j.collection.primitive.PrimitiveLongLongVisitor) PrimitiveLongLongMap(org.neo4j.collection.primitive.PrimitiveLongLongMap) Test(org.junit.Test)

Example 3 with PrimitiveLongLongMap

use of org.neo4j.collection.primitive.PrimitiveLongLongMap in project neo4j by neo4j.

the class PrimitiveLongMapTest method longLongKeyVisitorShouldNotSeeEntriesAfterRequestingBreakOut.

@Test
public void longLongKeyVisitorShouldNotSeeEntriesAfterRequestingBreakOut() {
    // GIVEN
    AtomicInteger counter = new AtomicInteger();
    try (PrimitiveLongLongMap map = Primitive.offHeapLongLongMap()) {
        map.put(1, 100);
        map.put(2, 200);
        map.put(3, 300);
        map.put(4, 400);
        // WHEN
        map.visitKeys(value -> counter.incrementAndGet() > 2);
    }
    // THEN
    assertThat(counter.get(), is(3));
}
Also used : PrimitiveLongLongMap(org.neo4j.collection.primitive.PrimitiveLongLongMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 4 with PrimitiveLongLongMap

use of org.neo4j.collection.primitive.PrimitiveLongLongMap in project neo4j by neo4j.

the class PrimitiveLongMapTest method longLongKeyVisitorShouldSeeAllEntriesIfItDoesNotBreakOut.

@SuppressWarnings("unchecked")
@Test
public void longLongKeyVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() {
    // GIVEN
    PrimitiveLongVisitor<RuntimeException> visitor = mock(PrimitiveLongVisitor.class);
    try (PrimitiveLongLongMap map = Primitive.offHeapLongLongMap()) {
        map.put(1, 100);
        map.put(2, 200);
        map.put(3, 300);
        // WHEN
        map.visitKeys(visitor);
    }
    // THEN
    verify(visitor).visited(1);
    verify(visitor).visited(2);
    verify(visitor).visited(3);
    verifyNoMoreInteractions(visitor);
}
Also used : PrimitiveLongLongMap(org.neo4j.collection.primitive.PrimitiveLongLongMap) Test(org.junit.Test)

Example 5 with PrimitiveLongLongMap

use of org.neo4j.collection.primitive.PrimitiveLongLongMap in project neo4j by neo4j.

the class PrimitiveLongMapTest method longLongEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut.

@Test
public void longLongEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() {
    // GIVEN
    AtomicInteger counter = new AtomicInteger();
    try (PrimitiveLongLongMap map = Primitive.offHeapLongLongMap()) {
        map.put(1, 100);
        map.put(2, 200);
        map.put(3, 300);
        map.put(4, 400);
        // WHEN
        map.visitEntries((key, value) -> counter.incrementAndGet() > 2);
    }
    // THEN
    assertThat(counter.get(), is(3));
}
Also used : PrimitiveLongLongMap(org.neo4j.collection.primitive.PrimitiveLongLongMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

PrimitiveLongLongMap (org.neo4j.collection.primitive.PrimitiveLongLongMap)5 Test (org.junit.Test)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PrimitiveLongLongVisitor (org.neo4j.collection.primitive.PrimitiveLongLongVisitor)1 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)1 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)1 CheckPoint (org.neo4j.kernel.impl.transaction.log.entry.CheckPoint)1 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)1