use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class FabricServicesBootstrap method createBoltDatabaseManagementServiceProvider.
public BoltGraphDatabaseManagementServiceSPI createBoltDatabaseManagementServiceProvider(BoltGraphDatabaseManagementServiceSPI kernelDatabaseManagementService, DatabaseManagementService managementService, Monitors monitors, SystemNanoClock clock) {
FabricExecutor fabricExecutor = dependencies.resolveDependency(FabricExecutor.class);
TransactionManager transactionManager = dependencies.resolveDependency(TransactionManager.class);
FabricDatabaseManager fabricDatabaseManager = dependencies.resolveDependency(FabricDatabaseManager.class);
var serverConfig = dependencies.resolveDependency(Config.class);
var transactionIdTracker = new TransactionIdTracker(managementService, monitors, clock);
var databaseManager = (DatabaseManager<DatabaseContext>) dependencies.resolveDependency(DatabaseManager.class);
var databaseIdRepository = databaseManager.databaseIdRepository();
var transactionBookmarkManagerFactory = dependencies.resolveDependency(TransactionBookmarkManagerFactory.class);
var localGraphTransactionIdTracker = new LocalGraphTransactionIdTracker(transactionIdTracker, databaseIdRepository, serverConfig);
var fabricDatabaseManagementService = dependencies.satisfyDependency(new BoltFabricDatabaseManagementService(fabricExecutor, fabricConfig, transactionManager, fabricDatabaseManager, localGraphTransactionIdTracker, transactionBookmarkManagerFactory));
return new BoltGraphDatabaseManagementServiceSPI() {
@Override
public BoltGraphDatabaseServiceSPI database(String databaseName, MemoryTracker memoryTracker) throws UnavailableException, DatabaseNotFoundException {
if (fabricDatabaseManager.hasMultiGraphCapabilities(databaseName)) {
return fabricDatabaseManagementService.database(databaseName, memoryTracker);
}
return kernelDatabaseManagementService.database(databaseName, memoryTracker);
}
@Override
public Optional<CustomBookmarkFormatParser> getCustomBookmarkFormatParser() {
return fabricDatabaseManagementService.getCustomBookmarkFormatParser();
}
};
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class GBPTreeGenericCountsStoreTest method shouldNotApplyTransactionOnCreatedCountsStoreDuringRecovery.
@Test
void shouldNotApplyTransactionOnCreatedCountsStoreDuringRecovery() throws IOException {
// given
int labelId = 123;
incrementNodeCount(BASE_TX_ID + 1, labelId, 4);
countsStore.checkpoint(NULL);
incrementNodeCount(BASE_TX_ID + 2, labelId, -2);
closeCountsStore();
deleteCountsStore();
GBPTreeCountsStore.Monitor monitor = mock(GBPTreeCountsStore.Monitor.class);
// instantiate, but don't start
instantiateCountsStore(new Rebuilder() {
@Override
public void rebuild(CountUpdater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
updater.increment(nodeKey(labelId), 2);
}
@Override
public long lastCommittedTxId() {
return BASE_TX_ID + 2;
}
}, writable(), monitor);
// when doing recovery of the last transaction (since this is on an empty counts store then making the count negative, i.e. 0 - 2)
// applying this negative delta would have failed in the updater.
incrementNodeCount(BASE_TX_ID + 2, labelId, -2);
verify(monitor).ignoredTransaction(BASE_TX_ID + 2);
countsStore.start(NULL, INSTANCE);
// then
assertEquals(2, countsStore.read(nodeKey(labelId), NULL));
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class DatabaseIT method shutdownStopMustOnlyReleaseMemoryOnce.
@Test
void shutdownStopMustOnlyReleaseMemoryOnce() throws Exception {
MemoryTracker otherMemoryTracker = getOtherMemoryTracker();
long beforeShutdown = otherMemoryTracker.usedNativeMemory();
database.shutdown();
long afterShutdown = otherMemoryTracker.usedNativeMemory();
assertThat(afterShutdown).isLessThan(beforeShutdown);
database.stop();
long afterStop = otherMemoryTracker.usedNativeMemory();
assertEquals(afterStop, afterShutdown);
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class BatchingNeoStoresTest method shouldRebuildCountsStoreEvenIfExistsInEmptyDb.
@Test
void shouldRebuildCountsStoreEvenIfExistsInEmptyDb() throws IOException {
// given
try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, RecoveryCleanupWorkCollector.immediate(), CountsBuilder.EMPTY, writable(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, DEFAULT_DATABASE_NAME, 1_000)) {
countsStore.start(NULL, INSTANCE);
countsStore.checkpoint(NULL);
}
// when
try (BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache(fileSystem, pageCache, PageCacheTracer.NULL, databaseLayout, LATEST_RECORD_FORMATS, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults(), INSTANCE)) {
stores.createNew();
stores.buildCountsStore(new CountsBuilder() {
@Override
public void initialize(CountsAccessor.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
updater.incrementNodeCount(1, 10);
updater.incrementNodeCount(2, 20);
updater.incrementRelationshipCount(ANY_LABEL, 1, 2, 30);
updater.incrementRelationshipCount(1, 2, ANY_LABEL, 50);
}
@Override
public long lastCommittedTxId() {
return BASE_TX_ID + 1;
}
}, PageCacheTracer.NULL, NULL, INSTANCE);
}
// then
try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, RecoveryCleanupWorkCollector.immediate(), CountsBuilder.EMPTY, writable(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, DEFAULT_DATABASE_NAME, 1_000)) {
assertEquals(10, countsStore.nodeCount(1, NULL));
assertEquals(20, countsStore.nodeCount(2, NULL));
assertEquals(30, countsStore.relationshipCount(ANY_LABEL, 1, 2, NULL));
assertEquals(50, countsStore.relationshipCount(1, 2, ANY_LABEL, NULL));
}
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class HeapTrackingLongEnumerationListTest method addRemoveScenario.
@Test
void addRemoveScenario() {
MemoryTracker memoryTracker = new LocalMemoryTracker();
HeapTrackingLongEnumerationList<Long> table = HeapTrackingLongEnumerationList.create(memoryTracker, 4);
assertEmpty(table);
table.add(0L);
table.add(1L);
table.add(2L);
assertContainsOnly(table, 0, 2);
table.remove(0L);
table.remove(1L);
assertContainsOnly(table, 2);
table.remove(2);
assertEmpty(table);
table.add(3L);
table.add(4L);
table.add(5L);
assertContainsOnly(table, 3, 5);
table.remove(5);
assertContainsOnly(table, 3, 4);
table.remove(4);
assertContainsOnly(table, 3);
long measured1 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured1, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
table.add(6L);
assertContainsOnly(table, new long[] { 3L, 6L });
long measured2 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured2, memoryTracker.estimatedHeapMemory() + 2 * HeapEstimator.LONG_SIZE);
assertEquals(HeapEstimator.LONG_SIZE, measured2 - measured1);
// New chunk needed
table.add(7L);
assertContainsOnly(table, new long[] { 3L, 6, 7L });
// New chunk allocated because of poor alignment in tail chunks
table.add(8L);
assertContainsOnly(table, new long[] { 3L, 6L, 7L, 8L });
table.remove(6L);
assertContainsOnly(table, new long[] { 3L, 7L, 8L });
// Should recycle chunk
table.remove(3L);
assertContainsOnly(table, new long[] { 7L, 8L });
// Should recycle chunk
table.remove(7L);
assertContainsOnly(table, 8L);
// Memory should be back to one chunk + one value
long measured3 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured3, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
assertEquals(measured1, measured3);
table.add(9L);
table.add(10L);
table.add(11L);
assertContainsOnly(table, 8, 11);
table.remove(8L);
table.remove(10L);
table.remove(11L);
assertContainsOnly(table, 9);
table.add(12L);
assertContainsOnly(table, new long[] { 9L, 12L });
table.remove(9L);
assertContainsOnly(table, 12);
// Memory should be one chunk + one value
long measured4 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured4, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
assertEquals(measured3, measured4);
table.close();
}
Aggregations