This is an automated email from the ASF dual-hosted git repository. ptupitsyn pushed a commit to branch ignite-14067 in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 9879c15722625bf60bf9aacc7a04ccbeae82025f Author: Pavel Tupitsyn <[email protected]> AuthorDate: Thu Jan 28 12:38:33 2021 +0300 Add localCandidatesMax to reduce allocations --- .../processors/cache/GridCacheEntryEx.java | 10 +++++++ .../processors/cache/GridCacheMapEntry.java | 17 +++++++++++ .../internal/processors/cache/GridCacheMvcc.java | 33 ++++++++++++++++++++++ .../distributed/dht/GridDhtTxPrepareFuture.java | 6 ++-- .../java/org/apache/ignite/cache/PutAllTxTest.java | 11 ++++---- 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java index fb68256..cf765a5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java @@ -987,6 +987,16 @@ public interface GridCacheEntryEx { throws GridCacheEntryRemovedException; /** + * Gets all local candidates. + * + * @param maxVer Exclusive upper version boundary. + * @return All local candidates. + * @throws GridCacheEntryRemovedException If entry was removed. + */ + public Collection<GridCacheMvccCandidate> localCandidatesMax(GridCacheVersion maxVer) + throws GridCacheEntryRemovedException; + + /** * Gets all remote versions. * * @param exclude Exclude version. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java index 5f39b50..523d65f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java @@ -3925,6 +3925,23 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme } /** {@inheritDoc} */ + @Override public Collection<GridCacheMvccCandidate> localCandidatesMax(GridCacheVersion maxVer) + throws GridCacheEntryRemovedException { + lockEntry(); + + try { + checkObsolete(); + + GridCacheMvcc mvcc = mvccExtras(); + + return mvcc == null ? Collections.<GridCacheMvccCandidate>emptyList() : mvcc.localCandidatesMax(maxVer); + } + finally { + unlockEntry(); + } + } + + /** {@inheritDoc} */ @Override public Collection<GridCacheMvccCandidate> remoteMvccSnapshot(GridCacheVersion... exclude) { return Collections.emptyList(); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvcc.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvcc.java index be28ae7..ca4a66e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvcc.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvcc.java @@ -1381,6 +1381,14 @@ public final class GridCacheMvcc { } /** + * @param maxVers TODO. + * @return Collection of local candidates. + */ + public Collection<GridCacheMvccCandidate> localCandidatesMax(GridCacheVersion maxVers) { + return candidates(locs, false, true, maxVers); + } + + /** * @param reentries Flag to include reentries. * @param excludeVers Exclude versions. * @return Collection of local candidates. @@ -1427,6 +1435,31 @@ public final class GridCacheMvcc { } /** + * @param col Collection of candidates. + * @param reentries Reentry flag. + * @param cp Whether to copy or not. + * @param maxVers TODO. + * @return Collection of candidates minus the exclude versions. + */ + private List<GridCacheMvccCandidate> candidates(List<GridCacheMvccCandidate> col, + boolean reentries, boolean cp, GridCacheVersion maxVers) { + if (col == null) + return Collections.emptyList(); + + assert !col.isEmpty(); + + List<GridCacheMvccCandidate> cands = new ArrayList<>(col.size()); + + for (GridCacheMvccCandidate c : col) { + // Don't include reentries. + if ((reentries || !c.reentry()) && c.version().isLess(maxVers)) + cands.add(c); + } + + return cands; + } + + /** * @param threadId Thread ID to check. * @param exclude Versions to ignore. * @return {@code True} if lock is owned by the thread with given ID. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java index 5afa379..79d68c9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java @@ -1757,9 +1757,9 @@ public final class GridDhtTxPrepareFuture extends GridCacheCompoundFuture<Ignite for (IgniteTxEntry entry : entries) { try { - for (GridCacheMvccCandidate cand : entry.cached().localCandidates()) { - if (cand.version().isLess(baseVer)) - lessPending.add(cand.version()); + Collection<GridCacheMvccCandidate> candidates = entry.cached().localCandidatesMax(baseVer); + for (GridCacheMvccCandidate cand : candidates) { + lessPending.add(cand.version()); } } catch (GridCacheEntryRemovedException ignored) { diff --git a/modules/core/src/test/java/org/apache/ignite/cache/PutAllTxTest.java b/modules/core/src/test/java/org/apache/ignite/cache/PutAllTxTest.java index ccebf8c..da2be14 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/PutAllTxTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/PutAllTxTest.java @@ -18,16 +18,15 @@ public class PutAllTxTest extends GridCommonAbstractTest { Ignition.start(getConfiguration("server2")); Ignite ignite = Ignition.start(getConfiguration("client").setClientMode(true)); - IgniteCache<Integer, String> cache = ignite.createCache( - new CacheConfiguration<Integer, String>("c") + IgniteCache<Integer, Integer> cache = ignite.createCache( + new CacheConfiguration<Integer, Integer>("c") .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)); - int count = 40000; - int valSize = 1000; + int count = 50000; - Map<Integer, String> data = new TreeMap<>(); + Map<Integer, Integer> data = new TreeMap<>(); for (int i = 0; i < count; i++) - data.put(i, new String(new char[valSize]) + UUID.randomUUID()); + data.put(i, i); long begin = System.nanoTime();
