cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefa...@apache.org
Subject [2/6] cassandra git commit: Avoid referencing DatabaseDescriptor in AbstractType
Date Tue, 31 May 2016 13:01:13 GMT
Avoid referencing DatabaseDescriptor in AbstractType

Patch by Alex Petrov; reviewed by Stefania Alborghetti for CASSANDRA-11912


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/57ead56f
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/57ead56f
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/57ead56f

Branch: refs/heads/cassandra-3.7
Commit: 57ead56f3bf03775ecc199de91477610d15c4a44
Parents: 81ffc46
Author: Alex Petrov <oleksandr.petrov@gmail.com>
Authored: Tue May 31 14:52:58 2016 +0200
Committer: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Committed: Tue May 31 14:53:48 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/config/DatabaseDescriptor.java    |  5 ++++
 .../apache/cassandra/db/ClusteringPrefix.java   |  6 ++--
 .../db/SinglePartitionReadCommand.java          |  2 +-
 .../cassandra/db/marshal/AbstractType.java      | 30 ++++----------------
 .../apache/cassandra/db/rows/BufferCell.java    |  5 ++--
 .../compaction/BlacklistingCompactionsTest.java | 19 +++++++------
 .../sstable/SSTableCorruptionDetectionTest.java |  7 +++--
 .../io/sstable/SSTableWriterTestBase.java       | 11 +++----
 9 files changed, 38 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6d5117f..80a07a2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.7
+ * Avoid referencing DatabaseDescriptor in AbstractType (CASSANDRA-11912)
  * Fix sstables not being protected from removal during index build (CASSANDRA-11905)
  * cqlsh: Suppress stack trace from Read/WriteFailures (CASSANDRA-11032)
  * Remove unneeded code to repair index summaries that have

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
index dcda76f..cda2eaa 100644
--- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
+++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
@@ -823,6 +823,11 @@ public class DatabaseDescriptor
         return conf.max_value_size_in_mb * 1024 * 1024;
     }
 
+    public static void setMaxValueSize(int maxValueSizeInBytes)
+    {
+        conf.max_value_size_in_mb = maxValueSizeInBytes / 1024 / 1024;
+    }
+
     /**
      * Creates all storage-related directories.
      */

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/src/java/org/apache/cassandra/db/ClusteringPrefix.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ClusteringPrefix.java b/src/java/org/apache/cassandra/db/ClusteringPrefix.java
index 8d28637..7f7f964 100644
--- a/src/java/org/apache/cassandra/db/ClusteringPrefix.java
+++ b/src/java/org/apache/cassandra/db/ClusteringPrefix.java
@@ -23,7 +23,7 @@ import java.security.MessageDigest;
 import java.util.*;
 
 import org.apache.cassandra.cache.IMeasurableMemory;
-import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.*;
 import org.apache.cassandra.db.rows.*;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.io.util.DataInputPlus;
@@ -343,7 +343,7 @@ public interface ClusteringPrefix extends IMeasurableMemory, Clusterable
                 {
                     values[offset] = isNull(header, offset)
                                 ? null
-                                : (isEmpty(header, offset) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
: types.get(offset).readValue(in));
+                                : (isEmpty(header, offset) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
: types.get(offset).readValue(in, DatabaseDescriptor.getMaxValueSize()));
                     offset++;
                 }
             }
@@ -479,7 +479,7 @@ public interface ClusteringPrefix extends IMeasurableMemory, Clusterable
             int i = deserializedSize++;
             nextValues[i] = Serializer.isNull(nextHeader, i)
                           ? null
-                          : (Serializer.isEmpty(nextHeader, i) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
: serializationHeader.clusteringTypes().get(i).readValue(in));
+                          : (Serializer.isEmpty(nextHeader, i) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
: serializationHeader.clusteringTypes().get(i).readValue(in, DatabaseDescriptor.getMaxValueSize()));
             return true;
         }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
index d5f2dc4..6784770 100644
--- a/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
+++ b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
@@ -1016,7 +1016,7 @@ public class SinglePartitionReadCommand extends ReadCommand
         public ReadCommand deserialize(DataInputPlus in, int version, boolean isDigest, int
digestVersion, boolean isForThrift, CFMetaData metadata, int nowInSec, ColumnFilter columnFilter,
RowFilter rowFilter, DataLimits limits, Optional<IndexMetadata> index)
         throws IOException
         {
-            DecoratedKey key = metadata.decorateKey(metadata.getKeyValidator().readValue(in));
+            DecoratedKey key = metadata.decorateKey(metadata.getKeyValidator().readValue(in,
DatabaseDescriptor.getMaxValueSize()));
             ClusteringIndexFilter filter = ClusteringIndexFilter.serializer.deserialize(in,
version, metadata);
             return new SinglePartitionReadCommand(isDigest, digestVersion, isForThrift, metadata,
nowInSec, columnFilter, rowFilter, limits, key, filter);
         }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/src/java/org/apache/cassandra/db/marshal/AbstractType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
