use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class DataStreamStore method putHashIndexTask.
private void putHashIndexTask(Transaction t, Map<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> rowsToMetadata) {
Multimap<DataStreamHashAidxTable.DataStreamHashAidxRow, DataStreamHashAidxTable.DataStreamHashAidxColumnValue> indexMap = HashMultimap.create();
for (Entry<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> e : rowsToMetadata.entrySet()) {
DataStreamMetadataTable.DataStreamMetadataRow 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());
}
DataStreamHashAidxTable.DataStreamHashAidxRow hashRow = DataStreamHashAidxTable.DataStreamHashAidxRow.of(hash);
DataStreamHashAidxTable.DataStreamHashAidxColumn column = DataStreamHashAidxTable.DataStreamHashAidxColumn.of(row.getId());
DataStreamHashAidxTable.DataStreamHashAidxColumnValue columnValue = DataStreamHashAidxTable.DataStreamHashAidxColumnValue.of(column, 0L);
indexMap.put(hashRow, columnValue);
}
DataStreamHashAidxTable hiTable = tables.getDataStreamHashAidxTable(t);
hiTable.put(indexMap);
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class TestHashComponentsMetadataCleanupTask method cellsCleanedUp.
@Override
public boolean cellsCleanedUp(Transaction t, Set<Cell> cells) {
TestHashComponentsStreamMetadataTable metaTable = tables.getTestHashComponentsStreamMetadataTable(t);
Collection<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow> rows = Lists.newArrayListWithCapacity(cells.size());
for (Cell cell : cells) {
rows.add(TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow.BYTES_HYDRATOR.hydrateFromBytes(cell.getRowName()));
}
Map<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> currentMetadata = metaTable.getMetadatas(rows);
Set<Long> toDelete = Sets.newHashSet();
for (Map.Entry<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> e : currentMetadata.entrySet()) {
if (e.getValue().getStatus() != Status.STORED) {
toDelete.add(e.getKey().getId());
}
}
TestHashComponentsStreamStore.of(tables).deleteStreams(t, toDelete);
return false;
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class TestHashComponentsStreamStore method putMetadataAndHashIndexTask.
@Override
protected void putMetadataAndHashIndexTask(Transaction t, Map<Long, StreamMetadata> streamIdsToMetadata) {
TestHashComponentsStreamMetadataTable mdTable = tables.getTestHashComponentsStreamMetadataTable(t);
Map<Long, StreamMetadata> prevMetadatas = getMetadata(t, streamIdsToMetadata.keySet());
Map<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> rowsToStoredMetadata = Maps.newHashMap();
Map<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> rowsToUnstoredMetadata = Maps.newHashMap();
for (Entry<Long, StreamMetadata> e : streamIdsToMetadata.entrySet()) {
long streamId = e.getKey();
StreamMetadata metadata = e.getValue();
StreamMetadata prevMetadata = prevMetadatas.get(streamId);
if (metadata.getStatus() == Status.STORED) {
if (prevMetadata == null || prevMetadata.getStatus() != Status.STORING) {
// This can happen if we cleanup old streams.
throw new TransactionFailedRetriableException("Cannot mark a stream as stored that isn't currently storing: " + prevMetadata);
}
rowsToStoredMetadata.put(TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow.of(streamId), metadata);
} else if (metadata.getStatus() == Status.STORING) {
// This will prevent two users trying to store the same id.
if (prevMetadata != null) {
throw new TransactionFailedRetriableException("Cannot reuse the same stream id: " + streamId);
}
rowsToUnstoredMetadata.put(TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow.of(streamId), metadata);
}
}
putHashIndexTask(t, rowsToStoredMetadata);
Map<TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow, StreamMetadata> rowsToMetadata = Maps.newHashMap();
rowsToMetadata.putAll(rowsToStoredMetadata);
rowsToMetadata.putAll(rowsToUnstoredMetadata);
mdTable.putMetadata(rowsToMetadata);
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class TestHashComponentsStreamStore method touchMetadataWhileStoringForConflicts.
private void touchMetadataWhileStoringForConflicts(Transaction t, Long id, long blockNumber) {
TestHashComponentsStreamMetadataTable metaTable = tables.getTestHashComponentsStreamMetadataTable(t);
TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow row = TestHashComponentsStreamMetadataTable.TestHashComponentsStreamMetadataRow.of(id);
StreamMetadata metadata = metaTable.getMetadatas(ImmutableSet.of(row)).values().iterator().next();
Preconditions.checkState(metadata.getStatus() == Status.STORING, "This stream is being cleaned up while storing blocks: %s", id);
Builder builder = StreamMetadata.newBuilder(metadata);
builder.setLength(blockNumber * BLOCK_SIZE_IN_BYTES + 1);
metaTable.putMetadata(row, builder.build());
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class StreamTestMaxMemMetadataCleanupTask method cellsCleanedUp.
@Override
public boolean cellsCleanedUp(Transaction t, Set<Cell> cells) {
StreamTestMaxMemStreamMetadataTable metaTable = tables.getStreamTestMaxMemStreamMetadataTable(t);
Collection<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow> rows = Lists.newArrayListWithCapacity(cells.size());
for (Cell cell : cells) {
rows.add(StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow.BYTES_HYDRATOR.hydrateFromBytes(cell.getRowName()));
}
Map<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> currentMetadata = metaTable.getMetadatas(rows);
Set<Long> toDelete = Sets.newHashSet();
for (Map.Entry<StreamTestMaxMemStreamMetadataTable.StreamTestMaxMemStreamMetadataRow, StreamMetadata> e : currentMetadata.entrySet()) {
if (e.getValue().getStatus() != Status.STORED) {
toDelete.add(e.getKey().getId());
}
}
StreamTestMaxMemStreamStore.of(tables).deleteStreams(t, toDelete);
return false;
}
Aggregations