szaszm commented on a change in pull request #605: MINIFICPP-550 - Implement
RocksDB controller service and component st…
URL: https://github.com/apache/nifi-minifi-cpp/pull/605#discussion_r365972219
##########
File path: extensions/sftp/processors/ListSFTP.cpp
##########
@@ -507,85 +463,87 @@ ListSFTP::ListedEntity::ListedEntity(uint64_t
timestamp_, uint64_t size_)
, size(size_) {
}
-bool ListSFTP::persistTrackingTimestampsCache(const std::string& hostname,
const std::string& username, const std::string& remote_path) {
- std::ofstream file(tracking_timestamps_state_filename_);
- if (!file.is_open()) {
- logger_->log_error("Failed to store state to Tracking Timestamps state
file \"%s\"", tracking_timestamps_state_filename_.c_str());
+bool ListSFTP::persistTrackingTimestampsCache(const
std::shared_ptr<core::ProcessContext>& context, const std::string& hostname,
const std::string& username, const std::string& remote_path) {
+ auto state_manager = context->getStateManager();
+ if (state_manager == nullptr) {
return false;
}
- file << "hostname=" << hostname << "\n";
- file << "username=" << username << "\n";
- file << "remote_path=" << remote_path << "\n";
- file << "listing.timestamp=" << last_listed_latest_entry_timestamp_ << "\n";
- file << "processed.timestamp=" << last_processed_latest_entry_timestamp_ <<
"\n";
+ std::unordered_map<std::string, std::string> state;
+ state["listing_strategy"] = LISTING_STRATEGY_TRACKING_TIMESTAMPS;
+ state["hostname"] = hostname;
+ state["username"] = username;
+ state["remote_path"] = remote_path;
+ state["listing.timestamp"] =
std::to_string(last_listed_latest_entry_timestamp_);
+ state["processed.timestamp"] =
std::to_string(last_processed_latest_entry_timestamp_);
size_t i = 0;
for (const auto& identifier : latest_identifiers_processed_) {
- file << "id." << i << "=" << identifier << "\n";
+ state["id." + std::to_string(i)] = identifier;
++i;
}
+ state_manager->set(state);
+ if (!state_manager->persist()) {
+ return false;
+ }
return true;
}
-bool ListSFTP::updateFromTrackingTimestampsCache(const std::string& hostname,
const std::string& username, const std::string& remote_path) {
- std::ifstream file(tracking_timestamps_state_filename_);
- if (!file.is_open()) {
- logger_->log_error("Failed to open Tracking Timestamps state file \"%s\"",
tracking_timestamps_state_filename_.c_str());
- return false;
- }
+bool ListSFTP::updateFromTrackingTimestampsCache(const
std::shared_ptr<core::ProcessContext>& context, const std::string& hostname,
const std::string& username, const std::string& remote_path) {
Review comment:
Why do we use `shared_ptr const&`? If we can guarantee that the pointed-to
object stays alive while we have a reference to it, then a regular observer
pointer (plain ptr or tagged `observer_ptr`) states the purpose better.
This type says: "I'm a pointer to a mutable `ProcessContext` with shared
ownership that can be reassigned by someone else to point to another mutable
`ProcessContext` with shared ownership."
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services