Search in sources :

Example 1 with BigTableZeroCopyWriter

use of org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter in project cassandra by apache.

the class CassandraEntireSSTableStreamReader method read.

/**
 * @param in where this reads data from
 * @return SSTable transferred
 * @throws IOException if reading the remote sstable fails. Will throw an RTE if local write fails.
 */
// input needs to remain open, streams on top of it can't be closed
@SuppressWarnings("resource")
@Override
public SSTableMultiWriter read(DataInputPlus in) throws Throwable {
    ColumnFamilyStore cfs = ColumnFamilyStore.getIfExists(tableId);
    if (cfs == null) {
        // schema was dropped during streaming
        throw new IOException("Table " + tableId + " was dropped during streaming");
    }
    ComponentManifest manifest = header.componentManifest;
    long totalSize = manifest.totalSize();
    logger.debug("[Stream #{}] Started receiving sstable #{} from {}, size = {}, table = {}", session.planId(), fileSequenceNumber, session.peer, prettyPrintMemory(totalSize), cfs.metadata());
    BigTableZeroCopyWriter writer = null;
    try {
        writer = createWriter(cfs, totalSize, manifest.components());
        long bytesRead = 0;
        for (Component component : manifest.components()) {
            long length = manifest.sizeOf(component);
            logger.debug("[Stream #{}] Started receiving {} component from {}, componentSize = {}, readBytes = {}, totalSize = {}", session.planId(), component, session.peer, prettyPrintMemory(length), prettyPrintMemory(bytesRead), prettyPrintMemory(totalSize));
            writer.writeComponent(component.type, in, length);
            session.progress(writer.descriptor.filenameFor(component), ProgressInfo.Direction.IN, length, length);
            bytesRead += length;
            logger.debug("[Stream #{}] Finished receiving {} component from {}, componentSize = {}, readBytes = {}, totalSize = {}", session.planId(), component, session.peer, prettyPrintMemory(length), prettyPrintMemory(bytesRead), prettyPrintMemory(totalSize));
        }
        UnaryOperator<StatsMetadata> transform = stats -> stats.mutateLevel(header.sstableLevel).mutateRepairedMetadata(messageHeader.repairedAt, messageHeader.pendingRepair, false);
        String description = String.format("level %s and repairedAt time %s and pendingRepair %s", header.sstableLevel, messageHeader.repairedAt, messageHeader.pendingRepair);
        writer.descriptor.getMetadataSerializer().mutate(writer.descriptor, description, transform);
        return writer;
    } catch (Throwable e) {
        logger.error("[Stream {}] Error while reading sstable from stream for table = {}", session.planId(), cfs.metadata(), e);
        if (writer != null)
            e = writer.abort(e);
        throw e;
    }
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) BigTableZeroCopyWriter(org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter) Logger(org.slf4j.Logger) ProgressInfo(org.apache.cassandra.streaming.ProgressInfo) TableId(org.apache.cassandra.schema.TableId) StreamReceiver(org.apache.cassandra.streaming.StreamReceiver) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) File(org.apache.cassandra.io.util.File) IOException(java.io.IOException) UnaryOperator(java.util.function.UnaryOperator) FBUtilities.prettyPrintMemory(org.apache.cassandra.utils.FBUtilities.prettyPrintMemory) String.format(java.lang.String.format) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader) SSTableMultiWriter(org.apache.cassandra.io.sstable.SSTableMultiWriter) StreamSession(org.apache.cassandra.streaming.StreamSession) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) LifecycleNewTracker(org.apache.cassandra.db.lifecycle.LifecycleNewTracker) Component(org.apache.cassandra.io.sstable.Component) Descriptor(org.apache.cassandra.io.sstable.Descriptor) SSTableFormat(org.apache.cassandra.io.sstable.format.SSTableFormat) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) Directories(org.apache.cassandra.db.Directories) BigTableZeroCopyWriter(org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) IOException(java.io.IOException) Component(org.apache.cassandra.io.sstable.Component)

Example 2 with BigTableZeroCopyWriter

use of org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter in project cassandra by apache.

the class CassandraEntireSSTableStreamReader method createWriter.

@SuppressWarnings("resource")
protected BigTableZeroCopyWriter createWriter(ColumnFamilyStore cfs, long totalSize, Collection<Component> components) throws IOException {
    File dataDir = getDataDir(cfs, totalSize);
    StreamReceiver streamReceiver = session.getAggregator(tableId);
    assert streamReceiver instanceof CassandraStreamReceiver;
    LifecycleNewTracker lifecycleNewTracker = CassandraStreamReceiver.fromReceiver(session.getAggregator(tableId)).createLifecycleNewTracker();
    Descriptor desc = cfs.newSSTableDescriptor(dataDir, header.version, header.format);
    logger.debug("[Table #{}] {} Components to write: {}", cfs.metadata(), desc.filenameFor(Component.DATA), components);
    return new BigTableZeroCopyWriter(desc, cfs.metadata, lifecycleNewTracker, components);
}
Also used : LifecycleNewTracker(org.apache.cassandra.db.lifecycle.LifecycleNewTracker) StreamReceiver(org.apache.cassandra.streaming.StreamReceiver) BigTableZeroCopyWriter(org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter) Descriptor(org.apache.cassandra.io.sstable.Descriptor) File(org.apache.cassandra.io.util.File)

Aggregations

LifecycleNewTracker (org.apache.cassandra.db.lifecycle.LifecycleNewTracker)2 Descriptor (org.apache.cassandra.io.sstable.Descriptor)2 BigTableZeroCopyWriter (org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter)2 File (org.apache.cassandra.io.util.File)2 StreamReceiver (org.apache.cassandra.streaming.StreamReceiver)2 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 UnaryOperator (java.util.function.UnaryOperator)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Directories (org.apache.cassandra.db.Directories)1 Component (org.apache.cassandra.io.sstable.Component)1 SSTableMultiWriter (org.apache.cassandra.io.sstable.SSTableMultiWriter)1 SSTableFormat (org.apache.cassandra.io.sstable.format.SSTableFormat)1 StatsMetadata (org.apache.cassandra.io.sstable.metadata.StatsMetadata)1 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)1 TableId (org.apache.cassandra.schema.TableId)1 ProgressInfo (org.apache.cassandra.streaming.ProgressInfo)1 StreamSession (org.apache.cassandra.streaming.StreamSession)1 StreamMessageHeader (org.apache.cassandra.streaming.messages.StreamMessageHeader)1