Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split store cursor in order to flat them with the tx cursors
- Loading branch information
1 parent
77b436b
commit 8cf9e50
Showing
5 changed files
with
209 additions
and
100 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
...ity/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StoreAbstractPropertyCursor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,137 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.impl.api.store; | |||
|
|||
import java.util.function.IntPredicate; | |||
|
|||
import org.neo4j.cursor.Cursor; | |||
import org.neo4j.kernel.impl.locking.Lock; | |||
import org.neo4j.kernel.impl.store.RecordCursor; | |||
import org.neo4j.kernel.impl.store.RecordCursors; | |||
import org.neo4j.kernel.impl.store.record.PropertyRecord; | |||
import org.neo4j.kernel.impl.store.record.Record; | |||
import org.neo4j.storageengine.api.PropertyItem; | |||
|
|||
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE; | |||
|
|||
public abstract class StoreAbstractPropertyCursor implements Cursor<PropertyItem>, PropertyItem | |||
{ | |||
protected final StorePropertyPayloadCursor payload; | |||
private final RecordCursor<PropertyRecord> recordCursor; | |||
|
|||
protected boolean fetched; | |||
private IntPredicate propertyKeyIds; | |||
private Lock lock; | |||
|
|||
StoreAbstractPropertyCursor( RecordCursors cursors ) | |||
{ | |||
this.payload = new StorePropertyPayloadCursor( cursors.propertyString(), cursors.propertyArray() ); | |||
this.recordCursor = cursors.property(); | |||
} | |||
|
|||
protected final void initialize( IntPredicate propertyKeyIds, long firstPropertyId, Lock lock ) | |||
{ | |||
this.propertyKeyIds = propertyKeyIds; | |||
this.lock = lock; | |||
recordCursor.placeAt( firstPropertyId, FORCE ); | |||
} | |||
|
|||
@Override | |||
public final boolean next() | |||
{ | |||
return fetched = fetchNext(); | |||
} | |||
|
|||
private boolean fetchNext() | |||
{ | |||
while ( loop() ) | |||
{ | |||
// Are there more properties to return for this current record we're at? | |||
if ( payload.next() ) | |||
{ | |||
return true; | |||
} | |||
|
|||
// No, OK continue down the chain and hunt for more... | |||
if ( recordCursor.next() ) | |||
{ | |||
// All good, we can get values off of this record | |||
PropertyRecord propertyRecord = recordCursor.get(); | |||
payload.init( propertyKeyIds, propertyRecord.getBlocks(), propertyRecord.getNumberOfBlocks() ); | |||
if ( payload.next() ) | |||
{ | |||
return true; | |||
} | |||
} | |||
else if ( Record.NO_NEXT_PROPERTY.is( recordCursor.get().getNextProp() ) ) | |||
{ | |||
// No more records in this chain, i.e. no more properties. | |||
return false; | |||
} | |||
|
|||
// Sort of alright, this record isn't in use, but could just be due to concurrent delete. | |||
// Continue to next record in the chain and try there. | |||
} | |||
return false; | |||
} | |||
|
|||
protected abstract boolean loop(); | |||
|
|||
@Override | |||
public final PropertyItem get() | |||
{ | |||
if ( !fetched ) | |||
{ | |||
throw new IllegalStateException(); | |||
} | |||
return this; | |||
} | |||
|
|||
@Override | |||
public final int propertyKeyId() | |||
{ | |||
return payload.propertyKeyId(); | |||
} | |||
|
|||
@Override | |||
public final Object value() | |||
{ | |||
return payload.value(); | |||
} | |||
|
|||
@Override | |||
public final void close() | |||
{ | |||
try | |||
{ | |||
fetched = false; | |||
payload.close(); | |||
propertyKeyIds = null; | |||
doClose(); | |||
} | |||
finally | |||
{ | |||
lock.release(); | |||
lock = null; | |||
} | |||
} | |||
|
|||
protected abstract void doClose(); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...unity/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StoreSinglePropertyCursor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.impl.api.store; | |||
|
|||
import java.util.function.Consumer; | |||
|
|||
import org.neo4j.kernel.impl.locking.Lock; | |||
import org.neo4j.kernel.impl.store.RecordCursors; | |||
|
|||
public class StoreSinglePropertyCursor extends StoreAbstractPropertyCursor | |||
{ | |||
private final Consumer<StoreSinglePropertyCursor> instanceCache; | |||
|
|||
StoreSinglePropertyCursor( RecordCursors cursors, Consumer<StoreSinglePropertyCursor> instanceCache ) | |||
{ | |||
super( cursors ); | |||
this.instanceCache = instanceCache; | |||
} | |||
|
|||
public StoreSinglePropertyCursor init( int propertyKeyId, long firstPropertyId, Lock lock ) | |||
{ | |||
initialize( key -> key == propertyKeyId, firstPropertyId, lock ); | |||
return this; | |||
} | |||
|
|||
@Override | |||
protected boolean loop() | |||
{ | |||
return !fetched; | |||
} | |||
|
|||
@Override | |||
protected void doClose() | |||
{ | |||
instanceCache.accept( this ); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters