dcapwell commented on a change in pull request #1428:
URL: https://github.com/apache/cassandra/pull/1428#discussion_r796991609



##########
File path: conf/cassandra.yaml
##########
@@ -1625,3 +1625,6 @@ enable_drop_compact_storage: false
 # Guardrail to allow/disallow list operations that require read before write, 
i.e. setting list element by index and
 # removing list elements by either index or value. Defaults to true.
 #     read_before_write_list_operations_enabled: true
+
+# The maximum number of gossip state transitions per peer to store for the 
gossip_state_transitions virtual table
+max_gossip_state_transitions_size: 10

Review comment:
       please comment out, new features must not rely on the yaml so should be 
commented out to act more like documentation
   

##########
File path: src/java/org/apache/cassandra/config/Config.java
##########
@@ -570,6 +570,11 @@
      */
     public volatile double range_tombstone_list_growth_factor = 1.5;
 
+    /**
+     * The maximum number of gossip state transitions per peer to store for 
the gossip_state_transitions virtual table
+     */
+    public int max_gossip_state_transitions_size = 10;

Review comment:
       should be `gossip_state_max_transition_size` to be in-line with 
https://issues.apache.org/jira/browse/CASSANDRA-15234

##########
File path: src/java/org/apache/cassandra/gms/Gossiper.java
##########
@@ -148,6 +160,11 @@
     /* subscribers for interest in EndpointState change */
     private final List<IEndpointStateChangeSubscriber> subscribers = new 
CopyOnWriteArrayList<>();
 
+    /* list of the most recent N gossip state transitions.
+     * N is defined by the max_gossip_state_transitions_size configuration. */
+    @VisibleForTesting
+    final Map<InetAddressAndPort, Queue<GossipStateTransition>> 
gossipStateTransitionMap = new ConcurrentHashMap<>();

Review comment:
       host costly is this if your cluster has 1k nodes?

##########
File path: 
src/java/org/apache/cassandra/db/virtual/GossipStateTransitionsTable.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.virtual;
+
+import java.util.Date;
+
+import org.apache.cassandra.db.marshal.InetAddressType;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.db.marshal.TimestampType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.gms.GossipStateTransition;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.schema.TableMetadata;
+
+/**
+ * A {@link VirtualTable} that returns the {@code 
max_gossip_state_transitions_size} most recent gossip state
+ * transitions. The table only considers peers in the ring (it doesn't track 
transitions for evicted peers).
+ *
+ * <p>The {@code max_gossip_state_transitions_size} property can be configured 
in the {@code cassandra.yaml}
+ * configuration file.
+ */
+final class GossipStateTransitionsTable extends AbstractVirtualTable
+{
+    public static final String TABLE_NAME = "gossip_state_transitions";
+    public static final String TABLE_COMMENT = "recent gossip state 
transitions";
+
+    private static final String ADDRESS = "address";
+    private static final String PORT = "port";
+    private static final String TIMESTAMP = "timestamp";
+    private static final String HOSTNAME = "hostname";
+    private static final String GENERATION = "generation";
+    private static final String HEARTBEAT = "heartbeat";
+
+    // Fields coming from @org.apache.cassandra.gms.ApplicationState
+    private static final String STATUS = "status";
+    private static final String LOAD = "load";
+    private static final String SCHEMA = "schema";
+    private static final String DC = "dc";
+    private static final String RACK = "rack";
+    private static final String RELEASE_VERSION = "release_version";
+    private static final String REMOVAL_COORDINATOR = "removal_coordinator";
+    private static final String INTERNAL_IP = "internal_ip";
+    private static final String RPC_ADDRESS = "rpc_address";
+    private static final String SEVERITY = "severity";
+    private static final String NET_VERSION = "net_version";
+    private static final String HOST_ID = "host_id";
+    private static final String TOKENS = "tokens";
+    private static final String RPC_READY = "rpc_ready";
+    private static final String INTERNAL_ADDRESS_AND_PORT = 
"internal_address_and_port";
+    private static final String NATIVE_ADDRESS_AND_PORT = 
"native_address_and_port";
+    private static final String STATUS_WITH_PORT = "status_with_port";
+    private static final String SSTABLE_VERSIONS = "sstable_versions";
+
+    /**
+     * Constructs a new {@link GossipStateTransitionsTable} with the given 
{@code keyspace}.
+     *
+     * @param keyspace the name of the keyspace
+     */
+    GossipStateTransitionsTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, TABLE_NAME)
+                           .comment(TABLE_COMMENT)
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new 
LocalPartitioner(InetAddressType.instance))
+                           .addPartitionKeyColumn(ADDRESS, 
InetAddressType.instance)
+                           .addClusteringColumn(PORT, Int32Type.instance)

