Permalink
Browse files

Fixed issues with dupes in ScaleoutStore.

- If second binary search fails bail out.

#1831
  • Loading branch information...
1 parent 1e926f7 commit 1675795fb2b43caefc4a85cf3e243778760cd11e @davidfowl davidfowl committed Apr 10, 2013
Showing with 10 additions and 6 deletions.
  1. +10 −6 src/Microsoft.AspNet.SignalR.Core/Messaging/ScaleoutStore.cs
View
16 src/Microsoft.AspNet.SignalR.Core/Messaging/ScaleoutStore.cs
@@ -216,13 +216,15 @@ public MessageStoreResult<ScaleoutMapping> GetMessages(ulong firstMessageIdReque
public MessageStoreResult<ScaleoutMapping> GetMessagesByMappingId(ulong mappingId)
{
var minMessageId = (ulong)Volatile.Read(ref _minMessageId);
+ int idxIntoFragment;
// look for the fragment containing the start of the data requested by the client
Fragment thisFragment;
- if (TryGetFragmentFromMappingId(mappingId, out thisFragment))
+ if (TryGetFragmentFromMappingId(mappingId, out thisFragment) &&
+ thisFragment.TrySearch(mappingId, out idxIntoFragment))
{
// Skip the first message
- int idxIntoFragment = thisFragment.Search(mappingId) + 1;
+ idxIntoFragment++;
ulong firstMessageIdRequestedByClient = GetMessageId(thisFragment.FragmentNum, (uint)idxIntoFragment);
return GetMessages(firstMessageIdRequestedByClient);
@@ -232,7 +234,7 @@ public MessageStoreResult<ScaleoutMapping> GetMessagesByMappingId(ulong mappingI
while (true)
{
ulong fragmentNum;
- int idxIntoFragmentsArray, idxIntoFragment;
+ int idxIntoFragmentsArray;
GetFragmentOffsets(minMessageId, out fragmentNum, out idxIntoFragmentsArray, out idxIntoFragment);
Fragment fragment = _fragments[idxIntoFragmentsArray];
@@ -349,7 +351,7 @@ public bool HasValue(ulong id)
return id >= MinValue && id <= MaxValue;
}
- public int Search(ulong id)
+ public bool TrySearch(ulong id, out int index)
{
int low = 0;
int high = Length;
@@ -370,11 +372,13 @@ public int Search(ulong id)
}
else if (id == mapping.Id)
{
- return mid;
+ index = mid;
+ return true;
}
}
- return -1;
+ index = -1;
+ return false;
}
}
}

0 comments on commit 1675795

Please sign in to comment.