@@ -242,14 +242,14 @@ bool CentralWorker::_determineRange() {
242
242
nInfoR.keyCount = protoItem->mapsize ();
243
243
_neighborRight.setKeyCount (nInfoR.keyCount ); // TODO add a timestamp to this data.
244
244
nInfoR.recentAdds = protoItem->recentadds ();
245
- proto::WorkerRangeString protoRange = protoItem->range ();
245
+ proto::WorkerRange protoRange = protoItem->range ();
246
246
LOGS (_log, LOG_LVL_INFO, funcName << " rightNeighbor workerId=" << workerId <<
247
247
" keyCount=" << nInfoR.keyCount << " recentAdds=" << nInfoR.recentAdds );
248
248
bool valid = protoRange.valid ();
249
249
StringRange rightRange;
250
250
if (valid) {
251
- std::string min = protoRange.min ( );
252
- std::string max = protoRange.max ( );
251
+ CompositeKey min (protoRange. minint (), protoRange.minstr () );
252
+ CompositeKey max (protoRange. maxint (), protoRange.maxstr () );
253
253
bool unlimited = protoRange.maxunlimited ();
254
254
rightRange.setMinMax (min, max, unlimited);
255
255
LOGS (_log, LOG_LVL_INFO, funcName << " rightRange=" << rightRange);
@@ -386,7 +386,7 @@ void CentralWorker::_shift(Direction direction, int keysToShift) {
386
386
for (int j=0 ; j < sz; ++j) {
387
387
proto::KeyInfo const & protoKI = protoKeyList->keypair (j);
388
388
ChunkSubchunk chSub (protoKI.chunk (), protoKI.subchunk ());
389
- keyList.push_back (std::make_pair (protoKI.key ( ), chSub));
389
+ keyList.push_back (std::make_pair (CompositeKey ( protoKI.keyint (), protoKI. keystr () ), chSub));
390
390
}
391
391
insertKeys (keyList, false );
392
392
}
@@ -403,8 +403,8 @@ void CentralWorker::_shift(Direction direction, int keysToShift) {
403
403
// Construct a message with that many keys and send it (sending the highest keys)
404
404
proto::KeyList protoKeyList;
405
405
protoKeyList.set_keycount (keysToShift);
406
- std::string minKey ( " " ); // smallest value of a key sent to right neighbor
407
- std::string maxKey ( " " );
406
+ CompositeKey minKey = CompositeKey::minValue ( ); // smallest value of a key is sent to right neighbor
407
+ CompositeKey maxKey = CompositeKey::minValue ( );
408
408
{
409
409
std::lock_guard<std::mutex> lck (_idMapMtx);
410
410
if (not _transferListToRight.empty ()) {
@@ -420,7 +420,8 @@ void CentralWorker::_shift(Direction direction, int keysToShift) {
420
420
_transferListToRight.push_back (std::make_pair (iter->first , iter->second ));
421
421
proto::KeyInfo* protoKI = protoKeyList.add_keypair ();
422
422
minKey = iter->first ;
423
- protoKI->set_key (minKey);
423
+ protoKI->set_keyint (minKey.kInt );
424
+ protoKI->set_keystr (minKey.kStr );
424
425
protoKI->set_chunk (iter->second .chunk );
425
426
protoKI->set_subchunk (iter->second .subchunk );
426
427
_keyValueMap.erase (iter);
@@ -472,8 +473,8 @@ void CentralWorker::finishShiftFromRight() {
472
473
StringElement::UPtr CentralWorker::buildKeyList (int keysToShift) {
473
474
std::string funcName = " CentralWorker::buildKeyList" ;
474
475
proto::KeyList protoKeyList;
475
- std::string minKey ( " " ); // smallest key sent
476
- std::string maxKey ( " " ); // largest key sent
476
+ CompositeKey minKey = CompositeKey::minValue ( ); // smallest key sent
477
+ CompositeKey maxKey = CompositeKey::minValue ( ); // largest key sent
477
478
{
478
479
LOGS (_log, LOG_LVL_INFO, funcName);
479
480
std::lock_guard<std::mutex> lck (_idMapMtx);
@@ -492,15 +493,16 @@ StringElement::UPtr CentralWorker::buildKeyList(int keysToShift) {
492
493
_transferListWithLeft.push_back (std::make_pair (iter->first , iter->second ));
493
494
proto::KeyInfo* protoKI = protoKeyList.add_keypair ();
494
495
maxKey = iter->first ;
495
- protoKI->set_key (maxKey);
496
+ protoKI->set_keyint (maxKey.kInt );
497
+ protoKI->set_keystr (maxKey.kStr );
496
498
protoKI->set_chunk (iter->second .chunk );
497
499
protoKI->set_subchunk (iter->second .subchunk );
498
500
_keyValueMap.erase (iter);
499
501
}
500
502
// Adjust our range;
501
503
auto iter = _keyValueMap.begin ();
502
504
auto minKey = _strRange.getMin ();
503
- if (minKey != " " ) {
505
+ if (minKey != CompositeKey::minValue () ) {
504
506
if (iter->first != minKey) {
505
507
_strRange.setMin (iter->first );
506
508
_rangeChanged = true ;
@@ -625,7 +627,7 @@ void CentralWorker::cancelShiftsWithLeftNeighbor() {
625
627
_transferListWithLeft.clear ();
626
628
627
629
// Fix the bottom of the range.
628
- if (_strRange.getMin () != " " ) {
630
+ if (_strRange.getMin () != CompositeKey::minValue () ) {
629
631
_strRange.setMin (_keyValueMap.begin ()->first );
630
632
}
631
633
}
@@ -667,12 +669,12 @@ void CentralWorker::_workerInfoReceive(std::unique_ptr<proto::WorkerListItem>& p
667
669
portTcp = protoAddr.tcpport ();
668
670
}
669
671
StringRange strRange;
670
- if (protoList->has_rangestr ()) {
671
- proto::WorkerRangeString protoRange= protoList->rangestr ();
672
+ if (protoList->has_range ()) {
673
+ proto::WorkerRange protoRange = protoList->range ();
672
674
bool valid = protoRange.valid ();
673
675
if (valid) {
674
- std::string min = protoRange.min ( );
675
- std::string max = protoRange.max ( );
676
+ CompositeKey min (protoRange. minint (), protoRange.minstr () );
677
+ CompositeKey max (protoRange. maxint (), protoRange.maxstr () );
676
678
bool unlimited = protoRange.maxunlimited ();
677
679
strRange.setMinMax (min, max, unlimited);
678
680
}
@@ -717,7 +719,7 @@ StringRange CentralWorker::updateRangeWithLeftData(StringRange const& leftNeighb
717
719
std::unique_lock<std::mutex> lck (_idMapMtx);
718
720
if (not _strRange.getValid ()) {
719
721
// Our range has not been set, so base it on the range of the left neighbor.
720
- auto min = StringRange::incrementString (leftNeighborRange.getMax ());
722
+ auto min = StringRange::increment (leftNeighborRange.getMax ());
721
723
auto max = min;
722
724
_strRange.setMinMax (min, max, leftNeighborRange.getUnlimited ());
723
725
newLeftNeighborRange.setMax (max, false );
@@ -770,7 +772,7 @@ void CentralWorker::_workerKeyInsertReq(LoaderMsg const& inMsg, std::unique_ptr<
770
772
NetworkAddress nAddr (protoAddr.ip (), protoAddr.udpport ());
771
773
772
774
proto::KeyInfo protoKeyInfo = protoData->keyinfo ();
773
- std::string key = protoKeyInfo.key ( );
775
+ CompositeKey key (protoKeyInfo. keyint (), protoKeyInfo.keystr () );
774
776
ChunkSubchunk chunkInfo (protoKeyInfo.chunk (), protoKeyInfo.subchunk ());
775
777
776
778
// / see if the key should be inserted into our map
@@ -794,7 +796,8 @@ void CentralWorker::_workerKeyInsertReq(LoaderMsg const& inMsg, std::unique_ptr<
794
796
msg.appendToData (msgData);
795
797
// protoKeyInfo should still be the same
796
798
proto::KeyInfo protoReply;
797
- protoReply.set_key (key);
799
+ protoReply.set_keyint (key.kInt );
800
+ protoReply.set_keystr (key.kStr );
798
801
protoReply.set_chunk (chunkInfo.chunk );
799
802
protoReply.set_subchunk (chunkInfo.subchunk );
800
803
StringElement strElem;
@@ -824,7 +827,7 @@ void CentralWorker::_forwardKeyInsertRequest(NetworkAddress const& targetAddr, L
824
827
std::unique_ptr<proto::KeyInfoInsert>& protoData) {
825
828
// Aside from hops, the proto buffer should be the same.
826
829
proto::KeyInfo protoKeyInfo = protoData->keyinfo ();
827
- auto key = protoKeyInfo.key ( );
830
+ CompositeKey key (protoKeyInfo. keyint (), protoKeyInfo.keystr () );
828
831
// The proto buffer should be the same, just need a new message.
829
832
int hops = protoData->hops () + 1 ;
830
833
if (hops > 4 ) { // TODO replace magic number with variable set via config file.
@@ -870,7 +873,7 @@ void CentralWorker::_workerKeyInfoReq(LoaderMsg const& inMsg, std::unique_ptr<pr
870
873
NetworkAddress nAddr (protoAddr.ip (), protoAddr.udpport ());
871
874
872
875
proto::KeyInfo protoKeyInfo = protoData->keyinfo ();
873
- std::string key = protoKeyInfo.key ( );
876
+ CompositeKey key (protoKeyInfo. keyint (), protoKeyInfo.keystr () );
874
877
875
878
// / see if the key is in our map
876
879
std::unique_lock<std::mutex> lck (_idMapMtx);
@@ -885,7 +888,8 @@ void CentralWorker::_workerKeyInfoReq(LoaderMsg const& inMsg, std::unique_ptr<pr
885
888
BufferUdp msgData;
886
889
msg.appendToData (msgData);
887
890
proto::KeyInfo protoReply;
888
- protoReply.set_key (key);
891
+ protoReply.set_keyint (key.kInt );
892
+ protoReply.set_keystr (key.kStr );
889
893
if (iter == _keyValueMap.end ()) {
890
894
// key not found message.
891
895
protoReply.set_chunk (0 );
@@ -1005,12 +1009,9 @@ std::unique_ptr<proto::WorkerKeysInfo> CentralWorker::_workerKeysInfoBuilder() {
1005
1009
protoWKI->set_wid (_ourId);
1006
1010
protoWKI->set_mapsize (mapSize);
1007
1011
protoWKI->set_recentadds (recentAdds);
1008
- // TODO make a function to load WorkerRangeString, happens a bit.
1009
- proto::WorkerRangeString *protoRange = protoWKI->mutable_range ();
1010
- protoRange->set_valid (range.getValid ());
1011
- protoRange->set_min (range.getMin ());
1012
- protoRange->set_max (range.getMax ());
1013
- protoRange->set_maxunlimited (range.getUnlimited ());
1012
+ // TODO Maybe make a function to load WorkerRangeString, happens a bit. &&&
1013
+ proto::WorkerRange *protoRange = protoWKI->mutable_range ();
1014
+ range.loadProtoRange (*protoRange);
1014
1015
proto::Neighbor *protoLeft = protoWKI->mutable_left ();
1015
1016
protoLeft->set_wid (_neighborLeft.getId ());
1016
1017
proto::Neighbor *protoRight = protoWKI->mutable_right ();
0 commit comments