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);
}
}
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);
}
}
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());
}
}
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");
}
}
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());
}
}
Aggregations