use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class PartitionedFileSetDataset method onFailure.
@Override
public void onFailure() throws DataSetException {
try {
rollbackPartitionOperations();
((FileSetDataset) files).onFailure();
} catch (Throwable caught) {
Throwables.propagateIfPossible(caught, DataSetException.class);
throw new DataSetException("Unable to rollback", caught);
}
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class PartitionedFileSetDataset method assertNotExists.
// Throws PartitionAlreadyExistsException if the partition key already exists.
// Otherwise, returns the rowkey corresponding to the PartitionKey.
@ReadOnly
byte[] assertNotExists(PartitionKey key, boolean supportNonTransactional) {
byte[] rowKey = generateRowKey(key, partitioning);
if (tx == null && supportNonTransactional) {
if (LOG.isWarnEnabled()) {
StringBuilder sb = new StringBuilder();
for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) {
sb.append("\n\tat ").append(stackTraceElement.toString());
}
SAMPLING_LOG.warn("Operation should be performed within a transaction. " + "This operation may require a transaction in the future. {}", sb);
}
// to handle backwards compatibility (user might have called PartitionedFileSet#getPartitionOutput outside
// of a transaction), we can't check partition existence via the partitionsTable. As an fallback approach,
// check the filesystem.
Location partitionLocation = files.getLocation(getOutputPath(key));
if (exists(partitionLocation)) {
throw new DataSetException(String.format("Location %s for partition key %s already exists: ", partitionLocation, key));
}
} else {
Row row = partitionsTable.get(rowKey);
if (!row.isEmpty()) {
throw new PartitionAlreadyExistsException(getName(), key);
}
}
return rowKey;
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class PartitionedFileSetDataset method getOutputFormatConfiguration.
@Override
public Map<String, String> getOutputFormatConfiguration() {
checkNotExternal();
// copy the output properties of the embedded file set to the output arguments
Map<String, String> outputArgs = new HashMap<>(files.getOutputFormatConfiguration());
// we set the file set's output path in the definition's getDataset(), so there is no need to configure it again.
// here we just want to validate that an output partition key or dynamic partitioner was specified in the arguments.
PartitionKey outputKey = PartitionedFileSetArguments.getOutputPartitionKey(runtimeArguments, getPartitioning());
if (outputKey == null) {
String dynamicPartitionerClassName = PartitionedFileSetArguments.getDynamicPartitioner(runtimeArguments);
if (dynamicPartitionerClassName == null) {
throw new DataSetException("Either a Partition key or a DynamicPartitioner class must be given as a runtime argument.");
}
copyDynamicPartitionerArguments(runtimeArguments, outputArgs);
outputArgs.put(Constants.Dataset.Partitioned.HCONF_ATTR_OUTPUT_FORMAT_CLASS_NAME, files.getOutputFormatClassName());
outputArgs.put(Constants.Dataset.Partitioned.HCONF_ATTR_OUTPUT_DATASET, getName());
} else {
assertNotExists(outputKey, true);
}
return ImmutableMap.copyOf(outputArgs);
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class BufferingTable method compareAndSwap.
@ReadWrite
@Override
public boolean compareAndSwap(byte[] row, byte[] column, byte[] expectedValue, byte[] newValue) {
ensureTransactionIsStarted();
// TODO: add support for empty values; see https://issues.cask.co/browse/TEPHRA-45 for details.
if (newValue != null && newValue.length == 0) {
warnAboutEmptyValue(column);
}
// NOTE: there is more efficient way to do it, but for now we want more simple implementation, not over-optimizing
byte[][] columns = new byte[][] { column };
try {
byte[] currentValue = getRowMap(row, columns).get(column);
reportRead(1);
if (Arrays.equals(expectedValue, currentValue)) {
putInternal(row, columns, new byte[][] { newValue });
reportWrite(1, getSize(row) + getSize(column) + getSize(newValue));
return true;
}
} catch (Exception e) {
LOG.debug("compareAndSwap failed for table: " + getTransactionAwareName() + ", row: " + Bytes.toStringBinary(row), e);
throw new DataSetException("compareAndSwap failed", e);
}
return false;
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class BufferingTable method delete.
/**
* NOTE: Depending on the use-case, calling this method may be much less efficient than calling same method
* with columns as parameters because it will require a round trip to persistent store.
*/
@WriteOnly
@Override
public void delete(byte[] row) {
ensureTransactionIsStarted();
// this is going to be expensive, but the only we can do as delete implementation act on per-column level
try {
Map<byte[], byte[]> rowMap = getRowMap(row);
delete(row, rowMap.keySet().toArray(new byte[rowMap.keySet().size()][]));
// "0" because we don't know what gets deleted
reportWrite(1, 0);
} catch (Exception e) {
LOG.debug("delete failed for table: " + getTransactionAwareName() + ", row: " + Bytes.toStringBinary(row), e);
throw new DataSetException("delete failed", e);
}
}
Aggregations