Search in sources :

Example 11 with DataSetException

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);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) FileSetDataset(io.cdap.cdap.data2.dataset2.lib.file.FileSetDataset)

Example 12 with DataSetException

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;
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) Row(io.cdap.cdap.api.dataset.table.Row) PartitionAlreadyExistsException(io.cdap.cdap.api.dataset.lib.PartitionAlreadyExistsException) Location(org.apache.twill.filesystem.Location) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Example 13 with DataSetException

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);
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) HashMap(java.util.HashMap) PartitionKey(io.cdap.cdap.api.dataset.lib.PartitionKey)

Example 14 with DataSetException

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;
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) ReadWrite(io.cdap.cdap.api.annotation.ReadWrite)

Example 15 with DataSetException

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);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) WriteOnly(io.cdap.cdap.api.annotation.WriteOnly)

Aggregations

DataSetException (io.cdap.cdap.api.dataset.DataSetException)37 IOException (java.io.IOException)27 ReadOnly (io.cdap.cdap.api.annotation.ReadOnly)7 Map (java.util.Map)6 TransactionFailureException (org.apache.tephra.TransactionFailureException)6 Location (org.apache.twill.filesystem.Location)6 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)5 Result (io.cdap.cdap.api.dataset.table.Result)5 NavigableMap (java.util.NavigableMap)5 Test (org.junit.Test)5 PartitionAlreadyExistsException (io.cdap.cdap.api.dataset.lib.PartitionAlreadyExistsException)4 TimePartitionedFileSet (io.cdap.cdap.api.dataset.lib.TimePartitionedFileSet)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 WriteOnly (io.cdap.cdap.api.annotation.WriteOnly)3 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)3 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)3 Put (io.cdap.cdap.api.dataset.table.Put)3 Row (io.cdap.cdap.api.dataset.table.Row)3 DatasetId (io.cdap.cdap.proto.id.DatasetId)3 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)3