Skip to content

Commit 661f7d9

Browse files
authored
Decouple LockManager from engine and create tests (#8717)
* Decouple LockManager from engine * Add LockManager test disabled. * Correction * Fix test, thanks to Vlad. * Enable test. * Make test run faster. * Fix crash in Android build. * Move LockManagerTest to src/lock/tests * More LockManager test.
1 parent 8d5bb71 commit 661f7d9

8 files changed

Lines changed: 325 additions & 72 deletions

File tree

builds/posix/make.shared.variables

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Engine_Objects:= $(call dirObjects,jrd) $(call dirObjects,dsql) $(call dirObject
9292
$(call dirObjects,jrd/sys-packages) $(call dirObjects,jrd/trace) \
9393
$(call makeObjects,lock,lock.cpp)
9494

95-
Engine_Test_Objects:= $(call dirObjects,jrd/tests)
95+
Engine_Test_Objects:= $(call dirObjects,jrd/tests) $(call dirObjects,lock/tests)
9696

9797
AllObjects += $(Engine_Objects) $(Engine_Test_Objects)
9898

builds/win32/msvc15/engine_test.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@
263263
<ItemGroup>
264264
<ClCompile Include="..\..\..\src\jrd\tests\RecordNumberTest.cpp" />
265265
</ItemGroup>
266+
<ItemGroup>
267+
<ClCompile Include="..\..\..\src\lock\tests\LockManagerTest.cpp" />
268+
</ItemGroup>
266269
<ItemGroup>
267270
<ProjectReference Include="alice.vcxproj">
268271
<Project>{0d616380-1a5a-4230-a80b-021360e4e669}</Project>

builds/win32/msvc15/engine_test.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
<ClCompile Include="..\..\..\src\jrd\tests\RecordNumberTest.cpp">
2525
<Filter>source</Filter>
2626
</ClCompile>
27+
<ClCompile Include="..\..\..\src\lock\tests\LockManagerTest.cpp">
28+
<Filter>source</Filter>
29+
</ClCompile>
2730
</ItemGroup>
2831
</Project>

src/jrd/lck.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ namespace
9595
}
9696
#endif
9797

98+
99+
ISC_STATUS LockManagerEngineCallbacks::getCancelState() const
100+
{
101+
return tdbb->getCancelState();
102+
}
103+
104+
ULONG LockManagerEngineCallbacks::adjustWait(ULONG wait) const
105+
{
106+
return tdbb->adjustWait(wait);
107+
}
108+
109+
void LockManagerEngineCallbacks::checkoutRun(std::function<void()> func) const
110+
{
111+
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::UNNECESSARY);
112+
func();
113+
}
114+
115+
98116
// globals and macros
99117

100118
inline LOCK_OWNER_T LCK_OWNER_ID_DBB(thread_db* tdbb)
@@ -155,8 +173,8 @@ inline bool CONVERT(thread_db* tdbb, CheckStatusWrapper* statusVector, Lock* loc
155173

156174
return lock->lck_compatible ?
157175
internal_enqueue(tdbb, statusVector, lock, level, wait, true) :
158-
dbb->lockManager()->convert(tdbb, statusVector, lock->lck_id, level, wait, lock->lck_ast,
159-
lock->lck_object);
176+
dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id, level,
177+
wait, lock->lck_ast, lock->lck_object);
160178
}
161179

162180
inline void DEQUEUE(thread_db* tdbb, Lock* lock)
@@ -177,7 +195,7 @@ inline USHORT DOWNGRADE(thread_db* tdbb, Lock* lock)
177195

178196
USHORT ret = lock->lck_compatible ?
179197
internal_downgrade(tdbb, &statusVector, lock) :
180-
dbb->lockManager()->downgrade(tdbb, &statusVector, lock->lck_id);
198+
dbb->lockManager()->downgrade(LockManagerEngineCallbacks(tdbb), &statusVector, lock->lck_id);
181199

182200
fb_assert(statusVector.isEmpty());
183201

