use of org.neo4j.util.concurrent.WorkSync in project neo4j by neo4j.
the class ApplyRecoveredTransactionsTest method applyExternalTransaction.
private void applyExternalTransaction(long transactionId, Command... commands) throws Exception {
LockService lockService = mock(LockService.class);
when(lockService.acquireNodeLock(anyLong(), any(LockType.class))).thenReturn(LockService.NO_LOCK);
when(lockService.acquireRelationshipLock(anyLong(), any(LockType.class))).thenReturn(LockService.NO_LOCK);
Map<IdType, WorkSync<IdGenerator, IdGeneratorUpdateWork>> idGeneratorWorkSyncs = new EnumMap<>(IdType.class);
for (IdType idType : IdType.values()) {
idGeneratorWorkSyncs.put(idType, new WorkSync<>(idGeneratorFactory.get(idType)));
}
NeoStoreTransactionApplierFactory applier = new NeoStoreTransactionApplierFactory(INTERNAL, neoStores, mock(CacheAccessBackDoor.class), lockService);
CommandsToApply tx = new GroupOfCommands(transactionId, commands);
CommandHandlerContract.apply(applier, txApplier -> {
tx.accept(txApplier);
return false;
}, new GroupOfCommands(transactionId, commands));
}
use of org.neo4j.util.concurrent.WorkSync in project neo4j by neo4j.
the class LargeFreelistCreationDeletionIT method shouldAlternateLargeCreationsAndDeletionsAndNotLoseIds.
@Test
void shouldAlternateLargeCreationsAndDeletionsAndNotLoseIds() throws Throwable {
long[][] allocatedIds = new long[THREADS][];
for (int i = 0; i < THREADS; i++) {
allocatedIds[i] = new long[ALLOCATIONS_PER_THREAD];
}
for (int r = 0; r < 3; r++) {
// Create
try (var freelist = new IndexedIdGenerator(pageCache, directory.file("file.id"), immediate(), IdType.NODE, false, () -> 0, Long.MAX_VALUE, writable(), Config.defaults(), DEFAULT_DATABASE_NAME, NULL)) {
// Make sure ID cache is filled so that initial allocations won't slide highId unnecessarily.
freelist.maintenance(NULL);
Race race = new Race();
WorkSync<IndexedIdGenerator, Ids> workSync = new WorkSync<>(freelist);
for (int t = 0; t < THREADS; t++) {
int thread = t;
race.addContestant(throwing(() -> {
int cursor = 0;
for (int i = 0; i < TRANSACTIONS_PER_THREAD; i++) {
long[] txIds = new long[ALLOCATIONS_PER_TRANSACTION];
for (int a = 0; a < txIds.length; a++) {
long id = freelist.nextId(NULL);
allocatedIds[thread][cursor++] = id;
txIds[a] = id;
}
workSync.apply(new Ids(txIds));
Thread.sleep(1);
}
}), 1);
}
race.go();
assertAllUnique(allocatedIds);
// Delete
try (Marker marker = freelist.marker(NULL)) {
for (long[] perThread : allocatedIds) {
for (long id : perThread) {
marker.markDeleted(id);
}
}
}
// Checkpoint
freelist.checkpoint(NULL);
System.out.println(freelist.getHighId());
}
}
}
use of org.neo4j.util.concurrent.WorkSync in project neo4j by neo4j.
the class SchemaRuleCommandTest method setup.
@BeforeEach
void setup() {
Map<IdType, WorkSync<IdGenerator, IdGeneratorUpdateWork>> idGeneratorWorkSyncs = new EnumMap<>(IdType.class);
for (IdType idType : IdType.values()) {
idGeneratorWorkSyncs.put(idType, new WorkSync<>(mock(IdGenerator.class)));
}
storeApplier = new NeoStoreTransactionApplierFactory(INTERNAL, neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
}
Aggregations