Permalink
Browse files

Using a separate redis connection to read keys when removing an index

  • Loading branch information...
1 parent 60f7779 commit 366448f184b8579a5cdaf7be7a014a4027568f52 @tareqabedrabbo tareqabedrabbo committed Apr 28, 2011
Showing with 20 additions and 9 deletions.
  1. +20 −9 src/main/java/org/neo4j/index/redis/RedisTransaction.java
@@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.Map;
+import java.util.Set;
import javax.transaction.xa.XAException;
@@ -91,15 +92,25 @@ else if ( kvCommand instanceof KeyValueCommand.RemoveCommand )
// For future deletion of the index
transaction.srem( indexName, redisKey );
}
-// else if ( kvCommand instanceof KeyValueCommand.DeleteIndexCommand )
-// {
-// // TODO this doesn't really scale... getting all the keys for an
-// // index can potentially eat up the entire heap.
-// for ( String indexKey : redisResource.smembers( indexName ) )
-// {
-// transaction.del( indexKey );
-// }
-// }
+ else if ( kvCommand instanceof KeyValueCommand.DeleteIndexCommand ) {
+ // TODO this doesn't really scale... getting all the keys for an
+ // index can potentially eat up the entire heap. Consider replacing with a list.
+
+ // acquire a separate redis connection to read the all the index keys.
+ // using the current redisResource is not possible because of the ongoing transaction
+ Jedis readOnlyRedisResource = null;
+ Set<String> members;
+ try {
+ readOnlyRedisResource = getDataSource().acquireResource();
+ members = readOnlyRedisResource.smembers(indexName);
+ } finally {
+ getDataSource().releaseResource(readOnlyRedisResource);
+ }
+
+ for (String indexKey : members) {
+ transaction.del(indexKey);
+ }
+ }
}
}
closeTxData();

0 comments on commit 366448f

Please sign in to comment.