bdeggleston commented on code in PR #4559:
URL: https://github.com/apache/cassandra/pull/4559#discussion_r2886827328


##########
src/java/org/apache/cassandra/tcm/Startup.java:
##########
@@ -281,12 +283,15 @@ public static void 
initializeFromGossip(Function<Processor, Processor> wrapProce
                                                                       
logSpec));
 
         ClusterMetadataService.instance().log().ready();
-        MutationTrackingService.instance.registerTCMListener();
+
+        if (DatabaseDescriptor.getMutationTrackingEnabled())
+            MutationTrackingService.instance().registerMetadataListener();
+
         initMessaging.run();
         try
         {
             CommitLog.instance.recoverSegmentsOnDisk();
-            MutationJournal.instance.replayStaticSegments();
+            MutationJournal.instance().replayStaticSegments();

Review Comment:
   should this also be guarded by 
`DatabaseDescriptor.getMutationTrackingEnabled()`?



##########
src/java/org/apache/cassandra/replication/MutationTrackingService.java:
##########
@@ -97,7 +98,59 @@
 // TODO (expected): handle topology changes
 public class MutationTrackingService
 {
-    private static final ScheduledExecutorPlus executor = 
executorFactory().scheduled("Mutation-Tracking-Service", NORMAL);
+    public static final String DISABLED_MESSAGE = "Mutation tracking is not 
enabled. (See mutation_tracking.enabled in cassandra.yaml)";
+
+    private static final MutationTrackingService instance;
+    private static final ScheduledExecutorPlus executor;
+
+    static
+    {
+        if (DatabaseDescriptor.getMutationTrackingEnabled())
+        {
+            instance = new MutationTrackingService();
+            executor = 
executorFactory().scheduled("Mutation-Tracking-Service", NORMAL);
+        }
+        else
+        {
+            instance = null;
+            executor = null;
+        }
+    }
+
+    /**
+     * Callers of this method should have validated that mutation tracking is 
enabled
+     */
+    public static MutationTrackingService instance()
+    {
+        if (instance == null)
+            throw new IllegalStateException(DISABLED_MESSAGE);
+        return instance;
+    }
+
+    public static boolean isEnabled()
+    {
+        return DatabaseDescriptor.getMutationTrackingEnabled();
+    }
+
+    public static void ensureEnabled()
+    {
+        if (!DatabaseDescriptor.getMutationTrackingEnabled())
+            throw new IllegalStateException("Mutation tracking is not 
enabled");

Review Comment:
   can we use the `DISABLED` error message here as well?



##########
src/java/org/apache/cassandra/db/compaction/writers/CompactionAwareWriter.java:
##########
@@ -97,7 +98,10 @@ public CompactionAwareWriter(ColumnFamilyStore cfs,
         sstableWriter = SSTableRewriter.construct(cfs, txn, keepOriginals, 
maxAge, earlyOpenAllowed);
         minRepairedAt = CompactionTask.getMinRepairedAt(nonExpiredSSTables);
         pendingRepair = CompactionTask.getPendingRepair(nonExpiredSSTables);
-        coordinatorLogOffsets = 
CompactionTask.getCoordinatorLogOffsets(nonExpiredSSTables);
+
+        coordinatorLogOffsets = 
DatabaseDescriptor.getMutationTrackingEnabled() ? 
CompactionTask.getCoordinatorLogOffsets(nonExpiredSSTables)

Review Comment:
   Is there a reason we can't keep these around? IIRC no offsets means that the 
sstable is seen as repaired. I know that the only way this could cause a 
problem would be if you started the node with mutation tracked keyspaces and 
mutation tracking disabled, which would mean we wouldn't startup.



##########
test/distributed/org/apache/cassandra/distributed/test/tracking/MutationTrackingFeatureFlagTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.distributed.test.tracking;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.cassandra.config.Config;
+import org.apache.cassandra.config.YamlConfigurationLoader;
+import org.apache.cassandra.distributed.api.IInvokableInstance;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.db.virtual.MutationTrackingTables;
+import org.apache.cassandra.db.virtual.SystemViewsKeyspace;
+import org.apache.cassandra.db.virtual.VirtualTable;
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.distributed.api.IIsolatedExecutor;
+import org.apache.cassandra.distributed.test.TestBaseImpl;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.schema.SchemaConstants;
+import org.apache.cassandra.utils.AssertionUtils;
+
+import static org.apache.cassandra.distributed.api.Feature.NETWORK;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import static 
org.apache.cassandra.replication.MutationTrackingService.DISABLED_MESSAGE;
+
+public class MutationTrackingFeatureFlagTest extends TestBaseImpl
+{
+    @Test
+    public void shouldHideMutationTracking()  throws IOException
+    {
+        try (Cluster cluster = builder().withNodes(3).withConfig(c -> 
c.with(NETWORK).set("mutation_tracking.enabled", false)).start())
+        {
+            // We shouldn't be able to create a tracked keyspace: 
+            Assertions.assertThatThrownBy(() -> cluster.schemaChange("CREATE 
KEYSPACE " + KEYSPACE + 
+                                                                     " WITH 
replication = {'class': 'SimpleStrategy', 'replication_factor': 3}" +
+                                                                     " AND 
replication_type='tracked'"))
+                      
.has(AssertionUtils.isThrowableInstanceof(InvalidRequestException.class))
+                      .hasMessage(DISABLED_MESSAGE);
+
+            cluster.schemaChange("CREATE KEYSPACE " + KEYSPACE + " WITH 
replication = {'class': 'SimpleStrategy', 'replication_factor': 3} AND 
replication_type='untracked'");
+
+            // We shouldn't be able to alter a keyspace to make it tracked: 
+            Assertions.assertThatThrownBy(() -> cluster.schemaChange("ALTER 
KEYSPACE " + KEYSPACE + " WITH replication_type='tracked'"))
+                      
.has(AssertionUtils.isThrowableInstanceof(InvalidRequestException.class))
+                      .hasMessage(DISABLED_MESSAGE);
+
+            // Mutation tracking system keyspace tables should not be present:
+            assertNull(cluster.get(1).callOnInstance(() -> 
Schema.instance.getTableMetadata(SchemaConstants.SYSTEM_KEYSPACE_NAME, 
SystemKeyspace.HOST_LOG_ID)));
+            assertNull(cluster.get(1).callOnInstance(() -> 
Schema.instance.getTableMetadata(SchemaConstants.SYSTEM_KEYSPACE_NAME, 
SystemKeyspace.SHARDS)));
+            assertNull(cluster.get(1).callOnInstance(() -> 
Schema.instance.getTableMetadata(SchemaConstants.SYSTEM_KEYSPACE_NAME, 
SystemKeyspace.COORDINATOR_LOGS)));
+            
+            // Make sure virtual tables don't exist:
+            IIsolatedExecutor.SerializableCallable<Stream<VirtualTable>> 
hasMutationTrackingTables =
+                    () -> 
SystemViewsKeyspace.instance.tables().stream().filter(t -> 
t.getClass().equals(MutationTrackingTables.MutationTrackingShardsTable.class));

Review Comment:
   we should confirm MutationJournalTable is also for completeness



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

Reply via email to