index 9d1cc8a..9c7ac49 100644
--- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
@@ -27,11 +27,9 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
-import com.google.common.annotations.VisibleForTesting;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.db.TypeSizes;
@@ -83,22 +81,10 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
     public final ComparisonType comparisonType;
     public final boolean isByteOrderComparable;
 
-    /**
-     * The maximum size of values for this type, used when some values are not of fixed length,
-     * that is valueLengthIfFixed() returns -1.
-     */
-    public int maxValueSize;
-
     protected AbstractType(ComparisonType comparisonType)
     {
-        this(comparisonType, DatabaseDescriptor.getMaxValueSize());
-    }
-
-    protected AbstractType(ComparisonType comparisonType, int maxValueSize)
-    {
         this.comparisonType = comparisonType;
         this.isByteOrderComparable = comparisonType == ComparisonType.BYTE_ORDER;
-        this.maxValueSize = maxValueSize;
         reverseComparator = (o1, o2) -> AbstractType.this.compare(o2, o1);
         try
         {
@@ -114,17 +100,6 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
         }
     }
 
-    /**
-     * Change the maximum value size, this should only be called for testing.
-     * Unfortunately, ensuring we use a type created with a different maxValueSize
-     * is too hard at the moment, due to the pervasive use of the type's singleton instances.
-     */
-    @VisibleForTesting
-    public void setMaxValueSize(int maxValueSize)
-    {
-        this.maxValueSize = maxValueSize;
-    }
-
     public static List<String> asCQLTypeStringList(List<AbstractType<?>>
abstractTypes)
     {
         List<String> r = new ArrayList<>(abstractTypes.size());
@@ -408,6 +383,11 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
 
     public ByteBuffer readValue(DataInputPlus in) throws IOException
     {
+        return readValue(in, Integer.MAX_VALUE);
+    }
+
+    public ByteBuffer readValue(DataInputPlus in, int maxValueSize) throws IOException
+    {
         int length = valueLengthIfFixed();
 
         if (length >= 0)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/src/java/org/apache/cassandra/db/rows/BufferCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/rows/BufferCell.java b/src/java/org/apache/cassandra/db/rows/BufferCell.java
index 0a2c528..22b629a 100644
--- a/src/java/org/apache/cassandra/db/rows/BufferCell.java
+++ b/src/java/org/apache/cassandra/db/rows/BufferCell.java
@@ -20,8 +20,7 @@ package org.apache.cassandra.db.rows;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.config.CFMetaData;
-import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.*;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.context.CounterContext;
 import org.apache.cassandra.db.marshal.ByteType;
@@ -300,7 +299,7 @@ public class BufferCell extends AbstractCell
                 }
                 else
                 {
-                    value = header.getType(column).readValue(in);
+                    value = header.getType(column).readValue(in, DatabaseDescriptor.getMaxValueSize());
                     if (isCounter)
                         value = helper.maybeClearCounterValue(value);
                 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/test/unit/org/apache/cassandra/db/compaction/BlacklistingCompactionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/compaction/BlacklistingCompactionsTest.java
b/test/unit/org/apache/cassandra/db/compaction/BlacklistingCompactionsTest.java
index 21ce450..df2d8a9 100644
--- a/test/unit/org/apache/cassandra/db/compaction/BlacklistingCompactionsTest.java
+++ b/test/unit/org/apache/cassandra/db/compaction/BlacklistingCompactionsTest.java
@@ -25,6 +25,7 @@ import java.io.RandomAccessFile;
 import java.util.*;
 
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -54,6 +55,7 @@ public class BlacklistingCompactionsTest
     private static final String KEYSPACE1 = "BlacklistingCompactionsTest";
     private static final String STANDARD_STCS = "Standard_STCS";
     private static final String STANDARD_LCS = "Standard_LCS";
+    private static int maxValueSize;
 
     @After
     public void leakDetect() throws InterruptedException
@@ -78,18 +80,17 @@ public class BlacklistingCompactionsTest
                                     SchemaLoader.standardCFMD(KEYSPACE1, STANDARD_STCS).compaction(CompactionParams.DEFAULT),
                                     SchemaLoader.standardCFMD(KEYSPACE1, STANDARD_LCS).compaction(CompactionParams.lcs(Collections.emptyMap())));
 
-        Keyspace keyspace = Keyspace.open(KEYSPACE1);
-        for (String tableName : new String[] {STANDARD_STCS, STANDARD_LCS})
-        {
-            final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(tableName);
-
-            for (ColumnDefinition cd : cfs.metadata.allColumns())
-                cd.type.setMaxValueSize(1024 * 1024); // set max value size to 1MB
-        }
-
+        maxValueSize = DatabaseDescriptor.getMaxValueSize();
+        DatabaseDescriptor.setMaxValueSize(1024 * 1024);
         closeStdErr();
     }
 
