use of io.cdap.cdap.api.annotation.WriteOnly in project cdap by caskdata.
the class IndexedTable method delete.
@WriteOnly
@Override
public void delete(byte[] row, byte[][] columns) {
Row existingRow = table.get(row, columns);
if (existingRow.isEmpty()) {
// no row to delete
return;
}
// delete all index entries
deleteIndexEntries(existingRow);
// delete the row's columns
table.delete(row, columns);
}
use of io.cdap.cdap.api.annotation.WriteOnly in project cdap by caskdata.
the class IndexedObjectStore method write.
/**
* Writes to the dataset, deleting any existing secondaryKey corresponding to the key and updates the indexTable with
* the secondaryKey that is passed.
*
* @param key key for storing the object
* @param object object to be stored
* @param secondaryKeys indices that can be used to lookup the object
*/
@WriteOnly
public void write(byte[] key, T object, byte[][] secondaryKeys) {
writeToObjectStore(key, object);
// Update the secondaryKeys
// logic:
// - Get existing secondary keys
// - Compute diff between existing secondary keys and new secondary keys
// - Remove the secondaryKeys that are removed
// - Add the new keys that are added
Row row = index.get(getPrefixedPrimaryKey(key));
Set<byte[]> existingSecondaryKeys = new TreeSet<>(Bytes.BYTES_COMPARATOR);
if (!row.isEmpty()) {
existingSecondaryKeys = row.getColumns().keySet();
}
Set<byte[]> newSecondaryKeys = new TreeSet<>(Bytes.BYTES_COMPARATOR);
newSecondaryKeys.addAll(Arrays.asList(secondaryKeys));
List<byte[]> secondaryKeysDeleted = secondaryKeysToDelete(existingSecondaryKeys, newSecondaryKeys);
if (secondaryKeysDeleted.size() > 0) {
deleteSecondaryKeys(key, secondaryKeysDeleted.toArray(new byte[secondaryKeysDeleted.size()][]));
}
List<byte[]> secondaryKeysAdded = secondaryKeysToAdd(existingSecondaryKeys, newSecondaryKeys);
// for each key store the secondaryKey. This will be used while deleting old index values.
if (secondaryKeysAdded.size() > 0) {
byte[][] fooValues = new byte[secondaryKeysAdded.size()][];
Arrays.fill(fooValues, EMPTY_VALUE);
index.put(getPrefixedPrimaryKey(key), secondaryKeysAdded.toArray(new byte[secondaryKeysAdded.size()][]), fooValues);
}
for (byte[] secondaryKey : secondaryKeysAdded) {
// update the index.
index.put(secondaryKey, key, EMPTY_VALUE);
}
}
use of io.cdap.cdap.api.annotation.WriteOnly 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);
}
}
use of io.cdap.cdap.api.annotation.WriteOnly in project cdap by caskdata.
the class IndexedTable method put.
@WriteOnly
@Override
public void put(byte[] row, byte[] column, byte[] value) {
Put put = new Put(row);
put.add(column, value);
put(put);
}
use of io.cdap.cdap.api.annotation.WriteOnly in project cdap by caskdata.
the class IndexedTable method delete.
@WriteOnly
@Override
public void delete(byte[] row) {
Row existingRow = table.get(row);
if (existingRow.isEmpty()) {
// no row to delete
return;
}
// delete all index entries
deleteIndexEntries(existingRow);
// delete the row
table.delete(row);
}
Aggregations