@@ -2100,11 +2100,11 @@ struct RdbLoader::ObjSettings {
21002100// The first chunk carries the object type and key. Continuation chunks carry only payload,
21012101// so we keep the object type, key, db, settings, and pending read.
21022102struct RdbLoader ::StreamState {
2103+ std::string key;
21032104 DbIndex db_index;
21042105 int type;
21052106 PendingRead pending_read;
21062107 ObjSettings settings;
2107- std::string key;
21082108};
21092109
21102110RdbLoader::RdbLoader (Service* service, RdbLoadContext* load_context, std::string snapshot_id)
@@ -2187,12 +2187,6 @@ error_code RdbLoader::Load(io::Source* src) {
21872187 GetCurrentDbSlice ().IncrLoadInProgress ();
21882188 }
21892189
2190- auto finalize_curr_chunk = [&] {
2191- if (!stop_early_.load (memory_order_relaxed))
2192- return FinishCurrentChunk ();
2193- return kOk ;
2194- };
2195-
21962190 while (!stop_early_.load (memory_order_relaxed)) {
21972191 if (pause_) {
21982192 ThisFiber::SleepFor (100ms);
@@ -2248,15 +2242,15 @@ error_code RdbLoader::Load(io::Source* src) {
22482242 }
22492243
22502244 if (type == RDB_OPCODE_EOF) {
2251- if (current_chunk_state_.has_value () || !stream_states_.empty ()) {
2252- if (current_chunk_state_.has_value ()) {
2253- LOG (ERROR) << " eof seen while a previous chunk is not yet finished, stream id "
2254- << current_chunk_state_->stream_id << " , remaining bytes "
2255- << current_chunk_state_->remaining_payload_bytes
2256- << " , pending stream states: " << stream_states_.size ();
2257- return RdbError (errc::rdb_chunk_payload_remaining);
2258- }
2245+ if (current_chunk_state_) {
2246+ LOG (ERROR) << " eof seen while a previous chunk is not yet finished, stream id "
2247+ << current_chunk_state_->stream_id << " , remaining bytes "
2248+ << current_chunk_state_->remaining_payload_bytes
2249+ << " , pending stream states: " << stream_states_.size ();
2250+ return RdbError (errc::rdb_chunk_payload_remaining);
2251+ }
22592252
2253+ if (!stream_states_.empty ()) {
22602254 LOG (ERROR) << " eof seen while pending stream states: " << stream_states_.size ();
22612255 return RdbError (errc::rdb_chunk_payload_remaining);
22622256 }
@@ -2402,7 +2396,7 @@ error_code RdbLoader::Load(io::Source* src) {
24022396 // path below will read its type and key.
24032397 if (stream_states_.contains (current_chunk_state_->stream_id )) {
24042398 RETURN_ON_ERR (LoadValueChunk ());
2405- RETURN_ON_ERR (finalize_curr_chunk ());
2399+ RETURN_ON_ERR (FinalizeCurrentChunkIfNeeded ());
24062400 }
24072401 continue ;
24082402 }
@@ -2423,7 +2417,7 @@ error_code RdbLoader::Load(io::Source* src) {
24232417 VLOG (2 ) << " LoadKeyValPair key=" << last_key_loaded_ << " rdb_type=" << type
24242418 << " db= " << cur_db_index_;
24252419 settings.Reset ();
2426- RETURN_ON_ERR (finalize_curr_chunk ());
2420+ RETURN_ON_ERR (FinalizeCurrentChunkIfNeeded ());
24272421 } // main load loop
24282422
24292423 DVLOG (1 ) << " RdbLoad loop finished" ;
@@ -3010,11 +3004,11 @@ error_code RdbLoader::LoadKeyValPair(int type, ObjSettings* settings) {
30103004 // the next chunk with the same stream id arrives.
30113005 if (!finalized && current_chunk_state_) {
30123006 StreamState stream_state{
3007+ .key = std::move (key),
30133008 .db_index = cur_db_index_,
30143009 .type = type,
30153010 .pending_read = std::move (pending_read_),
30163011 .settings = *settings,
3017- .key = std::move (key),
30183012 };
30193013 const bool inserted =
30203014 stream_states_.try_emplace (current_chunk_state_->stream_id , std::move (stream_state)).second ;
@@ -3286,6 +3280,12 @@ error_code RdbLoader::HandleShardDocIndex() {
32863280 return kOk ;
32873281}
32883282
3283+ std::error_code RdbLoader::FinalizeCurrentChunkIfNeeded () {
3284+ if (stop_early_.load (memory_order_relaxed))
3285+ return kOk ;
3286+ return FinishCurrentChunk ();
3287+ }
3288+
32893289error_code RdbLoader::LoadVectorIndexNodes (uint64_t elements_number,
32903290 std::vector<search::HnswNodeData>* nodes) {
32913291 nodes->reserve (elements_number);
0 commit comments