@Override protected boolean validateCommit() { applyRemoteCommits(this.activeTxRecord); return super.validateCommit(); }
public static ActiveTransactionsRecord updateToMostRecentCommit(ActiveTransactionsRecord currentCommitRecord, int mostRecentGlobalTxNum) { logger.debug("Must apply commits from {} up to {}", currentCommitRecord.transactionNumber, mostRecentGlobalTxNum); while (currentCommitRecord.transactionNumber < mostRecentGlobalTxNum) { ActiveTransactionsRecord newCommitRecord = applyRemoteCommits(currentCommitRecord); if (newCommitRecord == currentCommitRecord) { logger.debug("There was nothing yet to process"); // try { // Thread.sleep(3000); // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } Thread.yield(); } else { logger.debug("Processed remote commits up to {}", newCommitRecord.transactionNumber); } currentCommitRecord = newCommitRecord; } return currentCommitRecord; }
public static ActiveTransactionsRecord tryToApplyRemoteCommits(ActiveTransactionsRecord record) { logger.debug("Try to apply remote commits if any."); // avoid locking if queue is empty if (ClusterUtils.getRemoteCommits().isEmpty()) { // logger.debug("No remote commits to apply. Great."); /* we need to always return the most recent committed number: - if inside a commit (already holding the commit lock), this ensures that we're able to detect record advances caused by the processing of the remote commits queue (e.g. while we were waiting to acquire the global lock) - if starting a new transaction, it attempts to improve on the version we see (here it would be acceptable to just return the record had) */ return findActiveRecordForNumber(record, Transaction.getMostRecentCommitedNumber()); } // COMMIT_LOCK.lock(); // change to tryLock to allow the starting transactions to begin without waiting for a long commit (which in fact may already have processed the queue :-)) if (COMMIT_LOCK.tryLock()) { try { return applyRemoteCommits(record); } finally { COMMIT_LOCK.unlock(); } } else { return findActiveRecordForNumber(record, Transaction.getMostRecentCommitedNumber()); } }