public RemoteTaskQueue(ILog logger, ISerializer serializer, IGlobalTime globalTime, ICassandraCluster cassandraCluster, IRtqSettings rtqSettings, IRtqTaskDataRegistry taskDataRegistry, IRtqProfiler rtqProfiler) { QueueKeyspace = rtqSettings.QueueKeyspace; TaskTtl = rtqSettings.TaskTtl; Logger = logger.ForContext("CassandraDistributedTaskQueue"); Serializer = serializer; GlobalTime = globalTime; TaskDataRegistry = taskDataRegistry; enableContinuationOptimization = rtqSettings.EnableContinuationOptimization; minTicksHolder = new RtqMinTicksHolder(cassandraCluster, rtqSettings); TaskMinimalStartTicksIndex = new TaskMinimalStartTicksIndex(cassandraCluster, serializer, rtqSettings, new OldestLiveRecordTicksHolder(minTicksHolder), Logger); var taskMetaStorage = new TaskMetaStorage(cassandraCluster, serializer, rtqSettings, Logger); EventLogRepository = new EventLogRepository(serializer, cassandraCluster, rtqSettings, minTicksHolder); childTaskIndex = new ChildTaskIndex(cassandraCluster, rtqSettings, serializer, taskMetaStorage); HandleTasksMetaStorage = new HandleTasksMetaStorage(taskMetaStorage, TaskMinimalStartTicksIndex, EventLogRepository, GlobalTime, childTaskIndex, taskDataRegistry, Logger); TaskDataStorage = new TaskDataStorage(cassandraCluster, rtqSettings, Logger); TaskExceptionInfoStorage = new TaskExceptionInfoStorage(cassandraCluster, serializer, rtqSettings, Logger); HandleTaskCollection = new HandleTaskCollection(HandleTasksMetaStorage, TaskDataStorage, TaskExceptionInfoStorage, rtqProfiler); lazyRemoteLockCreator = new Lazy <IRemoteLockCreator>(() => { var remoteLockImplementationSettings = CassandraRemoteLockImplementationSettings.Default(rtqSettings.QueueKeyspace, RtqColumnFamilyRegistry.LocksColumnFamilyName); var remoteLockImplementation = new CassandraRemoteLockImplementation(cassandraCluster, serializer, remoteLockImplementationSettings); var remoteLockerMetrics = new RemoteLockerMetrics($"{rtqSettings.QueueKeyspace}_{RtqColumnFamilyRegistry.LocksColumnFamilyName}"); return(new RemoteLocker(remoteLockImplementation, remoteLockerMetrics, Logger)); }); Profiler = rtqProfiler; }
public RemoteLockerTester(RemoteLockerTesterConfig config = null) { config = config ?? RemoteLockerTesterConfig.Default(); var localRivalOptimizationIsEnabled = config.LocalRivalOptimization != LocalRivalOptimization.Disabled; var serializer = new Serializer(new AllPropertiesExtractor(), null, GroBufOptions.MergeOnRead); ICassandraCluster cassandraCluster = new CassandraCluster(config.CassandraClusterSettings, logger); if (config.CassandraFailProbability.HasValue) { cassandraCluster = new FailedCassandraCluster(cassandraCluster, config.CassandraFailProbability.Value); } var timestampProvider = new StochasticTimestampProvider(config.TimestampProviderStochasticType, config.LockTtl); var implementationSettings = new CassandraRemoteLockImplementationSettings(timestampProvider, SingleCassandraNodeSetUpFixture.RemoteLockKeyspace, SingleCassandraNodeSetUpFixture.RemoteLockColumnFamily, config.LockTtl, config.LockMetadataTtl, config.KeepLockAliveInterval, config.ChangeLockRowThreshold); var cassandraRemoteLockImplementation = new CassandraRemoteLockImplementation(cassandraCluster, serializer, implementationSettings); remoteLockers = new RemoteLocker[config.LockersCount]; remoteLockerMetrics = new RemoteLockerMetrics("dummyKeyspace"); if (localRivalOptimizationIsEnabled) { var remoteLocker = new RemoteLocker(cassandraRemoteLockImplementation, remoteLockerMetrics, logger); for (var i = 0; i < config.LockersCount; i++) { remoteLockers[i] = remoteLocker; } } else { for (var i = 0; i < config.LockersCount; i++) { remoteLockers[i] = new RemoteLocker(new CassandraRemoteLockImplementation(cassandraCluster, serializer, implementationSettings), remoteLockerMetrics, logger); } } // it is important to use another CassandraCluster (with another setting of attempts, for example) cassandraRemoteLockImplementationForCheckings = new CassandraRemoteLockImplementation(new CassandraCluster(SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(), logger), serializer, implementationSettings); }
private static IRemoteLockCreator[] PrepareRemoteLockCreators(int threadCount, LocalRivalOptimization localRivalOptimization, CassandraRemoteLockImplementation remoteLockImplementation) { var remoteLockCreators = new IRemoteLockCreator[threadCount]; var remoteLockerMetrics = new RemoteLockerMetrics(null); if (localRivalOptimization == LocalRivalOptimization.Enabled) { var singleRemoteLocker = new RemoteLocker(remoteLockImplementation, remoteLockerMetrics, logger); for (var i = 0; i < threadCount; i++) { remoteLockCreators[i] = singleRemoteLocker; } } else { for (var i = 0; i < threadCount; i++) { remoteLockCreators[i] = new RemoteLocker(remoteLockImplementation, remoteLockerMetrics, logger); } } return(remoteLockCreators); }