ServerLockCleaner { public Pair<Long, PrimaryLock> cleanPrimaryLock(ColumnCoordinate columnCoordinate, long prewriteTs) throws IOException { ThemisLock lock = cpClient.getLockAndErase(columnCoordinate, prewriteTs); if (lock != null && !(lock instanceof PrimaryLock)) { throw new ThemisFatalException("encounter no-primary lock when cleanPrimaryLock, column=" + columnCoordinate + ", prewriteTs=" + prewriteTs + ", lock=" + lock); } PrimaryLock primaryLock = (PrimaryLock)lock; Long commitTs = primaryLock != null ? null : getTimestampOfWriteIndexingPrewriteTs(columnCoordinate, prewriteTs); if (commitTs == null) { ThemisCpStatistics.getThemisCpStatistics().cleanLockByEraseCount.inc(); } else { ThemisCpStatistics.getThemisCpStatistics().cleanLockByCommitCount.inc(); } return new Pair<Long, PrimaryLock>(commitTs, primaryLock); } 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 testCleanPrimaryLock() throws IOException { writeLockAndData(COLUMN); Pair<Long, PrimaryLock> result = lockCleaner.cleanPrimaryLock(COLUMN, prewriteTs); Assert.assertNull(result.getFirst()); Assert.assertEquals(getLock(COLUMN), result.getSecond()); Assert.assertNull(readLockBytes(COLUMN)); boolean[] isPuts = new boolean[]{true, false}; for (boolean isPut : isPuts) { deleteOldDataAndUpdateTs(); writeWriteColumn(COLUMN, prewriteTs, commitTs, isPut); result = lockCleaner.cleanPrimaryLock(COLUMN, prewriteTs); Assert.assertEquals(commitTs, result.getFirst().longValue()); Assert.assertNull(result.getSecond()); } deleteOldDataAndUpdateTs(); result = lockCleaner.cleanPrimaryLock(COLUMN, prewriteTs); Assert.assertNull(result.getFirst()); Assert.assertNull(result.getSecond()); }