4747import java .util .function .Predicate ;
4848import org .apache .ignite .IgniteCheckedException ;
4949import org .apache .ignite .configuration .DataRegionConfiguration ;
50+ import org .apache .ignite .failure .FailureContext ;
5051import org .apache .ignite .internal .IgniteInternalFuture ;
5152import org .apache .ignite .internal .mem .unsafe .UnsafeMemoryProvider ;
5253import org .apache .ignite .internal .pagemem .FullPageId ;
5556import org .apache .ignite .internal .pagemem .PageUtils ;
5657import org .apache .ignite .internal .pagemem .impl .PageMemoryNoStoreImpl ;
5758import org .apache .ignite .internal .processors .cache .persistence .DataStructure ;
59+ import org .apache .ignite .internal .processors .cache .persistence .diagnostic .pagelocktracker .PageLockTrackerManager ;
5860import org .apache .ignite .internal .processors .cache .persistence .tree .BPlusTree ;
5961import org .apache .ignite .internal .processors .cache .persistence .tree .io .BPlusIO ;
6062import org .apache .ignite .internal .processors .cache .persistence .tree .io .BPlusInnerIO ;
6466import org .apache .ignite .internal .processors .cache .persistence .tree .reuse .ReuseList ;
6567import org .apache .ignite .internal .processors .cache .persistence .tree .util .PageLockListener ;
6668import org .apache .ignite .internal .processors .metric .impl .LongAdderMetric ;
69+ import org .apache .ignite .internal .processors .failure .FailureProcessor ;
6770import org .apache .ignite .internal .util .GridConcurrentHashSet ;
6871import org .apache .ignite .internal .util .GridRandom ;
6972import org .apache .ignite .internal .util .GridStripedLock ;
7477import org .apache .ignite .internal .util .typedef .internal .SB ;
7578import org .apache .ignite .internal .util .typedef .internal .U ;
7679import org .apache .ignite .testframework .GridTestUtils ;
80+ import org .apache .ignite .testframework .junits .GridTestKernalContext ;
81+ import org .apache .ignite .testframework .junits .WithSystemProperty ;
7782import org .apache .ignite .testframework .junits .common .GridCommonAbstractTest ;
7883import org .jetbrains .annotations .Nullable ;
7984import org .jsr166 .ConcurrentLinkedHashMap ;
8085import org .junit .Test ;
8186
87+ import static org .apache .ignite .IgniteSystemProperties .IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL ;
8288import static org .apache .ignite .internal .pagemem .PageIdUtils .effectivePageId ;
8389import static org .apache .ignite .internal .processors .cache .persistence .tree .BPlusTree .rnd ;
8490import static org .apache .ignite .internal .processors .database .BPlusTreeSelfTest .TestTree .threadId ;
8894
8995/**
9096 */
97+ @ WithSystemProperty (key = IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL , value = "20000" )
9198public class BPlusTreeSelfTest extends GridCommonAbstractTest {
9299 /** */
93100 private static final short LONG_INNER_IO = 30000 ;
@@ -137,6 +144,9 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
137144 /** Future. */
138145 private volatile GridCompoundFuture <?, ?> asyncRunFut ;
139146
147+ /** Tracking of locks holding. */
148+ private PageLockTrackerManager lockTrackerManager ;
149+
140150 /**
141151 * Check that we do not keep any locks at the moment.
142152 */
@@ -157,6 +167,10 @@ protected void assertNoLocks() {
157167 pageMem = createPageMemory ();
158168
159169 reuseList = createReuseList (CACHE_ID , pageMem , 0 , true );
170+
171+ lockTrackerManager = new PageLockTrackerManager (log , "testTreeManager" );
172+
173+ lockTrackerManager .start ();
160174 }
161175
162176 /**
@@ -208,6 +222,9 @@ protected ReuseList createReuseList(int cacheId, PageMemory pageMem, long rootId
208222 if (pageMem != null )
209223 pageMem .stop (true );
210224
225+ if (lockTrackerManager != null )
226+ lockTrackerManager .stop ();
227+
211228 MAX_PER_PAGE = 0 ;
212229 PUT_INC = 1 ;
213230 RMV_INC = -1 ;
@@ -2701,7 +2718,7 @@ public static void checkPageId(long pageId, long pageAddr) {
27012718 */
27022719 protected TestTree createTestTree (boolean canGetRow ) throws IgniteCheckedException {
27032720 TestTree tree = new TestTree (
2704- reuseList , canGetRow , CACHE_ID , pageMem , allocateMetaPage ().pageId (), new TestPageLockListener () );
2721+ reuseList , canGetRow , CACHE_ID , pageMem , allocateMetaPage ().pageId (), lockTrackerManager );
27052722
27062723 assertEquals (0 , tree .size ());
27072724 assertEquals (0 , tree .rootLevel ());
@@ -2738,7 +2755,7 @@ public TestTree(
27382755 int cacheId ,
27392756 PageMemory pageMem ,
27402757 long metaPageId ,
2741- TestPageLockListener lsnr
2758+ PageLockTrackerManager lockTrackerManager
27422759 ) throws IgniteCheckedException {
27432760 super (
27442761 "test" ,
@@ -2751,8 +2768,14 @@ public TestTree(
27512768 reuseList ,
27522769 new IOVersions <>(new LongInnerIO (canGetRow )),
27532770 new IOVersions <>(new LongLeafIO ()),
2754- null ,
2755- lsnr
2771+ new FailureProcessor (new GridTestKernalContext (log )) {
2772+ @ Override public boolean process (FailureContext failureCtx ) {
2773+ lockTrackerManager .dumpLocksToLog ();
2774+
2775+ return true ;
2776+ }
2777+ },
2778+ new TestPageLockListener (lockTrackerManager .createPageLockTracker ("testTree" ))
27562779 );
27572780
27582781 PageIO .registerTest (latestInnerIO (), latestLeafIO ());
@@ -3036,19 +3059,32 @@ private static class TestPageLockListener implements PageLockListener {
30363059 /** */
30373060 static ConcurrentMap <Object , Map <Long , Long >> writeLocks = new ConcurrentHashMap <>();
30383061
3062+ /** */
3063+ private final PageLockListener delegate ;
3064+
3065+ /**
3066+ * @param delegate Real implementation of page lock listener.
3067+ */
3068+ private TestPageLockListener (
3069+ PageLockListener delegate ) {
3070+
3071+ this .delegate = delegate ;
3072+ }
30393073
30403074 /** {@inheritDoc} */
30413075 @ Override public void onBeforeReadLock (int cacheId , long pageId , long page ) {
3076+ delegate .onBeforeReadLock (cacheId , pageId , page );
3077+
30423078 if (PRINT_LOCKS )
30433079 X .println (" onBeforeReadLock: " + U .hexLong (pageId ));
3044- //
3045- // U.dumpStack();
30463080
30473081 assertNull (beforeReadLock .put (threadId (), pageId ));
30483082 }
30493083
30503084 /** {@inheritDoc} */
30513085 @ Override public void onReadLock (int cacheId , long pageId , long page , long pageAddr ) {
3086+ delegate .onReadLock (cacheId , pageId , page , pageAddr );
3087+
30523088 if (PRINT_LOCKS )
30533089 X .println (" onReadLock: " + U .hexLong (pageId ));
30543090
@@ -3065,6 +3101,8 @@ private static class TestPageLockListener implements PageLockListener {
30653101
30663102 /** {@inheritDoc} */
30673103 @ Override public void onReadUnlock (int cacheId , long pageId , long page , long pageAddr ) {
3104+ delegate .onReadUnlock (cacheId , pageId , page , pageAddr );
3105+
30683106 if (PRINT_LOCKS )
30693107 X .println (" onReadUnlock: " + U .hexLong (pageId ));
30703108
@@ -3077,6 +3115,8 @@ private static class TestPageLockListener implements PageLockListener {
30773115
30783116 /** {@inheritDoc} */
30793117 @ Override public void onBeforeWriteLock (int cacheId , long pageId , long page ) {
3118+ delegate .onBeforeWriteLock (cacheId , pageId , page );
3119+
30803120 if (PRINT_LOCKS )
30813121 X .println (" onBeforeWriteLock: " + U .hexLong (pageId ));
30823122
@@ -3085,10 +3125,10 @@ private static class TestPageLockListener implements PageLockListener {
30853125
30863126 /** {@inheritDoc} */
30873127 @ Override public void onWriteLock (int cacheId , long pageId , long page , long pageAddr ) {
3128+ delegate .onWriteLock (cacheId , pageId , page , pageAddr );
3129+
30883130 if (PRINT_LOCKS )
30893131 X .println (" onWriteLock: " + U .hexLong (pageId ));
3090- //
3091- // U.dumpStack();
30923132
30933133 if (pageAddr != 0L ) {
30943134 checkPageId (pageId , pageAddr );
@@ -3106,6 +3146,8 @@ private static class TestPageLockListener implements PageLockListener {
31063146
31073147 /** {@inheritDoc} */
31083148 @ Override public void onWriteUnlock (int cacheId , long pageId , long page , long pageAddr ) {
3149+ delegate .onWriteUnlock (cacheId , pageId , page , pageAddr );
3150+
31093151 if (PRINT_LOCKS )
31103152 X .println (" onWriteUnlock: " + U .hexLong (pageId ));
31113153
0 commit comments