use of org.neo4j.memory.MemoryPools in project neo4j by neo4j.
the class BatchingNeoStoresTest method someDataInTheDatabase.
private void someDataInTheDatabase(Config config) throws Exception {
NullLog nullLog = NullLog.getInstance();
try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
Lifespan life = new Lifespan()) {
// TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.propertyKeyDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.labelDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.relationshipTypeDoCreateForName(name, internal, id);
}
};
TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
IndexConfigCompleter indexConfigCompleter = index -> index;
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
// Create the relationship type token
TxState txState = new TxState();
NeoStores neoStores = storageEngine.testAccessNeoStores();
CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
commandCreationContext.initialize(NULL);
propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
apply(txState, commandCreationContext, storageEngine);
// Finally, we're initialized and ready to create two nodes and a relationship
txState = new TxState();
long node1 = commandCreationContext.reserveNode();
long node2 = commandCreationContext.reserveNode();
txState.nodeDoCreate(node1);
txState.nodeDoCreate(node2);
txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
apply(txState, commandCreationContext, storageEngine);
neoStores.flush(NULL);
}
}
use of org.neo4j.memory.MemoryPools in project neo4j by neo4j.
the class ConfiguringPageCacheFactoryTest method shouldFitAsManyPagesAsItCan.
@Test
void shouldFitAsManyPagesAsItCan() {
// Given
long pageCount = 60;
long memory = MuninnPageCache.memoryRequiredForPages(pageCount);
Config config = Config.defaults(pagecache_memory, Long.toString(memory));
// When
ConfiguringPageCacheFactory factory = new ConfiguringPageCacheFactory(fs, config, PageCacheTracer.NULL, NullLog.getInstance(), jobScheduler, Clocks.nanoClock(), new MemoryPools());
// Then
try (PageCache cache = factory.getOrCreatePageCache()) {
assertThat(cache.pageSize()).isEqualTo(PAGE_SIZE);
assertThat(cache.maxCachedPages()).isEqualTo(pageCount);
}
}
use of org.neo4j.memory.MemoryPools in project neo4j by neo4j.
the class BoltMemoryPoolIT method reportConsumedHeapMemory.
@Test
void reportConsumedHeapMemory() {
var bufAllocator = createTestAllocator(false);
var allocatorMetric = bufAllocator.metric();
assertEquals(0, allocatorMetric.usedDirectMemory());
assertEquals(0, allocatorMetric.usedDirectMemory());
var memoryTracker = new BoltMemoryPool(new MemoryPools(), allocatorMetric);
var buffer = bufAllocator.buffer(requestedSize);
try {
assertEquals(requestedSize, buffer.capacity());
assertEquals(requestedSize, memoryTracker.usedHeap());
assertEquals(requestedSize, memoryTracker.totalUsed());
} finally {
buffer.release();
}
assertEquals(0, memoryTracker.usedHeap());
assertEquals(0, memoryTracker.totalUsed());
}
use of org.neo4j.memory.MemoryPools in project neo4j by neo4j.
the class HeapTrackingLongIntHashMapTest method setUp.
@BeforeEach
void setUp() {
memoryPool = new MemoryPools().pool(MemoryGroup.TRANSACTION, 0L, null);
memoryTracker = new LocalMemoryTracker(memoryPool);
}
use of org.neo4j.memory.MemoryPools in project neo4j by neo4j.
the class HeapTrackingUnifiedMapTest method setUp.
@BeforeEach
void setUp() {
memoryPool = new MemoryPools().pool(MemoryGroup.TRANSACTION, 0L, null);
memoryTracker = new LocalMemoryTracker(memoryPool);
}
Aggregations