Search in sources :

Example 1 with StorageReader

use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.

the class GraphStoreFixture method nodeAsUpdates.

public EntityUpdates nodeAsUpdates(long nodeId) {
    try (StorageReader storeReader = storageEngine.newReader();
        StorageNodeCursor nodeCursor = storeReader.allocateNodeCursor(NULL);
        StoragePropertyCursor propertyCursor = storeReader.allocatePropertyCursor(NULL, INSTANCE)) {
        nodeCursor.single(nodeId);
        long[] labels;
        if (!nodeCursor.next() || !nodeCursor.hasProperties() || (labels = nodeCursor.labels()).length == 0) {
            return null;
        }
        nodeCursor.properties(propertyCursor);
        EntityUpdates.Builder update = EntityUpdates.forEntity(nodeId, true).withTokens(labels);
        while (propertyCursor.next()) {
            update.added(propertyCursor.propertyKey(), propertyCursor.propertyValue());
        }
        return update.build();
    }
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 2 with StorageReader

use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.

the class EntityValueUpdatesTest method assertNoLoading.

private static StorageReader assertNoLoading() {
    StorageReader reader = mock(StorageReader.class);
    IllegalStateException exception = new IllegalStateException("Should never attempt to load properties!");
    when(reader.allocateNodeCursor(any())).thenThrow(exception);
    when(reader.allocateRelationshipScanCursor(any())).thenThrow(exception);
    when(reader.allocateRelationshipTraversalCursor(any())).thenThrow(exception);
    when(reader.allocatePropertyCursor(any(), any())).thenThrow(exception);
    return reader;
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader)

Example 3 with StorageReader

use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.

the class TransactionRecordStateTest method indexUpdatesOf.

private Iterable<Iterable<IndexEntryUpdate<IndexDescriptor>>> indexUpdatesOf(NeoStores neoStores, CommandsToApply transaction) throws IOException {
    IndexUpdatesExtractor extractor = new IndexUpdatesExtractor();
    transaction.accept(extractor);
    StorageReader reader = new RecordStorageReader(neoStores);
    List<Iterable<IndexEntryUpdate<IndexDescriptor>>> updates = new ArrayList<>();
    OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(neoStores.getNodeStore(), schemaCache, new PropertyPhysicalToLogicalConverter(neoStores.getPropertyStore(), NULL), reader, NULL, INSTANCE);
    onlineIndexUpdates.feed(extractor.getNodeCommands(), extractor.getRelationshipCommands(), transaction.transactionId());
    updates.add(onlineIndexUpdates);
    reader.close();
    return updates;
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) LongIterable(org.eclipse.collections.api.LongIterable) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 4 with StorageReader

use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method createTransaction.

private KernelTransactionImplementation createTransaction() {
    KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
    try {
        StorageEngine storageEngine = mock(StorageEngine.class);
        StorageReader storageReader = mock(StorageReader.class);
        when(storageEngine.newReader()).thenReturn(storageReader);
        Locks.Client locks = mock(Locks.Client.class);
        when(transaction.lockClient()).thenReturn(locks);
        when(transaction.tokenRead()).thenReturn(tokenRead);
        when(transaction.schemaRead()).thenReturn(schemaRead);
        when(transaction.schemaWrite()).thenReturn(schemaWrite);
        TransactionState transactionState = mock(TransactionState.class);
        when(transaction.txState()).thenReturn(transactionState);
        when(transaction.indexUniqueCreate(any(IndexPrototype.class))).thenAnswer(i -> i.<IndexPrototype>getArgument(0).materialise(INDEX_ID));
        when(transaction.newStorageReader()).thenReturn(mock(StorageReader.class));
    } catch (InvalidTransactionTypeKernelException e) {
        fail("Expected write transaction");
    }
    return transaction;
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Locks(org.neo4j.kernel.impl.locking.Locks) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Example 5 with StorageReader

use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.

the class KernelTransactionsTest method transactionClosesUnderlyingStoreReaderWhenDisposed.

@Test
void transactionClosesUnderlyingStoreReaderWhenDisposed() throws Throwable {
    StorageReader storeStatement1 = mock(StorageReader.class);
    StorageReader storeStatement2 = mock(StorageReader.class);
    StorageReader storeStatement3 = mock(StorageReader.class);
    KernelTransactions kernelTransactions = newKernelTransactions(mock(TransactionCommitProcess.class), storeStatement1, storeStatement2, storeStatement3);
    // start and close 3 transactions from different threads
    startAndCloseTransaction(kernelTransactions);
    executorService.submit(() -> startAndCloseTransaction(kernelTransactions)).get();
    // this is to guarantee that the execution will be in a new thread, not reused one
    var executorService2 = Executors.newSingleThreadExecutor();
    try {
        executorService2.submit(() -> startAndCloseTransaction(kernelTransactions)).get();
    } finally {
        executorService2.shutdown();
    }
    kernelTransactions.disposeAll();
    verify(storeStatement1).close();
    verify(storeStatement2).close();
    verify(storeStatement3).close();
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) Test(org.junit.jupiter.api.Test)

Aggregations

StorageReader (org.neo4j.storageengine.api.StorageReader)12 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)5 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)4 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)4 StorageEngine (org.neo4j.storageengine.api.StorageEngine)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Dependencies (org.neo4j.collection.Dependencies)3 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)3 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)2 TxState (org.neo4j.kernel.impl.api.state.TxState)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 TokenHolders (org.neo4j.token.TokenHolders)2 TokenHolder (org.neo4j.token.api.TokenHolder)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1