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);
}
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;
});
}
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;
}
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()));
}
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;
}
Aggregations