From a0f85a19ba36f71288c7b45575befd98d7d77ed4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 24 May 2017 11:44:30 +0200 Subject: [PATCH] Cleanup time access ShardDataTree does not need to expose the ticker, just a readTime() method. This makes the users slightly more readable. Change-Id: I9aa72a2d3625f40a2a44b0838ff344437293e1e3 Signed-off-by: Robert Varga --- .../datastore/AbstractFrontendHistory.java | 2 +- .../cluster/datastore/LeaderFrontendState.java | 2 +- .../cluster/datastore/ShardDataTree.java | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java index 8a0cfd8a90..88c2a7d361 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java @@ -70,7 +70,7 @@ abstract class AbstractFrontendHistory implements Identifiable handleTransactionRequest(final TransactionRequest request, diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java index 7e5addaefd..1ea3c53a5f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java @@ -146,7 +146,7 @@ final class LeaderFrontendState implements Identifiable { // We have to send the response only after persistence has completed final ShardDataTreeTransactionChain chain = tree.ensureTransactionChain(historyId, () -> { LOG.debug("{}: persisted history {}", persistenceId, historyId); - envelope.sendSuccess(new LocalHistorySuccess(historyId, request.getSequence()), tree.ticker().read() - now); + envelope.sendSuccess(new LocalHistorySuccess(historyId, request.getSequence()), tree.readTime() - now); }); localHistories.put(historyId, LocalFrontendHistory.create(persistenceId, tree, chain)); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java index ed36813d49..b32874c5fa 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java @@ -14,7 +14,6 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; -import com.google.common.base.Ticker; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -181,8 +180,8 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { return logContext; } - final Ticker ticker() { - return shard.ticker(); + final long readTime() { + return shard.ticker().read(); } public TipProducingDataTree getDataTree() { @@ -745,7 +744,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { tip.validate(modification); LOG.debug("{}: Transaction {} validated", logContext, cohort.getIdentifier()); cohort.successfulCanCommit(); - entry.lastAccess = ticker().read(); + entry.lastAccess = readTime(); return; } catch (ConflictingModificationAppliedException e) { LOG.warn("{}: Store Tx {}: Conflicting modification for path {}.", logContext, cohort.getIdentifier(), @@ -845,7 +844,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { // Set the tip of the data tree. tip = Verify.verifyNotNull(candidate); - entry.lastAccess = ticker().read(); + entry.lastAccess = readTime(); pendingTransactions.remove(); pendingCommits.add(entry); @@ -960,7 +959,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { ShardDataTreeCohort createFailedCohort(final TransactionIdentifier txId, final DataTreeModification mod, final Exception failure) { SimpleShardDataTreeCohort cohort = new SimpleShardDataTreeCohort.DeadOnArrival(this, mod, txId, failure); - pendingTransactions.add(new CommitEntry(cohort, ticker().read())); + pendingTransactions.add(new CommitEntry(cohort, readTime())); return cohort; } @@ -968,7 +967,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { ShardDataTreeCohort createReadyCohort(final TransactionIdentifier txId, final DataTreeModification mod) { SimpleShardDataTreeCohort cohort = new SimpleShardDataTreeCohort.Normal(this, mod, txId, cohortRegistry.createCohort(schemaContext, txId, COMMIT_STEP_TIMEOUT)); - pendingTransactions.add(new CommitEntry(cohort, ticker().read())); + pendingTransactions.add(new CommitEntry(cohort, readTime())); return cohort; } @@ -985,7 +984,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { @SuppressFBWarnings(value = "DB_DUPLICATE_SWITCH_CLAUSES", justification = "See inline comments below.") void checkForExpiredTransactions(final long transactionCommitTimeoutMillis) { final long timeout = TimeUnit.MILLISECONDS.toNanos(transactionCommitTimeoutMillis); - final long now = ticker().read(); + final long now = readTime(); final Queue currentQueue = !pendingFinishCommits.isEmpty() ? pendingFinishCommits : !pendingCommits.isEmpty() ? pendingCommits : pendingTransactions; -- 2.36.6