Search in sources :

Example 1 with MemoryTracker

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

the class UnsafeDirectByteBufferFactoryTest method shouldHandleMultipleClose.

@Test
void shouldHandleMultipleClose() {
    // given
    MemoryTracker tracker = new LocalMemoryTracker();
    UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator();
    // when
    factory.allocate(256, tracker);
    factory.close();
    // then
    assertEquals(0, tracker.usedNativeMemory());
    factory.close();
    assertEquals(0, tracker.usedNativeMemory());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 2 with MemoryTracker

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

the class UnsafeDirectByteBufferFactoryTest method shouldFreeOnClose.

@Test
void shouldFreeOnClose() {
    // given
    MemoryTracker tracker = new LocalMemoryTracker();
    try (UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator()) {
        // when
        factory.allocate(256, tracker);
    }
    // then
    assertEquals(0, tracker.usedNativeMemory());
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 3 with MemoryTracker

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

the class GBPTreeGenericCountsStoreTest method shouldRebuildOnMismatchingLastCommittedTxId.

@Test
void shouldRebuildOnMismatchingLastCommittedTxId() throws IOException {
    // given some pre-state
    long countsStoreTxId = BASE_TX_ID + 1;
    try (CountUpdater updater = countsStore.updater(countsStoreTxId, NULL)) {
        updater.increment(nodeKey(1), 1);
    }
    // when
    countsStore.checkpoint(NULL);
    closeCountsStore();
    MutableBoolean rebuildTriggered = new MutableBoolean();
    openCountsStore(new Rebuilder() {

        @Override
        public long lastCommittedTxId() {
            return countsStoreTxId + 1;
        }

        @Override
        public void rebuild(CountUpdater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
            rebuildTriggered.setTrue();
        }
    });
    // then
    assertThat(rebuildTriggered.booleanValue()).isTrue();
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Rebuilder(org.neo4j.internal.counts.GBPTreeGenericCountsStore.Rebuilder) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 4 with MemoryTracker

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

the class GBPTreeGenericCountsStoreTest method shouldNotRebuildOnMismatchingLastCommittedTxIdButMatchingAfterRecovery.

@Test
void shouldNotRebuildOnMismatchingLastCommittedTxIdButMatchingAfterRecovery() throws IOException {
    // given some pre-state
    long countsStoreTxId = BASE_TX_ID + 1;
    CountsKey key = nodeKey(1);
    try (CountUpdater updater = countsStore.updater(countsStoreTxId, NULL)) {
        updater.increment(key, 1);
    }
    // leaving a gap intentionally
    try (CountUpdater updater = countsStore.updater(countsStoreTxId + 2, NULL)) {
        updater.increment(key, 3);
    }
    countsStore.checkpoint(NULL);
    // when
    closeCountsStore();
    MutableBoolean rebuildTriggered = new MutableBoolean();
    instantiateCountsStore(new Rebuilder() {

        @Override
        public long lastCommittedTxId() {
            return countsStoreTxId + 2;
        }

        @Override
        public void rebuild(CountUpdater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
            rebuildTriggered.setTrue();
        }
    }, writable(), NO_MONITOR);
    // and do recovery
    try (CountUpdater updater = countsStore.updater(countsStoreTxId + 1, NULL)) {
        updater.increment(key, 7);
    }
    // already applied
    assertThat(countsStore.updater(countsStoreTxId + 2, NULL)).isNull();
    countsStore.start(NULL, INSTANCE);
    // then
    assertThat(rebuildTriggered.booleanValue()).isFalse();
    assertThat(countsStore.read(key, NULL)).isEqualTo(11);
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Rebuilder(org.neo4j.internal.counts.GBPTreeGenericCountsStore.Rebuilder) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 5 with MemoryTracker

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

the class RecordStorageMigratorIT method shouldBeAbleToMigrateWithoutErrors.

@ParameterizedTest
@MethodSource("versions")
void shouldBeAbleToMigrateWithoutErrors(String version, LogPosition expectedLogPosition, Function<TransactionId, Boolean> txIdComparator) throws Exception {
    // GIVEN a legacy database
    Path prepare = testDirectory.directory("prepare");
    var fs = testDirectory.getFileSystem();
    MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, databaseLayout.databaseDirectory(), prepare);
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    LogService logService = new SimpleLogService(logProvider, logProvider);
    RecordStoreVersionCheck check = getVersionCheck(pageCache, databaseLayout);
    String versionToMigrateFrom = getVersionToMigrateFrom(check);
    RecordStorageMigrator migrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
    // WHEN migrating
    migrator.migrate(databaseLayout, migrationLayout, progressMonitor.startSection("section"), versionToMigrateFrom, getVersionToMigrateTo(check), EMPTY);
    migrator.moveMigratedFiles(migrationLayout, databaseLayout, versionToMigrateFrom, getVersionToMigrateTo(check));
    // THEN starting the new store should be successful
    assertThat(testDirectory.getFileSystem().fileExists(databaseLayout.relationshipGroupDegreesStore())).isTrue();
    GBPTreeRelationshipGroupDegreesStore.DegreesRebuilder noRebuildAssertion = new GBPTreeRelationshipGroupDegreesStore.DegreesRebuilder() {

        @Override
        public void rebuild(RelationshipGroupDegreesStore.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
            throw new IllegalStateException("Rebuild should not be required");
        }

        @Override
        public long lastCommittedTxId() {
            try {
                return new RecordStorageEngineFactory().readOnlyTransactionIdStore(fs, databaseLayout, pageCache, NULL).getLastCommittedTransactionId();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    };
    try (GBPTreeRelationshipGroupDegreesStore groupDegreesStore = new GBPTreeRelationshipGroupDegreesStore(pageCache, databaseLayout.relationshipGroupDegreesStore(), testDirectory.getFileSystem(), immediate(), noRebuildAssertion, writable(), PageCacheTracer.NULL, GBPTreeGenericCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), counts_store_max_cached_entries.defaultValue())) {
        // The rebuild would happen here in start and will throw exception (above) if invoked
        groupDegreesStore.start(NULL, INSTANCE);
        // The store keeps track of committed transactions.
        // It is essential that it starts with the transaction
        // that is the last committed one at the upgrade time.
        assertEquals(TX_ID, groupDegreesStore.txId());
    }
    StoreFactory storeFactory = new StoreFactory(databaseLayout, CONFIG, new ScanOnOpenOverwritingIdGeneratorFactory(fs, databaseLayout.getDatabaseName()), pageCache, fs, logService.getInternalLogProvider(), PageCacheTracer.NULL, writable());
    storeFactory.openAllNeoStores().close();
    assertThat(logProvider).forLevel(ERROR).doesNotHaveAnyLogs();
}
Also used : Path(java.nio.file.Path) RecordStorageEngineFactory(org.neo4j.internal.recordstorage.RecordStorageEngineFactory) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) UncheckedIOException(java.io.UncheckedIOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) MemoryTracker(org.neo4j.memory.MemoryTracker) GBPTreeRelationshipGroupDegreesStore(org.neo4j.internal.counts.GBPTreeRelationshipGroupDegreesStore) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ScanOnOpenOverwritingIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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