Permalink
Browse files

Changed reset and destroyRequestQueue to avoid any heavy weight synch…

…ronization methods. This should fix deadlock issue.
  • Loading branch information...
1 parent 2b30b33 commit 2768eef1dc34f6496eeaa4781308792c00276a35 @jayjwylie jayjwylie committed Nov 8, 2012
Showing with 15 additions and 8 deletions.
  1. +15 −8 src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java
View
23 src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java
@@ -243,11 +243,13 @@ protected void destroyRequest(AsyncResourceRequest<V> resourceRequest) {
* @param requestQueue The queue for which all resource requests are to be
* destroyed.
*/
- private synchronized void destroyRequestQueue(Queue<AsyncResourceRequest<V>> requestQueue) {
- AsyncResourceRequest<V> resourceRequest = requestQueue.poll();
- while(resourceRequest != null) {
- destroyRequest(resourceRequest);
- resourceRequest = requestQueue.poll();
+ private void destroyRequestQueue(Queue<AsyncResourceRequest<V>> requestQueue) {
+ if(requestQueue != null) {
+ AsyncResourceRequest<V> resourceRequest = requestQueue.poll();
+ while(resourceRequest != null) {
+ destroyRequest(resourceRequest);
+ resourceRequest = requestQueue.poll();
+ }
}
}
@@ -283,9 +285,14 @@ public void close() {
@Override
public void reset(K key) {
// First, destroy enqueued resource requests (if any exist).
- Queue<AsyncResourceRequest<V>> requestQueue = requestQueueMap.get(key);
- if(requestQueue != null) {
- destroyRequestQueue(requestQueue);
+ Queue<AsyncResourceRequest<V>> requestQueueToDestroy = requestQueueMap.get(key);
+ if(requestQueueToDestroy != null) {
+ // Swap in a new requestQueue so that the current requestQueue can
+ // be destroyed without the need of any synchronization primitives
+ Queue<AsyncResourceRequest<V>> newRequestQueue = new ConcurrentLinkedQueue<AsyncResourceRequest<V>>();
+ if(requestQueueMap.replace(key, requestQueueToDestroy, newRequestQueue)) {
+ destroyRequestQueue(requestQueueToDestroy);
+ }
}
// Second, destroy resources in the pool.

0 comments on commit 2768eef

Please sign in to comment.