use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class AbstractDynamicStore method readFullByteArrayFromHeavyRecords.
/**
* @return Pair< header-in-first-record , all-other-bytes >
*/
public static Pair<byte[], byte[]> readFullByteArrayFromHeavyRecords(Iterable<DynamicRecord> records, PropertyType propertyType) {
byte[] header = null;
List<byte[]> byteList = new ArrayList<>();
int totalSize = 0, i = 0;
for (DynamicRecord record : records) {
int offset = 0;
if (i++ == 0) {
// This is the first one, read out the header separately
header = propertyType.readDynamicRecordHeader(record.getData());
offset = header.length;
}
byteList.add(record.getData());
totalSize += record.getData().length - offset;
}
byte[] bArray = new byte[totalSize];
assert header != null : "header should be non-null since records should not be empty: " + Iterables.toString(records, ", ");
int sourceOffset = header.length;
int offset = 0;
for (byte[] currentArray : byteList) {
System.arraycopy(currentArray, sourceOffset, bArray, offset, currentArray.length - sourceOffset);
offset += currentArray.length - sourceOffset;
sourceOffset = 0;
}
return Pair.of(header, bArray);
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class DynamicNodeLabels method putSorted.
public static Collection<DynamicRecord> putSorted(NodeRecord node, long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator) {
long existingLabelsField = node.getLabelField();
long existingLabelsBits = parseLabelsBody(existingLabelsField);
Collection<DynamicRecord> changedDynamicRecords = node.getDynamicLabelRecords();
long labelField = node.getLabelField();
if (fieldPointsToDynamicRecordOfLabels(labelField)) {
// There are existing dynamic label records, get them
nodeStore.ensureHeavy(node, existingLabelsBits);
changedDynamicRecords = node.getDynamicLabelRecords();
setNotInUse(changedDynamicRecords);
}
if (!InlineNodeLabels.tryInlineInNodeRecord(node, labelIds, changedDynamicRecords)) {
Iterator<DynamicRecord> recycledRecords = changedDynamicRecords.iterator();
Collection<DynamicRecord> allocatedRecords = allocateRecordsForDynamicLabels(node.getId(), labelIds, new ReusableRecordsCompositeAllocator(recycledRecords, allocator));
// Set the rest of the previously set dynamic records as !inUse
while (recycledRecords.hasNext()) {
DynamicRecord removedRecord = recycledRecords.next();
removedRecord.setInUse(false);
allocatedRecords.add(removedRecord);
}
node.setLabelField(dynamicPointer(allocatedRecords), allocatedRecords);
changedDynamicRecords = allocatedRecords;
}
return changedDynamicRecords;
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class AbstractDynamicStoreTest method newTestableDynamicStore.
private AbstractDynamicStore newTestableDynamicStore() {
DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
AbstractDynamicStore store = new AbstractDynamicStore(fileName, Config.empty(), IdType.ARRAY_BLOCK, idGeneratorFactory, pageCache, NullLogProvider.getInstance(), "test", BLOCK_SIZE, formats.dynamic(), formats.storeVersion()) {
@Override
public void accept(Processor processor, DynamicRecord record) {
// Ignore
}
@Override
public String getTypeDescriptor() {
return "TestDynamicStore";
}
};
store.initialise(true);
return store;
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.
@Test
public void shouldCreateConsistentUniquenessConstraint() throws Exception {
// given
BatchInserter inserter = newBatchInserter();
// when
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// then
GraphDatabaseAPI graphdb = (GraphDatabaseAPI) switchToEmbeddedGraphDatabaseService(inserter);
try {
NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore store = neoStores.getSchemaStore();
SchemaStorage storage = new SchemaStorage(store);
List<Long> inUse = new ArrayList<>();
DynamicRecord record = store.nextRecord();
for (long i = 1, high = store.getHighestPossibleIdInUse(); i <= high; i++) {
store.getRecord(i, record, RecordLoad.FORCE);
if (record.inUse() && record.isStartRecord()) {
inUse.add(i);
}
}
assertEquals("records in use", 2, inUse.size());
SchemaRule rule0 = storage.loadSingleSchemaRule(inUse.get(0));
SchemaRule rule1 = storage.loadSingleSchemaRule(inUse.get(1));
IndexRule indexRule;
ConstraintRule constraintRule;
if (rule0 instanceof IndexRule) {
indexRule = (IndexRule) rule0;
constraintRule = (ConstraintRule) rule1;
} else {
constraintRule = (ConstraintRule) rule0;
indexRule = (IndexRule) rule1;
}
assertEquals("index should reference constraint", constraintRule.getId(), indexRule.getOwningConstraint().longValue());
assertEquals("constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex());
} finally {
graphdb.shutdown();
}
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class SchemaStorage method loadAllSchemaRules.
<ReturnType extends SchemaRule> Iterator<ReturnType> loadAllSchemaRules(final Predicate<ReturnType> predicate, final Class<ReturnType> returnType, final boolean ignoreMalformed) {
return new PrefetchingIterator<ReturnType>() {
private final long highestId = schemaStore.getHighestPossibleIdInUse();
private long currentId = 1;
/*record 0 contains the block size*/
private final byte[] scratchData = newRecordBuffer();
private final DynamicRecord record = schemaStore.newRecord();
@Override
protected ReturnType fetchNextOrNull() {
while (currentId <= highestId) {
long id = currentId++;
schemaStore.getRecord(id, record, RecordLoad.FORCE);
if (record.inUse() && record.isStartRecord()) {
try {
SchemaRule schemaRule = loadSingleSchemaRuleViaBuffer(id, scratchData);
if (returnType.isInstance(schemaRule)) {
ReturnType returnRule = returnType.cast(schemaRule);
if (predicate.test(returnRule)) {
return returnRule;
}
}
} catch (MalformedSchemaRuleException e) {
if (!ignoreMalformed) {
throw new RuntimeException(e);
}
}
}
}
return null;
}
};
}
Aggregations