use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class ValueStreamStore method touchMetadataWhileStoringForConflicts.
private void touchMetadataWhileStoringForConflicts(Transaction t, Long id, long blockNumber) {
ValueStreamMetadataTable metaTable = tables.getValueStreamMetadataTable(t);
ValueStreamMetadataTable.ValueStreamMetadataRow row = ValueStreamMetadataTable.ValueStreamMetadataRow.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: " + 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 AbstractPersistentStreamStore method storeStreams.
@Override
public Map<Long, Sha256Hash> storeStreams(final Transaction tx, final Map<Long, InputStream> streams) {
if (streams.isEmpty()) {
return ImmutableMap.of();
}
Map<Long, StreamMetadata> idsToEmptyMetadata = Maps.transformValues(streams, Functions.constant(getEmptyMetadata()));
putMetadataAndHashIndexTask(tx, idsToEmptyMetadata);
Map<Long, StreamMetadata> idsToMetadata = Maps.transformEntries(streams, (id, stream) -> storeBlocksAndGetFinalMetadata(tx, id, stream));
putMetadataAndHashIndexTask(tx, idsToMetadata);
Map<Long, Sha256Hash> hashes = Maps.transformValues(idsToMetadata, metadata -> new Sha256Hash(metadata.getHash().toByteArray()));
return hashes;
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class DataMetadataCleanupTask method cellsCleanedUp.
@Override
public boolean cellsCleanedUp(Transaction t, Set<Cell> cells) {
DataStreamMetadataTable metaTable = tables.getDataStreamMetadataTable(t);
Collection<DataStreamMetadataTable.DataStreamMetadataRow> rows = Lists.newArrayListWithCapacity(cells.size());
for (Cell cell : cells) {
rows.add(DataStreamMetadataTable.DataStreamMetadataRow.BYTES_HYDRATOR.hydrateFromBytes(cell.getRowName()));
}
Map<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> currentMetadata = metaTable.getMetadatas(rows);
Set<Long> toDelete = Sets.newHashSet();
for (Map.Entry<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> e : currentMetadata.entrySet()) {
if (e.getValue().getStatus() != Status.STORED) {
toDelete.add(e.getKey().getId());
}
}
DataStreamStore.of(tables).deleteStreams(t, toDelete);
return false;
}
use of com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata in project atlasdb by palantir.
the class DataStreamStore method lookupStreamIdsByHash.
@Override
public Map<Sha256Hash, Long> lookupStreamIdsByHash(Transaction t, final Set<Sha256Hash> hashes) {
if (hashes.isEmpty()) {
return ImmutableMap.of();
}
DataStreamHashAidxTable idx = tables.getDataStreamHashAidxTable(t);
Set<DataStreamHashAidxTable.DataStreamHashAidxRow> rows = getHashIndexRowsForHashes(hashes);
Multimap<DataStreamHashAidxTable.DataStreamHashAidxRow, DataStreamHashAidxTable.DataStreamHashAidxColumnValue> m = idx.getRowsMultimap(rows);
Map<Long, Sha256Hash> hashForStreams = Maps.newHashMap();
for (DataStreamHashAidxTable.DataStreamHashAidxRow r : m.keySet()) {
for (DataStreamHashAidxTable.DataStreamHashAidxColumnValue 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 DataStreamStore method putMetadataAndHashIndexTask.
@Override
protected void putMetadataAndHashIndexTask(Transaction t, Map<Long, StreamMetadata> streamIdsToMetadata) {
DataStreamMetadataTable mdTable = tables.getDataStreamMetadataTable(t);
Map<Long, StreamMetadata> prevMetadatas = getMetadata(t, streamIdsToMetadata.keySet());
Map<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> rowsToStoredMetadata = Maps.newHashMap();
Map<DataStreamMetadataTable.DataStreamMetadataRow, 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(DataStreamMetadataTable.DataStreamMetadataRow.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(DataStreamMetadataTable.DataStreamMetadataRow.of(streamId), metadata);
}
}
putHashIndexTask(t, rowsToStoredMetadata);
Map<DataStreamMetadataTable.DataStreamMetadataRow, StreamMetadata> rowsToMetadata = Maps.newHashMap();
rowsToMetadata.putAll(rowsToStoredMetadata);
rowsToMetadata.putAll(rowsToUnstoredMetadata);
mdTable.putMetadata(rowsToMetadata);
}
Aggregations