bakaid commented on a change in pull request #605:
URL: https://github.com/apache/nifi-minifi-cpp/pull/605#discussion_r415336687
##########
File path: extensions/sql/processors/QueryDatabaseTable.cpp
##########
@@ -308,19 +240,43 @@ void QueryDatabaseTable::processOnSchedule(const
core::ProcessContext &context)
context.getProperty(s_sqlQuery.getName(), sqlQuery_);
context.getProperty(s_maxRowsPerFlowFile.getName(), maxRowsPerFlowFile_);
- std::string stateDir;
- context.getProperty(s_stateDirectory.getName(), stateDir);
- if (stateDir.empty()) {
- logger_->log_error("State Directory is empty");
- return;
+ mapState_.clear();
+
+ state_manager_ = context.getStateManager();
+ if (state_manager_ == nullptr) {
+ throw Exception(PROCESSOR_EXCEPTION, "Failed to get StateManager");
}
- pState_ = std::make_unique<State>(tableName_, stateDir, getUUIDStr(),
logger_);
- if (!*pState_) {
- return;
+ std::unordered_map<std::string, std::string> state_map;
+ if (state_manager_->get(state_map)) {
+ if (state_map[TABLENAME_KEY] != tableName_) {
+ state_manager_->clear();
+ } else {
+ for (auto&& elem : state_map) {
+ if (elem.first.find(MAXVALUE_KEY_PREFIX) == 0) {
+ mapState_.emplace(elem.first.substr(MAXVALUE_KEY_PREFIX.length()),
std::move(elem.second));
+ }
+ }
+ }
+ } else {
+ // Try to migrate legacy state file
+ std::string stateDir;
+ context.getProperty(s_stateDirectory.getName(), stateDir);
+ if (!stateDir.empty()) {
+ LegacyState legacyState(tableName_, stateDir, getUUIDStr(), logger_);
+ if (legacyState) {
+ mapState_ = legacyState.getStateMap();
+ if (saveState() && state_manager_->persist()) {
+ logger_->log_info("State migration successful");
+ legacyState.moveStateFileToMigrated();
+ } else {
+ logger_->log_warn("Failed to persists migrated state");
+ }
+ } else {
+ logger_->log_warn("Could not migrate state from specified State
Directory %s", stateDir);
+ }
+ }
Review comment:
It is short and very much unlikely to be reused, so I don't see much
benefit in moving to a function.
----------------------------------------------------------------
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]