Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit fb2faea

Browse files
authored
Merge pull request #822 from IBM/dev-dlherms2
bb:Altered the fix for the getHandle race condition above
2 parents 7ef15cf + 156c0f4 commit fb2faea

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

bb/src/BBTagInfoMap.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ int BBTagInfoMap::addTagInfo(const LVKey* pLVKey, const BBJob pJob, const BBTagI
5757

5858
LOG(bb,debug) << "BBTagInfoMap::addTagInfo(): LVKey " << *pLVKey << ", job (" << pJob.getJobId() << "," << pJob.getJobStepId() << "), tagid " << pTagId.getTag() << ", generated handle " << pGeneratedHandle;
5959

60-
// It is possible to enter this section of code without the transfer queue locked.
60+
// It is possible to enter this section of code without the local metadata locked.
6161
// Inserting into a std::map is not thread safe, so we must acquire the lock around
6262
// the insert.
63+
int l_TransferQueueWasUnlocked = unlockTransferQueueIfNeeded((LVKey*)0, "BBTagInfoMap::getTagInfo");
6364
int l_LocalMetadataWasLocked = lockLocalMetadataIfNeeded(pLVKey, "BBTagInfoMap::addTagInfo");
6465

6566
tagInfoMap[pTagId] = *pTagInfo;
@@ -70,6 +71,11 @@ int BBTagInfoMap::addTagInfo(const LVKey* pLVKey, const BBJob pJob, const BBTagI
7071
unlockLocalMetadata(pLVKey, "BBTagInfoMap::addTagInfo");
7172
}
7273

74+
if (l_TransferQueueWasUnlocked)
75+
{
76+
lockTransferQueue((LVKey*)0, "BBTagInfoMap::getTagInfo");
77+
}
78+
7379
if (pGeneratedHandle) {
7480
rc = update_xbbServerAddData(pLVKey, pJob, pTagId.getTag(), pTagInfo);
7581
}

bb/src/TagInfo.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ int TagInfo::addTagHandle(const LVKey* pLVKey, const BBJob pJob, const uint64_t
3636

3737
TagInfo* l_TagInfo = 0;
3838
HandleInfo* l_HandleInfo = 0;
39+
int l_TransferQueueWasUnlocked = 0;
40+
int l_LocalMetadataLocked = 0;
3941
int l_TagInfoLocked = 0;
4042

41-
int l_LocalMetadataUnlocked = unlockLocalMetadataIfNeeded(pLVKey, "addTagHandle");
42-
4343
try
4444
{
4545
bfs::path l_JobStepPath(g_BBServer_Metadata_Path);
@@ -52,7 +52,12 @@ int TagInfo::addTagHandle(const LVKey* pLVKey, const BBJob pJob, const uint64_t
5252
LOG_ERROR_TEXT_RC_AND_BAIL(errorText, rc);
5353
}
5454

55+
l_TransferQueueWasUnlocked = unlockTransferQueueIfNeeded(pLVKey, "addTagHandle");
56+
// This lock serializes amongst request/transfer threads on this bbServer...
57+
l_LocalMetadataLocked = lockLocalMetadataIfNeeded(pLVKey, "addTagHandle");
58+
// This lock serializes amongst bbServers...
5559
rc = TagInfo::lock(l_JobStepPath);
60+
5661
if (!rc)
5762
{
5863
l_TagInfoLocked = 1;
@@ -150,6 +155,16 @@ int TagInfo::addTagHandle(const LVKey* pLVKey, const BBJob pJob, const uint64_t
150155
TagInfo::unlock();
151156
}
152157

158+
if (l_LocalMetadataLocked)
159+
{
160+
unlockLocalMetadata(pLVKey, "addTagHandle");
161+
}
162+
163+
if (l_TransferQueueWasUnlocked)
164+
{
165+
lockTransferQueue(pLVKey, "addTagHandle");
166+
}
167+
153168
if (l_HandleInfo)
154169
{
155170
delete l_HandleInfo;
@@ -162,11 +177,6 @@ int TagInfo::addTagHandle(const LVKey* pLVKey, const BBJob pJob, const uint64_t
162177
l_TagInfo = 0;
163178
}
164179

165-
if (l_LocalMetadataUnlocked)
166-
{
167-
lockLocalMetadata(pLVKey, "addTagHandle");
168-
}
169-
170180
return rc;
171181
}
172182

bb/src/TagInfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ const int MAXIMUM_TAGINFO_LOADTIME = 10; // In seconds
5454
| External methods
5555
*******************************************************************************/
5656
extern void lockLocalMetadata(const LVKey* pLVKey, const char* pMethod);
57-
extern int unlockLocalMetadataIfNeeded(const LVKey* pLVKey, const char* pMethod);
57+
extern int lockLocalMetadataIfNeeded(const LVKey* pLVKey, const char* pMethod);
58+
extern void unlockLocalMetadata(const LVKey* pLVKey, const char* pMethod);
59+
extern void lockTransferQueue(const LVKey* pLVKey, const char* pMethod);
60+
extern int unlockTransferQueueIfNeeded(const LVKey* pLVKey, const char* pMethod);
5861

5962

6063
/*******************************************************************************

bb/src/bbserver.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ void msgin_gettransferhandle(txp::Id id, const std::string& pConnectionName, txp
700700
verifyInitLockState();
701701

702702
uint64_t l_Handle = UNDEFINED_HANDLE;
703-
int l_LocalMetadataLocked = 0;
704703
LVKey l_LVKey;
705704
LVKey* l_LVKeyPtr = &l_LVKey;
706705
char lv_uuid_str[LENGTH_UUID_STR] = {'\0'};
@@ -746,8 +745,6 @@ void msgin_gettransferhandle(txp::Id id, const std::string& pConnectionName, txp
746745

747746
switchIds(msg);
748747

749-
lockLocalMetadata((LVKey*)0, "msgin_gettransferhandle");
750-
l_LocalMetadataLocked = 1;
751748
// NOTE: We set up to wait 2 minutes for the necessary LVKey to appear if we can't find
752749
// it right away and the handle is not in the cross-bbServer metadata.
753750
// This closes the window during activate server between the activation
@@ -844,12 +841,6 @@ void msgin_gettransferhandle(txp::Id id, const std::string& pConnectionName, txp
844841
LOG_ERROR_RC_WITH_EXCEPTION(__FILE__, __FUNCTION__, __LINE__, e, rc);
845842
}
846843

847-
if (l_LocalMetadataLocked)
848-
{
849-
l_LocalMetadataLocked = 0;
850-
unlockLocalMetadata((LVKey*)0, "msgin_gettransferhandle");
851-
}
852-
853844
// Build the response message
854845
txp::Msg* response;
855846
msg->buildResponseMsg(response);

0 commit comments

Comments
 (0)