Search in sources :

Example 6 with IdGenerator

use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.

the class FullCheck method consistencyCheckNonSchemaIndexes.

private static void consistencyCheckNonSchemaIndexes(InconsistencyReport report, ProgressListener listener, ConsistencyCheckable labelScanStore, ConsistencyCheckable relationshipTypeScanStore, IndexStatisticsStore indexStatisticsStore, CountsStore countsStore, RelationshipGroupDegreesStore groupDegreesStore, List<IdGenerator> idGenerators, CursorContext cursorContext) {
    consistencyCheckSingleCheckable(report, listener, labelScanStore, RecordType.LABEL_SCAN_DOCUMENT, cursorContext);
    consistencyCheckSingleCheckable(report, listener, relationshipTypeScanStore, RecordType.RELATIONSHIP_TYPE_SCAN_DOCUMENT, cursorContext);
    consistencyCheckSingleCheckable(report, listener, indexStatisticsStore, RecordType.INDEX_STATISTICS, cursorContext);
    consistencyCheckSingleCheckable(report, listener, countsStore, RecordType.COUNTS, cursorContext);
    if (hasGroupDegreesStore(groupDegreesStore)) {
        // The relationship group degrees store has no "NULL_STORE" because it's otherwise not needed and it's not
        // checked in the other parts of the consistency checker since degrees in general aren't checked (due to performance implications).
        // This is why we use null instead for this particular store.
        consistencyCheckSingleCheckable(report, listener, groupDegreesStore, RecordType.RELATIONSHIP_GROUP, cursorContext);
    }
    for (IdGenerator idGenerator : idGenerators) {
        consistencyCheckSingleCheckable(report, listener, idGenerator, RecordType.ID_STORE, cursorContext);
    }
}
Also used : IdGenerator(org.neo4j.internal.id.IdGenerator)

Example 7 with IdGenerator

use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.

the class IdContextFactoryBuilderTest method useProvidedPageCacheCursorOnIdMaintenance.

@Test
void useProvidedPageCacheCursorOnIdMaintenance() throws IOException {
    PageCacheTracer cacheTracer = new DefaultPageCacheTracer();
    Config config = defaults();
    var idContextFactory = IdContextFactoryBuilder.of(fs, jobScheduler, config, cacheTracer).build();
    var idContext = idContextFactory.createIdContext(from("test", UUID.randomUUID()));
    var idGeneratorFactory = idContext.getIdGeneratorFactory();
    var idController = idContext.getIdController();
    idController.initialize(() -> () -> true);
    Path file = testDirectory.file("b");
    IdType idType = IdType.NODE;
    try (IdGenerator idGenerator = idGeneratorFactory.create(pageCache, file, idType, 1, false, 100, writable(), config, NULL, immutable.empty())) {
        idGenerator.marker(NULL).markDeleted(1);
        idGeneratorFactory.clearCache(NULL);
        assertThat(cacheTracer.pins()).isZero();
        assertThat(cacheTracer.unpins()).isZero();
        assertThat(cacheTracer.hits()).isZero();
        idController.maintenance();
        assertThat(cacheTracer.pins()).isGreaterThan(0);
        assertThat(cacheTracer.unpins()).isGreaterThan(0);
        assertThat(cacheTracer.hits()).isGreaterThan(0);
    }
}
Also used : Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) IdGenerator(org.neo4j.internal.id.IdGenerator) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) IdType(org.neo4j.internal.id.IdType) Test(org.junit.jupiter.api.Test)

Example 8 with IdGenerator

use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.

the class IndexedIdGeneratorRecoverabilityTest method avoidNormalizationDuringRecovery.

