cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/3] cassandra git commit: Call forceStaticInitialization first in activate and make sure offline tools properly handle DatabaseDescriptor static exceptions
Date Mon, 12 Oct 2015 12:55:53 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 87da74eb5 -> fe0f44741


Call forceStaticInitialization first in activate and make sure offline tools properly handle
DatabaseDescriptor static exceptions

patch by carlyeks; reviewed by pauloricardomg for CASSANDRA-10412


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

Branch: refs/heads/trunk
Commit: 83b9740a5ec13142f5d4bd8fe46e86172533595c
Parents: cccaa17
Author: Carl Yeksigian <carl@apache.org>
Authored: Wed Oct 7 08:46:12 2015 -0400
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Oct 12 14:45:58 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/service/CassandraDaemon.java      | 30 +++++-----
 .../cassandra/tools/SSTableExpiredBlockers.java |  4 +-
 .../apache/cassandra/tools/SSTableExport.java   |  1 +
 .../apache/cassandra/tools/SSTableImport.java   |  2 +
 .../cassandra/tools/SSTableLevelResetter.java   |  2 +
 .../cassandra/tools/SSTableMetadataViewer.java  |  2 +
 .../cassandra/tools/SSTableOfflineRelevel.java  |  3 +
 .../tools/SSTableRepairedAtSetter.java          |  2 +
 .../cassandra/tools/StandaloneScrubber.java     |  2 +
 .../cassandra/tools/StandaloneSplitter.java     |  2 +
 .../cassandra/tools/StandaloneUpgrader.java     |  2 +
 .../cassandra/tools/StandaloneVerifier.java     |  2 +
 src/java/org/apache/cassandra/tools/Util.java   | 58 ++++++++++++++++++++
 14 files changed, 99 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 215bd76..efae4ab 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.3
+ * Avoid NoClassDefFoundError during DataDescriptor initialization on windows (CASSANDRA-10412)
  * Preserve case of quoted Role & User names (CASSANDRA-10394)
  * cqlsh pg-style-strings broken (CASSANDRA-10484)
  * Make Hadoop CF splits more polite to custom orderered partitioners (CASSANDRA-10400)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/service/CassandraDaemon.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java b/src/java/org/apache/cassandra/service/CassandraDaemon.java
