Search in sources :

Example 61 with StreamMetadata

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

the class AbstractGenericStreamStore method loadStreamAsFile.

@Override
public final File loadStreamAsFile(Transaction transaction, T id) {
    StreamMetadata metadata = getMetadata(transaction, id);
    checkStreamStored(id, metadata);
    return loadToNewTempFile(transaction, id, metadata);
}
Also used : StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata)

Example 62 with StreamMetadata

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

the class AbstractPersistentStreamStore method storeBlocksAndGetHashlessMetadata.

protected final StreamMetadata storeBlocksAndGetHashlessMetadata(@Nullable Transaction tx, long id, InputStream stream) {
    CountingInputStream countingStream = new CountingInputStream(stream);
    // Try to store the bytes in the stream and get length
    try {
        storeBlocksFromStream(tx, id, countingStream);
    } catch (IOException e) {
        long length = countingStream.getCount();
        StreamMetadata metadata = StreamMetadata.newBuilder().setStatus(Status.FAILED).setLength(length).setHash(com.google.protobuf.ByteString.EMPTY).build();
        storeMetadataAndIndex(id, metadata);
        log.error("Could not store stream {}. Failed after {} bytes.", id, length, e);
        throw Throwables.rewrapAndThrowUncheckedException("Failed to store stream.", e);
    }
    long length = countingStream.getCount();
    return StreamMetadata.newBuilder().setStatus(Status.STORED).setLength(length).setHash(com.google.protobuf.ByteString.EMPTY).build();
}
Also used : StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata) CountingInputStream(com.google.common.io.CountingInputStream) IOException(java.io.IOException)

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