Review comment:
       heh, `ClientsTable` does this (`(address), port`), 
`InternodeOutboundTable/InternodeInboundTable` does `(address, port)`, 
`PendingHintsTable` does `(host_id)`... we are not consistent cross tables... 
heh

##########
File path: 
src/java/org/apache/cassandra/db/virtual/GossipStateTransitionsTable.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.virtual;
+
+import java.util.Date;
+
+import org.apache.cassandra.db.marshal.InetAddressType;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.db.marshal.TimestampType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.gms.GossipStateTransition;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.schema.TableMetadata;
+
+/**
+ * A {@link VirtualTable} that returns the {@code 
max_gossip_state_transitions_size} most recent gossip state
+ * transitions. The table only considers peers in the ring (it doesn't track 
transitions for evicted peers).
+ *
+ * <p>The {@code max_gossip_state_transitions_size} property can be configured 
in the {@code cassandra.yaml}
+ * configuration file.
+ */
+final class GossipStateTransitionsTable extends AbstractVirtualTable
+{
+    public static final String TABLE_NAME = "gossip_state_transitions";
+    public static final String TABLE_COMMENT = "recent gossip state 
transitions";
+
+    private static final String ADDRESS = "address";
+    private static final String PORT = "port";
+    private static final String TIMESTAMP = "timestamp";
+    private static final String HOSTNAME = "hostname";
+    private static final String GENERATION = "generation";
+    private static final String HEARTBEAT = "heartbeat";
+
+    // Fields coming from @org.apache.cassandra.gms.ApplicationState
+    private static final String STATUS = "status";
+    private static final String LOAD = "load";
+    private static final String SCHEMA = "schema";
+    private static final String DC = "dc";
+    private static final String RACK = "rack";
+    private static final String RELEASE_VERSION = "release_version";
+    private static final String REMOVAL_COORDINATOR = "removal_coordinator";
+    private static final String INTERNAL_IP = "internal_ip";
+    private static final String RPC_ADDRESS = "rpc_address";
+    private static final String SEVERITY = "severity";
+    private static final String NET_VERSION = "net_version";
+    private static final String HOST_ID = "host_id";
+    private static final String TOKENS = "tokens";
+    private static final String RPC_READY = "rpc_ready";
+    private static final String INTERNAL_ADDRESS_AND_PORT = 
"internal_address_and_port";
+    private static final String NATIVE_ADDRESS_AND_PORT = 
"native_address_and_port";
+    private static final String STATUS_WITH_PORT = "status_with_port";
+    private static final String SSTABLE_VERSIONS = "sstable_versions";
+
+    /**
+     * Constructs a new {@link GossipStateTransitionsTable} with the given 
{@code keyspace}.
+     *
+     * @param keyspace the name of the keyspace
+     */
+    GossipStateTransitionsTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, TABLE_NAME)
+                           .comment(TABLE_COMMENT)
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new 
LocalPartitioner(InetAddressType.instance))
+                           .addPartitionKeyColumn(ADDRESS, 
InetAddressType.instance)
+                           .addClusteringColumn(PORT, Int32Type.instance)

Review comment:
       started a side conversation with @clohfink and he was making the point 
that we should really consider how this table will be used so we know what the 
PK should be, one argument is "last N gossip transitions makes more sense, so 
PK=time is best".
   
   @frankgh what is the use case you are solving for?

##########
File path: src/java/org/apache/cassandra/gms/Gossiper.java
##########
@@ -393,6 +411,51 @@ public void onChange(InetAddressAndPort endpoint, 
ApplicationState state, Versio
                     minVersionSupplier.recompute();
             }
         });