index 075c8f7..2a23550 100644
--- a/src/java/org/apache/cassandra/service/CassandraDaemon.java
+++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java
@@ -480,19 +480,20 @@ public class CassandraDaemon
      */
     public void activate()
     {
-        String pidFile = System.getProperty("cassandra-pidfile");
-
-        if (FBUtilities.isWindows())
-        {
-            // We need to adjust the system timer on windows from the default 15ms down to
the minimum of 1ms as this
-            // impacts timer intervals, thread scheduling, driver interrupts, etc.
-            WindowsTimer.startTimerPeriod(DatabaseDescriptor.getWindowsTimerInterval());
-        }
-
+        // Do not put any references to DatabaseDescriptor above the forceStaticInitialization
call.
         try
         {
             try
             {
+                DatabaseDescriptor.forceStaticInitialization();
+            }
+            catch (ExceptionInInitializerError e)
+            {
+                throw e.getCause();
+            }
+
+            try
+            {
                 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
                 mbs.registerMBean(new StandardMBean(new NativeAccess(), NativeAccessMBean.class),
new ObjectName(MBEAN_NAME));
             }
@@ -502,14 +503,17 @@ public class CassandraDaemon
                 //Allow the server to start even if the bean can't be registered
             }
 
-            try {
-                DatabaseDescriptor.forceStaticInitialization();
-            } catch (ExceptionInInitializerError e) {
-                throw e.getCause();
+            if (FBUtilities.isWindows())
+            {
+                // We need to adjust the system timer on windows from the default 15ms down
to the minimum of 1ms as this
+                // impacts timer intervals, thread scheduling, driver interrupts, etc.
+                WindowsTimer.startTimerPeriod(DatabaseDescriptor.getWindowsTimerInterval());
             }
 
             setup();
 
+            String pidFile = System.getProperty("cassandra-pidfile");
+
             if (pidFile != null)
             {
                 new File(pidFile).deleteOnExit();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableExpiredBlockers.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableExpiredBlockers.java b/src/java/org/apache/cassandra/tools/SSTableExpiredBlockers.java
index ab9305e..0d8c5e5 100644
--- a/src/java/org/apache/cassandra/tools/SSTableExpiredBlockers.java
+++ b/src/java/org/apache/cassandra/tools/SSTableExpiredBlockers.java
@@ -24,7 +24,6 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Multimap;
 
@@ -56,6 +55,9 @@ public class SSTableExpiredBlockers
             out.println("Usage: sstableexpiredblockers <keyspace> <table>");
             System.exit(1);
         }
+
+        Util.initDatabaseDescriptor();
+
         String keyspace = args[args.length - 2];
         String columnfamily = args[args.length - 1];
         Schema.instance.loadFromDisk(false);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableExport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java
index 9f833e7..46155c0 100644
--- a/src/java/org/apache/cassandra/tools/SSTableExport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableExport.java
@@ -405,6 +405,7 @@ public class SSTableExport
             System.exit(1);
         }
 
+        Util.initDatabaseDescriptor();
 
         String[] keys = cmd.getOptionValues(KEY_OPTION);
         String[] excludes = cmd.getOptionValues(EXCLUDEKEY_OPTION);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableImport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableImport.java b/src/java/org/apache/cassandra/tools/SSTableImport.java
index b2d63aa..817dfef 100644
--- a/src/java/org/apache/cassandra/tools/SSTableImport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableImport.java
@@ -511,6 +511,8 @@ public class SSTableImport
             isSorted = true;
         }
 
+        Util.initDatabaseDescriptor();
+
         Schema.instance.loadFromDisk(false);
         if (Schema.instance.getNonSystemKeyspaces().size() < 1)
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java b/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
index d73a325..9f0af05 100644
--- a/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
+++ b/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
@@ -56,6 +56,8 @@ public class SSTableLevelResetter
             System.exit(1);
         }
 
+        Util.initDatabaseDescriptor();
+
         // TODO several daemon threads will run from here.
         // So we have to explicitly call System.exit.
         try

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java b/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
index 6330915..2665f40 100644
--- a/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
+++ b/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
@@ -43,6 +43,8 @@ public class SSTableMetadataViewer
             System.exit(1);
         }
 
+        Util.initDatabaseDescriptor();
+
         for (String fname : args)
         {
             if (new File(fname).exists())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableOfflineRelevel.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableOfflineRelevel.java b/src/java/org/apache/cassandra/tools/SSTableOfflineRelevel.java
index f7e477f..71e4cfc 100644
--- a/src/java/org/apache/cassandra/tools/SSTableOfflineRelevel.java
+++ b/src/java/org/apache/cassandra/tools/SSTableOfflineRelevel.java
@@ -83,6 +83,9 @@ public class SSTableOfflineRelevel
             out.println("Usage: sstableofflinerelevel [--dry-run] <keyspace> <columnfamily>");
             System.exit(1);
         }
+
+        Util.initDatabaseDescriptor();
+
         boolean dryRun = args[0].equals("--dry-run");
         String keyspace = args[args.length - 2];
         String columnfamily = args[args.length - 1];

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/SSTableRepairedAtSetter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableRepairedAtSetter.java b/src/java/org/apache/cassandra/tools/SSTableRepairedAtSetter.java
index 2ddb632..ff362cc 100644
--- a/src/java/org/apache/cassandra/tools/SSTableRepairedAtSetter.java
+++ b/src/java/org/apache/cassandra/tools/SSTableRepairedAtSetter.java
@@ -63,6 +63,8 @@ public class SSTableRepairedAtSetter
             System.exit(1);
         }
 
