Search in sources :

Example 11 with Sha256Hash

use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.

the class UserPhotosStreamStore method putHashIndexTask.

private void putHashIndexTask(Transaction t, Map<UserPhotosStreamMetadataTable.UserPhotosStreamMetadataRow, StreamMetadata> rowsToMetadata) {
    Multimap<UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxRow, UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxColumnValue> indexMap = HashMultimap.create();
    for (Entry<UserPhotosStreamMetadataTable.UserPhotosStreamMetadataRow, StreamMetadata> e : rowsToMetadata.entrySet()) {
        UserPhotosStreamMetadataTable.UserPhotosStreamMetadataRow 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());
        }
        UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxRow hashRow = UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxRow.of(hash);
        UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxColumn column = UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxColumn.of(row.getId());
        UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxColumnValue columnValue = UserPhotosStreamHashAidxTable.UserPhotosStreamHashAidxColumnValue.of(column, 0L);
        indexMap.put(hashRow, columnValue);
    }
    UserPhotosStreamHashAidxTable hiTable = tables.getUserPhotosStreamHashAidxTable(t);
    hiTable.put(indexMap);
}
Also used : Sha256Hash(com.palantir.util.crypto.Sha256Hash) StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata)

Example 12 with Sha256Hash

use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.

the class ProfileStoreTest method storeImage.

private void storeImage(final UUID userId) {
    runWithRetry(store -> {
        Sha256Hash imageHash = Sha256Hash.computeHash(IMAGE);
        store.updateImage(userId, imageHash, new ByteArrayInputStream(IMAGE));
        UserProfile storedData = store.getUserData(userId);
        Assert.assertEquals(USER, storedData);
        return null;
    });
}
Also used : UserProfile(com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile) ByteArrayInputStream(java.io.ByteArrayInputStream) Sha256Hash(com.palantir.util.crypto.Sha256Hash)

Example 13 with Sha256Hash

use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.

the class AllValueTypesTestTable method getColumn4s.

public Map<AllValueTypesTestRow, Sha256Hash> getColumn4s(Collection<AllValueTypesTestRow> rows) {
    Map<Cell, AllValueTypesTestRow> cells = Maps.newHashMapWithExpectedSize(rows.size());
    for (AllValueTypesTestRow row : rows) {
        cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("c4")), row);
    }
    Map<Cell, byte[]> results = t.get(tableRef, cells.keySet());
    Map<AllValueTypesTestRow, Sha256Hash> ret = Maps.newHashMapWithExpectedSize(results.size());
    for (Entry<Cell, byte[]> e : results.entrySet()) {
        Sha256Hash val = Column4.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue();
        ret.put(cells.get(e.getKey()), val);
    }
    return ret;
}
Also used : Sha256Hash(com.palantir.util.crypto.Sha256Hash) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 14 with Sha256Hash

use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.

the class AbstractPersistentStreamStore method storeStream.

@Override
public Pair<Long, Sha256Hash> storeStream(InputStream stream) {
    // Store empty metadata before doing anything
    long id = storeEmptyMetadata();
    StreamMetadata metadata = storeBlocksAndGetFinalMetadata(null, id, stream);
    storeMetadataAndIndex(id, metadata);
    return Pair.create(id, new Sha256Hash(metadata.getHash().toByteArray()));
}
Also used : StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata) Sha256Hash(com.palantir.util.crypto.Sha256Hash)

Example 15 with Sha256Hash

use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.

the class ValueStreamStore method lookupStreamIdsByHash.

@Override
public Map<Sha256Hash, Long> lookupStreamIdsByHash(Transaction t, final Set<Sha256Hash> hashes) {
    if (hashes.isEmpty()) {
        return ImmutableMap.of();
    }
    ValueStreamHashAidxTable idx = tables.getValueStreamHashAidxTable(t);
    Set<ValueStreamHashAidxTable.ValueStreamHashAidxRow> rows = getHashIndexRowsForHashes(hashes);
    Multimap<ValueStreamHashAidxTable.ValueStreamHashAidxRow, ValueStreamHashAidxTable.ValueStreamHashAidxColumnValue> m = idx.getRowsMultimap(rows);
    Map<Long, Sha256Hash> hashForStreams = Maps.newHashMap();
    for (ValueStreamHashAidxTable.ValueStreamHashAidxRow r : m.keySet()) {
        for (ValueStreamHashAidxTable.ValueStreamHashAidxColumnValue v : m.get(r)) {
            Long streamId = v.getColumnName().getStreamId();
            Sha256Hash hash = r.getHash();
            if (hashForStreams.containsKey(streamId)) {
                AssertUtils.assertAndLog(log, hashForStreams.get(streamId).equals(hash), "(BUG) Stream ID has 2 different hashes: " + streamId);
            }
            hashForStreams.put(streamId, hash);
        }
    }
    Map<Long, StreamMetadata> metadata = getMetadata(t, hashForStreams.keySet());
    Map<Sha256Hash, Long> ret = Maps.newHashMap();
    for (Map.Entry<Long, StreamMetadata> e : metadata.entrySet()) {
        if (e.getValue().getStatus() != Status.STORED) {
            continue;
        }
        Sha256Hash hash = hashForStreams.get(e.getKey());
        ret.put(hash, e.getKey());
    }
    return ret;
}
Also used : Sha256Hash(com.palantir.util.crypto.Sha256Hash) StreamMetadata(com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Sha256Hash (com.palantir.util.crypto.Sha256Hash)40 StreamMetadata (com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata)27 Map (java.util.Map)13 ImmutableMap (com.google.common.collect.ImmutableMap)11 ByteString (com.google.protobuf.ByteString)9 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LinkedHashMap (java.util.LinkedHashMap)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)4 Value (com.palantir.atlasdb.keyvalue.api.Value)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 List (java.util.List)3 SortedMap (java.util.SortedMap)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)2 StreamTestStreamHashAidxTable (com.palantir.atlasdb.schema.stream.generated.StreamTestStreamHashAidxTable)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 NavigableMap (java.util.NavigableMap)2