use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException in project atlasdb by palantir.
the class UpdateExecutor method update.
public void update(Cell cell, long ts, byte[] oldValue, byte[] newValue) {
Object[] args = new Object[] { cell.getRowName(), cell.getColumnName(), ts, newValue, cell.getRowName(), cell.getColumnName(), ts, oldValue };
String prefixedTableName = prefixedTableNames.get(tableRef, conns);
String sqlString = "/* UPDATE (" + prefixedTableName + ") */" + " UPDATE " + prefixedTableName + "" + " SET row_name = ?, col_name = ?, ts = ?, val = ?" + " WHERE row_name = ?" + " AND col_name = ?" + " AND ts = ?" + " AND val = ?";
PalantirSqlConnection connection = (PalantirSqlConnection) conns.get();
while (true) {
int updated = connection.updateCountRowsUnregisteredQuery(sqlString, args);
if (updated != 0) {
return;
}
List<byte[]> currentValue = getCurrentValue(connection, cell, ts, prefixedTableName);
byte[] onlyValue = Iterables.getOnlyElement(currentValue, null);
if (!Arrays.equals(onlyValue, oldValue)) {
throw new CheckAndSetException(cell, tableRef, oldValue, currentValue);
}
}
}
use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException in project atlasdb by palantir.
the class PersistentLockManagerTest method doesNotDeadlockOnShutdownIfLockCannotBeAcquired.
@Test(timeout = 10_000)
// for acquirePersistentLockWithRetry
@SuppressWarnings("FutureReturnValueIgnored")
public void doesNotDeadlockOnShutdownIfLockCannotBeAcquired() throws InterruptedException {
CountDownLatch acquireStarted = new CountDownLatch(1);
when(mockPls.acquireBackupLock(any())).then(inv -> {
acquireStarted.countDown();
throw new CheckAndSetException("foo");
});
executor.submit(manager::acquirePersistentLockWithRetry);
acquireStarted.await();
manager.shutdown();
}
use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException in project atlasdb by palantir.
the class SchemaMetadataServiceImpl method putSchemaMetadata.
@Override
public void putSchemaMetadata(String schemaName, SchemaMetadata schemaMetadata) {
byte[] serializedMetadata = schemaMetadata.persistToBytes();
while (!Thread.currentThread().isInterrupted()) {
Optional<byte[]> existingMetadata = loadMetadataCellFromKeyValueService(schemaName);
CheckAndSetRequest request = existingMetadata.map(existingData -> CheckAndSetRequest.singleCell(AtlasDbConstants.DEFAULT_SCHEMA_METADATA_TABLE, createCellForGivenSchemaName(schemaName), existingData, serializedMetadata)).orElse(CheckAndSetRequest.newCell(AtlasDbConstants.DEFAULT_SCHEMA_METADATA_TABLE, createCellForGivenSchemaName(schemaName), serializedMetadata));
try {
keyValueService.checkAndSet(request);
log.info("Successfully updated the schema metadata to {}.", UnsafeArg.of("committedUpdate", request));
return;
} catch (CheckAndSetException e) {
log.info("Failed to update the schema metadata: {}. Retrying.", UnsafeArg.of("attemptedUpdate", request));
}
}
}
use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException in project atlasdb by palantir.
the class DbKvs method executePutUnlessExists.
private void executePutUnlessExists(CheckAndSetRequest checkAndSetRequest) {
try {
Map<Cell, byte[]> value = ImmutableMap.of(checkAndSetRequest.cell(), checkAndSetRequest.newValue());
putUnlessExists(checkAndSetRequest.table(), value);
} catch (KeyAlreadyExistsException e) {
throw new CheckAndSetException("Value unexpectedly present when running check and set", e);
}
}
use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException in project atlasdb by palantir.
the class LockStoreTest method noErrorIfLockOpenedWhileCreatingTable.
@Test
public void noErrorIfLockOpenedWhileCreatingTable() {
doThrow(new CheckAndSetException("foo", null, null, ImmutableList.of())).when(kvs).checkAndSet(anyObject());
// should not throw
new LockStoreImpl.LockStorePopulator(kvs).populate();
}
Aggregations