+        Util.initDatabaseDescriptor();
+
         boolean setIsRepaired = args[1].equals("--is-repaired");
 
         List<String> fileNames;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/StandaloneScrubber.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/StandaloneScrubber.java b/src/java/org/apache/cassandra/tools/StandaloneScrubber.java
index cd87d8b..3551b3d 100644
--- a/src/java/org/apache/cassandra/tools/StandaloneScrubber.java
+++ b/src/java/org/apache/cassandra/tools/StandaloneScrubber.java
@@ -54,6 +54,8 @@ public class StandaloneScrubber
     public static void main(String args[])
     {
         Options options = Options.parseArgs(args);
+        Util.initDatabaseDescriptor();
+
         try
         {
             // load keyspace descriptions.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/StandaloneSplitter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/StandaloneSplitter.java b/src/java/org/apache/cassandra/tools/StandaloneSplitter.java
index 4545ab6..95fed3c 100644
--- a/src/java/org/apache/cassandra/tools/StandaloneSplitter.java
+++ b/src/java/org/apache/cassandra/tools/StandaloneSplitter.java
@@ -52,6 +52,8 @@ public class StandaloneSplitter
     public static void main(String args[])
     {
         Options options = Options.parseArgs(args);
+        Util.initDatabaseDescriptor();
+
         try
         {
             // load keyspace descriptions.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/StandaloneUpgrader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/StandaloneUpgrader.java b/src/java/org/apache/cassandra/tools/StandaloneUpgrader.java
index c5dfba0..2c2a7e0 100644
--- a/src/java/org/apache/cassandra/tools/StandaloneUpgrader.java
+++ b/src/java/org/apache/cassandra/tools/StandaloneUpgrader.java
@@ -48,6 +48,8 @@ public class StandaloneUpgrader
     public static void main(String args[])
     {
         Options options = Options.parseArgs(args);
+        Util.initDatabaseDescriptor();
+
         try
         {
             // load keyspace descriptions.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/StandaloneVerifier.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/StandaloneVerifier.java b/src/java/org/apache/cassandra/tools/StandaloneVerifier.java
index f71f58d..fb7f218 100644
--- a/src/java/org/apache/cassandra/tools/StandaloneVerifier.java
+++ b/src/java/org/apache/cassandra/tools/StandaloneVerifier.java
@@ -52,6 +52,8 @@ public class StandaloneVerifier
     public static void main(String args[])
     {
         Options options = Options.parseArgs(args);
+        Util.initDatabaseDescriptor();
+
         try
         {
             // load keyspace descriptions.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83b9740a/src/java/org/apache/cassandra/tools/Util.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/Util.java b/src/java/org/apache/cassandra/tools/Util.java
new file mode 100644
index 0000000..6e23361
--- /dev/null
+++ b/src/java/org/apache/cassandra/tools/Util.java
@@ -0,0 +1,58 @@
+/*
+ * 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.tools;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.exceptions.ConfigurationException;
+
+public final class Util
+{
+    private Util()
+    {
+    }
+
+    /**
+     * This is used by standalone tools to force static initialization of DatabaseDescriptor,
and fail if configuration
+     * is bad.
+     */
+    public static void initDatabaseDescriptor()
+    {
+        try
+        {
+            DatabaseDescriptor.forceStaticInitialization();
+        }
+        catch (ExceptionInInitializerError e)
+        {
+            Throwable cause = e.getCause();
+            boolean logStackTrace = !(cause instanceof ConfigurationException) || ((ConfigurationException)
cause).logStackTrace;
+            System.out.println("Exception (" + cause.getClass().getName() + ") encountered
during startup: " + cause.getMessage());
+
+            if (logStackTrace)
+            {
+                cause.printStackTrace();
+                System.exit(3);
+            }
+            else
+            {
+                System.err.println(cause.getMessage());
+                System.exit(3);
+            }
+        }
+    }
+}


Mime
View raw message