Permalink
Browse files

fix for null cache issue

  • Loading branch information...
1 parent d56c809 commit 882c98e0896c3b78330bff76cc9bb2cc0de237b0 @nrelbuilder nrelbuilder committed Oct 3, 2012
@@ -106,16 +106,14 @@ public Row find(DboTableMeta colFamily, byte[] rowKey) {
c = new EmptyCache(this);
}
+ //NOTE: I would put a finally to clear out the threadlocal normally BUT sometimes log statements may
+ //cause further finds to be called which come in here as well and on their way BACK up the stack, they set
+ //the cache to NULL before the find actually happens(ie. very bad).
CacheThreadLocal.setCache(c);
- try {
- //A layer below will read the thread local and pass it to lowest layer to use
-
- AbstractCursor<KeyValue<Row>> rowsFromDb = session.find(colFamily, rowKeys, skipCache, batchSize);
-
- return rowsFromDb;
- } finally {
- CacheThreadLocal.setCache(null);
- }
+
+ //A layer below will read the thread local and pass it to lowest layer to use
+ AbstractCursor<KeyValue<Row>> rowsFromDb = session.find(colFamily, rowKeys, skipCache, batchSize);
+ return rowsFromDb;
}
public RowHolder<Row> fromCache(DboTableMeta colFamily, byte[] key) {
@@ -292,11 +292,16 @@ public void close() {
public AbstractCursor<KeyValue<Row>> find(DboTableMeta colFamily,
Iterable<byte[]> rowKeys, Cache realCache, int batchSize, BatchListener l, MetaLookup mgr) {
BatchListener list = l;
+ //NOTE: get the cache here before the below log statement which used to clear out the trhead local as it ends
+ //up doing a find through the cache layer that used to clear the thread local
+ Cache cache = CacheThreadLocal.getCache();
+
if(log.isInfoEnabled()) {
list = new LogBatchFetch("CF="+colFamily, l, batchSize);
}
- Cache cache = CacheThreadLocal.getCache();
+ if(cache == null)
+ throw new IllegalArgumentException("bug, above layer needs to call CacheThradLocal.setCache(cache) with non-null cache");
return session.find(colFamily, rowKeys, cache, batchSize, list, mgr);
}

0 comments on commit 882c98e

Please sign in to comment.