use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class StreamTestWithHashStreamStore method touchMetadataWhileMarkingUsedForConflicts.
@Override
protected void touchMetadataWhileMarkingUsedForConflicts(Transaction t, Iterable<Long> ids) {
StreamTestWithHashStreamMetadataTable metaTable = tables.getStreamTestWithHashStreamMetadataTable(t);
Set<StreamTestWithHashStreamMetadataTable.StreamTestWithHashStreamMetadataRow> rows = Sets.newHashSet();
for (Long id : ids) {
rows.add(StreamTestWithHashStreamMetadataTable.StreamTestWithHashStreamMetadataRow.of(id));
}
Map<StreamTestWithHashStreamMetadataTable.StreamTestWithHashStreamMetadataRow, StreamMetadata> metadatas = metaTable.getMetadatas(rows);
for (Map.Entry<StreamTestWithHashStreamMetadataTable.StreamTestWithHashStreamMetadataRow, 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<StreamTestWithHashStreamMetadataTable.StreamTestWithHashStreamMetadataRow> 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());
}
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class StreamTestWithHashStreamStore method lookupStreamIdsByHash.
@Override
public Map<Sha256Hash, Long> lookupStreamIdsByHash(Transaction t, final Set<Sha256Hash> hashes) {
if (hashes.isEmpty()) {
return ImmutableMap.of();
}
StreamTestWithHashStreamHashAidxTable idx = tables.getStreamTestWithHashStreamHashAidxTable(t);
Set<StreamTestWithHashStreamHashAidxTable.StreamTestWithHashStreamHashAidxRow> rows = getHashIndexRowsForHashes(hashes);
Multimap<StreamTestWithHashStreamHashAidxTable.StreamTestWithHashStreamHashAidxRow, StreamTestWithHashStreamHashAidxTable.StreamTestWithHashStreamHashAidxColumnValue> m = idx.getRowsMultimap(rows);
Map<Long, Sha256Hash> hashForStreams = Maps.newHashMap();
for (StreamTestWithHashStreamHashAidxTable.StreamTestWithHashStreamHashAidxRow r : m.keySet()) {
for (StreamTestWithHashStreamHashAidxTable.StreamTestWithHashStreamHashAidxColumnValue 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.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class TestHashComponentsStreamStore method lookupStreamIdsByHash.
@Override
public Map<Sha256Hash, Long> lookupStreamIdsByHash(Transaction t, final Set<Sha256Hash> hashes) {
if (hashes.isEmpty()) {
return ImmutableMap.of();
}
TestHashComponentsStreamHashAidxTable idx = tables.getTestHashComponentsStreamHashAidxTable(t);
Set<TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow> rows = getHashIndexRowsForHashes(hashes);
Multimap<TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow, TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumnValue> m = idx.getRowsMultimap(rows);
Map<Long, Sha256Hash> hashForStreams = Maps.newHashMap();
for (TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow r : m.keySet()) {
for (TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumnValue 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.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class TestHashComponentsStreamStore method deleteStreams.
/**
* This should only be used from the cleanup tasks.
*/
void deleteStreams(Transaction t, final Set<Long> streamIds) {
if (streamIds.isEmpty()) {
return;
}
Set<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow> smRows = Sets.newHashSet();
Multimap<TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow, TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumn> shToDelete = HashMultimap.create();
for (Long streamId : streamIds) {
smRows.add(TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow.of(streamId));
}
TestHashComponentsStreamMetadataTable table = tables.getTestHashComponentsStreamMetadataTable(t);
Map<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> metadatas = table.getMetadatas(smRows);
Set<TestHashComponentsStreamValueTable.TestHashComponentsStreamValueRow> streamValueToDelete = Sets.newHashSet();
for (Entry<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> e : metadatas.entrySet()) {
Long streamId = e.getKey().getId();
long blocks = getNumberOfBlocksFromMetadata(e.getValue());
for (long i = 0; i < blocks; i++) {
streamValueToDelete.add(TestHashComponentsStreamValueTable.TestHashComponentsStreamValueRow.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);
}
TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow hashRow = TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow.of(hash);
TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumn column = TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumn.of(streamId);
shToDelete.put(hashRow, column);
}
tables.getTestHashComponentsStreamHashAidxTable(t).delete(shToDelete);
tables.getTestHashComponentsStreamValueTable(t).delete(streamValueToDelete);
table.delete(smRows);
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class TestHashComponentsStreamStore method putHashIndexTask.
private void putHashIndexTask(Transaction t, Map<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> rowsToMetadata) {
Multimap<TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow, TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumnValue> indexMap = HashMultimap.create();
for (Entry<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> e : rowsToMetadata.entrySet()) {
TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow 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());
}
TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow hashRow = TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxRow.of(hash);
TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumn column = TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumn.of(row.getId());
TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumnValue columnValue = TestHashComponentsStreamHashAidxTable.TestHashComponentsStreamHashAidxColumnValue.of(column, 0L);
indexMap.put(hashRow, columnValue);
}
TestHashComponentsStreamHashAidxTable hiTable = tables.getTestHashComponentsStreamHashAidxTable(t);
hiTable.put(indexMap);
}
Aggregations