+
+        subscribers.add(new IEndpointStateChangeSubscriber()

Review comment:
       you are dropping the event type, in cases like `onRemove` this can be an 
internal decision, so 0 gossip state change will be present in the row, so the 
only difference would be the timestamp on creating the `GossipStateTransition` 
and not the actual contents of the state.

##########
File path: 
src/java/org/apache/cassandra/db/virtual/GossipStateTransitionsTable.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.virtual;
+
+import java.util.Date;
+
+import org.apache.cassandra.db.marshal.InetAddressType;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.db.marshal.TimestampType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.gms.GossipStateTransition;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.schema.TableMetadata;
+
+/**
+ * A {@link VirtualTable} that returns the {@code 
max_gossip_state_transitions_size} most recent gossip state
+ * transitions. The table only considers peers in the ring (it doesn't track 
transitions for evicted peers).
+ *
+ * <p>The {@code max_gossip_state_transitions_size} property can be configured 
in the {@code cassandra.yaml}
+ * configuration file.
+ */
+final class GossipStateTransitionsTable extends AbstractVirtualTable
+{
+    public static final String TABLE_NAME = "gossip_state_transitions";
+    public static final String TABLE_COMMENT = "recent gossip state 
transitions";
+
+    private static final String ADDRESS = "address";
+    private static final String PORT = "port";
+    private static final String TIMESTAMP = "timestamp";
+    private static final String HOSTNAME = "hostname";
+    private static final String GENERATION = "generation";
+    private static final String HEARTBEAT = "heartbeat";
+
+    // Fields coming from @org.apache.cassandra.gms.ApplicationState
+    private static final String STATUS = "status";
+    private static final String LOAD = "load";
+    private static final String SCHEMA = "schema";
+    private static final String DC = "dc";
+    private static final String RACK = "rack";
+    private static final String RELEASE_VERSION = "release_version";
+    private static final String REMOVAL_COORDINATOR = "removal_coordinator";
+    private static final String INTERNAL_IP = "internal_ip";
+    private static final String RPC_ADDRESS = "rpc_address";
+    private static final String SEVERITY = "severity";
+    private static final String NET_VERSION = "net_version";
+    private static final String HOST_ID = "host_id";
+    private static final String TOKENS = "tokens";
+    private static final String RPC_READY = "rpc_ready";
+    private static final String INTERNAL_ADDRESS_AND_PORT = 
"internal_address_and_port";
+    private static final String NATIVE_ADDRESS_AND_PORT = 
"native_address_and_port";
+    private static final String STATUS_WITH_PORT = "status_with_port";
+    private static final String SSTABLE_VERSIONS = "sstable_versions";
+
+    /**
+     * Constructs a new {@link GossipStateTransitionsTable} with the given 
{@code keyspace}.
+     *
+     * @param keyspace the name of the keyspace
+     */
+    GossipStateTransitionsTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, TABLE_NAME)
+                           .comment(TABLE_COMMENT)
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new 
LocalPartitioner(InetAddressType.instance))
+                           .addPartitionKeyColumn(ADDRESS, 
InetAddressType.instance)
+                           .addClusteringColumn(PORT, Int32Type.instance)
+                           .addClusteringColumn(TIMESTAMP, 
TimestampType.instance)
+                           .addRegularColumn(HOSTNAME, UTF8Type.instance)
+                           .addRegularColumn(GENERATION, Int32Type.instance)
+                           .addRegularColumn(HEARTBEAT, Int32Type.instance)
+                           .addRegularColumn(STATUS, UTF8Type.instance)
+                           .addRegularColumn(LOAD, UTF8Type.instance)
+                           .addRegularColumn(SCHEMA, UTF8Type.instance)
+                           .addRegularColumn(DC, UTF8Type.instance)
+                           .addRegularColumn(RACK, UTF8Type.instance)
+                           .addRegularColumn(RELEASE_VERSION, 
UTF8Type.instance)
+                           .addRegularColumn(REMOVAL_COORDINATOR, 
UTF8Type.instance)
+                           .addRegularColumn(INTERNAL_IP, UTF8Type.instance)
+                           .addRegularColumn(RPC_ADDRESS, UTF8Type.instance)
+                           .addRegularColumn(SEVERITY, UTF8Type.instance)
+                           .addRegularColumn(NET_VERSION, UTF8Type.instance)
+                           .addRegularColumn(HOST_ID, UTF8Type.instance)
+                           .addRegularColumn(TOKENS, UTF8Type.instance)
+                           .addRegularColumn(RPC_READY, UTF8Type.instance)
+                           .addRegularColumn(INTERNAL_ADDRESS_AND_PORT, 
UTF8Type.instance)
+                           .addRegularColumn(NATIVE_ADDRESS_AND_PORT, 
UTF8Type.instance)
+                           .addRegularColumn(STATUS_WITH_PORT, 
UTF8Type.instance)
+                           .addRegularColumn(SSTABLE_VERSIONS, 
UTF8Type.instance)
+                           .build());
+    }