@@ -499,7 +517,7 @@ void LCK_fini(thread_db* tdbb, enum lck_owner_t owner_type)
499517
}
500518

501519
if (*owner_handle_ptr)
502-
dbb->lockManager()->shutdownOwner(tdbb, owner_handle_ptr);
520+
dbb->lockManager()->shutdownOwner(LockManagerEngineCallbacks(tdbb), owner_handle_ptr);
503521
}
504522

505523

@@ -841,7 +859,8 @@ void LCK_re_post(thread_db* tdbb, Lock* lock)
841859
return;
842860
}
843861

844-
dbb->lockManager()->repost(tdbb, lock->lck_ast, lock->lck_object, lock->lck_owner_handle);
862+
dbb->lockManager()->repost(LockManagerEngineCallbacks(tdbb),
863+
lock->lck_ast, lock->lck_object, lock->lck_owner_handle);
845864

846865
fb_assert(LCK_CHECK_LOCK(lock));
847866
}
@@ -945,7 +964,7 @@ static void enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector, Lock* loc
945964

946965
fb_assert(LCK_CHECK_LOCK(lock));
947966

948-
lock->lck_id = dbb->lockManager()->enqueue(tdbb, statusVector, lock->lck_id,
967+
lock->lck_id = dbb->lockManager()->enqueue(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id,
949968
lock->lck_type, lock->getKeyPtr(), lock->lck_length,
950969
level, lock->lck_ast, lock->lck_object, lock->lck_data, wait,
951970
lock->lck_owner_handle);
@@ -1335,8 +1354,8 @@ static USHORT internal_downgrade(thread_db* tdbb, CheckStatusWrapper* statusVect
13351354

13361355
if (level < first->lck_physical)
13371356
{
1338-
if (dbb->lockManager()->convert(tdbb, statusVector, first->lck_id, level, LCK_NO_WAIT,
1339-
external_ast, first))
1357+
if (dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector,
1358+
first->lck_id, level, LCK_NO_WAIT, external_ast, first))
13401359
{
13411360
for (Lock* lock = first; lock; lock = lock->lck_identical)
13421361
{
@@ -1402,8 +1421,8 @@ static bool internal_enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector,
14021421

14031422
if (level > match->lck_physical)
14041423
{
1405-
if (!dbb->lockManager()->convert(tdbb, statusVector, match->lck_id, level, wait,
1406-
external_ast, lock))
1424+
if (!dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector,
1425+
match->lck_id, level, wait, external_ast, lock))
14071426
{
14081427
return false;
14091428
}
@@ -1431,7 +1450,7 @@ static bool internal_enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector,
14311450
// enqueue the lock, but swap out the ast and the ast argument
14321451
// with the local ast handler, passing it the lock block itself
14331452

1434-
lock->lck_id = dbb->lockManager()->enqueue(tdbb, statusVector, lock->lck_id,
1453+
lock->lck_id = dbb->lockManager()->enqueue(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id,
14351454
lock->lck_type, lock->getKeyPtr(), lock->lck_length,
14361455
level, external_ast, lock, lock->lck_data, wait, lock->lck_owner_handle);
14371456

src/jrd/lck.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ enum lck_owner_t {
8686
LCK_OWNER_attachment // An attachment is the owner of the lock
8787
};
8888

89+
class LockManagerEngineCallbacks final : public LockManager::Callbacks
90+
{
91+
public:
92+
LockManagerEngineCallbacks(thread_db* aTdbb)
93+
: tdbb(aTdbb)
94+
{
95+
}
96+
97+
ISC_STATUS getCancelState() const override;
98+
ULONG adjustWait(ULONG wait) const override;
99+
void checkoutRun(std::function<void()> func) const override;
100+
101+
private:
102+
thread_db* const tdbb;
103+
};
104+
89105
class Lock : public pool_alloc_rpt<UCHAR, type_lck>
90106
{
91107
public:

0 commit comments

Comments
 (0)