Index: CoprocessorHost.java =================================================================== --- CoprocessorHost.java (revision 87270) +++ CoprocessorHost.java (working copy) @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Coprocessor; @@ -36,6 +37,7 @@ import org.apache.hadoop.hbase.client.coprocessor.Batch; import org.apache.hadoop.hbase.ipc.CoprocessorProtocol; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.SortedCopyOnWriteSet; import org.apache.hadoop.hbase.util.VersionInfo; import org.apache.hadoop.hbase.Server; @@ -87,7 +89,7 @@ * to allow GC'ing when no CoprocessorHost is using it * (@see HBASE-7205) */ - static ConcurrentMap classLoadersCache = + static ConcurrentMap> classLoadersCache = new MapMaker().concurrencyLevel(3).weakValues().makeMap(); public CoprocessorHost() { @@ -187,7 +189,18 @@ } else { // Have we already loaded the class, perhaps from an earlier region open // for the same table? - cl = classLoadersCache.get(path); + Pair pair = classLoadersCache.get(path); + if (pair != null) { + FileChecksum lastCheckSum = pair.getFirst(); + FileSystem fs = path.getFileSystem(this.conf); + if(fs.getFileChecksum(path).equals(lastCheckSum)) { + cl = pair.getSecond(); + } else { + LOG.info("the coprocessor jar '" + path + "' has been changed, reload it..."); + // remove the expired item from the cache + classLoadersCache.remove(path); + } + } if (cl != null){ LOG.debug("Found classloader "+ cl + "for "+path.toString()); try { @@ -248,10 +261,10 @@ cl = new CoprocessorClassLoader(paths, this.getClass().getClassLoader()); // cache cp classloader as a weak value, will be GC'ed when no reference left - ClassLoader prev = classLoadersCache.putIfAbsent(path, cl); + Pair prev = classLoadersCache.putIfAbsent(path, new Pair(fs.getFileChecksum(path), cl)); if (prev != null) { //lost update race, use already added classloader - cl = prev; + cl = prev.getSecond(); } try {