public CommitTimestamp locateCellCommitTimestamp()

in hbase-client/src/main/java/org/apache/omid/transaction/SnapshotFilterImpl.java [166:241]


    public CommitTimestamp locateCellCommitTimestamp(long cellStartTimestamp, long epoch,
                                                     CommitTimestampLocator locator, boolean isLowLatency) throws IOException {

        try {
            // 1) First check the cache
            Optional<Long> commitTimestamp = locator.readCommitTimestampFromCache(cellStartTimestamp);
            if (commitTimestamp.isPresent()) { // Valid commit timestamp
                return new CommitTimestamp(CACHE, commitTimestamp.get(), true);
            }

            // 2) Then check the commit table
            // If the data was written at a previous epoch, check whether the transaction was invalidated
            boolean invalidatedByOther = false;
            Optional<CommitTimestamp> commitTimestampFromCT = commitTableClient.getCommitTimestamp(cellStartTimestamp).get();
            if (commitTimestampFromCT.isPresent()) {
                if (isLowLatency && !commitTimestampFromCT.get().isValid())
                    invalidatedByOther = true;
                else
                    return commitTimestampFromCT.get();
            }

            // 3) Read from shadow cell
            Optional<CommitTimestamp> commitTimeStamp = readCommitTimestampFromShadowCell(cellStartTimestamp, locator);
            if (commitTimeStamp.isPresent()) {
                return commitTimeStamp.get();
            }

            // In case of LL, if found invalid ct cell, still must check sc in stage 3 then return
            if (invalidatedByOther) {
                assert(!commitTimestampFromCT.get().isValid());
                return commitTimestampFromCT.get();
            }

            // 4) Check the epoch and invalidate the entry
            // if the data was written by a transaction from a previous epoch (previous TSO)
            if (cellStartTimestamp < epoch || isLowLatency) {
                boolean invalidated = commitTableClient.tryInvalidateTransaction(cellStartTimestamp).get();
                if (invalidated) { // Invalid commit timestamp

                    // If we are running lowLatency Omid, we could have manged to invalidate a ct entry,
                    // but the committing client already wrote to shadow cells:
                    if (isLowLatency) {
                        commitTimeStamp = readCommitTimestampFromShadowCell(cellStartTimestamp, locator);
                        if (commitTimeStamp.isPresent()) {
                            // Remove false invalidation from commit table
                            commitTableClient.deleteCommitEntry(cellStartTimestamp);
                            return commitTimeStamp.get();
                        }
                    }

                    return new CommitTimestamp(COMMIT_TABLE, CommitTable.INVALID_TRANSACTION_MARKER, false);
                }
            }

            // 5) We did not manage to invalidate the transactions then check the commit table
            commitTimeStamp = commitTableClient.getCommitTimestamp(cellStartTimestamp).get();
            if (commitTimeStamp.isPresent()) {
                return commitTimeStamp.get();
            }

            // 6) Read from shadow cell
            commitTimeStamp = readCommitTimestampFromShadowCell(cellStartTimestamp, locator);
            if (commitTimeStamp.isPresent()) {
                return commitTimeStamp.get();
            }

            // *) Otherwise return not found
            return new CommitTimestamp(NOT_PRESENT, -1L /** TODO Check if we should return this */, true);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IOException("Interrupted while finding commit timestamp", e);
        } catch (ExecutionException e) {
            throw new IOException("Problem finding commit timestamp", e);
        }

    }