use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.
the class HotspottyDataStreamStore method lookupStreamIdsByHash.
@Override
public Map<Sha256Hash, Long> lookupStreamIdsByHash(Transaction t, final Set<Sha256Hash> hashes) {
if (hashes.isEmpty()) {
return ImmutableMap.of();
}
HotspottyDataStreamHashAidxTable idx = tables.getHotspottyDataStreamHashAidxTable(t);
Set<HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow> rows = getHashIndexRowsForHashes(hashes);
Multimap<HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow, HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumnValue> m = idx.getRowsMultimap(rows);
Map<Long, Sha256Hash> hashForStreams = Maps.newHashMap();
for (HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow r : m.keySet()) {
for (HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumnValue 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;
}
use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.
the class HotspottyDataStreamStore method deleteStreams.
/**
* This should only be used from the cleanup tasks.
*/
void deleteStreams(Transaction t, final Set<Long> streamIds) {
if (streamIds.isEmpty()) {
return;
}
Set<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow> smRows = Sets.newHashSet();
Multimap<HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow, HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumn> shToDelete = HashMultimap.create();
for (Long streamId : streamIds) {
smRows.add(HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow.of(streamId));
}
HotspottyDataStreamMetadataTable table = tables.getHotspottyDataStreamMetadataTable(t);
Map<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> metadatas = table.getMetadatas(smRows);
Set<HotspottyDataStreamValueTable.HotspottyDataStreamValueRow> streamValueToDelete = Sets.newHashSet();
for (Entry<HotspottyDataStreamMetadataTable.HotspottyDataStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
Long streamId = e.getKey().getId();
long blocks = getNumberOfBlocksFromMetadata(e.getValue());
for (long i = 0; i < blocks; i++) {
streamValueToDelete.add(HotspottyDataStreamValueTable.HotspottyDataStreamValueRow.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);
}
HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow hashRow = HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxRow.of(hash);
HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumn column = HotspottyDataStreamHashAidxTable.HotspottyDataStreamHashAidxColumn.of(streamId);
shToDelete.put(hashRow, column);
}
tables.getHotspottyDataStreamHashAidxTable(t).delete(shToDelete);
tables.getHotspottyDataStreamValueTable(t).delete(streamValueToDelete);
table.delete(smRows);
}
use of com.palantir.util.crypto.Sha256Hash 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);
}
use of com.palantir.util.crypto.Sha256Hash 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);
}
use of com.palantir.util.crypto.Sha256Hash in project atlasdb by palantir.
the class StreamTestMaxMemStreamStore method putHashIndexTask.
private void putHashIndexTask(Transaction t, Map<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> rowsToMetadata) {
Multimap<StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxRow, StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumnValue> indexMap = HashMultimap.create();
for (Entry<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> e : rowsToMetadata.entrySet()) {
StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow 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());
}
StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxRow hashRow = StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxRow.of(hash);
StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumn column = StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumn.of(row.getId());
StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumnValue columnValue = StreamTestMaxMemStreamHashAidxTable.StreamTestMaxMemStreamHashAidxColumnValue.of(column, 0L);
indexMap.put(hashRow, columnValue);
}
StreamTestMaxMemStreamHashAidxTable hiTable = tables.getStreamTestMaxMemStreamHashAidxTable(t);
hiTable.put(indexMap);
}
Aggregations