Skip to content

Commit

Permalink
Clean up get stats methods in (Queued)KeyedResourcePool. Fix error in…
Browse files Browse the repository at this point in the history
… test case.
  • Loading branch information
jayjwylie committed Oct 9, 2012
1 parent 0626f60 commit e070703
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
54 changes: 24 additions & 30 deletions src/java/voldemort/utils/pool/KeyedResourcePool.java
Expand Up @@ -297,17 +297,15 @@ public synchronized void reset(K key) {
* given key.
*/
public int getTotalResourceCount(K key) {
int rc = 0;
if(!resourcePoolMap.containsKey(key)) {
return rc;
}
try {
Pool<V> resourcePool = getResourcePoolForExistingKey(key);
rc = resourcePool.size.get();
} catch(IllegalArgumentException iae) {
logger.debug("getTotalResourceCount called on invalid key: ", iae);
if(resourcePoolMap.containsKey(key)) {
try {
Pool<V> resourcePool = getResourcePoolForExistingKey(key);
return resourcePool.size.get();
} catch(IllegalArgumentException iae) {
logger.debug("getTotalResourceCount called on invalid key: ", iae);
}
}
return rc;
return 0;
}

/**
Expand All @@ -332,17 +330,15 @@ public int getTotalResourceCount() {
* for given key.
*/
public int getCheckedInResourcesCount(K key) {
int rc = 0;
if(!resourcePoolMap.containsKey(key)) {
return rc;
}
try {
Pool<V> resourcePool = getResourcePoolForExistingKey(key);
rc = resourcePool.queue.size();
} catch(IllegalArgumentException iae) {
logger.debug("getCheckedInResourceCount called on invalid key: ", iae);
if(resourcePoolMap.containsKey(key)) {
try {
Pool<V> resourcePool = getResourcePoolForExistingKey(key);
return resourcePool.queue.size();
} catch(IllegalArgumentException iae) {
logger.debug("getCheckedInResourceCount called on invalid key: ", iae);
}
}
return rc;
return 0;
}

/**
Expand All @@ -367,17 +363,15 @@ public int getCheckedInResourceCount() {
* key.
*/
public int getBlockingGetsCount(K key) {
int rc = 0;
if(!resourcePoolMap.containsKey(key)) {
return rc;
}
try {
Pool<V> resourcePool = getResourcePoolForExistingKey(key);
rc = resourcePool.blockingGets.get();
} catch(IllegalArgumentException iae) {
logger.debug("getBlockingGetsCount called on invalid key: ", iae);
if(resourcePoolMap.containsKey(key)) {
try {
Pool<V> resourcePool = getResourcePoolForExistingKey(key);
return resourcePool.blockingGets.get();
} catch(IllegalArgumentException iae) {
logger.debug("getBlockingGetsCount called on invalid key: ", iae);
}
}
return rc;
return 0;
}

/**
Expand Down
20 changes: 9 additions & 11 deletions src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java
Expand Up @@ -329,18 +329,16 @@ protected Queue<AsyncResourceRequest<V>> getRequestQueueForExistingKey(K key) {
* exists for given key.
*/
public int getRegisteredResourceRequestCount(K key) {
int rc = 0;
if(!requestQueueMap.containsKey(key)) {
return rc;
}
try {
Queue<AsyncResourceRequest<V>> requestQueue = getRequestQueueForExistingKey(key);
// FYI: .size() is not constant time in the next call. ;)
rc = requestQueue.size();
} catch(IllegalArgumentException iae) {
logger.debug("getRegisteredResourceRequestCount called on invalid key: ", iae);
if(requestQueueMap.containsKey(key)) {
try {
Queue<AsyncResourceRequest<V>> requestQueue = getRequestQueueForExistingKey(key);
// FYI: .size() is not constant time in the next call. ;)
return requestQueue.size();
} catch(IllegalArgumentException iae) {
logger.debug("getRegisteredResourceRequestCount called on invalid key: ", iae);
}
}
return rc;
return 0;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/unit/voldemort/store/memory/SlowStorageEngineTest.java
Expand Up @@ -66,7 +66,9 @@ public void setUp() throws Exception {
// unit tests assert on specific delays occurring.
OpTimeMap queued = new OpTimeMap(10, 20, 30, 40, 50);
OpTimeMap concurrent = new OpTimeMap(50, 40, 30, 20, 10);
this.store = new SlowStorageEngine<ByteArray, byte[], byte[]>("test", queued, concurrent);
this.store = new SlowStorageEngine<ByteArray, byte[], byte[]>(new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"),
queued,
concurrent);
}

@Override
Expand Down

0 comments on commit e070703

Please sign in to comment.