use of org.neo4j.memory.EmptyMemoryTracker.INSTANCE in project neo4j by neo4j.
the class RelationshipChangesForNodeTest method shouldVisitRelationshipIds.
@Test
void shouldVisitRelationshipIds() {
// given
RelationshipChangesForNode changes = createRelationshipChangesForNode(REMOVE, INSTANCE);
MutableIntObjectMap<Map<RelationshipDirection, MutableLongSet>> expected = IntObjectMaps.mutable.empty();
MutableLongSet allExpected = LongSets.mutable.empty();
for (int id = 0; id < 100; id++) {
int type = random.nextInt(5);
RelationshipDirection direction = random.nextBoolean() ? random.nextBoolean() ? OUTGOING : INCOMING : LOOP;
changes.addRelationship(id, type, direction);
expected.getIfAbsentPut(type, HashMap::new).computeIfAbsent(direction, d -> LongSets.mutable.empty()).add(id);
allExpected.add(id);
}
// when
MutableLongSet allChangedIds = LongSets.mutable.empty();
changes.visitIds(allChangedIds::add);
// then
assertThat(allChangedIds).isEqualTo(allExpected);
// and when
changes.visitIdsSplit(typeIds -> {
Map<RelationshipDirection, MutableLongSet> dirMap = expected.remove(typeIds.type());
visitExpectedIds(typeIds, dirMap, OUTGOING, RelationshipModifications.NodeRelationshipTypeIds::out);
visitExpectedIds(typeIds, dirMap, INCOMING, RelationshipModifications.NodeRelationshipTypeIds::in);
visitExpectedIds(typeIds, dirMap, LOOP, RelationshipModifications.NodeRelationshipTypeIds::loop);
assertThat(dirMap).isEmpty();
return false;
}, RelationshipModifications.noAdditionalDataDecorator());
assertThat(expected).isEmpty();
}
use of org.neo4j.memory.EmptyMemoryTracker.INSTANCE in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method writeSomeDataWithVersion.
private void writeSomeDataWithVersion(Path file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor, KernelVersion version) throws IOException {
try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystem.write(file), logVersion, CURRENT_LOG_FORMAT_VERSION, file, EMPTY_ACCESSOR);
PositionAwarePhysicalFlushableChecksumChannel writableLogChannel = new PositionAwarePhysicalFlushableChecksumChannel(versionedStoreChannel, new HeapScopedBuffer(1, KibiByte, INSTANCE))) {
writeLogHeader(writableLogChannel, new LogHeader(logVersion, 2L, StoreId.UNKNOWN));
writableLogChannel.beginChecksum();
Consumer<LogPositionMarker> consumer = marker -> {
try {
writableLogChannel.getCurrentPosition(marker);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
LogEntryWriter first = new LogEntryWriter(writableLogChannel, version);
visitor.visit(Pair.of(first, consumer));
}
}
use of org.neo4j.memory.EmptyMemoryTracker.INSTANCE in project neo4j by neo4j.
the class DynamicIndexStoreViewTest method shouldVisitAllRelationshipsWithoutTokenIndexes.
@Test
void shouldVisitAllRelationshipsWithoutTokenIndexes() {
StubStorageCursors cursors = new StubStorageCursors().withoutTokenIndexes();
IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
int targetType = 1;
int notTargetType = 2;
int[] targetTypeArray = { targetType };
String targetPropertyKey = "key";
Value propertyValue = Values.stringValue("value");
MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
long id = 0;
int wantedPropertyUpdates = 5;
for (int i = 0; i < wantedPropertyUpdates; i++) {
// Relationship fitting our target
cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
relationshipsWithTargetType.add(id++);
// Relationship with different type
cursors.withRelationship(id, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
relationshipsWithTargetType.add(id++);
}
int targetPropertyKeyId = cursors.propertyKeyTokenHolder().getIdByName(targetPropertyKey);
IntPredicate propertyKeyIdFilter = value -> value == targetPropertyKeyId;
DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
StoreScan storeScan = storeView.visitRelationships(targetTypeArray, propertyKeyIdFilter, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
assertThat(tokenConsumer.batches.size()).isEqualTo(1);
assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
use of org.neo4j.memory.EmptyMemoryTracker.INSTANCE in project neo4j by neo4j.
the class NeoStoresTest method reinitializeStores.
private void reinitializeStores(DatabaseLayout databaseLayout) {
Dependencies dependencies = new Dependencies();
Config config = Config.defaults(GraphDatabaseSettings.fail_on_missing_files, false);
dependencies.satisfyDependency(config);
closeStorageEngine();
IdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
TokenHolders tokenHolders = new TokenHolders(createReadOnlyTokenHolder(TokenHolder.TYPE_PROPERTY_KEY), createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL), createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE));
storageEngine = new RecordStorageEngine(databaseLayout, config, pageCache, fs, nullLogProvider(), tokenHolders, new DatabaseSchemaState(nullLogProvider()), new StandardConstraintRuleAccessor(), i -> i, NO_LOCK_SERVICE, mock(Health.class), idGeneratorFactory, new DefaultIdController(), immediate(), PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE);
life = new LifeSupport();
life.add(storageEngine);
life.add(storageEngine.schemaAndTokensLifecycle());
life.start();
NeoStores neoStores = storageEngine.testAccessNeoStores();
pStore = neoStores.getPropertyStore();
nodeStore = neoStores.getNodeStore();
storageReader = storageEngine.newReader();
}
use of org.neo4j.memory.EmptyMemoryTracker.INSTANCE in project neo4j by neo4j.
the class OnlineIndexUpdatesTest method setUp.
@BeforeEach
void setUp() throws IOException {
life = new LifeSupport();
Config config = Config.defaults();
NullLogProvider nullLogProvider = NullLogProvider.getInstance();
StoreFactory storeFactory = new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName()), pageCache, fileSystem, nullLogProvider, NULL, writable());
neoStores = storeFactory.openAllNeoStores(true);
GBPTreeCountsStore counts = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, immediate(), new CountsComputer(neoStores, pageCache, NULL, databaseLayout, INSTANCE, NullLog.getInstance()), writable(), NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1_000);
life.add(wrapInLifecycle(counts));
nodeStore = neoStores.getNodeStore();
relationshipStore = neoStores.getRelationshipStore();
PropertyStore propertyStore = neoStores.getPropertyStore();
schemaCache = new SchemaCache(new StandardConstraintRuleAccessor(), index -> index);
propertyPhysicalToLogicalConverter = new PropertyPhysicalToLogicalConverter(neoStores.getPropertyStore(), CursorContext.NULL);
life.start();
propertyCreator = new PropertyCreator(neoStores.getPropertyStore(), new PropertyTraverser(CursorContext.NULL), CursorContext.NULL, INSTANCE);
recordAccess = new DirectRecordAccess<>(neoStores.getPropertyStore(), Loaders.propertyLoader(propertyStore, CursorContext.NULL));
}
Aggregations