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