hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1068102 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java
Date Mon, 07 Feb 2011 20:28:57 GMT
Author: todd
Date: Mon Feb  7 20:28:57 2011
New Revision: 1068102

URL: http://svn.apache.org/viewvc?rev=1068102&view=rev
Log:
HBASE-3470. Check that hbase-default.xml is loaded from within jar

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1068102&r1=1068101&r2=1068102&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Mon Feb  7 20:28:57 2011
@@ -91,6 +91,8 @@ Release 0.90.1 - Unreleased
   BUG FIXES
    HBASE-3483  Memstore lower limit should trigger asynchronous flushes
 
+  IMPROVEMENTS
+   HBASE-3470  Check that hbase-default.xml is loaded from within jar
 
 Release 0.90.0 - January 19th, 2011
   INCOMPATIBLE CHANGES

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java?rev=1068102&r1=1068101&r2=1068102&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java Mon Feb  7 20:28:57
2011
@@ -19,6 +19,7 @@
  */
 package org.apache.hadoop.hbase;
 
+import java.net.URL;
 import java.util.Map.Entry;
 
 import org.apache.commons.logging.Log;
@@ -58,7 +59,35 @@ public class HBaseConfiguration extends 
     }
   }
 
+  /**
+   * Check that the hbase-defaults.xml file is being loaded from within
+   * the hbase jar, rather than somewhere else on the classpath.
+   */
+  private static void checkDefaultsInJar(Configuration conf) {
+    ClassLoader cl = conf.getClassLoader();
+    URL url = cl.getResource("hbase-default.xml");
+    if (url == null) {
+      // This is essentially an assertion failure - we compile this
+      // into our own jar, so there's something really wacky about
+      // the classloader context!
+      throw new AssertionError("hbase-default.xml not on classpath");
+    }
+    if (!"jar".equals(url.getProtocol()) &&
+        !url.getPath().endsWith("target/classes/hbase-default.xml")) {
+      throw new RuntimeException(
+        "hbase-defaults.xml is being loaded from " + url + " rather than " +
+        "the HBase JAR. This is dangerous since you may pick up defaults " +
+        "from a previously installed version of HBase. Please remove " +
+        "hbase-default.xml from your configuration directory.");
+    }
+  }
+
+    
+
+
   public static Configuration addHbaseResources(Configuration conf) {
+    checkDefaultsInJar(conf);
+
     conf.addResource("hbase-default.xml");
     conf.addResource("hbase-site.xml");
     return conf;



Mime
View raw message