ServerLockCleaner { public void cleanLock(ThemisLock lock) throws IOException { long beginTs = System.nanoTime(); try { PrimaryLock primary = getPrimaryLockWithColumn(lock); Pair<Long, PrimaryLock> cleanResult = cleanPrimaryLock(primary.getColumn(), primary.getTimestamp()); primary = cleanResult.getSecond() == null ? primary : cleanResult.getSecond(); cleanSecondaryLocks(primary, cleanResult.getFirst()); ThemisCpStatistics.getThemisCpStatistics().cleanLockSuccessCount.inc(); } catch (IOException e) { ThemisCpStatistics.getThemisCpStatistics().cleanLockFailCount.inc(); throw e; } finally { ThemisCpStatistics.updateLatency(ThemisCpStatistics.getThemisCpStatistics().cleanLockLatency, beginTs, "lock=" + lock); } } ServerLockCleaner(HConnection conn, ThemisCoprocessorClient cpClient); static PrimaryLock getPrimaryLockWithColumn(ThemisLock lock); void cleanLock(ThemisLock lock); Pair<Long, PrimaryLock> cleanPrimaryLock(ColumnCoordinate columnCoordinate,
      long prewriteTs); Long getTimestampOfWriteIndexingPrewriteTs(ColumnCoordinate columnCoordinate, long timestamp); Get createGetOfWriteColumnsIndexingPrewriteTs(ColumnCoordinate columnCoordinate, long timestamp); void cleanSecondaryLocks(PrimaryLock primaryLock, Long commitTs); void eraseLockAndData(ColumnCoordinate column, long timestamp); void eraseLockAndData(byte[] tableName, byte[] row, Collection<Column> columns, long timestamp);  }
@Test public void testCleanLockFromPrimary() throws IOException { ThemisLock from = getLock(COLUMN); writeLockAndData(COLUMN); prepareCleanSecondaryLocks(false); lockCleaner.cleanLock(from); checkTransactionRollback(); deleteOldDataAndUpdateTs(); writePutAndData(COLUMN, prewriteTs, commitTs); prepareCleanSecondaryLocks(true); from = getLock(COLUMN); lockCleaner.cleanLock(from); checkTransactionCommitSuccess(); deleteOldDataAndUpdateTs(); writeData(COLUMN, prewriteTs); prepareCleanSecondaryLocks(false); from = getLock(COLUMN); lockCleaner.cleanLock(from); checkTransactionRollback(); }
@Test public void testCleanLockFromSecondary() throws IOException { ColumnCoordinate columnCoordinate = SECONDARY_COLUMNS[1]; ThemisLock from = getLock(columnCoordinate); writeLockAndData(COLUMN); prepareCleanSecondaryLocks(false); lockCleaner.cleanLock(from); checkTransactionRollback(); deleteOldDataAndUpdateTs(); writePutAndData(COLUMN, prewriteTs, commitTs); prepareCleanSecondaryLocks(true); from = getLock(columnCoordinate); lockCleaner.cleanLock(from); checkColumnsCommitSuccess(new ColumnCoordinate[]{COLUMN, SECONDARY_COLUMNS[0], SECONDARY_COLUMNS[1]}); checkColumnsPrewriteSuccess(new ColumnCoordinate[]{SECONDARY_COLUMNS[2], SECONDARY_COLUMNS[3]}); deleteOldDataAndUpdateTs(); writeData(COLUMN, prewriteTs); prepareCleanSecondaryLocks(false); from = getLock(columnCoordinate); lockCleaner.cleanLock(from); checkColumnsRallback(new ColumnCoordinate[]{COLUMN, SECONDARY_COLUMNS[0], SECONDARY_COLUMNS[1]}); checkColumnsPrewriteSuccess(new ColumnCoordinate[]{SECONDARY_COLUMNS[2], SECONDARY_COLUMNS[3]}); }