import org.onap.music.main.ReturnType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
/*
* This is the lock store that is built on top of Cassandra that is used by MUSIC to maintain lock state.
public class CassaLockStore {
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CassaLockStore.class);
- private static String table_prepend_name = "lockQ_";
+ public static final String table_prepend_name = "lockQ_";
private MusicDataStore dsHandle;
public CassaLockStore() {
table = table_prepend_name+table;
String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ " ( key text, lockReference bigint, createTime text, acquireTime text, guard bigint static, "
- + "lockType text, owner text, PRIMARY KEY ((key), lockReference) ) "
+ + "lockType text, leasePeriodTime bigint, owner text, PRIMARY KEY ((key), lockReference) ) "
+ "WITH CLUSTERING ORDER BY (lockReference ASC);";
PreparedQueryObject queryObject = new PreparedQueryObject();
}
public boolean checkForDeadlock(String keyspace, String table, String lockName, LockType locktype, String owner, boolean forAcquire) throws MusicServiceException, MusicQueryException {
- if (locktype.equals(LockType.READ)) return false;
- if (owner==null || owner.length()==0) return false;
+ if (locktype.equals(LockType.READ))
+ return false;
+ if (owner==null || owner.length()==0)
+ return false;
String lockTable = table_prepend_name + table;
PreparedQueryObject queryObject = new PreparedQueryObject();
ddu.setExisting(row.getString("key"), row.getString("owner"), ("0".equals(row.getString("acquiretime")))?OwnershipType.CREATED:OwnershipType.ACQUIRED);
}
boolean deadlock = ddu.checkForDeadlock(lockName, owner, forAcquire?OwnershipType.ACQUIRED:OwnershipType.CREATED);
- if (deadlock) logger.warn("Deadlock detected when " + owner + " tried to create lock on " + keyspace + "." + lockTable + "." + lockName);
+ if (deadlock)
+ logger.warn("Deadlock detected when " + owner + " tried to create lock on " + keyspace + "." + lockTable + "." + lockName);
return deadlock;
}
}
public List<String> getAllLocksForOwner(String ownerId, String keyspace, String table) throws MusicServiceException, MusicQueryException {
- List<String> toRet = new ArrayList<String>();
+ List<String> toRet = new ArrayList<>();
String lockTable = table_prepend_name + table;
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("SELECT key, lockreference FROM " + keyspace + "." + lockTable);
}
public ReturnType promoteLock(String keyspace, String table, String key, String lockRef)
- throws MusicLockingException, MusicServiceException, MusicQueryException {
+ throws MusicServiceException, MusicQueryException {
String lockqtable = table_prepend_name + table;
String selectQuery = "select * from " + keyspace + "." + lockqtable + " where key=?;";