Review comment:
       Personal preference, you can use the CREATE TABLE string syntax, calling 
`CreateTableStatement.parse(format(cql, table), 
SchemaConstants.SYSTEM_KEYSPACE_NAME)` will do that for you

##########
File path: 
test/unit/org/apache/cassandra/db/virtual/GossipStateTransitionsTableTest.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.virtual;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.UntypedResultSet;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.utils.FBUtilities;
+
+import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for the {@link GossipStateTransitionsTable} virtual table.
+ */
+public class GossipStateTransitionsTableTest extends CQLTester
+{
+    private static final String KS_NAME = "vts";
+
+    @SuppressWarnings("FieldCanBeLocal")
+    private VirtualTable table;
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        // limit the transitions to record to 2 per host
+        DatabaseDescriptor.setMaxGossipStateTransitionsSize(2);
+        setUpClass();
+        startJMXServer();
+    }
+
+    @Before
+    public void config()
+    {
+        table = new GossipStateTransitionsTable(KS_NAME);

Review comment:
       unsafe pattern; is there a reason you need to keep creating the table? I 
had to "fix"/"work around" this pattern in 
https://issues.apache.org/jira/browse/CASSANDRA-17295
   
   A safer pattern is to set this up in the `setup` method, you also don't need 
to save the table to this class

##########
File path: 
test/unit/org/apache/cassandra/db/virtual/GossipStateTransitionsTableTest.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.virtual;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.UntypedResultSet;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.utils.FBUtilities;
+
+import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for the {@link GossipStateTransitionsTable} virtual table.
+ */
+public class GossipStateTransitionsTableTest extends CQLTester
+{
+    private static final String KS_NAME = "vts";
+
+    @SuppressWarnings("FieldCanBeLocal")
+    private VirtualTable table;
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        // limit the transitions to record to 2 per host
+        DatabaseDescriptor.setMaxGossipStateTransitionsSize(2);
+        setUpClass();
+        startJMXServer();
+    }
+
+    @Before
+    public void config()
+    {
+        table = new GossipStateTransitionsTable(KS_NAME);
+        VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, 
ImmutableList.of(table)));
+    }
+
+    @Test
+    public void testSelectAllWhenNoGossipStateTransitionsHaveBeenRecorded() 
throws Throwable
+    {
+        assertEmpty(execute("SELECT * FROM vts.gossip_state_transitions"));
+    }
+
+    @Test
+    public void testSelectAllWithStateTransitions() throws Throwable
+    {
+        long testStartMillis = currentTimeMillis();
+        try
+        {
+            requireNetwork(); // triggers gossip state transitions
+
+            UntypedResultSet resultSet = execute("SELECT * FROM 
vts.gossip_state_transitions");
+
+            assertThat(resultSet.size()).isGreaterThan(0)
+                                        .isLessThanOrEqualTo(2);
+
+            for (UntypedResultSet.Row row : resultSet)
+            {
+                assertThat(row.getColumns().size()).isEqualTo(24);
+                
assertThat(row.getTimestamp("timestamp").getTime()).isGreaterThan(testStartMillis)
+                                                                   
.isLessThan(currentTimeMillis());

Review comment:
       this can be flaky as millis is free to go backwards (yay clocks!), and 
also free to not change.

##########
File path: test/unit/org/apache/cassandra/gms/GossiperTest.java
##########
@@ -190,6 +191,7 @@ public void testLargeGenerationJump() throws 
UnknownHostException, InterruptedEx
         {
             // clean up the gossip states
             Gossiper.instance.endpointStateMap.clear();
+            Gossiper.instance.gossipStateTransitionMap.clear();

Review comment:
       to be more maintainable should we not have a `cleanup` method?  Seeing a 
lot of other maps not cleaned up, so this gets corrupted 




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