@Test public void testConstructLocks() throws IOException { ThemisLock expectLock = getPrimaryLock(); List<KeyValue> kvs = new ArrayList<KeyValue>(); kvs.add(getLockKv(KEYVALUE, ThemisLock.toByte(expectLock))); String rawClientLockTTL = conf.get(TransactionConstant.CLIENT_LOCK_TTL_KEY); int clientLockTTL = 10; Threads.sleep(clientLockTTL); Assert.assertTrue(System.currentTimeMillis() - expectLock.getTimestamp() > clientLockTTL); List<ThemisLock> locks = LockCleaner.constructLocks(TABLENAME, kvs, cpClient, clientLockTTL); Assert.assertEquals(1, locks.size()); Assert.assertTrue(expectLock.equals(locks.get(0))); Assert.assertTrue(COLUMN.equals(locks.get(0).getColumn())); Assert.assertTrue(locks.get(0).isLockExpired()); conf.set(TransactionConstant.CLIENT_LOCK_TTL_KEY, rawClientLockTTL != null ? rawClientLockTTL : "0"); kvs.add(KEYVALUE); try { LockCleaner.constructLocks(TABLENAME, kvs, cpClient, 0); Assert.fail(); } catch (ThemisFatalException e) {} }
public static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs, ThemisCoprocessorClient cpClient, int clientLockTTL) throws IOException { List<ThemisLock> locks = new ArrayList<ThemisLock>(); if (lockKvs != null) { for (KeyValue kv : lockKvs) { ColumnCoordinate lockColumn = new ColumnCoordinate(tableName, kv.getRow(), kv.getFamily(), kv.getQualifier()); if (!ColumnUtil.isLockColumn(lockColumn)) { throw new ThemisFatalException("get no-lock column when constructLocks, kv=" + kv); } ThemisLock lock = ThemisLock.parseFromByte(kv.getValue()); ColumnCoordinate dataColumn = new ColumnCoordinate(tableName, lockColumn.getRow(), ColumnUtil.getDataColumn(lockColumn)); lock.setColumn(dataColumn); checkLockExpired(lock, cpClient, clientLockTTL); locks.add(lock); } } return locks; }
LockCleaner extends ServerLockCleaner { public static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs, ThemisCoprocessorClient cpClient, int clientLockTTL) throws IOException { List<ThemisLock> locks = new ArrayList<ThemisLock>(); if (lockKvs != null) { for (KeyValue kv : lockKvs) { ColumnCoordinate lockColumn = new ColumnCoordinate(tableName, kv.getRow(), kv.getFamily(), kv.getQualifier()); if (!ColumnUtil.isLockColumn(lockColumn)) { throw new ThemisFatalException("get no-lock column when constructLocks, kv=" + kv); } ThemisLock lock = ThemisLock.parseFromByte(kv.getValue()); ColumnCoordinate dataColumn = new ColumnCoordinate(tableName, lockColumn.getRow(), ColumnUtil.getDataColumn(lockColumn)); lock.setColumn(dataColumn); checkLockExpired(lock, cpClient, clientLockTTL); locks.add(lock); } } return locks; } }
LockCleaner extends ServerLockCleaner { public static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs, ThemisCoprocessorClient cpClient, int clientLockTTL) throws IOException { List<ThemisLock> locks = new ArrayList<ThemisLock>(); if (lockKvs != null) { for (KeyValue kv : lockKvs) { ColumnCoordinate lockColumn = new ColumnCoordinate(tableName, kv.getRow(), kv.getFamily(), kv.getQualifier()); if (!ColumnUtil.isLockColumn(lockColumn)) { throw new ThemisFatalException("get no-lock column when constructLocks, kv=" + kv); } ThemisLock lock = ThemisLock.parseFromByte(kv.getValue()); ColumnCoordinate dataColumn = new ColumnCoordinate(tableName, lockColumn.getRow(), ColumnUtil.getDataColumn(lockColumn)); lock.setColumn(dataColumn); checkLockExpired(lock, cpClient, clientLockTTL); locks.add(lock); } } return locks; } LockCleaner(Configuration conf, HConnection conn, WorkerRegister register,
      ThemisCoprocessorClient cpClient); }
LockCleaner extends ServerLockCleaner { public static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs, ThemisCoprocessorClient cpClient, int clientLockTTL) throws IOException { List<ThemisLock> locks = new ArrayList<ThemisLock>(); if (lockKvs != null) { for (KeyValue kv : lockKvs) { ColumnCoordinate lockColumn = new ColumnCoordinate(tableName, kv.getRow(), kv.getFamily(), kv.getQualifier()); if (!ColumnUtil.isLockColumn(lockColumn)) { throw new ThemisFatalException("get no-lock column when constructLocks, kv=" + kv); } ThemisLock lock = ThemisLock.parseFromByte(kv.getValue()); ColumnCoordinate dataColumn = new ColumnCoordinate(tableName, lockColumn.getRow(), ColumnUtil.getDataColumn(lockColumn)); lock.setColumn(dataColumn); checkLockExpired(lock, cpClient, clientLockTTL); locks.add(lock); } } return locks; } LockCleaner(Configuration conf, HConnection conn, WorkerRegister register,
      ThemisCoprocessorClient cpClient); static LockCleaner getLockCleaner(Configuration conf, HConnection conn,
      WorkerRegister register, ThemisCoprocessorClient cpClient); boolean shouldCleanLock(ThemisLock lock); static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs,
      ThemisCoprocessorClient cpClient, int clientLockTTL); static void checkLockExpired(ThemisLock lock, ThemisCoprocessorClient cpClient,
      int clientLockTTL); void tryToCleanLocks(byte[] tableName, List<KeyValue> lockColumns); boolean checkLockExpiredAndTryToCleanLock(ThemisLock lock); boolean tryToCleanLock(ThemisLock lock); }
LockCleaner extends ServerLockCleaner { public static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs, ThemisCoprocessorClient cpClient, int clientLockTTL) throws IOException { List<ThemisLock> locks = new ArrayList<ThemisLock>(); if (lockKvs != null) { for (KeyValue kv : lockKvs) { ColumnCoordinate lockColumn = new ColumnCoordinate(tableName, kv.getRow(), kv.getFamily(), kv.getQualifier()); if (!ColumnUtil.isLockColumn(lockColumn)) { throw new ThemisFatalException("get no-lock column when constructLocks, kv=" + kv); } ThemisLock lock = ThemisLock.parseFromByte(kv.getValue()); ColumnCoordinate dataColumn = new ColumnCoordinate(tableName, lockColumn.getRow(), ColumnUtil.getDataColumn(lockColumn)); lock.setColumn(dataColumn); checkLockExpired(lock, cpClient, clientLockTTL); locks.add(lock); } } return locks; } LockCleaner(Configuration conf, HConnection conn, WorkerRegister register,
      ThemisCoprocessorClient cpClient); static LockCleaner getLockCleaner(Configuration conf, HConnection conn,
      WorkerRegister register, ThemisCoprocessorClient cpClient); boolean shouldCleanLock(ThemisLock lock); static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs,
      ThemisCoprocessorClient cpClient, int clientLockTTL); static void checkLockExpired(ThemisLock lock, ThemisCoprocessorClient cpClient,
      int clientLockTTL); void tryToCleanLocks(byte[] tableName, List<KeyValue> lockColumns); boolean checkLockExpiredAndTryToCleanLock(ThemisLock lock); boolean tryToCleanLock(ThemisLock lock);  }