Skip to content

MINIFICPP-1244 Support the Initial Start Position property in TailFile#1052

Closed
lordgamez wants to merge 22 commits intoapache:mainfrom
lordgamez:MINIFICPP-1244
Closed

MINIFICPP-1244 Support the Initial Start Position property in TailFile#1052
lordgamez wants to merge 22 commits intoapache:mainfrom
lordgamez:MINIFICPP-1244

Conversation

@lordgamez
Copy link
Contributor

@lordgamez lordgamez commented Apr 14, 2021

Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.

processAllRotatedFiles(session, state);
} else if (initial_start_position_ == "Current Time") {
state.position_ = utils::file::FileUtils::file_size(full_file_name);
state.last_read_time_ = std::chrono::system_clock::now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to compute the checksum of the file up to this point. Otherwise, when

  1. MiNiFi starts with Current Time at the middle of test.log
  2. onTrigger() reads a few more lines (and computes the checksum, but only from the middle)
  3. test.log gets rolled over to test.log.1
  4. onTrigger() gets called again, it will compute the checksum of test.log.1 from the beginning, and the checksum will not match the state, so it will re-read test.log.1 from the beginning rather than from the point where it left off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I added this use case as a separate test and added the fix in 1eaf3d3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use utils::file::FileUtils::computeChecksum() as it is done in findRotatedFiles() (line 656), mainly for consistency, but it's also slightly shorter/simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip, I totally missed this, updated in 7a926a3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason on Windows the test case fails, have to investigate it further

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that as I previously created a rolled over file for all tests which was later rewritten in the rollover scenario with the same filename and it was identified as a new file on Windows. Extracted the new test as a separate test case in cbd9e21 where I removed this from the test setup.

}
return utils::nullopt;
}
std::string getRequiredPropertyOrThrow(const core::ProcessContext* context, const std::string& property_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that getProperty already throws on missing required properties
here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it, maybe @hunyadi-dev can comment on it as it was introduced in #940. Are there any differences in the behavior of getProperty and getRequiredPropertyOrThrow?

@szaszm szaszm closed this in a0a7776 May 3, 2021
dam4rus pushed a commit to dam4rus/nifi-minifi-cpp that referenced this pull request May 18, 2021
Closes apache#1052

Signed-off-by: Marton Szasz <szaszm01@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants