Search in sources :

Example 36 with StreamMetadata

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

the class ValueStreamStore method touchMetadataWhileMarkingUsedForConflicts.

@Override
protected void touchMetadataWhileMarkingUsedForConflicts(Transaction t, Iterable<Long> ids) {
    ValueStreamMetadataTable metaTable = tables.getValueStreamMetadataTable(t);
    Set<ValueStreamMetadataTable.ValueStreamMetadataRow> rows = Sets.newHashSet();
    for (Long id : ids) {
        rows.add(ValueStreamMetadataTable.ValueStreamMetadataRow.of(id));
    }
    Map<ValueStreamMetadataTable.ValueStreamMetadataRow, StreamMetadata> metadatas = metaTable.getMetadatas(rows);
    for (Map.Entry<ValueStreamMetadataTable.ValueStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
        StreamMetadata metadata = e.getValue();
        Preconditions.checkState(metadata.getStatus() == Status.STORED, "Stream: " + e.getKey().getId() + " has status: " + metadata.getStatus());
        metaTable.putMetadata(e.getKey(), metadata);
    }
    SetView<ValueStreamMetadataTable.ValueStreamMetadataRow> 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 37 with StreamMetadata

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

the class ValueStreamStore method deleteStreams.

/**
 * This should only be used from the cleanup tasks.
 */
void deleteStreams(Transaction t, final Set<Long> streamIds) {
    if (streamIds.isEmpty()) {
        return;
    }
    Set<ValueStreamMetadataTable.ValueStreamMetadataRow> smRows = Sets.newHashSet();
    Multimap<ValueStreamHashAidxTable.ValueStreamHashAidxRow, ValueStreamHashAidxTable.ValueStreamHashAidxColumn> shToDelete = HashMultimap.create();
    for (Long streamId : streamIds) {
        smRows.add(ValueStreamMetadataTable.ValueStreamMetadataRow.of(streamId));
    }
    ValueStreamMetadataTable table = tables.getValueStreamMetadataTable(t);
    Map<ValueStreamMetadataTable.ValueStreamMetadataRow, StreamMetadata> metadatas = table.getMetadatas(smRows);
    Set<ValueStreamValueTable.ValueStreamValueRow> streamValueToDelete = Sets.newHashSet();
    for (Entry<ValueStreamMetadataTable.ValueStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
        Long streamId = e.getKey().getId();
        long blocks = getNumberOfBlocksFromMetadata(e.getValue());
        for (long i = 0; i < blocks; i++) {
            streamValueToDelete.add(ValueStreamValueTable.ValueStreamValueRow.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);
        }
        ValueStreamHashAidxTable.ValueStreamHashAidxRow hashRow = ValueStreamHashAidxTable.ValueStreamHashAidxRow.of(hash);
        ValueStreamHashAidxTable.ValueStreamHashAidxColumn column = ValueStreamHashAidxTable.ValueStreamHashAidxColumn.of(streamId);
        shToDelete.put(hashRow, column);
    }
    tables.getValueStreamHashAidxTable(t).delete(shToDelete);
    tables.getValueStreamValueTable(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)

Example 38 with StreamMetadata

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

the class StreamTestMaxMemStreamStore method touchMetadataWhileStoringForConflicts.

private void touchMetadataWhileStoringForConflicts(Transaction t, Long id, long blockNumber) {
    StreamTestMaxMemStreamMetadataTable metaTable = tables.getStreamTestMaxMemStreamMetadataTable(t);
    StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow row = StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow.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 39 with StreamMetadata

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

the class StreamTestMaxMemStreamStore method deleteStreams.

/**
 * This should only be used from the cleanup tasks.
 */
void deleteStreams(Transaction t, final Set<Long> streamIds) {
    if (streamIds.isEmpty()) {
        return;
    }
    Set<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow> smRows = Sets.newHashSet();
    Multimap<StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxRow, StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumn> shToDelete = HashMultimap.create();
    for (Long streamId : streamIds) {
        smRows.add(StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow.of(streamId));
    }
    StreamTestMaxMemStreamMetadataTable table = tables.getStreamTestMaxMemStreamMetadataTable(t);
    Map<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> metadatas = table.getMetadatas(smRows);
    Set<StreamTestMaxMemStreamValueTable.StreamTestMaxMemStreamValueRow> streamValueToDelete = Sets.newHashSet();
    for (Entry<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
        Long streamId = e.getKey().getId();
        long blocks = getNumberOfBlocksFromMetadata(e.getValue());
        for (long i = 0; i < blocks; i++) {
            streamValueToDelete.add(StreamTestMaxMemStreamValueTable.StreamTestMaxMemStreamValueRow.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);
        }
        StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxRow hashRow = StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxRow.of(hash);
        StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumn column = StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumn.of(streamId);
        shToDelete.put(hashRow, column);
    }
    tables.getStreamTestMaxMemStreamHashAidxTable(t).delete(shToDelete);
    tables.getStreamTestMaxMemStreamValueTable(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)

Example 40 with StreamMetadata

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

the class StreamTestMaxMemStreamStore method touchMetadataWhileMarkingUsedForConflicts.

@Override
protected void touchMetadataWhileMarkingUsedForConflicts(Transaction t, Iterable<Long> ids) {
    StreamTestMaxMemStreamMetadataTable metaTable = tables.getStreamTestMaxMemStreamMetadataTable(t);
    Set<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow> rows = Sets.newHashSet();
    for (Long id : ids) {
        rows.add(StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow.of(id));
    }
    Map<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> metadatas = metaTable.getMetadatas(rows);
    for (Map.Entry<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, 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<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow> 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)

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