use of com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal in project atlasdb by palantir.
the class TimeLockHelperServices method create.
static TimeLockHelperServices create(String namespace, MetricsManager metricsManager, Set<Schema> schemas, LockWatchStarter lockWatchStarter, LockWatchCachingConfig lockWatchCachingConfig, Supplier<Optional<RequestBatchersFactory.MultiClientRequestBatchers>> requestBatcherProvider) {
LockWatchManagerInternal lockWatchManager = LockWatchManagerImpl.create(metricsManager, schemas, lockWatchStarter, lockWatchCachingConfig);
LockWatchCache lockWatchCache = lockWatchManager.getCache();
RequestBatchersFactory requestBatchersFactory = RequestBatchersFactory.create(lockWatchCache, Namespace.of(namespace), requestBatcherProvider.get());
return ImmutableTimeLockHelperServices.builder().lockWatchManager(lockWatchManager).requestBatchersFactory(requestBatchersFactory).build();
}
use of com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal in project atlasdb by palantir.
the class LockWatchIntegrationTestUtilities method awaitTableWatched.
/**
* The lock watch manager registers watch events every five seconds - therefore, tables may not be watched
* immediately after a TimeLock leader election. By requesting an update with an empty version, we guarantee that
* we only receive a single event containing a snapshot of the current lock watch event state, including watched
* tables.
*/
public static void awaitTableWatched(TransactionManager txnManager, TableReference tableReference) {
LockWatchManagerInternal lockWatchManager = extractInternalLockWatchManager(txnManager);
Awaitility.await("Tables are watched").atMost(Duration.ofSeconds(5)).pollDelay(Duration.ofMillis(100)).until(() -> getLockWatchState(txnManager, lockWatchManager).map(event -> event.accept(new LockWatchCreatedEventVisitor(createdEvent -> createdEvent.references().contains(LockWatchReferences.entireTable(tableReference.getQualifiedName()))))).orElse(false));
}
use of com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal in project atlasdb by palantir.
the class LockWatchIntegrationTestUtilities method awaitAllUnlocked.
/**
* By requesting a snapshot, we get a single snapshot event that contains all currently held lock descriptors.
* As unlocks are asynchronous, we must wait for the unlocks to go through to guarantee consistent testing.
*/
public static void awaitAllUnlocked(TransactionManager txnManager) {
LockWatchManagerInternal lockWatchManager = extractInternalLockWatchManager(txnManager);
Awaitility.await("All descriptors are unlocked").atMost(Duration.ofSeconds(5)).pollDelay(Duration.ofMillis(100)).until(() -> getLockWatchState(txnManager, lockWatchManager).map(event -> event.accept(new LockWatchCreatedEventVisitor(createdEvent -> createdEvent.lockDescriptors().isEmpty()))).orElse(false));
}
use of com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal in project atlasdb by palantir.
the class DefaultLockAndTimestampServiceFactory method getLockAndTimestampServices.
private static LockAndTimestampServices getLockAndTimestampServices(MetricsManager metricsManager, Refreshable<ServerListConfig> timelockServerListConfig, UserAgent userAgent, String timelockNamespace, Optional<LockDiagnosticComponents> lockDiagnosticComponents, ReloadingFactory reloadingFactory, Optional<TimeLockFeedbackBackgroundTask> timeLockFeedbackBackgroundTask, Optional<TimeLockRequestBatcherProviders> timelockRequestBatcherProviders, Set<Schema> schemas, LockWatchCachingConfig cachingConfig) {
AtlasDbDialogueServiceProvider serviceProvider = AtlasDbDialogueServiceProvider.create(timelockServerListConfig, reloadingFactory, userAgent, metricsManager.getTaggedRegistry());
LockRpcClient lockRpcClient = serviceProvider.getLockRpcClient();
LockService lockService = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), LockService.class, RemoteLockServiceAdapter.create(lockRpcClient, timelockNamespace));
ConjureTimelockService conjureTimelockService = serviceProvider.getConjureTimelockService();
TimelockRpcClient timelockClient = serviceProvider.getTimelockRpcClient();
// TODO(fdesouza): Remove this once PDS-95791 is resolved.
ConjureTimelockService withDiagnosticsConjureTimelockService = lockDiagnosticComponents.<ConjureTimelockService>map(components -> new LockDiagnosticConjureTimelockService(conjureTimelockService, components.clientLockDiagnosticCollector(), components.localLockTracker())).orElse(conjureTimelockService);
NamespacedTimelockRpcClient namespacedTimelockRpcClient = new DefaultNamespacedTimelockRpcClient(timelockClient, timelockNamespace);
LeaderElectionReportingTimelockService leaderElectionReportingTimelockService = LeaderElectionReportingTimelockService.create(withDiagnosticsConjureTimelockService, timelockNamespace);
timeLockFeedbackBackgroundTask.ifPresent(task -> task.registerLeaderElectionStatistics(leaderElectionReportingTimelockService));
NamespacedConjureTimelockService namespacedConjureTimelockService = TimestampCorroboratingTimelockService.create(timelockNamespace, metricsManager.getTaggedRegistry(), leaderElectionReportingTimelockService);
NamespacedConjureLockWatchingService lockWatchingService = new NamespacedConjureLockWatchingService(serviceProvider.getConjureLockWatchingService(), timelockNamespace);
Supplier<InternalMultiClientConjureTimelockService> multiClientTimelockServiceSupplier = getMultiClientTimelockServiceSupplier(serviceProvider);
Supplier<Optional<RequestBatchersFactory.MultiClientRequestBatchers>> requestBatcherProvider = () -> timelockRequestBatcherProviders.map(batcherProviders -> ImmutableMultiClientRequestBatchers.of(batcherProviders.commitTimestamps().getBatcher(multiClientTimelockServiceSupplier), batcherProviders.startTransactions().getBatcher(multiClientTimelockServiceSupplier)));
TimeLockHelperServices timeLockHelperServices = TimeLockHelperServices.create(timelockNamespace, metricsManager, schemas, lockWatchingService, cachingConfig, requestBatcherProvider);
LockWatchManagerInternal lockWatchManager = timeLockHelperServices.lockWatchManager();
RemoteTimelockServiceAdapter remoteTimelockServiceAdapter = RemoteTimelockServiceAdapter.create(namespacedTimelockRpcClient, namespacedConjureTimelockService, getLeaderTimeGetter(timelockNamespace, timelockRequestBatcherProviders, namespacedConjureTimelockService, multiClientTimelockServiceSupplier), timeLockHelperServices.requestBatchersFactory());
TimestampManagementService timestampManagementService = new RemoteTimestampManagementAdapter(serviceProvider.getTimestampManagementRpcClient(), timelockNamespace);
return ImmutableLockAndTimestampServices.builder().lock(lockService).timestamp(new TimelockTimestampServiceAdapter(remoteTimelockServiceAdapter)).timestampManagement(timestampManagementService).timelock(remoteTimelockServiceAdapter).lockWatcher(lockWatchManager).addResources(remoteTimelockServiceAdapter::close).addResources(lockWatchManager::close).build();
}
Aggregations