hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r1056503 - in /hive/trunk: CHANGES.txt metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
Date Fri, 07 Jan 2011 21:00:42 GMT
Author: cws
Date: Fri Jan  7 21:00:41 2011
New Revision: 1056503

URL: http://svn.apache.org/viewvc?rev=1056503&view=rev
Log:
HIVE-1899 Add a factory method for creating a synchronized wrapper for IMetaStoreClient (John
Sichi via cws)

Modified:
    hive/trunk/CHANGES.txt
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
    hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java

Modified: hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hive/trunk/CHANGES.txt?rev=1056503&r1=1056502&r2=1056503&view=diff
==============================================================================
--- hive/trunk/CHANGES.txt (original)
+++ hive/trunk/CHANGES.txt Fri Jan  7 21:00:41 2011
@@ -142,6 +142,8 @@ Trunk -  Unreleased
 
   IMPROVEMENTS
 
+    HIVE-1899 Add a factory method for creating a synchronized wrapper for IMetaStoreClient
(John Sichi via cws)
+
     HIVE-1852 Reduce unnecessary DFSClient.rename() calls (Ning Zhang via jssarma)
 
     HIVE-1712. Migrating metadata from derby to mysql thrown NullPointerException (Jake Farrell
via pauly)

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java?rev=1056503&r1=1056502&r2=1056503&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
(original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
Fri Jan  7 21:00:41 2011
@@ -21,6 +21,10 @@ package org.apache.hadoop.hive.metastore
 import static org.apache.hadoop.hive.metastore.MetaStoreUtils.DEFAULT_DATABASE_NAME;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -922,4 +926,41 @@ public class HiveMetaStoreClient impleme
     return client.drop_index_by_name(dbName, tblName, name, deleteData);
   }
 
+  /**
+   * Creates a synchronized wrapper for any {@link IMetaStoreClient}.
+   * This may be used by multi-threaded applications until we have
+   * fixed all reentrancy bugs.
+   *
+   * @param client unsynchronized client
+   *
+   * @return synchronized client
+   */
+  public static IMetaStoreClient newSynchronizedClient(
+      IMetaStoreClient client) {
+    return (IMetaStoreClient) Proxy.newProxyInstance(
+      HiveMetaStoreClient.class.getClassLoader(),
+      new Class [] { IMetaStoreClient.class },
+      new SynchronizedHandler(client));
+  }
+
+  private static class SynchronizedHandler implements InvocationHandler {
+    private final IMetaStoreClient client;
+    private static final Object lock = SynchronizedHandler.class;
+
+    SynchronizedHandler(IMetaStoreClient client) {
+      this.client = client;
+    }
+
+    public Object invoke(Object proxy, Method method, Object [] args)
+        throws Throwable {
+      try {
+        synchronized (lock) {
+          return method.invoke(client, args);
+        }
+      } catch (InvocationTargetException e) {
+        throw e.getTargetException();
+      }
+    }
+  }
+  
 }

Modified: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java?rev=1056503&r1=1056502&r2=1056503&view=diff
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
(original)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
Fri Jan  7 21:00:41 2011
@@ -1009,4 +1009,16 @@ public abstract class TestHiveMetaStore 
 
     client.add_partition(part);
   }
+
+  /**
+   * Tests {@link HiveMetaStoreClient#newSynchronizedClient}.  Does not
+   * actually test multithreading, but does verify that the proxy
+   * at least works correctly.
+   */
+  public void testSynchronized() throws Exception {
+    IMetaStoreClient synchronizedClient =
+      HiveMetaStoreClient.newSynchronizedClient(client);
+    List<String> databases = synchronizedClient.getAllDatabases();
+    assertEquals(1, databases.size());
+  }
 }



Mime
View raw message