Permalink
Browse files

Reload only existing pairs

  • Loading branch information...
1 parent 7873604 commit 93683d09d11d75207fae5dcd1c5cfab203e991cd @patricioe patricioe committed Jul 16, 2012
Showing with 17 additions and 5 deletions.
  1. +17 −5 core/src/main/java/me/prettyprint/cassandra/locking/HLockManagerImpl.java
@@ -88,9 +88,11 @@ public void acquire(HLock lock) {
}
}
+ List<String> canBeEarlierSortedList = null;
+
// If everyone acknowledged to have seen me then ...
if (recv_all_acks) {
- List<String> canBeEarlierSortedList = Lists.newArrayList(canBeEarlier.keySet());
+ canBeEarlierSortedList = Lists.newArrayList(canBeEarlier.keySet());
// sort them
Collections.sort(canBeEarlierSortedList);
nextWaitingClientId = canBeEarlierSortedList.get(0);
@@ -111,12 +113,13 @@ public void acquire(HLock lock) {
smartWait(lockManagerConfigurator.getBackOffRetryDelayInMillis());
// Refresh the list
- canBeEarlier = readExistingLocks(lock.getPath());
+ canBeEarlier = readExistingLocks(lock.getPath(), canBeEarlierSortedList);
}
((HLockImpl) lock).setAcquired(true);
}
+
private void smartWait(long sleepTime) {
try {
Thread.sleep((sleepTime + (long) (Math.random() * sleepTime)));
@@ -202,11 +205,16 @@ private void deleteLock(HLock lock) {
* a lock path
* @return a list of locks waiting on this lockpath
*/
- private Map<String, String> readExistingLocks(String lockPath) {
+ private Map<String, String> readExistingLocks(String lockPath, List<String> columnNames) {
SliceQuery<String, String, String> sliceQuery = HFactory
.createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
- .setColumnFamily(lockManagerConfigurator.getLockManagerCF()).setKey(lockPath)
- .setRange(null, null, false, Integer.MAX_VALUE);
+ .setColumnFamily(lockManagerConfigurator.getLockManagerCF()).setKey(lockPath);
+
+ if (columnNames == null) {
+ sliceQuery.setRange(null, null, false, Integer.MAX_VALUE);
+ } else {
+ sliceQuery.setColumnNames(columnNames.toArray(new String[columnNames.size()]));
+ }
QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute();
@@ -219,6 +227,10 @@ private void deleteLock(HLock lock) {
return result;
}
+ private Map<String, String> readExistingLocks(String path) {
+ return readExistingLocks(path, null);
+ }
+
private HColumn<String, String> createColumnForLock(String name, String value) {
return createColumn(name, value, lockManagerConfigurator.getLocksTTLInMillis(), StringSerializer.get(),
StringSerializer.get());

0 comments on commit 93683d0

Please sign in to comment.