adelapena commented on code in PR #1723: URL: https://github.com/apache/cassandra/pull/1723#discussion_r975155200
########## test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java: ########## @@ -20,16 +20,18 @@ import java.util.UUID; import org.junit.Assert; +import org.junit.BeforeClass; Review Comment: Nit: unused import ########## src/java/org/apache/cassandra/db/partitions/BTreePartitionData.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.db.partitions; + +import java.util.Arrays; + +import com.google.common.annotations.VisibleForTesting; + +import org.apache.cassandra.db.DeletionInfo; +import org.apache.cassandra.db.RegularAndStaticColumns; +import org.apache.cassandra.db.rows.EncodingStats; +import org.apache.cassandra.db.rows.Row; +import org.apache.cassandra.db.rows.Rows; +import org.apache.cassandra.utils.ObjectSizes; +import org.apache.cassandra.utils.btree.BTree; + +/** + * Holder of the content of a partition, see AbstractBTreePartition. + * When updating a partition one holder is swapped for another atomically. + */ +public final class BTreePartitionData +{ + public static final BTreePartitionData EMPTY = new BTreePartitionData(RegularAndStaticColumns.NONE, BTree.empty(), DeletionInfo.LIVE, Rows.EMPTY_STATIC_ROW, EncodingStats.NO_STATS); + public static final long UNSHARED_HEAP_SIZE = ObjectSizes.measure(EMPTY); + + + final RegularAndStaticColumns columns; + final DeletionInfo deletionInfo; + // the btree of rows + final Object[] tree; + final Row staticRow; + public final EncodingStats stats; + + BTreePartitionData(RegularAndStaticColumns columns, + Object[] tree, + DeletionInfo deletionInfo, + Row staticRow, + EncodingStats stats) + { + this.columns = columns; + this.tree = tree; + this.deletionInfo = deletionInfo; + this.staticRow = staticRow == null ? Rows.EMPTY_STATIC_ROW : staticRow; + this.stats = stats; + } + + protected BTreePartitionData withColumns(RegularAndStaticColumns columns) + { + return new BTreePartitionData(columns, this.tree, this.deletionInfo, this.staticRow, this.stats); Review Comment: Fine with me. By the way, the method has been marked `protected final` when the class is `final`. Probably we should just change to default visibility, without `final`? ########## test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java: ########## @@ -20,16 +20,18 @@ import java.util.UUID; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; +import org.apache.cassandra.Util; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.db.memtable.Memtable; +import org.apache.cassandra.db.memtable.ShardedSkipListMemtable; Review Comment: Nit: unused import ########## src/java/org/apache/cassandra/db/tries/MemtableTrie.java: ########## @@ -0,0 +1,1039 @@ +/* + * 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.db.tries; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.concurrent.atomic.AtomicReferenceArray; + +import com.google.common.annotations.VisibleForTesting; + +import org.agrona.concurrent.UnsafeBuffer; +import org.apache.cassandra.io.compress.BufferType; +import org.apache.cassandra.io.util.FileUtils; +import org.apache.cassandra.utils.bytecomparable.ByteSource; +import org.apache.cassandra.utils.bytecomparable.ByteComparable; +import org.apache.cassandra.utils.ObjectSizes; +import org.github.jamm.MemoryLayoutSpecification; + +/** + * Memtable trie, i.e. an in-memory trie built for fast modification and reads executing concurrently with writes from + * a single mutator thread. + * + * Writes to this should be atomic (i.e. reads should see either the content before the write, or the content after the + * write; if any read sees the write, then any subsequent (i.e. started after it completed) read should also see it). + * This implementation does not currently guarantee this, but we still get the desired result as `apply` is only used + * with singleton tries. + */ +public class MemtableTrie<T> extends MemtableReadTrie<T> +{ + // See the trie format description in MemtableReadTrie. + + /** + * Trie size limit. This is not enforced, but users must check from time to time that it is not exceeded (using + * reachedAllocatedSizeThreshold()) and start switching to a new trie if it is. + * This must be done to avoid tries growing beyond their hard 2GB size limit (due to the 32-bit pointers). + */ + private static final int ALLOCATED_SIZE_THRESHOLD; + static + { + String propertyName = "dse.trie_size_limit_mb"; + // Default threshold + 10% == 1 GB. Adjusted slightly up to avoid a tiny final allocation for the 2G max. + int limitInMB = Integer.parseInt(System.getProperty(propertyName, + Integer.toString(1024 * 10 / 11 + 1))); + if (limitInMB < 1 || limitInMB > 2047) + throw new AssertionError(propertyName + " must be within 1 and 2047"); + ALLOCATED_SIZE_THRESHOLD = 1024 * 1024 * limitInMB; + } + + private int allocatedPos = 0; + private int contentCount = 0; + + private final BufferType bufferType; // on or off heap + + // constants for space calculations + private static final long EMPTY_SIZE_ON_HEAP; + private static final long EMPTY_SIZE_OFF_HEAP; + private static final long REFERENCE_ARRAY_ON_HEAP_SIZE = ObjectSizes.measureDeep(new AtomicReferenceArray<>(0)); + + static + { + MemtableTrie<Object> empty = new MemtableTrie<>(BufferType.ON_HEAP); + EMPTY_SIZE_ON_HEAP = ObjectSizes.measureDeep(empty); + empty = new MemtableTrie<>(BufferType.OFF_HEAP); + EMPTY_SIZE_OFF_HEAP = ObjectSizes.measureDeep(empty); + } + + public MemtableTrie(BufferType bufferType) + { + super(new UnsafeBuffer[31 - BUF_START_SHIFT], // last one is 1G for a total of ~2G bytes + new AtomicReferenceArray[29 - CONTENTS_START_SHIFT], // takes at least 4 bytes to write pointer to one content -> 4 times smaller than buffers + NONE); + this.bufferType = bufferType; + assert INITIAL_BUFFER_CAPACITY % BLOCK_SIZE == 0; + } + + // Buffer, content list and block management + + public static class SpaceExhaustedException extends Exception + { + public SpaceExhaustedException() + { + super("The hard 2GB limit on trie size has been exceeded"); + } + } + + final void putInt(int pos, int value) + { + getChunk(pos).putInt(inChunkPointer(pos), value); + } + + final void putIntOrdered(int pos, int value) + { + getChunk(pos).putIntOrdered(inChunkPointer(pos), value); + } Review Comment: This method doesn't seem to have any callers ########## src/java/org/apache/cassandra/db/tries/TrieEntriesIterator.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.db.tries; + +import java.util.AbstractMap; +import java.util.Arrays; Review Comment: Nit: unused import -- 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]

