Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HBase tables are released by their producing factories

SHDP-113
additionally reorder params on the HBaseUtils method for consistency
  • Loading branch information...
commit d4e9df40f254e40ac7053246c1c12429b47bb603 1 parent ee0aad4
Costin Leau authored
View
2  src/main/java/org/springframework/data/hadoop/hbase/HbaseInterceptor.java
@@ -53,7 +53,7 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable {
for (String tableName : tableNames) {
if (!HbaseSynchronizationManager.hasResource(tableName)) {
boundTables.add(tableName);
- HTableInterface table = HbaseUtils.getHTable(getTableFactory(), getCharset(), getConfiguration(), tableName);
+ HTableInterface table = HbaseUtils.getHTable(tableName, getConfiguration(), getCharset(), getTableFactory());
HbaseSynchronizationManager.bindResource(tableName, table);
}
}
View
4 src/main/java/org/springframework/data/hadoop/hbase/HbaseTemplate.java
@@ -72,11 +72,11 @@ public HbaseTemplate(Configuration configuration) {
}
private HTableInterface getTable(String tableName) {
- return HbaseUtils.getHTable(getTableFactory(), getCharset(), getConfiguration(), tableName);
+ return HbaseUtils.getHTable(tableName, getConfiguration(), getCharset(), getTableFactory());
}
private void releaseTable(String tableName, HTableInterface table) {
- HbaseUtils.releaseTable(tableName, table);
+ HbaseUtils.releaseTable(tableName, table, getTableFactory());
}
private boolean applyFlushSetting(HTableInterface table) {
View
35 src/main/java/org/springframework/data/hadoop/hbase/HbaseUtils.java
@@ -49,20 +49,20 @@ public static DataAccessException convertHbaseException(Exception ex) {
* @param tableName table name
* @return table instance
*/
- public static HTableInterface getHTable(Configuration configuration, String tableName) {
- return getHTable(null, getCharset(null), configuration, tableName);
+ public static HTableInterface getHTable(String tableName, Configuration configuration) {
+ return getHTable(tableName, configuration, getCharset(null), null);
}
/**
* Retrieves an Hbase table instance identified by its name and charset using the given table factory.
*
- * @param tableFactory table factory (may be null)
- * @param charset name charset (may be null)
- * @param configuration Hbase configuration object
* @param tableName table name
+ * @param configuration Hbase configuration object
+ * @param charset name charset (may be null)
+ * @param tableFactory table factory (may be null)
* @return table instance
*/
- public static HTableInterface getHTable(HTableInterfaceFactory tableFactory, Charset charset, Configuration configuration, String tableName) {
+ public static HTableInterface getHTable(String tableName, Configuration configuration, Charset charset, HTableInterfaceFactory tableFactory) {
if (HbaseSynchronizationManager.hasResource(tableName)) {
return (HTable) HbaseSynchronizationManager.getResource(tableName);
}
@@ -94,20 +94,37 @@ static Charset getCharset(String encoding) {
* @param table
*/
public static void releaseTable(String tableName, HTableInterface table) {
+ releaseTable(tableName, table, null);
+ }
+
+ /**
+ * Releases (and closes) the given table, created via the given configuration if it is not managed externally.
+ *
+ * @param tableName
+ * @param table
+ * @param tableFactory
+ */
+ public static void releaseTable(String tableName, HTableInterface table, HTableInterfaceFactory tableFactory) {
try {
- doReleaseTable(tableName, table);
+ doReleaseTable(tableName, table, tableFactory);
} catch (IOException ex) {
throw HbaseUtils.convertHbaseException(ex);
}
}
- private static void doReleaseTable(String tableName, HTableInterface table) throws IOException {
+ private static void doReleaseTable(String tableName, HTableInterface table, HTableInterfaceFactory tableFactory)
+ throws IOException {
if (table == null) {
return;
}
if (!isBoundToThread(tableName)) {
- table.close();
+ if (tableFactory != null) {
+ tableFactory.releaseHTableInterface(table);
+ }
+ else {
+ table.close();
+ }
}
}
View
14 src/test/java/org/springframework/data/hadoop/fs/HdfsResouceLoaderTest.java
@@ -73,7 +73,7 @@ public void before() throws Exception {
System.out.println("Current user is " + UserGroupInformation.getCurrentUser());
System.out.println("Home dir is " + fs.getHomeDirectory().toString());
-// System.out.println("Root folder is " + fs.exists(new Path("/")));
+ // System.out.println("Root folder is " + fs.exists(new Path("/")));
loader = new HdfsResourceLoader(cfb.getObject(), null);
}
@@ -285,4 +285,16 @@ public void testCompressedStream() throws Exception {
loader.setUseCodecs(true);
}
}
+
+ @Test
+ public void testURLCycle() throws Exception {
+ ConfigurationFactoryBean cfactory;
+ cfactory = new ConfigurationFactoryBean();
+ cfactory.setRegisterUrlHandler(true);
+ cfactory.afterPropertiesSet();
+
+ /* create hdfs resource loader */
+ HdfsResourceLoader ldr = new HdfsResourceLoader(cfactory.getObject(), null, null);
+ assertNotNull(ldr);
+ }
}
View
2  src/test/java/org/springframework/data/hadoop/hbase/BasicHBaseTest.java
@@ -112,7 +112,7 @@ public void testHBaseConnection() throws Exception {
public void testTemplate() throws Exception {
assertTrue(HbaseSynchronizationManager.getTableNames().isEmpty());
- final HTableInterface t = HbaseUtils.getHTable(config, tableName);
+ final HTableInterface t = HbaseUtils.getHTable(tableName, config);
template.execute(tableName, new TableCallback<Object>() {
@Override
Please sign in to comment.
Something went wrong with that request. Please try again.