Search in sources :

Example 1 with StreamMetadata

use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.

the class HotspottyDataMetadataCleanupTask method cellsCleanedUp.

@Override
public boolean cellsCleanedUp(Transaction t, Set<Cell> cells) {
    HotspottyDataStreamMetadataTable metaTable = tables.getHotspottyDataStreamMetadataTable(t);
    Collection<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow> rows = Lists.newArrayListWithCapacity(cells.size());
    for (Cell cell : cells) {
        rows.add(HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow.BYTES_HYDRATOR.hydrateFromBytes(cell.getRowName()));
    }
    Map<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> currentMetadata = metaTable.getMetadatas(rows);
    Set<Long> toDelete = Sets.newHashSet();
    for (Map.Entry<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> e : currentMetadata.entrySet()) {
        if (e.getValue().getStatus() != Status.STORED) {
            toDelete.add(e.getKey().getId());
        }
    }
    HotspottyDataStreamStore.of(tables).deleteStreams(t, toDelete);
    return false;
}
Also used : StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map)

Example 2 with StreamMetadata

use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.

the class HotspottyDataStreamStore method touchMetadataWhileStoringForConflicts.

private void touchMetadataWhileStoringForConflicts(Transaction t, Long id, long blockNumber) {
    HotspottyDataStreamMetadataTable metaTable = tables.getHotspottyDataStreamMetadataTable(t);
    HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow row = HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow.of(id);
    StreamMetadata metadata = metaTable.getMetadatas(ImmutableSet.of(row)).values().iterator().next();
    Preconditions.checkState(metadata.getStatus() == Status.STORING, "This stream is being cleaned up while storing blocks: %s", id);
    Builder builder = StreamMetadata.newBuilder(metadata);
    builder.setLength(blockNumber * BLOCK_SIZE_IN_BYTES + 1);
    metaTable.putMetadata(row, builder.build());
}
Also used : StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata) Builder(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata.Builder)

Example 3 with StreamMetadata

use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.

the class HotspottyDataStreamStore method putHashIndexTask.

private void putHashIndexTask(Transaction t, Map<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> rowsToMetadata) {
    Multimap<HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow, HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumnValue> indexMap = HashMultimap.create();
    for (Entry<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> e : rowsToMetadata.entrySet()) {
        HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow row = e.getKey();
        StreamMetadata metadata = e.getValue();
        Preconditions.checkArgument(metadata.getStatus() == Status.STORED, "Should only index successfully stored streams.");
        Sha256Hash hash = Sha256Hash.EMPTY;
        if (metadata.getHash() != com.google.protobuf.ByteString.EMPTY) {
            hash = new Sha256Hash(metadata.getHash().toByteArray());
        }
        HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow hashRow = HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow.of(hash);
        HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumn column = HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumn.of(row.getId());
        HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumnValue columnValue = HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumnValue.of(column, 0L);
        indexMap.put(hashRow, columnValue);
    }
    HotspottyDataStreamHashAidxTable hiTable = tables.getHotspottyDataStreamHashAidxTable(t);
    hiTable.put(indexMap);
}
Also used : Sha256Hash(com.palantir.util.crypto.Sha256Hash) StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata)

Example 4 with StreamMetadata

use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.

the class HotspottyDataStreamStore method touchMetadataWhileMarkingUsedForConflicts.

@Override
protected void touchMetadataWhileMarkingUsedForConflicts(Transaction t, Iterable<Long> ids) {
    HotspottyDataStreamMetadataTable metaTable = tables.getHotspottyDataStreamMetadataTable(t);
    Set<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow> rows = Sets.newHashSet();
    for (Long id : ids) {
        rows.add(HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow.of(id));
    }
    Map<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> metadatas = metaTable.getMetadatas(rows);
    for (Map.Entry<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
        StreamMetadata metadata = e.getValue();
        Preconditions.checkState(metadata.getStatus() == Status.STORED, "Stream: %s has status: %s", e.getKey().getId(), metadata.getStatus());
        metaTable.putMetadata(e.getKey(), metadata);
    }
    SetView<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow> missingRows = Sets.difference(rows, metadatas.keySet());
    if (!missingRows.isEmpty()) {
        throw new IllegalStateException("Missing metadata rows for:" + missingRows + " rows: " + rows + " metadata: " + metadatas + " txn timestamp: " + t.getTimestamp());
    }
}
Also used : StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with StreamMetadata

use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.

the class DataStreamStore method deleteStreams.

/**
 * This should only be used from the cleanup tasks.
 */
void deleteStreams(Transaction t, final Set<Long> streamIds) {
    if (streamIds.isEmpty()) {
        return;
    }
    Set<DataStreamMetadataTable.DataStreamMetadataRow> smRows = Sets.newHashSet();
    Multimap<DataStreamHashAidxTable.DataStreamHashAidxRow, DataStreamHashAidxTable.DataStreamHashAidxColumn> shToDelete = HashMultimap.create();
    for (Long streamId : streamIds) {
        smRows.add(DataStreamMetadataTable.DataStreamMetadataRow.of(streamId));
    }
    DataStreamMetadataTable table = tables.getDataStreamMetadataTable(t);
    Map<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> metadatas = table.getMetadatas(smRows);
    Set<DataStreamValueTable.DataStreamValueRow> streamValueToDelete = Sets.newHashSet();
    for (Entry<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
        Long streamId = e.getKey().getId();
        long blocks = getNumberOfBlocksFromMetadata(e.getValue());
        for (long i = 0; i < blocks; i++) {
            streamValueToDelete.add(DataStreamValueTable.DataStreamValueRow.of(streamId, i));
        }
        ByteString streamHash = e.getValue().getHash();
        Sha256Hash hash = Sha256Hash.EMPTY;
        if (streamHash != com.google.protobuf.ByteString.EMPTY) {
            hash = new Sha256Hash(streamHash.toByteArray());
        } else {
            log.error("Empty hash for stream {}", streamId);
        }
        DataStreamHashAidxTable.DataStreamHashAidxRow hashRow = DataStreamHashAidxTable.DataStreamHashAidxRow.of(hash);
        DataStreamHashAidxTable.DataStreamHashAidxColumn column = DataStreamHashAidxTable.DataStreamHashAidxColumn.of(streamId);
        shToDelete.put(hashRow, column);
    }
    tables.getDataStreamHashAidxTable(t).delete(shToDelete);
    tables.getDataStreamValueTable(t).delete(streamValueToDelete);
    table.delete(smRows);
}
Also used : ByteString(com.google.protobuf.ByteString) Sha256Hash(com.palantir.util.crypto.Sha256Hash) StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata)

Aggregations

StreamMetadata (com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata)62 Sha256Hash (com.palantir.util.crypto.Sha256Hash)27 Map (java.util.Map)25 ImmutableMap (com.google.common.collect.ImmutableMap)17 ByteString (com.google.protobuf.ByteString)9 Cell (com.palantir.atlasdb.keyvalue.api.Cell)9 Builder (com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata.Builder)9 TransactionFailedRetriableException (com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException)9 CountingInputStream (com.google.common.io.CountingInputStream)2 IOException (java.io.IOException)2 Functions (com.google.common.base.Functions)1 Preconditions (com.google.common.base.Preconditions)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Collections2 (com.google.common.collect.Collections2)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Multimaps (com.google.common.collect.Multimaps)1