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;
}
};
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class TokenStore method getStringFor.
public String getStringFor(RECORD nameRecord) {
ensureHeavy(nameRecord);
int recordToFind = nameRecord.getNameId();
Iterator<DynamicRecord> records = nameRecord.getNameRecords().iterator();
Collection<DynamicRecord> relevantRecords = new ArrayList<>();
while (recordToFind != Record.NO_NEXT_BLOCK.intValue() && records.hasNext()) {
DynamicRecord record = records.next();
if (record.inUse() && record.getId() == recordToFind) {
recordToFind = (int) record.getNextBlock();
// TODO: optimize here, high chance next is right one
relevantRecords.add(record);
records = nameRecord.getNameRecords().iterator();
}
}
return decodeString(nameStore.readFullByteArray(relevantRecords, PropertyType.STRING).other());
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_1 method visitLabelTokenCommand.
private Command visitLabelTokenCommand(ReadableChannel channel) throws IOException {
// id+in_use(byte)+type_blockId(int)+nr_type_records(int)
int id = channel.getInt();
byte inUseFlag = channel.get();
boolean inUse = false;
if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
inUse = true;
} else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
throw new IOException("Illegal in use flag: " + inUseFlag);
}
LabelTokenRecord record = new LabelTokenRecord(id);
record.setInUse(inUse);
record.setNameId(channel.getInt());
int nrTypeRecords = channel.getInt();
for (int i = 0; i < nrTypeRecords; i++) {
DynamicRecord dr = readDynamicRecord(channel);
if (dr == null) {
return null;
}
record.addNameRecord(dr);
}
return new Command.LabelTokenCommand(null, record);
}
use of org.neo4j.kernel.impl.store.record.DynamicRecord in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_0 method visitLabelTokenCommand.
private Command visitLabelTokenCommand(ReadableChannel channel) throws IOException {
// id+in_use(byte)+type_blockId(int)+nr_type_records(int)
int id = channel.getInt();
byte inUseFlag = channel.get();
boolean inUse = false;
if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
inUse = true;
} else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
throw new IOException("Illegal in use flag: " + inUseFlag);
}
LabelTokenRecord record = new LabelTokenRecord(id);
record.setInUse(inUse);
record.setNameId(channel.getInt());
int nrTypeRecords = channel.getInt();
for (int i = 0; i < nrTypeRecords; i++) {
DynamicRecord dr = readDynamicRecord(channel);
if (dr == null) {
return null;
}
record.addNameRecord(dr);
}
return new Command.LabelTokenCommand(null, record);
}
Aggregations