-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-28833 Add system views for cache locks #13347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2b73fba
a700ad4
d71519b
22d9f53
3000c75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import java.util.ArrayDeque; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Deque; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
|
|
@@ -49,6 +50,8 @@ | |
| import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; | ||
| import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey; | ||
| import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; | ||
| import org.apache.ignite.internal.systemview.CacheExplicitLockViewWalker; | ||
| import org.apache.ignite.internal.systemview.CacheKeyLockViewWalker; | ||
| import org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet; | ||
| import org.apache.ignite.internal.util.GridConcurrentFactory; | ||
| import org.apache.ignite.internal.util.GridConcurrentHashSet; | ||
|
|
@@ -67,6 +70,8 @@ | |
| import org.apache.ignite.lang.IgniteFuture; | ||
| import org.apache.ignite.lang.IgnitePredicate; | ||
| import org.apache.ignite.lang.IgniteUuid; | ||
| import org.apache.ignite.spi.systemview.view.CacheExplicitLockView; | ||
| import org.apache.ignite.spi.systemview.view.CacheKeyLockView; | ||
| import org.apache.ignite.util.deque.FastSizeDeque; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
|
|
@@ -94,6 +99,18 @@ public class GridCacheMvccManager extends GridCacheSharedManagerAdapter { | |
| private static final int MAX_NESTED_LSNR_CALLS = | ||
| getInteger(IGNITE_MAX_NESTED_LISTENER_CALLS, DFLT_MAX_NESTED_LISTENER_CALLS); | ||
|
|
||
| /** System view name for cache explicit locks. */ | ||
| public static final String CACHE_EXPLICIT_LOCKS_VIEW = "cacheExplicitLocks"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metricName("cache", "explicit", "locks")
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metricName returns "cache.explicit.locks", not "cacheExplicitLocks" |
||
|
|
||
| /** System view description for cache explicit locks. */ | ||
| public static final String CACHE_EXPLICIT_LOCKS_VIEW_DESC = "Explicit locks on cache keys"; | ||
|
|
||
| /** System view name for cache locks. */ | ||
| public static final String CACHE_KEY_LOCKS_VIEW = "cacheKeyLocks"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metricName("cache", "key", "locks") |
||
|
|
||
| /** System view description for cache keys locks. */ | ||
| public static final String CACHE_KEY_LOCKS_VIEW_DESC = "Held and queued locks on cache keys"; | ||
|
|
||
| /** Pending locks per thread. */ | ||
| private final ThreadLocal<Deque<GridCacheMvccCandidate>> pending = new ThreadLocal<>(); | ||
|
|
||
|
|
@@ -282,6 +299,33 @@ else if (log.isDebugEnabled()) | |
| pendingExplicit = GridConcurrentFactory.newMap(); | ||
|
|
||
| cctx.gridEvents().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT); | ||
|
|
||
| cctx.kernalContext().systemView().registerInnerCollectionView( | ||
| CACHE_EXPLICIT_LOCKS_VIEW, | ||
| CACHE_EXPLICIT_LOCKS_VIEW_DESC, | ||
| new CacheExplicitLockViewWalker(), | ||
| pendingExplicit.values(), | ||
| GridCacheExplicitLockSpan::candidates, | ||
| (threadId, lock) -> new CacheExplicitLockView(lock) | ||
| ); | ||
|
|
||
| cctx.kernalContext().systemView().registerInnerCollectionView( | ||
| CACHE_KEY_LOCKS_VIEW, | ||
| CACHE_KEY_LOCKS_VIEW_DESC, | ||
| new CacheKeyLockViewWalker(), | ||
| locked.values(), | ||
| entry -> { | ||
| entry.lockEntry(); | ||
| try { | ||
| GridCacheMvcc mvcc = entry.mvccExtras(); | ||
| return mvcc != null ? mvcc.localCandidates() : Collections.emptyList(); | ||
| } | ||
| finally { | ||
| entry.unlockEntry(); | ||
| } | ||
| }, | ||
| (entry, cand) -> new CacheKeyLockView(cand) | ||
| ); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.ignite.spi.systemview.view; | ||
|
|
||
| import org.apache.ignite.internal.binary.BinaryUtils; | ||
| import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; | ||
| import org.apache.ignite.internal.systemview.Order; | ||
| import org.apache.ignite.internal.systemview.SystemViewDescriptor; | ||
| import org.apache.ignite.lang.IgniteUuid; | ||
|
|
||
| /** | ||
| * Cache explicit lock representation for a {@link SystemView}. | ||
| * Shows locks acquired on current node (not hosted by current node). | ||
| */ | ||
| @SystemViewDescriptor | ||
| public class CacheExplicitLockView { | ||
| /** */ | ||
| private final GridCacheMvccCandidate cand; | ||
|
|
||
| /** | ||
| * @param cand Lock candidate | ||
| */ | ||
| public CacheExplicitLockView(GridCacheMvccCandidate cand) { | ||
| this.cand = cand; | ||
| } | ||
|
|
||
| /** | ||
| * @return Cache ID. | ||
| */ | ||
| @Order | ||
| public int cacheId() { | ||
| return cand.key().cacheId(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Key. | ||
| */ | ||
| @Order(1) | ||
| public String key() { | ||
| return cand.key().key().toString(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Thread ID. | ||
| */ | ||
| @Order(2) | ||
| public long threadId() { | ||
| return cand.threadId(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Version. | ||
| */ | ||
| @Order(3) | ||
| public IgniteUuid xid() { | ||
| return BinaryUtils.asIgniteUuid(cand.version()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.ignite.spi.systemview.view; | ||
|
|
||
| import java.util.UUID; | ||
| import org.apache.ignite.internal.binary.BinaryUtils; | ||
| import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate; | ||
| import org.apache.ignite.internal.systemview.Order; | ||
| import org.apache.ignite.internal.systemview.SystemViewDescriptor; | ||
| import org.apache.ignite.lang.IgniteUuid; | ||
|
|
||
| /** | ||
| * Cache key lock representation for a {@link SystemView}. | ||
| * Shows held cache key locks and queued cache key locks hosted on current node, | ||
| * including explicit locks and transactional locks. | ||
| */ | ||
| @SystemViewDescriptor | ||
| public class CacheKeyLockView { | ||
| /** Lock candidate. */ | ||
| private final GridCacheMvccCandidate cand; | ||
|
|
||
| /** | ||
| * @param cand Lock candidate | ||
| */ | ||
| public CacheKeyLockView(GridCacheMvccCandidate cand) { | ||
| this.cand = cand; | ||
| } | ||
|
|
||
| /** | ||
| * @return Cache ID. | ||
| */ | ||
| @Order | ||
| public int cacheId() { | ||
| return cand.key().cacheId(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Key. | ||
| */ | ||
| @Order(1) | ||
| public String key() { | ||
| return cand.key().key().toString(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Node ID. | ||
| */ | ||
| @Order(2) | ||
| public UUID nodeId() { | ||
| return cand.nodeId(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Originating node ID. | ||
| */ | ||
| @Order(3) | ||
| public UUID originatingNodeId() { | ||
| return cand.otherNodeId(); | ||
| } | ||
|
|
||
| /** | ||
| * @return "OWNER" flag. | ||
| */ | ||
| @Order(4) | ||
| public boolean isOwner() { | ||
| return cand.owner(); | ||
| } | ||
|
|
||
| /** | ||
| * @return "TX" flag. | ||
| */ | ||
| @Order(5) | ||
| public boolean isTx() { | ||
| return cand.tx(); | ||
| } | ||
|
|
||
| /** | ||
| * @return All enabled flags. | ||
| */ | ||
| @Order(6) | ||
| public String flags() { | ||
| return cand.enabledFlags(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Transaction ID. | ||
| */ | ||
| @Order(7) | ||
| public IgniteUuid xid() { | ||
| return BinaryUtils.asIgniteUuid(cand.version()); | ||
| } | ||
|
|
||
| /** | ||
| * @return Originating transaction ID. | ||
| */ | ||
| @Order(8) | ||
| public IgniteUuid originatingXid() { | ||
| return BinaryUtils.asIgniteUuid(cand.otherVersion()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create separate column for each flag, instead of complex string creation that will lead to gc pressure.