@@ -242,14 +242,14 @@ bool CentralWorker::_determineRange() {
242242 nInfoR.keyCount = protoItem->mapsize ();
243243 _neighborRight.setKeyCount (nInfoR.keyCount ); // TODO add a timestamp to this data.
244244 nInfoR.recentAdds = protoItem->recentadds ();
245- proto::WorkerRangeString protoRange = protoItem->range ();
245+ proto::WorkerRange protoRange = protoItem->range ();
246246 LOGS (_log, LOG_LVL_INFO, funcName << " rightNeighbor workerId=" << workerId <<
247247 " keyCount=" << nInfoR.keyCount << " recentAdds=" << nInfoR.recentAdds );
248248 bool valid = protoRange.valid ();
249249 StringRange rightRange;
250250 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 () );
253253 bool unlimited = protoRange.maxunlimited ();
254254 rightRange.setMinMax (min, max, unlimited);
255255 LOGS (_log, LOG_LVL_INFO, funcName << " rightRange=" << rightRange);
@@ -386,7 +386,7 @@ void CentralWorker::_shift(Direction direction, int keysToShift) {
386386 for (int j=0 ; j < sz; ++j) {
387387 proto::KeyInfo const & protoKI = protoKeyList->keypair (j);
388388 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));
390390 }
391391 insertKeys (keyList, false );
392392 }
@@ -403,8 +403,8 @@ void CentralWorker::_shift(Direction direction, int keysToShift) {
403403 // Construct a message with that many keys and send it (sending the highest keys)
404404 proto::KeyList protoKeyList;
405405 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 ( );
408408 {
409409 std::lock_guard<std::mutex> lck (_idMapMtx);
410410 if (not _transferListToRight.empty ()) {
@@ -420,7 +420,8 @@ void CentralWorker::_shift(Direction direction, int keysToShift) {
420420 _transferListToRight.push_back (std::make_pair (iter->first , iter->second ));
421421 proto::KeyInfo* protoKI = protoKeyList.add_keypair ();
422422 minKey = iter->first ;
423- protoKI->set_key (minKey);
423+ protoKI->set_keyint (minKey.kInt );
424+ protoKI->set_keystr (minKey.kStr );
424425 protoKI->set_chunk (iter->second .chunk );
425426 protoKI->set_subchunk (iter->second .subchunk );
426427 _keyValueMap.erase (iter);
@@ -472,8 +473,8 @@ void CentralWorker::finishShiftFromRight() {
472473StringElement::UPtr CentralWorker::buildKeyList (int keysToShift) {
473474 std::string funcName = " CentralWorker::buildKeyList" ;
474475 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
477478 {
478479 LOGS (_log, LOG_LVL_INFO, funcName);
479480 std::lock_guard<std::mutex> lck (_idMapMtx);
@@ -492,15 +493,16 @@ StringElement::UPtr CentralWorker::buildKeyList(int keysToShift) {
492493 _transferListWithLeft.push_back (std::make_pair (iter->first , iter->second ));
493494 proto::KeyInfo* protoKI = protoKeyList.add_keypair ();
494495 maxKey = iter->first ;
495- protoKI->set_key (maxKey);
496+ protoKI->set_keyint (maxKey.kInt );
497+ protoKI->set_keystr (maxKey.kStr );
496498 protoKI->set_chunk (iter->second .chunk );
497499 protoKI->set_subchunk (iter->second .subchunk );
498500 _keyValueMap.erase (iter);
499501 }
500502 // Adjust our range;
501503 auto iter = _keyValueMap.begin ();
502504 auto minKey = _strRange.getMin ();
503- if (minKey != " " ) {
505+ if (minKey != CompositeKey::minValue () ) {
504506 if (iter->first != minKey) {
505507 _strRange.setMin (iter->first );
506508 _rangeChanged = true ;
@@ -625,7 +627,7 @@ void CentralWorker::cancelShiftsWithLeftNeighbor() {
625627 _transferListWithLeft.clear ();
626628
627629 // Fix the bottom of the range.
628- if (_strRange.getMin () != " " ) {
630+ if (_strRange.getMin () != CompositeKey::minValue () ) {
629631 _strRange.setMin (_keyValueMap.begin ()->first );
630632 }
631633 }
@@ -667,12 +669,12 @@ void CentralWorker::_workerInfoReceive(std::unique_ptr<proto::WorkerListItem>& p
667669 portTcp = protoAddr.tcpport ();
668670 }
669671 StringRange strRange;
670- if (protoList->has_rangestr ()) {
671- proto::WorkerRangeString protoRange= protoList->rangestr ();
672+ if (protoList->has_range ()) {
673+ proto::WorkerRange protoRange = protoList->range ();
672674 bool valid = protoRange.valid ();
673675 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 () );
676678 bool unlimited = protoRange.maxunlimited ();
677679 strRange.setMinMax (min, max, unlimited);
678680 }
@@ -717,7 +719,7 @@ StringRange CentralWorker::updateRangeWithLeftData(StringRange const& leftNeighb
717719 std::unique_lock<std::mutex> lck (_idMapMtx);
718720 if (not _strRange.getValid ()) {
719721 // 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 ());
721723 auto max = min;
722724 _strRange.setMinMax (min, max, leftNeighborRange.getUnlimited ());
723725 newLeftNeighborRange.setMax (max, false );
@@ -770,7 +772,7 @@ void CentralWorker::_workerKeyInsertReq(LoaderMsg const& inMsg, std::unique_ptr<
770772 NetworkAddress nAddr (protoAddr.ip (), protoAddr.udpport ());
771773
772774 proto::KeyInfo protoKeyInfo = protoData->keyinfo ();
773- std::string key = protoKeyInfo.key ( );
775+ CompositeKey key (protoKeyInfo. keyint (), protoKeyInfo.keystr () );
774776 ChunkSubchunk chunkInfo (protoKeyInfo.chunk (), protoKeyInfo.subchunk ());
775777
776778 // / see if the key should be inserted into our map
@@ -794,7 +796,8 @@ void CentralWorker::_workerKeyInsertReq(LoaderMsg const& inMsg, std::unique_ptr<
794796 msg.appendToData (msgData);
795797 // protoKeyInfo should still be the same
796798 proto::KeyInfo protoReply;
797- protoReply.set_key (key);
799+ protoReply.set_keyint (key.kInt );
800+ protoReply.set_keystr (key.kStr );
798801 protoReply.set_chunk (chunkInfo.chunk );
799802 protoReply.set_subchunk (chunkInfo.subchunk );
800803 StringElement strElem;
@@ -824,7 +827,7 @@ void CentralWorker::_forwardKeyInsertRequest(NetworkAddress const& targetAddr, L
824827 std::unique_ptr<proto::KeyInfoInsert>& protoData) {
825828 // Aside from hops, the proto buffer should be the same.
826829 proto::KeyInfo protoKeyInfo = protoData->keyinfo ();
827- auto key = protoKeyInfo.key ( );
830+ CompositeKey key (protoKeyInfo. keyint (), protoKeyInfo.keystr () );
828831 // The proto buffer should be the same, just need a new message.
829832 int hops = protoData->hops () + 1 ;
830833 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
870873 NetworkAddress nAddr (protoAddr.ip (), protoAddr.udpport ());
871874
872875 proto::KeyInfo protoKeyInfo = protoData->keyinfo ();
873- std::string key = protoKeyInfo.key ( );
876+ CompositeKey key (protoKeyInfo. keyint (), protoKeyInfo.keystr () );
874877
875878 // / see if the key is in our map
876879 std::unique_lock<std::mutex> lck (_idMapMtx);
@@ -885,7 +888,8 @@ void CentralWorker::_workerKeyInfoReq(LoaderMsg const& inMsg, std::unique_ptr<pr
885888 BufferUdp msgData;
886889 msg.appendToData (msgData);
887890 proto::KeyInfo protoReply;
888- protoReply.set_key (key);
891+ protoReply.set_keyint (key.kInt );
892+ protoReply.set_keystr (key.kStr );
889893 if (iter == _keyValueMap.end ()) {
890894 // key not found message.
891895 protoReply.set_chunk (0 );
@@ -1005,12 +1009,9 @@ std::unique_ptr<proto::WorkerKeysInfo> CentralWorker::_workerKeysInfoBuilder() {
10051009 protoWKI->set_wid (_ourId);
10061010 protoWKI->set_mapsize (mapSize);
10071011 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);
10141015 proto::Neighbor *protoLeft = protoWKI->mutable_left ();
10151016 protoLeft->set_wid (_neighborLeft.getId ());
10161017 proto::Neighbor *protoRight = protoWKI->mutable_right ();
0 commit comments