use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class AssertLockedKeyValueService method put.
@Override
public void put(TableReference tableRef, Map<Cell, byte[]> values, long timestamp) {
if (tableRef.equals(TransactionConstants.TRANSACTION_TABLE)) {
SortedMap<LockDescriptor, LockMode> mapToAssertLockHeld = Maps.newTreeMap();
SortedMap<LockDescriptor, LockMode> mapToAssertLockNotHeld = Maps.newTreeMap();
for (Map.Entry<Cell, byte[]> e : values.entrySet()) {
LockDescriptor descriptor = AtlasRowLockDescriptor.of(tableRef.getQualifiedName(), e.getKey().getRowName());
if (Arrays.equals(e.getValue(), TransactionConstants.getValueForTimestamp(TransactionConstants.FAILED_COMMIT_TS))) {
mapToAssertLockNotHeld.put(descriptor, LockMode.READ);
} else {
mapToAssertLockHeld.put(descriptor, LockMode.READ);
}
}
try {
if (!mapToAssertLockHeld.isEmpty()) {
LockRequest request = LockRequest.builder(mapToAssertLockHeld).doNotBlock().lockAsManyAsPossible().build();
LockRefreshToken lock = lockService.lock(LockClient.ANONYMOUS.getClientId(), request);
Validate.isTrue(lock == null, "these should already be held");
}
if (!mapToAssertLockNotHeld.isEmpty()) {
LockRequest request = LockRequest.builder(mapToAssertLockNotHeld).doNotBlock().build();
LockRefreshToken lock = lockService.lock(LockClient.ANONYMOUS.getClientId(), request);
Validate.isTrue(lock != null, "these should already be waited for");
}
} catch (InterruptedException e) {
throw Throwables.throwUncheckedException(e);
}
}
super.put(tableRef, values, timestamp);
}
use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class LegacyTimelockService method lockImmutableTimestamp.
@Override
public LockImmutableTimestampResponse lockImmutableTimestamp(LockImmutableTimestampRequest request) {
long immutableLockTs = timestampService.getFreshTimestamp();
LockDescriptor lockDesc = AtlasTimestampLockDescriptor.of(immutableLockTs);
com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder(ImmutableSortedMap.of(lockDesc, LockMode.READ)).withLockedInVersionId(immutableLockTs).build();
LockRefreshToken lock;
try {
lock = lockService.lock(immutableTsLockClient.getClientId(), lockRequest);
} catch (InterruptedException e) {
throw Throwables.throwUncheckedException(e);
}
try {
return LockImmutableTimestampResponse.of(getImmutableTimestampInternal(immutableLockTs), LockTokenConverter.toTokenV2(lock));
} catch (Throwable e) {
if (lock != null) {
lockService.unlock(lock);
}
throw Throwables.rewrapAndThrowUncheckedException(e);
}
}
use of com.palantir.lock.LockRefreshToken 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.LockRefreshToken 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.LockRefreshToken in project atlasdb by palantir.
the class LockTokenConverterTest method assertConversionFromAndToLegacyPreservesId.
private void assertConversionFromAndToLegacyPreservesId(LockRefreshToken lockRefreshToken) {
LockToken tokenV2 = LockTokenConverter.toTokenV2(lockRefreshToken);
LockRefreshToken reconverted = LockTokenConverter.toLegacyToken(tokenV2);
assertThat(reconverted).isEqualTo(lockRefreshToken);
}
Aggregations