use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceImpl method unlockSimple.
@Override
public boolean unlockSimple(SimpleHeldLocksToken token) {
Preconditions.checkNotNull(token);
LockDescriptor fakeLockDesc = StringLockDescriptor.of("unlockSimple");
SortedLockCollection<LockDescriptor> fakeLockSet = LockCollections.of(ImmutableSortedMap.of(fakeLockDesc, LockMode.READ));
return unlock(new HeldLocksToken(token.getTokenId(), LockClient.ANONYMOUS, token.getCreationDateMs(), 0L, fakeLockSet, maxAllowedLockTimeout, 0L, "UnknownThread-unlockSimple"));
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceImpl method refreshLockRefreshTokens.
@Override
public Set<LockRefreshToken> refreshLockRefreshTokens(Iterable<LockRefreshToken> tokens) {
List<HeldLocksToken> fakeTokens = Lists.newArrayList();
LockDescriptor fakeLockDesc = StringLockDescriptor.of("refreshLockRefreshTokens");
SortedLockCollection<LockDescriptor> fakeLockSet = LockCollections.of(ImmutableSortedMap.of(fakeLockDesc, LockMode.READ));
for (LockRefreshToken token : tokens) {
fakeTokens.add(new HeldLocksToken(token.getTokenId(), LockClient.ANONYMOUS, 0L, 0L, fakeLockSet, maxAllowedLockTimeout, 0L, "UnknownThread-refreshLockRefreshTokens"));
}
return ImmutableSet.copyOf(Iterables.transform(refreshTokens(fakeTokens), HeldLocksTokens.getRefreshTokenFun()));
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceImpl method tryLocks.
private void tryLocks(LockClient client, LockRequest request, BlockingMode blockingMode, @Nullable Long deadline, LockGroupBehavior lockGroupBehavior, Map<? super ClientAwareReadWriteLock, ? super LockMode> locks, Map<? super LockDescriptor, ? super LockClient> failedLocks) throws InterruptedException {
String previousThreadName = null;
try {
previousThreadName = updateThreadName(request);
for (Entry<LockDescriptor, LockMode> entry : request.getLockDescriptors().entries()) {
if (blockingMode == BlockingMode.BLOCK_INDEFINITELY_THEN_RELEASE && !descriptorToLockMap.asMap().containsKey(entry.getKey())) {
continue;
}
ClientAwareReadWriteLock lock;
try {
lock = descriptorToLockMap.get(entry.getKey());
} catch (ExecutionException e) {
throw new RuntimeException(e.getCause());
}
if (locks.containsKey(lock)) {
// This is the 2nd time we are calling tryLocks and we already locked this one.
continue;
}
long startTime = System.currentTimeMillis();
@Nullable LockClient currentHolder = tryLock(lock.get(client, entry.getValue()), blockingMode, deadline);
if (log.isDebugEnabled() || isSlowLogEnabled()) {
long responseTimeMillis = System.currentTimeMillis() - startTime;
logSlowLockAcquisition(entry.getKey().toString(), currentHolder, responseTimeMillis);
}
if (currentHolder == null) {
locks.put(lock, entry.getValue());
} else {
failedLocks.put(entry.getKey(), currentHolder);
if (lockGroupBehavior == LOCK_ALL_OR_NONE) {
return;
}
}
}
} finally {
if (previousThreadName != null) {
tryRenameThread(previousThreadName);
}
}
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LegacyTimelockServiceTest method mockImmutableTsLockResponse.
private LockRefreshToken mockImmutableTsLockResponse() throws InterruptedException {
LockDescriptor descriptor = AtlasTimestampLockDescriptor.of(FRESH_TIMESTAMP);
com.palantir.lock.LockRequest expectedRequest = com.palantir.lock.LockRequest.builder(ImmutableSortedMap.of(descriptor, LockMode.READ)).withLockedInVersionId(FRESH_TIMESTAMP).build();
LockRefreshToken expectedToken = new LockRefreshToken(BigInteger.ONE, 123L);
when(lockService.lock(LOCK_CLIENT.getClientId(), expectedRequest)).thenReturn(expectedToken);
return expectedToken;
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceSerDeTest method testSerialisationAndDeserialisationOfLockResponseWithLockHolders.
@Test
public void testSerialisationAndDeserialisationOfLockResponseWithLockHolders() throws Exception {
HeldLocksToken token = LockServiceTestUtils.getFakeHeldLocksToken("client A", "Fake thread", new BigInteger("1"), "held-lock-1", "logger-lock");
Map<LockDescriptor, LockClient> lockHolders = ImmutableMap.of(StringLockDescriptor.of("lock_id"), LockClient.ANONYMOUS, StringLockDescriptor.of("lock_id2"), LockClient.of("client"));
LockResponse response = new LockResponse(token, lockHolders);
ObjectMapper mapper = new ObjectMapper();
LockResponse deserializedLockResponse = mapper.readValue(mapper.writeValueAsString(response), LockResponse.class);
assertEquals(lockHolders, deserializedLockResponse.getLockHolders());
}
Aggregations