You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "in-han (via GitHub)" <gi...@apache.org> on 2024/03/26 10:57:08 UTC

[I] Check iterator status after quit loop [kvrocks]

in-han opened a new issue, #2200:
URL: https://github.com/apache/kvrocks/issues/2200

   ### Search before asking
   
   - [X] I had searched in the [issues](https://github.com/apache/kvrocks/issues) and found no similar issues.
   
   
   ### Motivation
   
   From [rocksdb doc](https://github.com/facebook/rocksdb/wiki/Iterator#error-handling), need handle error when iterating.   Like bellow:
   ```
   for (it->Seek("hello"); it->Valid(); it->Next()) {
     // Do something with it->key() and it->value().
   }
   if (!it->status().ok()) {
     // Handle error. it->status().ToString() contains error message.
   }
   ```
   
   However, the code in kvrocks does not do this check. 
   For instance: 
   https://github.com/apache/kvrocks/blob/unstable/src/types/redis_hash.cc#L344
   
   ```
   rocksdb::Status Hash::GetAll(const Slice &user_key, std::vector<FieldValue> *field_values, HashFetchType type) {
     field_values->clear();
   
     std::string ns_key = AppendNamespacePrefix(user_key);
     HashMetadata metadata(false);
     LatestSnapShot ss(storage_);
     rocksdb::Status s = GetMetadata(GetOptions{.snapshot = ss.GetSnapShot()}, ns_key, &metadata);
     if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
   
     std::string prefix_key = InternalKey(ns_key, "", metadata.version, storage_->IsSlotIdEncoded()).Encode();
     std::string next_version_prefix_key =
         InternalKey(ns_key, "", metadata.version + 1, storage_->IsSlotIdEncoded()).Encode();
   
     rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
     read_options.snapshot = ss.GetSnapShot();
     rocksdb::Slice upper_bound(next_version_prefix_key);
     read_options.iterate_upper_bound = &upper_bound;
   
     auto iter = util::UniqueIterator(storage_, read_options);
     for (iter->Seek(prefix_key); iter->Valid() && iter->key().starts_with(prefix_key); iter->Next()) {
       if (type == HashFetchType::kOnlyKey) {
         InternalKey ikey(iter->key(), storage_->IsSlotIdEncoded());
         field_values->emplace_back(ikey.GetSubKey().ToString(), "");
       } else if (type == HashFetchType::kOnlyValue) {
         field_values->emplace_back("", iter->value().ToString());
       } else {
         InternalKey ikey(iter->key(), storage_->IsSlotIdEncoded());
         field_values->emplace_back(ikey.GetSubKey().ToString(), iter->value().ToString());
       }
     }
     return rocksdb::Status::OK();
   }
   ```
   
   
   
   
   
   ### Solution
   
   check iterator status.
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Check iterator status after quit loop [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on issue #2200:
URL: https://github.com/apache/kvrocks/issues/2200#issuecomment-2020182957

   @in-han Thanks for your feedback, would you like to submit a PR to improve this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Check iterator status after quit loop [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk closed issue #2200: Check iterator status after quit loop 
URL: https://github.com/apache/kvrocks/issues/2200


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Check iterator status after quit loop [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on issue #2200:
URL: https://github.com/apache/kvrocks/issues/2200#issuecomment-2021779072

   @han-ian Thank you!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Check iterator status after quit loop [kvrocks]

Posted by "han-ian (via GitHub)" <gi...@apache.org>.
han-ian commented on issue #2200:
URL: https://github.com/apache/kvrocks/issues/2200#issuecomment-2021747176

   @git-hulk Yes, I will do this next week.
   
   > @in-han Thanks for your feedback, would you like to submit a PR to improve this?
   
   Yeah, I will do it next week.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org