Skip to content
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

HPCC-18243 Reduce scope of collatorsLock spinlock #10401

Merged
merged 1 commit into from
Sep 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions roxie/udplib/udptrr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class CReceiveManager : implements IReceiveManager, public CInterface

Linked<IMessageCollator> defaultMessageCollator;
uid_map collators; // MORE - more sensible to use a jlib mapping I would have thought
SpinLock collatorsLock; // protects access to collators map and defaultMessageCollator
SpinLock collatorsLock; // protects access to collators map and defaultMessageCollator (note that defaultMessageCollator is not just set at startup)

public:
IMPLEMENT_IINTERFACE;
Expand Down Expand Up @@ -869,8 +869,10 @@ class CReceiveManager : implements IReceiveManager, public CInterface
{
ruid_t ruid = msgColl->queryRUID();
if (udpTraceLevel >= 2) DBGLOG("UdpReceiver: detach %p %u", msgColl, ruid);
SpinBlock b(collatorsLock);
collators.erase(ruid);
{
SpinBlock b(collatorsLock);
collators.erase(ruid);
}
msgColl->Release();
}

Expand Down Expand Up @@ -901,16 +903,16 @@ class CReceiveManager : implements IReceiveManager, public CInterface
pktHdr->ruid, pktHdr->msgId, pktHdr->msgSeq, pktHdr->pktSeq, pktHdr->length, pktHdr->nodeIndex);

Linked <IMessageCollator> msgColl;
bool isDefault = false;
{
SpinBlock b(collatorsLock);
try
{
msgColl.set(collators[pktHdr->ruid]);
if (!msgColl)
{
if (udpTraceLevel)
DBGLOG("UdpReceiver: CPacketCollator NO msg collator found - using default - ruid=" RUIDF " id=0x%.8X mseq=%u pkseq=0x%.8X node=%u", pktHdr->ruid, pktHdr->msgId, pktHdr->msgSeq, pktHdr->pktSeq, pktHdr->nodeIndex);
msgColl.set(defaultMessageCollator); // MORE - if we get a header, we can send an abort.
isDefault = true;
}
}
catch (IException *E)
Expand All @@ -927,6 +929,8 @@ class CReceiveManager : implements IReceiveManager, public CInterface
}
if (msgColl)
{
if (udpTraceLevel && isDefault)
DBGLOG("UdpReceiver: CPacketCollator NO msg collator found - using default - ruid=" RUIDF " id=0x%.8X mseq=%u pkseq=0x%.8X node=%u", pktHdr->ruid, pktHdr->msgId, pktHdr->msgSeq, pktHdr->pktSeq, pktHdr->nodeIndex);
if (msgColl->add_package(dataBuff))
{
dataBuff = 0;
Expand All @@ -949,9 +953,12 @@ class CReceiveManager : implements IReceiveManager, public CInterface
virtual IMessageCollator *createMessageCollator(IRowManager *rowManager, ruid_t ruid)
{
IMessageCollator *msgColl = createCMessageCollator(rowManager, ruid);
if (udpTraceLevel >= 2) DBGLOG("UdpReceiver: createMessageCollator %p %u", msgColl, ruid);
SpinBlock b(collatorsLock);
collators[ruid] = msgColl;
if (udpTraceLevel >= 2)
DBGLOG("UdpReceiver: createMessageCollator %p %u", msgColl, ruid);
{
SpinBlock b(collatorsLock);
collators[ruid] = msgColl;
}
msgColl->Link();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe after the SpinBlock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, as the object is still owned by the caller.

return msgColl;
}
Expand Down