use of org.neo4j.kernel.impl.store.DynamicStringStore in project neo4j by neo4j.
the class RecordLoading method safeLoadTokens.
static <RECORD extends TokenRecord> List<NamedToken> safeLoadTokens(TokenStore<RECORD> tokenStore, CursorContext cursorContext) {
long highId = tokenStore.getHighId();
List<NamedToken> tokens = new ArrayList<>();
DynamicStringStore nameStore = tokenStore.getNameStore();
List<DynamicRecord> nameRecords = new ArrayList<>();
MutableLongSet seenRecordIds = new LongHashSet();
int nameBlockSize = nameStore.getRecordDataSize();
try (RecordReader<RECORD> tokenReader = new RecordReader<>(tokenStore, true, cursorContext);
RecordReader<DynamicRecord> nameReader = new RecordReader<>(nameStore, false, cursorContext)) {
for (long id = 0; id < highId; id++) {
RECORD record = tokenReader.read(id);
nameRecords.clear();
if (record.inUse()) {
String name;
if (!NULL_REFERENCE.is(record.getNameId()) && safeLoadDynamicRecordChain(r -> nameRecords.add(r.copy()), nameReader, seenRecordIds, record.getNameId(), nameBlockSize)) {
record.addNameRecords(nameRecords);
name = tokenStore.getStringFor(record, StoreCursors.NULL);
} else {
name = format("<name not loaded due to token(%d) referencing unused name record>", id);
}
tokens.add(new NamedToken(name, toIntExact(id), record.isInternal()));
}
}
}
return tokens;
}
use of org.neo4j.kernel.impl.store.DynamicStringStore in project neo4j by neo4j.
the class SchemaChecker method checkTokens.
private static <R extends TokenRecord> void checkTokens(TokenStore<R> store, Function<R, ConsistencyReport.NameConsistencyReport> report, Function<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynamicRecordReport, PageCacheTracer pageCacheTracer) {
DynamicStringStore nameStore = store.getNameStore();
DynamicRecord nameRecord = nameStore.newRecord();
long highId = store.getHighId();
MutableLongSet seenNameRecordIds = LongSets.mutable.empty();
int blockSize = store.getNameStore().getRecordDataSize();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(CONSISTENCY_TOKEN_CHECKER_TAG));
RecordReader<R> tokenReader = new RecordReader<>(store, true, cursorContext);
RecordReader<DynamicRecord> nameReader = new RecordReader<>(store.getNameStore(), false, cursorContext)) {
for (long id = 0; id < highId; id++) {
R record = tokenReader.read(id);
if (record.inUse() && !NULL_REFERENCE.is(record.getNameId())) {
safeLoadDynamicRecordChain(r -> {
}, nameReader, seenNameRecordIds, record.getNameId(), blockSize, (i, r) -> dynamicRecordReport.apply(nameRecord).circularReferenceNext(r), (i, r) -> report.apply(record).nameBlockNotInUse(nameRecord), (i, r) -> dynamicRecordReport.apply(nameRecord).nextNotInUse(r), (i, r) -> dynamicRecordReport.apply(r).emptyBlock(), r -> dynamicRecordReport.apply(r).recordNotFullReferencesNext(), r -> dynamicRecordReport.apply(r).invalidLength());
}
}
}
}
use of org.neo4j.kernel.impl.store.DynamicStringStore in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportRelationshipLabelNameInconsistencies.
@Test
void shouldReportRelationshipLabelNameInconsistencies() throws Exception {
// given
final Reference<Integer> inconsistentName = new Reference<>();
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
inconsistentName.set(next.relationshipType());
tx.relationshipType(inconsistentName.get(), "FOO", false);
}
});
NeoStores neoStores = fixture.directStoreAccess().nativeStores();
StoreCursors storeCursors = fixture.getStoreCursors();
DynamicStringStore nameStore = neoStores.getRelationshipTypeTokenStore().getNameStore();
DynamicRecord record = nameStore.newRecord();
nameStore.getRecordByCursor(inconsistentName.get(), record, FORCE, storeCursors.readCursor(DYNAMIC_REL_TYPE_TOKEN_CURSOR));
record.setNextBlock(record.getId());
try (var storeCursor = storeCursors.writeCursor(DYNAMIC_REL_TYPE_TOKEN_CURSOR)) {
nameStore.updateRecord(record, storeCursor, NULL, storeCursors);
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.RELATIONSHIP_TYPE_NAME, 1).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.DynamicStringStore in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportPropertyKeyInconsistencies.
@Test
void shouldReportPropertyKeyInconsistencies() throws Exception {
// given
final Reference<int[]> propertyKeyNameIds = new Reference<>();
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
int[] nameIds = tx.propertyKey(next.propertyKey(), "FOO", false);
propertyKeyNameIds.set(nameIds);
}
});
NeoStores neoStores = fixture.directStoreAccess().nativeStores();
StoreCursors storeCursors = fixture.getStoreCursors();
DynamicStringStore nameStore = neoStores.getPropertyKeyTokenStore().getNameStore();
DynamicRecord record = nameStore.newRecord();
nameStore.getRecordByCursor(propertyKeyNameIds.get()[0], record, FORCE, storeCursors.readCursor(DYNAMIC_PROPERTY_KEY_TOKEN_CURSOR));
record.setInUse(false);
try (var storeCursor = storeCursors.writeCursor(DYNAMIC_PROPERTY_KEY_TOKEN_CURSOR)) {
nameStore.updateRecord(record, storeCursor, NULL, storeCursors);
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.PROPERTY_KEY, 1).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.DynamicStringStore in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportPropertyKeyNameInconsistencies.
@Test
void shouldReportPropertyKeyNameInconsistencies() throws Exception {
// given
final Reference<int[]> propertyKeyNameIds = new Reference<>();
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
int[] dynamicIds = tx.propertyKey(next.propertyKey(), "FOO", false);
propertyKeyNameIds.set(dynamicIds);
}
});
NeoStores neoStores = fixture.directStoreAccess().nativeStores();
StoreCursors storeCursors = fixture.getStoreCursors();
DynamicStringStore nameStore = neoStores.getPropertyKeyTokenStore().getNameStore();
DynamicRecord record = nameStore.newRecord();
nameStore.getRecordByCursor(propertyKeyNameIds.get()[0], record, FORCE, storeCursors.readCursor(DYNAMIC_PROPERTY_KEY_TOKEN_CURSOR));
record.setNextBlock(record.getId());
try (var storeCursor = storeCursors.writeCursor(DYNAMIC_PROPERTY_KEY_TOKEN_CURSOR)) {
nameStore.updateRecord(record, storeCursor, NULL, storeCursors);
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.PROPERTY_KEY_NAME, 1).andThatsAllFolks();
}
Aggregations