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));
}
}
}
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);
}
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);
}
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);
}
}
}
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);
}
}
}
Aggregations