+    @AfterClass
+    public static void tearDown()
+    {
+        DatabaseDescriptor.setMaxValueSize(maxValueSize);
+    }
+
     public static void closeStdErr()
     {
         // These tests generate an error message per CorruptSSTableException since it goes
through

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/test/unit/org/apache/cassandra/io/sstable/SSTableCorruptionDetectionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableCorruptionDetectionTest.java
b/test/unit/org/apache/cassandra/io/sstable/SSTableCorruptionDetectionTest.java
index 0c27fc8..4da8519 100644
--- a/test/unit/org/apache/cassandra/io/sstable/SSTableCorruptionDetectionTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/SSTableCorruptionDetectionTest.java
@@ -63,6 +63,7 @@ public class SSTableCorruptionDetectionTest extends SSTableWriterTestBase
     private static final String keyspace = "SSTableCorruptionDetectionTest";
     private static final String table = "corrupted_table";
 
+    private static int maxValueSize;
     private static Random random;
     private static SSTableWriter writer;
     private static LifecycleTransaction txn;
@@ -88,8 +89,8 @@ public class SSTableCorruptionDetectionTest extends SSTableWriterTestBase
         cfs = Keyspace.open(keyspace).getColumnFamilyStore(table);
         cfs.disableAutoCompaction();
 
-        for (ColumnDefinition cd : cfs.metadata.allColumns())
-            cd.type.setMaxValueSize(1024 * 1024);
+        maxValueSize = DatabaseDescriptor.getMaxValueSize();
+        DatabaseDescriptor.setMaxValueSize(1024 * 1024);
 
         long seed = System.nanoTime();
         logger.info("Seed {}", seed);
@@ -123,6 +124,8 @@ public class SSTableCorruptionDetectionTest extends SSTableWriterTestBase
     @AfterClass
     public static void tearDown()
     {
+        DatabaseDescriptor.setMaxValueSize(maxValueSize);
+
         txn.abort();
         writer.close();
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57ead56f/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTestBase.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTestBase.java b/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTestBase.java
index f2c97c0..5c7c7c0 100644
--- a/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTestBase.java
+++ b/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTestBase.java
@@ -60,6 +60,8 @@ public class SSTableWriterTestBase extends SchemaLoader
     private static Config.DiskAccessMode standardMode;
     private static Config.DiskAccessMode indexMode;
 
+    private static int maxValueSize;
+
     @BeforeClass
     public static void defineSchema() throws ConfigurationException
     {
@@ -78,15 +80,14 @@ public class SSTableWriterTestBase extends SchemaLoader
                                     SchemaLoader.standardCFMD(KEYSPACE, CF),
                                     SchemaLoader.standardCFMD(KEYSPACE, CF_SMALL_MAX_VALUE));
 
-        Keyspace keyspace = Keyspace.open(KEYSPACE);
-        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_SMALL_MAX_VALUE);
-        for (ColumnDefinition cd : cfs.metadata.allColumns())
-            cd.type.setMaxValueSize(1024 * 1024); // set max value size to 1MB
+        maxValueSize = DatabaseDescriptor.getMaxValueSize();
+        DatabaseDescriptor.setMaxValueSize(1024 * 1024); // set max value size to 1MB
     }
 
     @AfterClass
-    public static void revertDiskAccess()
+    public static void revertConfiguration()
     {
+        DatabaseDescriptor.setMaxValueSize(maxValueSize);
         DatabaseDescriptor.setDiskAccessMode(standardMode);
         DatabaseDescriptor.setIndexAccessMode(indexMode);
     }


Mime
View raw message