Search in sources :

Example 6 with MemoryTracker

use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.

the class BatchInsertTest method shouldBuildCorrectCountsStoreOnIncrementalImport.

@Test
void shouldBuildCorrectCountsStoreOnIncrementalImport() throws Exception {
    // given
    Label label = Label.label("Person");
    int denseNodeThreshold = dense_node_threshold.defaultValue();
    for (int r = 0; r < 3; r++) {
        // when
        BatchInserter inserter = newBatchInserter(denseNodeThreshold);
        try {
            for (int i = 0; i < 100; i++) {
                inserter.createNode(null, label);
            }
        } finally {
            inserter.shutdown();
        }
        // then
        try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fs, RecoveryCleanupWorkCollector.immediate(), new CountsBuilder() {

            @Override
            public void initialize(CountsAccessor.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
                throw new UnsupportedOperationException("Should not be required");
            }

            @Override
            public long lastCommittedTxId() {
                return TransactionIdStore.BASE_TX_ID;
            }
        }, readOnly(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1000)) {
            countsStore.start(NULL, INSTANCE);
            assertEquals((r + 1) * 100, countsStore.nodeCount(0, NULL));
        }
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) Label(org.neo4j.graphdb.Label) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) CountsAccessor(org.neo4j.counts.CountsAccessor) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsBuilder(org.neo4j.internal.counts.CountsBuilder) MemoryTracker(org.neo4j.memory.MemoryTracker) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 7 with MemoryTracker

use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.

the class DatabaseIT method shutdownShutdownMustOnlyReleaseMemoryOnce.

@Test
void shutdownShutdownMustOnlyReleaseMemoryOnce() throws Exception {
    MemoryTracker otherMemoryTracker = getOtherMemoryTracker();
    long beforeShutdown = otherMemoryTracker.usedNativeMemory();
    database.shutdown();
    long afterFirstShutdown = otherMemoryTracker.usedNativeMemory();
    assertThat(afterFirstShutdown).isLessThan(beforeShutdown);
    database.shutdown();
    long afterSecondShutdown = otherMemoryTracker.usedNativeMemory();
    assertEquals(afterSecondShutdown, afterFirstShutdown);
}
Also used : MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 8 with MemoryTracker

use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.

the class DatabaseIT method stopShutdownMustOnlyReleaseMemoryOnce.

@Test
void stopShutdownMustOnlyReleaseMemoryOnce() throws Exception {
    MemoryTracker otherMemoryTracker = getOtherMemoryTracker();
    long beforeStop = otherMemoryTracker.usedNativeMemory();
    database.stop();
    long afterStop = otherMemoryTracker.usedNativeMemory();
    assertThat(afterStop).isLessThan(beforeStop);
    database.shutdown();
    long afterShutdown = otherMemoryTracker.usedNativeMemory();
    assertEquals(afterShutdown, afterStop);
}
Also used : MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 9 with MemoryTracker

use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.

the class TxStateTransactionDataSnapshotIT method countRemovedRelationshipsWithPropertiesInTransactionStateSnapshot.

@Test
void countRemovedRelationshipsWithPropertiesInTransactionStateSnapshot() {
    List<Long> relationshipsIdToDelete;
    int attachedPropertySize = (int) ByteUnit.mebiBytes(1);
    try (Transaction transaction = database.beginTx()) {
        var start = transaction.createNode();
        var end = transaction.createNode();
        var relationship1 = start.createRelationshipTo(end, withName("type1"));
        var relationship2 = start.createRelationshipTo(end, withName("type2"));
        relationship1.setProperty("a", randomAscii(attachedPropertySize));
        relationship2.setProperty("a", randomAscii(attachedPropertySize));
        relationship2.setProperty("b", randomAscii(attachedPropertySize));
        relationshipsIdToDelete = List.of(relationship1.getId(), relationship2.getId());
        transaction.commit();
    }
    assertThat(relationshipsIdToDelete).hasSize(2);
    try (Transaction transaction = database.beginTx()) {
        relationshipsIdToDelete.forEach(id -> transaction.getRelationshipById(id).delete());
        var kernelTransaction = getKernelTransaction(transaction);
        var transactionState = kernelTransaction.txState();
        final MemoryTracker memoryTracker = kernelTransaction.memoryTracker();
        // reset to count only snapshot memory
        var trackingData = resetMemoryTracker(memoryTracker);
        try (var snapshot = new TxStateTransactionDataSnapshot(transactionState, kernelTransaction.newStorageReader(), kernelTransaction)) {
            assertThat(memoryTracker.usedNativeMemory()).isZero();
            assertThat(memoryTracker.estimatedHeapMemory()).isGreaterThanOrEqualTo(emptySnapshotSize + (3 * attachedPropertySize) + (2 * RelationshipPropertyEntryView.SHALLOW_SIZE));
        } finally {
            restoreMemoryTracker(memoryTracker, trackingData);
        }
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 10 with MemoryTracker

use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.

the class TxStateTransactionDataSnapshotIT method countRemovedNodeWithPropertiesInTransactionStateSnapshot.

@Test
void countRemovedNodeWithPropertiesInTransactionStateSnapshot() {
    long nodeIdToDelete;
    int attachedPropertySize = (int) ByteUnit.mebiBytes(1);
    try (Transaction transaction = database.beginTx()) {
        var node = transaction.createNode(label("label1"), label("label2"));
        node.setProperty("a", randomAscii(attachedPropertySize));
        node.setProperty("b", randomAscii(attachedPropertySize));
        nodeIdToDelete = node.getId();
        transaction.commit();
    }
    try (Transaction transaction = database.beginTx()) {
        transaction.getNodeById(nodeIdToDelete).delete();
        var kernelTransaction = getKernelTransaction(transaction);
        var transactionState = kernelTransaction.txState();
        final MemoryTracker memoryTracker = kernelTransaction.memoryTracker();
        // reset to count only snapshot memory
        var trackingData = resetMemoryTracker(memoryTracker);
        try (var snapshot = new TxStateTransactionDataSnapshot(transactionState, kernelTransaction.newStorageReader(), kernelTransaction)) {
            assertThat(memoryTracker.usedNativeMemory()).isZero();
            assertThat(memoryTracker.estimatedHeapMemory()).isGreaterThanOrEqualTo(emptySnapshotSize + (2 * attachedPropertySize) + (2 * NodePropertyEntryView.SHALLOW_SIZE) + (2 * LabelEntryView.SHALLOW_SIZE));
        } finally {
            restoreMemoryTracker(memoryTracker, trackingData);
        }
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Aggregations

MemoryTracker (org.neo4j.memory.MemoryTracker)44 Test (org.junit.jupiter.api.Test)22 LocalMemoryTracker (org.neo4j.memory.LocalMemoryTracker)10 CursorContext (org.neo4j.io.pagecache.context.CursorContext)9 Value (org.neo4j.values.storable.Value)6 Transaction (org.neo4j.graphdb.Transaction)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)5 Map (java.util.Map)4 Optional (java.util.Optional)4 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)4 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)4 Log (org.neo4j.logging.Log)4 ValueTuple (org.neo4j.values.storable.ValueTuple)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 Collections.emptyMap (java.util.Collections.emptyMap)3 Objects.requireNonNullElse (java.util.Objects.requireNonNullElse)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2