4646import java .util .function .Predicate ;
4747import org .apache .ignite .IgniteCheckedException ;
4848import org .apache .ignite .configuration .DataRegionConfiguration ;
49+ import org .apache .ignite .failure .FailureContext ;
4950import org .apache .ignite .internal .IgniteInternalFuture ;
5051import org .apache .ignite .internal .mem .unsafe .UnsafeMemoryProvider ;
5152import org .apache .ignite .internal .pagemem .FullPageId ;
5556import org .apache .ignite .internal .pagemem .impl .PageMemoryNoStoreImpl ;
5657import org .apache .ignite .internal .processors .cache .persistence .DataRegionMetricsImpl ;
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 ;
6365import org .apache .ignite .internal .processors .cache .persistence .tree .io .PageIO ;
6466import org .apache .ignite .internal .processors .cache .persistence .tree .reuse .ReuseList ;
6567import org .apache .ignite .internal .processors .cache .persistence .tree .util .PageLockListener ;
68+ import org .apache .ignite .internal .processors .failure .FailureProcessor ;
6669import org .apache .ignite .internal .util .GridConcurrentHashSet ;
6770import org .apache .ignite .internal .util .GridRandom ;
6871import org .apache .ignite .internal .util .GridStripedLock ;
7376import org .apache .ignite .internal .util .typedef .internal .SB ;
7477import org .apache .ignite .internal .util .typedef .internal .U ;
7578import org .apache .ignite .testframework .GridTestUtils ;
79+ import org .apache .ignite .testframework .junits .GridTestKernalContext ;
80+ import org .apache .ignite .testframework .junits .WithSystemProperty ;
7681import org .apache .ignite .testframework .junits .common .GridCommonAbstractTest ;
7782import org .jetbrains .annotations .Nullable ;
7883import org .jsr166 .ConcurrentLinkedHashMap ;
7984import org .junit .Test ;
8085
86+ import static org .apache .ignite .IgniteSystemProperties .IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL ;
8187import static org .apache .ignite .internal .pagemem .PageIdUtils .effectivePageId ;
8288import static org .apache .ignite .internal .processors .cache .persistence .tree .BPlusTree .rnd ;
8389import static org .apache .ignite .internal .processors .database .BPlusTreeSelfTest .TestTree .threadId ;
8793
8894/**
8995 */
96+ @ WithSystemProperty (key = IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL , value = "20000" )
9097public class BPlusTreeSelfTest extends GridCommonAbstractTest {
9198 /** */
9299 private static final short LONG_INNER_IO = 30000 ;
@@ -136,6 +143,9 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
136143 /** Future. */
137144 private volatile GridCompoundFuture <?, ?> asyncRunFut ;
138145
146+ /** Tracking of locks holding. */
147+ private PageLockTrackerManager lockTrackerManager ;
148+
139149 /**
140150 * Check that we do not keep any locks at the moment.
141151 */
@@ -156,6 +166,10 @@ protected void assertNoLocks() {
156166 pageMem = createPageMemory ();
157167
158168 reuseList = createReuseList (CACHE_ID , pageMem , 0 , true );
169+
170+ lockTrackerManager = new PageLockTrackerManager (log , "testTreeManager" );
171+
172+ lockTrackerManager .start ();
159173 }
160174
161175 /**
@@ -207,6 +221,9 @@ protected ReuseList createReuseList(int cacheId, PageMemory pageMem, long rootId
207221 if (pageMem != null )
208222 pageMem .stop (true );
209223
224+ if (lockTrackerManager != null )
225+ lockTrackerManager .stop ();
226+
210227 MAX_PER_PAGE = 0 ;
211228 PUT_INC = 1 ;
212229 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" ,
@@ -2750,8 +2767,14 @@ public TestTree(
27502767 reuseList ,
27512768 new IOVersions <>(new LongInnerIO (canGetRow )),
27522769 new IOVersions <>(new LongLeafIO ()),
2753- null ,
2754- lsnr
2770+ new FailureProcessor (new GridTestKernalContext (log )) {
2771+ @ Override public boolean process (FailureContext failureCtx ) {
2772+ lockTrackerManager .dumpLocksToLog ();
2773+
2774+ return true ;
2775+ }
2776+ },
2777+ new TestPageLockListener (lockTrackerManager .createPageLockTracker ("testTree" ))
27552778 );
27562779
27572780 PageIO .registerTest (latestInnerIO (), latestLeafIO ());
@@ -3035,19 +3058,32 @@ private static class TestPageLockListener implements PageLockListener {
30353058 /** */
30363059 static ConcurrentMap <Object , Map <Long , Long >> writeLocks = new ConcurrentHashMap <>();
30373060
3061+ /** */
3062+ private final PageLockListener delegate ;
3063+
3064+ /**
3065+ * @param delegate Real implementation of page lock listener.
3066+ */
3067+ private TestPageLockListener (
3068+ PageLockListener delegate ) {
3069+
3070+ this .delegate = delegate ;
3071+ }
30383072
30393073 /** {@inheritDoc} */
30403074 @ Override public void onBeforeReadLock (int cacheId , long pageId , long page ) {
3075+ delegate .onBeforeReadLock (cacheId , pageId , page );
3076+
30413077 if (PRINT_LOCKS )
30423078 X .println (" onBeforeReadLock: " + U .hexLong (pageId ));
3043- //
3044- // U.dumpStack();
30453079
30463080 assertNull (beforeReadLock .put (threadId (), pageId ));
30473081 }
30483082
30493083 /** {@inheritDoc} */
30503084 @ Override public void onReadLock (int cacheId , long pageId , long page , long pageAddr ) {
3085+ delegate .onReadLock (cacheId , pageId , page , pageAddr );
3086+
30513087 if (PRINT_LOCKS )
30523088 X .println (" onReadLock: " + U .hexLong (pageId ));
30533089
@@ -3064,6 +3100,8 @@ private static class TestPageLockListener implements PageLockListener {
30643100
30653101 /** {@inheritDoc} */
30663102 @ Override public void onReadUnlock (int cacheId , long pageId , long page , long pageAddr ) {
3103+ delegate .onReadUnlock (cacheId , pageId , page , pageAddr );
3104+
30673105 if (PRINT_LOCKS )
30683106 X .println (" onReadUnlock: " + U .hexLong (pageId ));
30693107
@@ -3076,6 +3114,8 @@ private static class TestPageLockListener implements PageLockListener {
30763114
30773115 /** {@inheritDoc} */
30783116 @ Override public void onBeforeWriteLock (int cacheId , long pageId , long page ) {
3117+ delegate .onBeforeWriteLock (cacheId , pageId , page );
3118+
30793119 if (PRINT_LOCKS )
30803120 X .println (" onBeforeWriteLock: " + U .hexLong (pageId ));
30813121
@@ -3084,10 +3124,10 @@ private static class TestPageLockListener implements PageLockListener {
30843124
30853125 /** {@inheritDoc} */
30863126 @ Override public void onWriteLock (int cacheId , long pageId , long page , long pageAddr ) {
3127+ delegate .onWriteLock (cacheId , pageId , page , pageAddr );
3128+
30873129 if (PRINT_LOCKS )
30883130 X .println (" onWriteLock: " + U .hexLong (pageId ));
3089- //
3090- // U.dumpStack();
30913131
30923132 if (pageAddr != 0L ) {
30933133 checkPageId (pageId , pageAddr );
@@ -3105,6 +3145,8 @@ private static class TestPageLockListener implements PageLockListener {
31053145
31063146 /** {@inheritDoc} */
31073147 @ Override public void onWriteUnlock (int cacheId , long pageId , long page , long pageAddr ) {
3148+ delegate .onWriteUnlock (cacheId , pageId , page , pageAddr );
3149+
31083150 if (PRINT_LOCKS )
31093151 X .println (" onWriteUnlock: " + U .hexLong (pageId ));
31103152
0 commit comments