spring-projects/spring-hadoop — pull request #18 by chinatimwu (2013-10-09 05:18:56+00:00)
Title: In HBase Ver 0.94.6, get erro log of "[Thread-2] ERROR org.apache.hadoop.hbase.client.HConnectionManager.deleteConnection:301 - Connection not found in the list, can't delete it..."

Indeed, there are two problems.

1) In the sample of spring-data-book-hadoop-hbase, UserUtils.java is not safe as HBaseConnection
may be not closed when ApplicationContext is closed. Because,
@Override
public void afterPropertiesSet() throws Exception {
admin = new HBaseAdmin(config);
}
will create a connection and increase a count of connections.
If we have two class as UserUtils.java, that means 'new HBaseAdmin(config)' will be invoked twice, then
the count of connections is 2.

However, when xxxApplicationContext.close(), the count will be only decreased once, so the connection will not
really be closed/released. The detail ref to HConnectionManager.deleteConnection (line 301 in hbase 0.94.6 version).

So, I think a more safe UserUtils.java should implements DisposableBean interface like these:

@Component
public class UserUtils implements InitializingBean, DisposableBean {

............

public void afterPropertiesSet() throws Exception {
admin = new HBaseAdmin(config);
}

public void destroy() {
try {
admin.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

.......
}

2) I doubt the usefulness of .

If upgrading hbase lib to 0.94.6, and modifying UserUtils.java as above, We will get
the following ERROR information when xxxApplicationContext.close() (due to HbaseConfigurationFactoryBean.destroy()):
12:21:07.824 [Thread-2] ERROR org.apache.hadoop.hbase.client.HConnectionManager.deleteConnection:301 - Connection not found in the list, can't delete it (connection key=HConnectionKey{properties={hbase.zookeeper.property.clientPort=2181, hbase.client.pause=1000, zookeeper.znode.parent=/hbase, hbase.client.retries.number=10, hbase.zookeeper.quorum=vs1}, username='tim'}). May be the key was modified?

In HConnectionManager.deleteConnection (line 301 in hbase 0.94.6):
public class HConnectionManager{
....
private static void deleteConnection(HConnectionKey connectionKey,
boolean staleConnection) {
synchronized (HBASE_INSTANCES) {
HConnectionImplementation connection = HBASE_INSTANCES
.get(connectionKey);
if (connection != null) {
connection.decCount();
if (connection.isZeroReference() || staleConnection) {
HBASE_INSTANCES.remove(connectionKey);
connection.internalClose();
}
}else {
301: LOG.error("Connection not found in the list, can't delete it "+
"(connection key="+connectionKey+"). May be the key was modified?");
}
}
}
....
}

We knows that when xxxxApplicationContext.close(), the HConnectionManager.deleteConnection() will be invoked.
As all connections will be correctlly closed if we use Spring HbaseTemplate, so BASE_INSTANCES.get(connectionKey) will
return null, then we will get this information.