adamdebreceni commented on code in PR #1509:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1509#discussion_r1106932691
##########
extensions/rocksdb-repos/DatabaseContentRepository.cpp:
##########
@@ -179,6 +180,37 @@ std::shared_ptr<io::BaseStream>
DatabaseContentRepository::write(const minifi::R
return std::make_shared<io::RocksDbStream>(claim.getContentFullPath(),
gsl::make_not_null<minifi::internal::RocksDatabase*>(db_.get()), true, batch);
}
+bool DatabaseContentRepository::clearOrphans() {
+ if (!is_valid_ || !db_)
+ return false;
+ auto opendb = db_->open();
+ if (!opendb) {
+ return false;
+ }
+ std::vector<std::string> keys;
Review Comment:
renamed
##########
extensions/rocksdb-repos/DatabaseContentRepository.cpp:
##########
@@ -179,6 +180,37 @@ std::shared_ptr<io::BaseStream>
DatabaseContentRepository::write(const minifi::R
return std::make_shared<io::RocksDbStream>(claim.getContentFullPath(),
gsl::make_not_null<minifi::internal::RocksDatabase*>(db_.get()), true, batch);
}
+bool DatabaseContentRepository::clearOrphans() {
+ if (!is_valid_ || !db_)
+ return false;
+ auto opendb = db_->open();
+ if (!opendb) {
+ return false;
+ }
+ std::vector<std::string> keys;
+ auto it = opendb->NewIterator(rocksdb::ReadOptions());
+ for (it->SeekToFirst(); it->Valid(); it->Next()) {
+ auto key = it->key().ToString();
+ auto claim_it = count_map_.find(key);
+ if (claim_it == count_map_.end() || claim_it->second == 0) {
+ logger_->log_debug("Deleting orphan resource %s", key);
+ keys.push_back(key);
+ }
+ }
+ auto batch = opendb->createWriteBatch();
+ for (auto& key : keys) {
+ batch.Delete(key);
+ }
+
+ rocksdb::Status status = opendb->Write(rocksdb::WriteOptions(), &batch);
+
+ if (!status.ok()) {
+ logger_->log_debug("Could not delete orphan contents from rocksdb
database: %s", status.ToString());
Review Comment:
changed it to error
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]