use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class NeoStoresTest method relDelete.
private void relDelete(long id) {
RelationshipVisitor<RuntimeException> visitor = (relId, type, startNode, endNode) -> transactionState.relationshipDoDelete(relId, type, startNode, endNode);
if (!transactionState.relationshipVisit(id, visitor)) {
try (StorageRelationshipScanCursor cursor = storageReader.allocateRelationshipScanCursor(NULL)) {
cursor.single(id);
if (!cursor.next()) {
throw new RuntimeException("Relationship " + id + " not found");
}
visitor.visit(id, cursor.type(), cursor.sourceNodeReference(), cursor.targetNodeReference());
}
}
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL 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.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class DelayedBufferTest method shouldHandleTheWholeWorkloadShebang.
@Test
void shouldHandleTheWholeWorkloadShebang() throws Throwable {
// GIVEN
final int size = 1_000;
final long bufferTime = 3;
VerifyingConsumer consumer = new VerifyingConsumer(size);
final FakeClock clock = Clocks.fakeClock();
Supplier<Long> chunkThreshold = clock::millis;
AtomicBoolean end = new AtomicBoolean();
Predicate<Long> safeThreshold = time -> end.get() || clock.millis() - bufferTime >= time;
final DelayedBuffer<Long> buffer = new DelayedBuffer<>(chunkThreshold, safeThreshold, 10, consumer);
MaintenanceThread maintenance = new MaintenanceThread(buffer, 5);
Race adders = new Race();
final int numberOfAdders = 20;
final byte[] offeredIds = new byte[size];
for (int i = 0; i < numberOfAdders; i++) {
final int finalI = i;
adders.addContestant(() -> {
for (int j = 0; j < size; j++) {
if (j % numberOfAdders == finalI) {
buffer.offer(j);
offeredIds[j] = 1;
clock.forward(2, MILLISECONDS);
}
}
});
}
// WHEN (multi-threaded) offering of ids
adders.go();
// ... ensuring the test is sane itself (did we really offer all these IDs?)
for (int i = 0; i < size; i++) {
assertEquals((byte) 1, offeredIds[i], "ID " + i);
}
maintenance.halt();
end.set(true);
buffer.maintenance(NULL);
buffer.close();
// THEN
consumer.assertHaveOnlySeenRange(0, size - 1);
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class GBPTreeGenericCountsStoreTest method assertCountsMatchesExpected.
private void assertCountsMatchesExpected(ConcurrentMap<CountsKey, AtomicLong> source, long baseCount) {
ConcurrentMap<CountsKey, AtomicLong> expected = new ConcurrentHashMap<>();
source.entrySet().stream().filter(// counts store won't have entries w/ 0 count
entry -> entry.getValue().get() != 0).forEach(// copy them over to the one we're going to verify
entry -> expected.put(entry.getKey(), entry.getValue()));
countsStore.visitAllCounts((key, count) -> {
AtomicLong expectedCount = expected.remove(key);
if (expectedCount == null) {
assertEquals(baseCount, count, () -> format("Counts store has wrong count for (absent) %s", key));
} else {
assertEquals(baseCount + expectedCount.get(), count, () -> format("Counts store has wrong count for %s", key));
}
}, NULL);
assertTrue(expected.isEmpty(), expected::toString);
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class GBPTreeGenericCountsStoreTest method generateAndApplyTransaction.
/**
* Generates a transaction, i.e. a counts change set. The data is random, but uses a seed which is the seed of the {@link RandomRule} in this test
* as well as the the supplied txId. Calling this method in any given test multiple times with any specific txId will generate the same data.
*
* @param expected map of counts to update with the generated changes.
* @param txId transaction id to generate transaction data for and ultimately apply to the counts store (and the expected map).
*/
private void generateAndApplyTransaction(ConcurrentMap<CountsKey, AtomicLong> expected, long txId) {
Random rng = new Random(random.seed() + txId);
try (CountUpdater updater = countsStore.updater(txId, NULL)) {
if (updater != null) {
int numberOfKeys = rng.nextInt(10);
for (int j = 0; j < numberOfKeys; j++) {
// chance to get -1
long delta = rng.nextInt(11) - 1;
CountsKey expectedKey;
if (rng.nextBoolean()) {
// Node
int labelId = randomTokenId(rng);
updater.increment(nodeKey(labelId), delta);
expectedKey = nodeKey(labelId);
} else {
// Relationship
int startLabelId = randomTokenId(rng);
int type = randomTokenId(rng);
int endLabelId = randomTokenId(rng);
updater.increment(relationshipKey(startLabelId, type, endLabelId), delta);
expectedKey = relationshipKey(startLabelId, type, endLabelId);
}
expected.computeIfAbsent(expectedKey, k -> new AtomicLong()).addAndGet(delta);
}
}
}
}
Aggregations