Example #1
0
 private long getCommitTimestampRollBackIfNecessary(
     long startTimestamp, Multimap<String, Cell> tableNameToCell) {
   Long commitTimestamp = transactionService.get(startTimestamp);
   if (commitTimestamp == null) {
     // Roll back this transaction (note that rolling back arbitrary transactions
     // can never cause correctness issues, only liveness issues)
     try {
       transactionService.putUnlessExists(startTimestamp, TransactionConstants.FAILED_COMMIT_TS);
     } catch (KeyAlreadyExistsException e) {
       String msg =
           "Could not roll back transaction with start timestamp "
               + startTimestamp
               + "; either"
               + " it was already rolled back (by a different transaction), or it committed successfully"
               + " before we could roll it back.";
       log.error(
           "This isn't a bug but it should be very infrequent. " + msg,
           new TransactionFailedRetriableException(msg, e));
     }
     commitTimestamp = transactionService.get(startTimestamp);
   }
   if (commitTimestamp == null) {
     throw new RuntimeException(
         "expected commit timestamp to be non-null for startTs: " + startTimestamp);
   }
   if (commitTimestamp == TransactionConstants.FAILED_COMMIT_TS) {
     for (String table : tableNameToCell.keySet()) {
       Map<Cell, Long> toDelete =
           Maps2.createConstantValueMap(tableNameToCell.get(table), startTimestamp);
       keyValueService.delete(table, Multimaps.forMap(toDelete));
     }
   }
   return commitTimestamp;
 }
Example #2
0
 private void deleteCellsAtTimestamps(
     TransactionManager txManager,
     String tableName,
     Multimap<Cell, Long> cellToTimestamp,
     Transaction.TransactionType transactionType) {
   if (!cellToTimestamp.isEmpty()) {
     for (Follower follower : followers) {
       follower.run(txManager, tableName, cellToTimestamp.keySet(), transactionType);
     }
     keyValueService.addGarbageCollectionSentinelValues(tableName, cellToTimestamp.keySet());
     keyValueService.delete(tableName, cellToTimestamp);
   }
 }
  private void sweepCells(
      String tableName, Multimap<Cell, Long> cellTsPairsToSweep, Set<Cell> sentinelsToAdd) {
    if (cellTsPairsToSweep.isEmpty()) {
      return;
    }

    for (Follower follower : followers) {
      follower.run(txManager, tableName, cellTsPairsToSweep.keySet(), TransactionType.HARD_DELETE);
    }
    if (!sentinelsToAdd.isEmpty()) {
      keyValueService.addGarbageCollectionSentinelValues(tableName, sentinelsToAdd);
    }
    keyValueService.delete(tableName, cellTsPairsToSweep);
  }