use of com.palantir.lock.LockClient in project atlasdb by palantir.
the class SweepTestUtils method setupTxManager.
public static SerializableTransactionManager setupTxManager(KeyValueService kvs, TimestampService tsService, SweepStrategyManager ssm, TransactionService txService) {
LockClient lockClient = LockClient.of("sweep client");
LockService lockService = LockServiceImpl.create(LockServerOptions.builder().isStandaloneServer(false).build());
Supplier<AtlasDbConstraintCheckingMode> constraints = () -> AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING;
ConflictDetectionManager cdm = ConflictDetectionManagers.createWithoutWarmingCache(kvs);
Cleaner cleaner = new NoOpCleaner();
SerializableTransactionManager txManager = SerializableTransactionManager.createForTest(kvs, tsService, lockClient, lockService, txService, constraints, cdm, ssm, cleaner, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, InMemorySweepQueue.writer());
setupTables(kvs);
return txManager;
}
use of com.palantir.lock.LockClient in project atlasdb by palantir.
the class TableTasksTest method setup.
@Before
public void setup() {
kvs = new InMemoryKeyValueService(true);
TimestampService tsService = new InMemoryTimestampService();
LockClient lockClient = LockClient.of("sweep client");
lockService = LockServiceImpl.create(LockServerOptions.builder().isStandaloneServer(false).build());
TransactionService txService = TransactionServices.createTransactionService(kvs);
Supplier<AtlasDbConstraintCheckingMode> constraints = Suppliers.ofInstance(AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING);
ConflictDetectionManager cdm = ConflictDetectionManagers.createWithoutWarmingCache(kvs);
SweepStrategyManager ssm = SweepStrategyManagers.createDefault(kvs);
Cleaner cleaner = new NoOpCleaner();
SerializableTransactionManager transactionManager = SerializableTransactionManager.createForTest(kvs, tsService, lockClient, lockService, txService, constraints, cdm, ssm, cleaner, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, MultiTableSweepQueueWriter.NO_OP);
txManager = transactionManager;
}
use of com.palantir.lock.LockClient in project atlasdb by palantir.
the class TestTimestampCommand method runAndVerifyCli.
private void runAndVerifyCli(Verifier verifier) throws Exception {
try (SingleBackendCliTestRunner runner = makeRunner(cliArgs.toArray(new String[0]))) {
TestAtlasDbServices services = runner.connect(moduleFactory);
LockService lockService = services.getLockService();
TimestampService tss = services.getTimestampService();
LockClient client = services.getTestLockClient();
Clock clock = GlobalClock.create(lockService);
long prePunch = clock.getTimeMillis();
punch(services, tss, clock);
long postPunch = clock.getTimeMillis();
long immutableTs = tss.getFreshTimestamp();
LockRequest request = LockRequest.builder(ImmutableSortedMap.of(lock, LockMode.WRITE)).withLockedInVersionId(immutableTs).doNotBlock().build();
LockRefreshToken token = lockService.lock(client.getClientId(), request);
long lastFreshTs = tss.getFreshTimestamps(1000).getUpperBound();
verifier.verify(runner, tss, immutableTs, prePunch, postPunch, lastFreshTs, true);
lockService.unlock(token);
lastFreshTs = tss.getFreshTimestamps(1000).getUpperBound();
// there are no locks so we now expect immutable to just be a fresh
runner.freshCommand();
verifier.verify(runner, tss, immutableTs, prePunch, postPunch, lastFreshTs, false);
}
}
use of com.palantir.lock.LockClient in project atlasdb by palantir.
the class LockServiceImpl method unlockAndFreeze.
@Override
public boolean unlockAndFreeze(HeldLocksToken token) {
Preconditions.checkNotNull(token);
@Nullable HeldLocks<HeldLocksToken> heldLocks = heldLocksTokenMap.remove(token);
if (heldLocks == null) {
if (log.isTraceEnabled()) {
log.trace(".unlockAndFreeze({}) returns false", token);
}
return false;
}
LockClient client = heldLocks.realToken.getClient();
if (client.isAnonymous()) {
heldLocksTokenMap.put(token, heldLocks);
lockTokenReaperQueue.add(token);
log.warn(UNLOCK_AND_FREEZE_FROM_ANONYMOUS_CLIENT, heldLocks.realToken);
throw new IllegalArgumentException(MessageFormatter.format(UNLOCK_AND_FREEZE_FROM_ANONYMOUS_CLIENT, heldLocks.realToken).getMessage());
}
if (heldLocks.locks.hasReadLock()) {
heldLocksTokenMap.put(token, heldLocks);
lockTokenReaperQueue.add(token);
log.warn(UNLOCK_AND_FREEZE, heldLocks.realToken);
throw new IllegalArgumentException(MessageFormatter.format(UNLOCK_AND_FREEZE, heldLocks.realToken).getMessage());
}
for (ClientAwareReadWriteLock lock : heldLocks.locks.getKeys()) {
lock.get(client, LockMode.WRITE).unlockAndFreeze();
}
lockClientMultimap.remove(client, token);
if (heldLocks.realToken.getVersionId() != null) {
versionIdMap.remove(client, heldLocks.realToken.getVersionId());
}
if (log.isTraceEnabled()) {
log.trace(".unlockAndFreeze({}) returns true", token);
}
return true;
}
use of com.palantir.lock.LockClient in project atlasdb by palantir.
the class LockServiceSerDeTest method testPathParamSerDeOfLockClient.
@Test
public void testPathParamSerDeOfLockClient() throws Exception {
LockClient lockClient = LockClient.of("xyz");
String serializedForm = lockClient.toString();
LockClient lockClient1 = new LockClient(serializedForm);
assertEquals(lockClient, lockClient1);
}
Aggregations