Implement a minimum lock expiration time.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/4945b6f2 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/4945b6f2 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/4945b6f2 Branch: refs/heads/USERGRID-1047 Commit: 4945b6f2d3a8a2d6e78c230bce6be09082dfa68c Parents: 289cc97 Author: Michael Russo <michaelaru...@gmail.com> Authored: Fri Jan 15 14:30:58 2016 -0800 Committer: Michael Russo <michaelaru...@gmail.com> Committed: Fri Jan 15 14:30:58 2016 -0800 ---------------------------------------------------------------------- .../cassandra/AstyanaxLockManagerImpl.java | 25 +++++++++++++++++++- .../persistence/core/astyanax/CassandraFig.java | 10 ++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/4945b6f2/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java index 1fcd1b7..a69aee2 100644 --- a/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java +++ b/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java @@ -52,6 +52,7 @@ public class AstyanaxLockManagerImpl implements LockManager { private final CassandraFig cassandraFig; private final Keyspace keyspace; private final ColumnFamily columnFamily; + private static final int MINIMUM_LOCK_EXPIRATION = 60000; // 1 minute @Inject public AstyanaxLockManagerImpl(CassandraFig cassandraFig, @@ -80,13 +81,35 @@ public class AstyanaxLockManagerImpl implements LockManager { consistencyLevel = ConsistencyLevel.valueOf(cassandraFig.getLocksCl()); }catch(IllegalArgumentException e){ + logger.warn( "Property {} value provided: {} is not valid", CassandraFig.LOCKS_CL, + cassandraFig.getLocksCl() ); + // just default it to local quorum if we can't parse consistencyLevel = ConsistencyLevel.CL_LOCAL_QUORUM; } + + int lockExpiration; + int lockConfigExpiration = cassandraFig.getLocksExpiration(); + if( lockConfigExpiration >= MINIMUM_LOCK_EXPIRATION ){ + + lockExpiration = Math.min(cassandraFig.getLocksExpiration(), Integer.MAX_VALUE); + + }else{ + + logger.warn("Property {} is not valid. Choose a value greater than or equal to {}", + CassandraFig.LOCKS_EXPIRATION, + MINIMUM_LOCK_EXPIRATION); + + // use the default if seomthing below the minimum is provided + lockExpiration = Integer.valueOf(CassandraFig.DEFAULT_LOCKS_EXPIRATION); + } + + + ColumnPrefixDistributedRowLock<String> lock = new ColumnPrefixDistributedRowLock<>(keyspace, columnFamily, lockPath) - .expireLockAfter( Integer.MAX_VALUE, TimeUnit.MILLISECONDS) + .expireLockAfter( lockExpiration, TimeUnit.MILLISECONDS) .withConsistencyLevel(consistencyLevel); http://git-wip-us.apache.org/repos/asf/usergrid/blob/4945b6f2/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java index caee5c1..e30ba9c 100644 --- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java +++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java @@ -46,11 +46,14 @@ public interface CassandraFig extends GuicyFig { String LOCKS_CL = "cassandra.lock.cl"; String LOCKS_SHARED_POOL_FLAG = "cassandra.lock.use_shared_pool"; String LOCKS_CONNECTIONS = "cassandra.lock.connections"; + String LOCKS_EXPIRATION = "cassandra.lock.expiration.milliseconds"; + // re-usable default values String DEFAULT_CONNECTION_POOLSIZE = "15"; + String DEFAULT_LOCKS_EXPIRATION = "3600000"; // 1 hour @Key( "cassandra.hosts" ) @@ -162,4 +165,11 @@ public interface CassandraFig extends GuicyFig { @Default( "org.apache.cassandra.locator.SimpleStrategy" ) String getLocksKeyspaceStrategy(); + /** + * Return the expiration that should be used for expiring a lock if it's not released + */ + @Key( LOCKS_EXPIRATION ) + @Default(DEFAULT_LOCKS_EXPIRATION) + int getLocksExpiration(); + }