Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-16228

TableMetrics are exposed before ColumnFamilyStore is fully initialized

    XMLWordPrintableJSON

    Details

      Description

      The ColumnFamilyStore exposes the TableMetrics before it is fully initialized, due to that it is possible to perform a call via the metrics that access uninitialized part of the ColumnFamilyStore

      The following test can be added to ColumnFamilyMetricTest to show the issue:

      @Test
      public void testStartupRaceConditionOnMetricListeners()
      {
       // Since the ColumnFamilyStore instance reference escapes during the construction
       // we have a race condition and listeners can see an instance that is in an unknown state.
       // This test just check that all callbacks can access the data without throwing any exception.
       registerMetricListener();
       SchemaLoader.createKeyspace("Keyspace2",
       KeyspaceParams.simple(1),
       SchemaLoader.standardCFMD("Keyspace2", "Standard2"));
      }
      
      private void registerMetricListener()
      {
       CassandraMetricsRegistry.Metrics.addListener(new MetricRegistryListener.Base()
       {
       @Override
       public void onGaugeAdded(String name, Gauge<?> gauge)
       {
       gauge.getValue();
       }
      
       @Override
       public void onGaugeRemoved(String name)
       {
      
       }
      
       @Override
       public void onCounterAdded(String name, Counter counter)
       {
       counter.getCount();
       }
      
       @Override
       public void onCounterRemoved(String name)
       {
      
       }
      
       @Override
       public void onHistogramAdded(String name, Histogram histogram)
       {
       histogram.getCount();
       }
      
       @Override
       public void onHistogramRemoved(String name)
       {
      
       }
      
       @Override
       public void onMeterAdded(String name, Meter meter)
       {
       meter.getCount();
       }
      
       @Override
       public void onMeterRemoved(String name)
       {
      
       }
      
       @Override
       public void onTimerAdded(String name, Timer timer)
       {
       timer.getCount();
       }
      
       @Override
       public void onTimerRemoved(String name)
       {
      
       }
       });

      While looking into that ticket we also discovered a problem with the used of Metered in CacheMetrics.
      Metrics reporter looks for metrics classes that are instance of the standard codahale classes. Due to that, other Metered implementations are not be exposed through the reporter. This ticket will also address that issue.

        Attachments

          Activity

            People

            • Assignee:
              e.dimitrova Ekaterina Dimitrova
              Reporter:
              e.dimitrova Ekaterina Dimitrova
              Authors:
              Ekaterina Dimitrova
              Reviewers:
              Benjamin Lerer
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: