use of org.neo4j.kernel.impl.store.record.AbstractBaseRecord in project neo4j by neo4j.
the class RecordStorageEngine method listStorageFiles.
@Override
public void listStorageFiles(Collection<StoreFileMetadata> atomic, Collection<StoreFileMetadata> replayable) {
atomic.add(new StoreFileMetadata(databaseLayout.countStore(), RecordFormat.NO_RECORD_SIZE));
atomic.add(new StoreFileMetadata(databaseLayout.relationshipGroupDegreesStore(), RecordFormat.NO_RECORD_SIZE));
for (StoreType type : StoreType.values()) {
final RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore(type);
StoreFileMetadata metadata = new StoreFileMetadata(recordStore.getStorageFile(), recordStore.getRecordSize());
replayable.add(metadata);
}
}
use of org.neo4j.kernel.impl.store.record.AbstractBaseRecord in project neo4j by neo4j.
the class SchemaStorage method streamAllSchemaRules.
@VisibleForTesting
Stream<SchemaRule> streamAllSchemaRules(boolean ignoreMalformed, CursorContext cursorContext) {
long startId = schemaStore.getNumberOfReservedLowIds();
long endId = schemaStore.getHighId();
Stream<IndexDescriptor> nli = Stream.empty();
KernelVersion currentVersion;
try {
currentVersion = versionSupplier.kernelVersion();
} catch (IllegalStateException ignored) {
// If KernelVersion is missing we are an older store.
currentVersion = KernelVersion.V4_2;
}
if (currentVersion.isLessThan(KernelVersion.VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
nli = Stream.of(IndexDescriptor.INJECTED_NLI);
}
return Stream.concat(LongStream.range(startId, endId).mapToObj(id -> schemaStore.getRecord(id, schemaStore.newRecord(), RecordLoad.LENIENT_ALWAYS, cursorContext)).filter(AbstractBaseRecord::inUse).flatMap(record -> readSchemaRuleThrowingRuntimeException(record, ignoreMalformed, cursorContext)), nli);
}
use of org.neo4j.kernel.impl.store.record.AbstractBaseRecord in project neo4j by neo4j.
the class RecordAssert method containsRecords.
// Build a contains matcher that matches all records of a single given type
// NOTE: This is a bit brittle, if you like it'd be easy to make it a general purpose
// list-of-records-of-any-type matcher. As-is, if you use it to match mixed-type records,
// behavior is undefined.
// NOTE: This nests diff functions for individual records; if you want a matcher for
// a single record, just refactor those out and have this delegate to them, see how
// the containsChanges delegates here for an example.
public DiffAssert<Iterable<? extends AbstractBaseRecord>> containsRecords(String recordPlural, Stream<? extends AbstractBaseRecord> expected) {
Map<Long, AbstractBaseRecord> expectedById = expected.collect(toMap(AbstractBaseRecord::getId, identity()));
return new DiffAssert<>() {
@Override
String diff(Iterable<? extends AbstractBaseRecord> actual) {
Set<Long> seen = new HashSet<>(expectedById.keySet());
for (AbstractBaseRecord record : actual) {
seen.remove(record.getId());
if (!expectedById.containsKey(record.getId())) {
return String.format("This record was not expected: %s", record);
}
String diff = diff(expectedById.get(record.getId()), record);
if (diff != null) {
return diff;
}
}
return null;
}
private String diff(AbstractBaseRecord expected, AbstractBaseRecord actual) {
if (expected instanceof NodeRecord) {
return diff((NodeRecord) expected, (NodeRecord) actual);
}
if (expected instanceof RelationshipRecord) {
return diff((RelationshipRecord) expected, (RelationshipRecord) actual);
}
if (expected instanceof RelationshipGroupRecord) {
return diff((RelationshipGroupRecord) expected, (RelationshipGroupRecord) actual);
}
throw new UnsupportedOperationException(String.format("No diff implementation (just add one, its easy) for: %s", expected));
}
private String diff(NodeRecord expected, NodeRecord actual) {
if (actual.getId() == expected.getId() && actual.getNextRel() == expected.getNextRel() && actual.getLabelField() == expected.getLabelField() && actual.getNextProp() == expected.getNextProp() && actual.isDense() == expected.isDense() && actual.isLight() == expected.isLight()) {
return null;
}
return describeDiff(expected.toString(), actual.toString());
}
private String diff(RelationshipGroupRecord expected, RelationshipGroupRecord actual) {
if (actual.getId() == expected.getId() && actual.getType() == expected.getType() && actual.getNext() == expected.getNext() && actual.getFirstOut() == expected.getFirstOut() && actual.getFirstIn() == expected.getFirstIn() && actual.getFirstLoop() == expected.getFirstLoop() && actual.getOwningNode() == expected.getOwningNode()) {
return null;
}
return describeDiff(expected.toString(), actual.toString());
}
private String diff(RelationshipRecord expected, RelationshipRecord actual) {
if (actual.getId() == expected.getId() && actual.getFirstNode() == expected.getFirstNode() && actual.getSecondNode() == expected.getSecondNode() && actual.getType() == expected.getType() && actual.getFirstPrevRel() == expected.getFirstPrevRel() && actual.getFirstNextRel() == expected.getFirstNextRel() && actual.getSecondPrevRel() == expected.getSecondPrevRel() && actual.getSecondNextRel() == expected.getSecondNextRel() && actual.isFirstInFirstChain() == expected.isFirstInFirstChain() && actual.isFirstInSecondChain() == expected.isFirstInSecondChain()) {
return null;
}
return describeDiff(expected.toString(), actual.toString());
}
private String describeDiff(String expected, String actual) {
StringBuilder arrow = new StringBuilder();
char[] expectedChars = expected.toCharArray();
char[] actualChars = actual.toCharArray();
for (int i = 0; i < Math.min(expectedChars.length, actualChars.length); i++) {
if (expectedChars[i] != actualChars[i]) {
break;
}
arrow.append('-');
}
return String.format("Record fields don't match.\n" + "Expected: %s\n" + "Actual: %s\n" + " %s", expected, actual, arrow.append('^').toString());
}
};
}
Aggregations