You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2020/12/02 06:33:52 UTC

[GitHub] [cassandra] jasonstack commented on a change in pull request #835: Cassandra 16259 (trunk)

jasonstack commented on a change in pull request #835:
URL: https://github.com/apache/cassandra/pull/835#discussion_r533927262



##########
File path: test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
##########
@@ -140,6 +133,101 @@ public void testStartupRaceConditionOnMetricListeners()
         }
     }
 
+    @Test
+    public void testEstimatedColumnCountHistogramAndEstimatedRowSizeHistogram()
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard2");
+
+        store.disableAutoCompaction();
+
+        try
+        {
+            // Ensure that there is no SSTables
+            store.truncateBlocking();
+
+            assertArrayEquals(new long[0], store.metric.estimatedColumnCountHistogram.getValue());
+
+            applyMutation(store.metadata(), "0", bytes(0), FBUtilities.timestampMicros());
+            applyMutation(store.metadata(), "1", bytes(1), FBUtilities.timestampMicros());
+
+            // Flushing first SSTable
+            store.forceBlockingFlush();
+
+            long[] estimatedColumnCountHistogram = store.metric.estimatedColumnCountHistogram.getValue();
+            assertNumberOfNonZeroValue(estimatedColumnCountHistogram, 1);
+            assertEquals(2, estimatedColumnCountHistogram[0]); //2 rows of one cell in 1 SSTable
+
+            long[] estimatedRowSizeHistogram = store.metric.estimatedPartitionSizeHistogram.getValue();
+            // Due to the timestamps we cannot guaranty the size of the row. So we can only check the number of histogram updates.
+            assertEquals(sumValues(estimatedRowSizeHistogram), 2);
+
+            applyMutation(store.metadata(), "2", bytes(2), FBUtilities.timestampMicros());
+
+            // Flushing second SSTable
+            store.forceBlockingFlush();
+
+            estimatedColumnCountHistogram = store.metric.estimatedColumnCountHistogram.getValue();
+            assertNumberOfNonZeroValue(estimatedColumnCountHistogram, 1);
+            assertEquals(3, estimatedColumnCountHistogram[0]); //2 rows of one cell in the first SSTable and 1 row of one cell int the second sstable
+
+            estimatedRowSizeHistogram = store.metric.estimatedPartitionSizeHistogram.getValue();
+            assertEquals(sumValues(estimatedRowSizeHistogram), 3);
+        }
+        finally
+        {
+            store.enableAutoCompaction();
+        }
+    }
+
+    @Test
+    public void testAddHistogram()
+    {
+        long[] sums = new long[] {0, 0, 0};
+        long[] smaller = new long[] {1, 2};
+
+        long[] result = TableMetrics.addHistogram(sums, smaller);
+        assertTrue(result == sums); // Check that we did not create a new array
+        assertArrayEquals(new long[]{1, 2, 0}, result);
+
+        long[] equal = new long[] {5, 6, 7};
+
+        result = TableMetrics.addHistogram(sums, equal);
+        assertTrue(result == sums); // Check that we did not create a new array
+        assertArrayEquals(new long[]{6, 8, 7}, result);
+
+        long[] empty = new long[0];
+
+        result = TableMetrics.addHistogram(sums, empty);
+        assertTrue(result == sums); // Check that we did not create a new array
+        assertArrayEquals(new long[]{6, 8, 7}, result);
+
+        long[] greater = new long[] {4, 3, 2, 1};
+        result = TableMetrics.addHistogram(sums, greater);
+        assertFalse(result == sums); // Check that we did not create a new array

Review comment:
       ```suggestion
           assertFalse(result == sums); // Check that we did create a new array
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org