@Test
void avoidNormalizationDuringRecovery() throws IOException {
    long id;
    long neighbourId;
    try (IdGenerator freelist = instantiateFreelist()) {
        freelist.start(NO_FREE_IDS, NULL);
        id = freelist.nextId(NULL);
        neighbourId = freelist.nextId(NULL);
        markUsed(freelist, id, neighbourId);
        markDeleted(freelist, id, neighbourId);
    // Crash (no checkpoint)
    }
    try (IdGenerator freelist = instantiateFreelist()) {
        // Recovery
        markUsed(freelist, id, neighbourId);
        markDeleted(freelist, id, neighbourId);
        // Neo4j does this on recovery, setHighId and checkpoint
        freelist.setHighId(neighbourId + 1);
        // mostly to get the generation persisted
        freelist.checkpoint(NULL);
        // Normal operations
        freelist.start(NO_FREE_IDS, NULL);
        markFree(freelist, id);
        long idAfterRecovery = freelist.nextId(NULL);
        assertEquals(id, idAfterRecovery);
        markUsed(freelist, id);
    }
    try (IdGenerator freelist = instantiateFreelist()) {
        // Recovery
        // If normalization happens on recovery then this transition, which really should be DELETED (last check-pointed state) -> USED
        // instead becomes normalized from DELETED -> FREE and the real transition becomes FREE -> RESERVED
        markUsed(freelist, id);
        // Normal operations
        freelist.start(NO_FREE_IDS, NULL);
        // <-- this must be OK
        markDeleted(freelist, id);
        // And as an extra measure of verification
        markFree(freelist, id);
        MutableLongSet expected = LongSets.mutable.with(id, neighbourId);
        assertTrue(expected.remove(freelist.nextId(NULL)));
        assertTrue(expected.remove(freelist.nextId(NULL)));
        assertTrue(expected.isEmpty());
    }
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IdGenerator(org.neo4j.internal.id.IdGenerator) Test(org.junit.jupiter.api.Test)

Example 9 with IdGenerator

use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.

the class IndexedIdGeneratorRecoverabilityTest method resetUsabilityOnRestartWithSomeWrites.

@Test
void resetUsabilityOnRestartWithSomeWrites() throws IOException {
    // Create the freelist
    try (IdGenerator freelist = instantiateFreelist()) {
        freelist.checkpoint(NULL);
    }
    final long id1;
    final long id2;
    final long id3;
    try (IdGenerator freelist = instantiateFreelist()) {
        id1 = freelist.nextId(NULL);
        id2 = freelist.nextId(NULL);
        id3 = freelist.nextId(NULL);
        markUsed(freelist, id1, id2, id3);
        // <-- Don't delete id3
        markDeleted(freelist, id1, id2);
        // Intentionally don't mark the ids as reusable
        freelist.checkpoint(NULL);
    }
    try (IdGenerator freelist = instantiateFreelist()) {
        freelist.start(NO_FREE_IDS, NULL);
        // Here we expected that id1 and id2 will be reusable, even if they weren't marked as such in the previous session
        // Making changes to the tree entry where they live will update the generation and all of a sudden the reusable bits
        // in that entry will matter when we want to allocate. This is why we now want to make a change to that tree entry
        // and after that do an allocation to see if we still get them.
        markDeleted(freelist, id3);
        final ImmutableLongSet reused = LongSets.immutable.of(freelist.nextId(NULL), freelist.nextId(NULL));
        assertEquals(LongSets.immutable.of(id1, id2), reused, "IDs are not reused");
    }
}
Also used : ImmutableLongSet(org.eclipse.collections.api.set.primitive.ImmutableLongSet) IdGenerator(org.neo4j.internal.id.IdGenerator) Test(org.junit.jupiter.api.Test)

Example 10 with IdGenerator

use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.

the class IndexedIdGeneratorRecoverabilityTest method persistHighIdBetweenCleanRestarts.

@Test
void persistHighIdBetweenCleanRestarts() {
    try (IdGenerator freelist = instantiateFreelist()) {
        freelist.nextId(NULL);
        assertEquals(1, freelist.getHighId());
        freelist.nextId(NULL);
        assertEquals(2, freelist.getHighId());
        freelist.checkpoint(NULL);
    }
    try (IdGenerator freelist = instantiateFreelist()) {
        assertEquals(2, freelist.getHighId());
    }
}
Also used : IdGenerator(org.neo4j.internal.id.IdGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

IdGenerator (org.neo4j.internal.id.IdGenerator)12 Test (org.junit.jupiter.api.Test)9 ImmutableLongSet (org.eclipse.collections.api.set.primitive.ImmutableLongSet)3 Path (java.nio.file.Path)2 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)2 Config (org.neo4j.configuration.Config)2 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)2 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 Monitors (org.neo4j.monitoring.Monitors)2 IOException (java.io.IOException)1 String.valueOf (java.lang.String.valueOf)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 Optional (java.util.Optional)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric)1