You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2023/08/04 09:07:08 UTC
[ignite] branch master updated: IGNITE-20113 IgniteTxStateImpl initial cleanup (#10868)
This is an automated email from the ASF dual-hosted git repository.
av pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new dec1fb41779 IGNITE-20113 IgniteTxStateImpl initial cleanup (#10868)
dec1fb41779 is described below
commit dec1fb41779245edc9fb6a01cedeb6a681c3f2c9
Author: Anton Vinogradov <av...@apache.org>
AuthorDate: Fri Aug 4 12:07:01 2023 +0300
IGNITE-20113 IgniteTxStateImpl initial cleanup (#10868)
---
.../cache/transactions/IgniteTxStateImpl.java | 67 +++++++++-------------
1 file changed, 28 insertions(+), 39 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java
index 3b8dce85ac3..ba27e787a25 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java
@@ -57,30 +57,30 @@ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC
*/
public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
/** Active cache IDs. */
- private GridIntList activeCacheIds = new GridIntList();
+ private final GridIntList activeCacheIds = new GridIntList();
/** Per-transaction read map. */
@GridToStringExclude
- protected Map<IgniteTxKey, IgniteTxEntry> txMap;
+ private Map<IgniteTxKey, IgniteTxEntry> txMap;
/** Read view on transaction map. */
@GridToStringExclude
- protected IgniteTxMap readView;
+ private IgniteTxMap readView;
/** Write view on transaction map. */
@GridToStringExclude
- protected IgniteTxMap writeView;
+ private IgniteTxMap writeView;
/** */
@GridToStringInclude
- protected Boolean recovery;
+ private Boolean recovery;
/** */
@GridToStringInclude
- protected Boolean mvccEnabled;
+ private Boolean mvccEnabled;
/** Cache ids used for mvcc caching. See {@link MvccCachingManager}. */
- private GridIntList mvccCachingCacheIds = new GridIntList();
+ private final GridIntList mvccCachingCacheIds = new GridIntList();
/** {@inheritDoc} */
@Override public boolean implicitSingle() {
@@ -141,10 +141,7 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
Map<Integer, Set<KeyCacheObject>> keysByCacheId = new HashMap<>();
for (IgniteTxKey key : txMap.keySet()) {
- Set<KeyCacheObject> set = keysByCacheId.get(key.cacheId());
-
- if (set == null)
- keysByCacheId.put(key.cacheId(), set = new HashSet<>());
+ Set<KeyCacheObject> set = keysByCacheId.computeIfAbsent(key.cacheId(), k -> new HashSet<>());
set.add(key.key());
}
@@ -225,11 +222,11 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
this.recovery = recovery;
- if (this.mvccEnabled != null && this.mvccEnabled != cacheCtx.mvccEnabled())
+ if (mvccEnabled != null && mvccEnabled != cacheCtx.mvccEnabled())
throw new IgniteCheckedException("Failed to enlist new cache to existing transaction " +
"(caches with different mvcc settings can't be enlisted in one transaction).");
- this.mvccEnabled = cacheCtx.mvccEnabled();
+ mvccEnabled = cacheCtx.mvccEnabled();
// Check if we can enlist new cache to transaction.
if (!activeCacheIds.contains(cacheId)) {
@@ -273,7 +270,7 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
if (activeCacheIds.isEmpty())
return cctx.exchange().lastTopologyFuture();
- GridCacheContext<?, ?> nonLocCtx = null;
+ GridCacheContext<?, ?> ctx = null;
Map<Integer, GridCacheContext> cacheCtxs = U.newHashMap(activeCacheIds.size());
@@ -282,16 +279,16 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(cacheId);
- if (nonLocCtx == null)
- nonLocCtx = cacheCtx;
+ if (ctx == null)
+ ctx = cacheCtx;
cacheCtxs.putIfAbsent(cacheCtx.cacheId(), cacheCtx);
}
- if (nonLocCtx == null)
+ if (ctx == null)
return cctx.exchange().lastTopologyFuture();
- nonLocCtx.topology().readLock();
+ ctx.topology().readLock();
for (Map.Entry<Integer, GridCacheContext> e : cacheCtxs.entrySet()) {
GridCacheContext activeCacheCtx = e.getValue();
@@ -306,26 +303,18 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
}
}
- return nonLocCtx.topology().topologyVersionFuture();
+ return ctx.topology().topologyVersionFuture();
}
/** {@inheritDoc} */
@Override public void topologyReadUnlock(GridCacheSharedContext cctx) {
if (!activeCacheIds.isEmpty()) {
- GridCacheContext<?, ?> nonLocCtx = null;
-
- for (int i = 0; i < activeCacheIds.size(); i++) {
- int cacheId = activeCacheIds.get(i);
-
- GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(cacheId);
-
- nonLocCtx = cacheCtx;
+ int cacheId = activeCacheIds.get(0);
- break;
- }
+ GridCacheContext<?, ?> ctx = (GridCacheContext<?, ?>)cctx.cacheContext(cacheId);
- if (nonLocCtx != null)
- nonLocCtx.topology().readUnlock();
+ if (ctx != null)
+ ctx.topology().readUnlock();
}
}
@@ -422,14 +411,14 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
/** {@inheritDoc} */
@Override public Collection<IgniteTxEntry> allEntries() {
- return txMap == null ? Collections.<IgniteTxEntry>emptySet() : txMap.values();
+ return txMap == null ? Collections.emptySet() : txMap.values();
}
/**
* @return All entries. Returned collection is copy of internal collection.
*/
public synchronized Collection<IgniteTxEntry> allEntriesCopy() {
- return txMap == null ? Collections.<IgniteTxEntry>emptySet() : new ArrayList<>(txMap.values());
+ return txMap == null ? Collections.emptySet() : new ArrayList<>(txMap.values());
}
/** {@inheritDoc} */
@@ -444,32 +433,32 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter {
/** {@inheritDoc} */
@Override public Set<IgniteTxKey> readSet() {
- return txMap == null ? Collections.<IgniteTxKey>emptySet() : readView.keySet();
+ return txMap == null ? Collections.emptySet() : readView.keySet();
}
/** {@inheritDoc} */
@Override public Set<IgniteTxKey> writeSet() {
- return txMap == null ? Collections.<IgniteTxKey>emptySet() : writeView.keySet();
+ return txMap == null ? Collections.emptySet() : writeView.keySet();
}
/** {@inheritDoc} */
@Override public Collection<IgniteTxEntry> writeEntries() {
- return writeView == null ? Collections.<IgniteTxEntry>emptyList() : writeView.values();
+ return writeView == null ? Collections.emptyList() : writeView.values();
}
/** {@inheritDoc} */
@Override public Collection<IgniteTxEntry> readEntries() {
- return readView == null ? Collections.<IgniteTxEntry>emptyList() : readView.values();
+ return readView == null ? Collections.emptyList() : readView.values();
}
/** {@inheritDoc} */
@Override public Map<IgniteTxKey, IgniteTxEntry> writeMap() {
- return writeView == null ? Collections.<IgniteTxKey, IgniteTxEntry>emptyMap() : writeView;
+ return writeView == null ? Collections.emptyMap() : writeView;
}
/** {@inheritDoc} */
@Override public Map<IgniteTxKey, IgniteTxEntry> readMap() {
- return readView == null ? Collections.<IgniteTxKey, IgniteTxEntry>emptyMap() : readView;
+ return readView == null ? Collections.emptyMap() : readView;
}
/** {@inheritDoc} */