nitsanw commented on code in PR #4402: URL: https://github.com/apache/cassandra/pull/4402#discussion_r2451251700
########## src/java/org/apache/cassandra/io/sstable/SSTableCursorWriter.java: ########## @@ -0,0 +1,681 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.io.sstable; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; + +import com.google.common.primitives.Ints; + +import org.agrona.collections.IntArrayList; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.ClusteringBoundOrBoundary; +import org.apache.cassandra.db.ClusteringPrefix; +import org.apache.cassandra.db.DecoratedKey; +import org.apache.cassandra.db.DeletionTime; +import org.apache.cassandra.db.LivenessInfo; +import org.apache.cassandra.db.SerializationHeader; +import org.apache.cassandra.db.partitions.PartitionStatisticsCollector; +import org.apache.cassandra.db.rows.Cell; +import org.apache.cassandra.db.rows.Cells; +import org.apache.cassandra.db.rows.RangeTombstoneMarker; +import org.apache.cassandra.db.rows.Row; +import org.apache.cassandra.db.rows.Rows; +import org.apache.cassandra.db.rows.SerializationHelper; +import org.apache.cassandra.db.rows.Unfiltered; +import org.apache.cassandra.db.rows.UnfilteredSerializer; +import org.apache.cassandra.dht.IPartitioner; +import org.apache.cassandra.io.FSWriteError; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.io.sstable.format.SSTableWriter; +import org.apache.cassandra.io.sstable.format.SortedTableWriter; +import org.apache.cassandra.io.sstable.format.big.BigFormatPartitionWriter; +import org.apache.cassandra.io.sstable.format.big.BigTableWriter; +import org.apache.cassandra.io.sstable.format.big.RowIndexEntry; +import org.apache.cassandra.io.sstable.metadata.MetadataCollector; +import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.io.util.DataOutputPlus; +import org.apache.cassandra.io.util.SequentialWriter; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.utils.BloomFilter; +import org.apache.cassandra.utils.ByteArrayUtil; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.concurrent.Ref; + +import static org.apache.cassandra.db.rows.UnfilteredSerializer.*; + +public class SSTableCursorWriter implements AutoCloseable +{ + private static final UnfilteredSerializer SERIALIZER = UnfilteredSerializer.serializer; + private static final ColumnMetadata[] EMPTY_COL_META = new ColumnMetadata[0]; + private final SortedTableWriter<?,?> ssTableWriter; + private final SequentialWriter dataWriter; + private final SortedTableWriter.AbstractIndexWriter indexWriter; + private final DeletionTime.Serializer deletionTimeSerializer; + private final MetadataCollector metadataCollector; + private final SerializationHeader serializationHeader; + /** + * See: {@link BloomFilter#reusableIndexes} + */ + private final long[] reusableIndexes = new long[21]; + private final boolean hasStaticColumns; + + private long partitionStart; + // ROW contents, needed because of the order of writing and the var int fields + private int rowFlags; // discovered as we go along + private int rowExtendedFlags; + private final byte[] copyColumnValueBuffer = new byte[4096]; // used to copy cell contents (maybe piecemiel if very large, since we don't have a direct read option) + private final DataOutputBuffer rowHeaderBuffer = new DataOutputBuffer(); // holds the contents between FLAGS and SIZE + private final DataOutputBuffer rowBuffer = new DataOutputBuffer(); + private final DeletionTime openMarker = DeletionTime.build(0,0); + + private final ColumnMetadata[] staticColumns; + private final ColumnMetadata[] regularColumns; + private final IntArrayList missingColumns = new IntArrayList(); + private ColumnMetadata[] columns; // points to static/regular + private int columnsWrittenCount = 0; + private int nextCellIndex = 0; + // Index info + private final DataOutputBuffer rowIndexEntries = new DataOutputBuffer(); + private final IntArrayList rowIndexEntriesOffsets = new IntArrayList(); + private final ClusteringDescriptor rowIndexEntryLastClustering = new ClusteringDescriptor(); + private int indexBlockStartOffset; + private int rowIndexEntryOffset; + private final int indexBlockThreshold; + + + private SSTableCursorWriter( Review Comment: Currently only BIG is supported, so I held off here. I think the index code split can be postponed to the time when the BTI format is supported. It may also be interesting to explore splitting the SSTable write phase and indexing phase so as to allow more flexibility in composing the phases (e.g. index on the fly/index per partition write/index at end of write, parallel index pass etc). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

