use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.
the class PhysicalLogCommandReaderV3_0_2 method readPropertyRecord.
private PropertyRecord readPropertyRecord(long id, ReadableChannel channel) throws IOException {
// in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+
// prev_prop_id(long)+next_prop_id(long)
PropertyRecord record = new PropertyRecord(id);
// 1
byte flags = channel.get();
boolean inUse = bitFlag(flags, Record.IN_USE.byteValue());
boolean nodeProperty = !bitFlag(flags, Record.REL_PROPERTY.byteValue());
boolean requireSecondaryUnit = bitFlag(flags, Record.REQUIRE_SECONDARY_UNIT);
boolean hasSecondaryUnit = bitFlag(flags, Record.HAS_SECONDARY_UNIT);
record.setRequiresSecondaryUnit(requireSecondaryUnit);
// 8
long nextProp = channel.getLong();
// 8
long prevProp = channel.getLong();
record.setNextProp(nextProp);
record.setPrevProp(prevProp);
// 8
long primitiveId = channel.getLong();
if (primitiveId != -1 && nodeProperty) {
record.setNodeId(primitiveId);
} else if (primitiveId != -1) {
record.setRelId(primitiveId);
}
if (hasSecondaryUnit) {
record.setSecondaryUnitId(channel.getLong());
}
int nrPropBlocks = channel.get();
assert nrPropBlocks >= 0;
if (nrPropBlocks > 0) {
record.setInUse(true);
}
while (nrPropBlocks-- > 0) {
PropertyBlock block = readPropertyBlock(channel);
if (block == null) {
return null;
}
record.addPropertyBlock(block);
}
int deletedRecords = readDynamicRecords(channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER);
if (deletedRecords == -1) {
return null;
}
assert deletedRecords >= 0;
while (deletedRecords-- > 0) {
DynamicRecord read = readDynamicRecord(channel);
if (read == null) {
return null;
}
record.addDeletedRecord(read);
}
if ((inUse && !record.inUse()) || (!inUse && record.inUse())) {
throw new IllegalStateException("Weird, inUse was read in as " + inUse + " but the record is " + record);
}
return record;
}
use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.
the class PropertyCreator method createPropertyChain.
public long createPropertyChain(PrimitiveRecord owner, Iterator<PropertyBlock> properties, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords) {
if (properties == null || !properties.hasNext()) {
return Record.NO_NEXT_PROPERTY.intValue();
}
PropertyRecord currentRecord = propertyRecords.create(propertyRecordIdGenerator.nextId(), owner).forChangingData();
currentRecord.setInUse(true);
currentRecord.setCreated();
PropertyRecord firstRecord = currentRecord;
while (properties.hasNext()) {
PropertyBlock block = properties.next();
if (currentRecord.size() + block.getSize() > PropertyType.getPayloadSize()) {
// Here it means the current block is done for
PropertyRecord prevRecord = currentRecord;
// Create new record
long propertyId = propertyRecordIdGenerator.nextId();
currentRecord = propertyRecords.create(propertyId, owner).forChangingData();
currentRecord.setInUse(true);
currentRecord.setCreated();
// Set up links
prevRecord.setNextProp(propertyId);
currentRecord.setPrevProp(prevRecord.getId());
// Now current is ready to start picking up blocks
}
currentRecord.addPropertyBlock(block);
}
return firstRecord.getId();
}
use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.
the class PropertyDeleter method removeProperty.
public <P extends PrimitiveRecord> void removeProperty(RecordProxy<Long, P, Void> primitiveProxy, int propertyKey, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords) {
PrimitiveRecord primitive = primitiveProxy.forReadingData();
// propertyData.getId();
long propertyId = traverser.findPropertyRecordContaining(primitive, propertyKey, propertyRecords, true);
RecordProxy<Long, PropertyRecord, PrimitiveRecord> recordChange = propertyRecords.getOrLoad(propertyId, primitive);
PropertyRecord propRecord = recordChange.forChangingData();
if (!propRecord.inUse()) {
throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
}
PropertyBlock block = propRecord.removePropertyBlock(propertyKey);
if (block == null) {
throw new IllegalStateException("Property with index[" + propertyKey + "] is not present in property[" + propertyId + "]");
}
for (DynamicRecord valueRecord : block.getValueRecords()) {
assert valueRecord.inUse();
valueRecord.setInUse(false, block.getType().intValue());
propRecord.addDeletedRecord(valueRecord);
}
if (propRecord.size() > 0) {
/*
* There are remaining blocks in the record. We do not unlink yet.
*/
propRecord.setChanged(primitive);
assert traverser.assertPropertyChain(primitive, propertyRecords);
} else {
unlinkPropertyRecord(propRecord, propertyRecords, primitiveProxy);
}
}
use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.
the class PropertyDeleter method deletePropertyChain.
public void deletePropertyChain(PrimitiveRecord primitive, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords) {
long nextProp = primitive.getNextProp();
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
RecordProxy<Long, PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.getOrLoad(nextProp, primitive);
// TODO forChanging/forReading piggy-backing
PropertyRecord propRecord = propertyChange.forChangingData();
for (PropertyBlock block : propRecord) {
for (DynamicRecord valueRecord : block.getValueRecords()) {
assert valueRecord.inUse();
valueRecord.setInUse(false);
propRecord.addDeletedRecord(valueRecord);
}
}
nextProp = propRecord.getNextProp();
propRecord.setInUse(false);
propRecord.setChanged(primitive);
// We do not remove them individually, but all together here
propRecord.clearPropertyBlocks();
}
primitive.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
}
use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.
the class PropertyTraverser method getPropertyChain.
public void getPropertyChain(long nextProp, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords, Listener<PropertyBlock> collector) {
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord propRecord = propertyRecords.getOrLoad(nextProp, null).forReadingData();
for (PropertyBlock propBlock : propRecord) {
collector.receive(propBlock);
}
nextProp = propRecord.getNextProp();
}
}
Aggregations