You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "mosermw (via GitHub)" <gi...@apache.org> on 2023/09/01 20:13:20 UTC

[GitHub] [nifi] mosermw opened a new pull request, #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

mosermw opened a new pull request, #7664:
URL: https://github.com/apache/nifi/pull/7664

   <!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
   <!-- contributor license agreements.  See the NOTICE file distributed with -->
   <!-- this work for additional information regarding copyright ownership. -->
   <!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
   <!-- (the "License"); you may not use this file except in compliance with -->
   <!-- the License.  You may obtain a copy of the License at -->
   <!--     http://www.apache.org/licenses/LICENSE-2.0 -->
   <!-- Unless required by applicable law or agreed to in writing, software -->
   <!-- distributed under the License is distributed on an "AS IS" BASIS, -->
   <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
   <!-- See the License for the specific language governing permissions and -->
   <!-- limitations under the License. -->
   
   # Summary
   
   [NIFI-12019](https://issues.apache.org/jira/browse/NIFI-12019)  This PR corrects SynchronousFileWatcher so that it resets its last checked timestamp whenever it uses the configured UpdateMonitor to check on the file being watched.
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [x] Build completed using `mvn clean install -P contrib-check`
     - [x] JDK 17
   
   ### Licensing
   
   - [n/a] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [n/a] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [n/a] Documentation formatting appears as expected in rendered files
   


-- 
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@nifi.apache.org

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


[GitHub] [nifi] mosermw commented on pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on PR #7664:
URL: https://github.com/apache/nifi/pull/7664#issuecomment-1729602721

   @joewitt I'm looking at this now.  SynchronousFileWatcher starts a background thread to check if a file has changed, so the unit test timing tolerances are likely too tight.  Not sure if there's a good pattern for testing things like this that remove timing issues from the test.


-- 
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@nifi.apache.org

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


[GitHub] [nifi] mosermw commented on a diff in pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on code in PR #7664:
URL: https://github.com/apache/nifi/pull/7664#discussion_r1316383800


##########
nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/monitor/SynchronousFileWatcher.java:
##########
@@ -77,21 +77,16 @@ public boolean checkAndReset() throws IOException {
     private boolean checkForUpdate() throws IOException {
         if (resourceLock.tryLock()) {
             try {
-                final StateWrapper wrapper = lastState.get();
+                final Object oldState = lastState.get().getState();
                 final Object newState = monitor.getCurrentState(path);
-                if (newState == null && wrapper.getState() == null) {
+                if (newState == null && oldState == null) {
                     return false;
                 }
-                if (newState == null || wrapper.getState() == null) {
-                    lastState.set(new StateWrapper(newState));
+                lastState.set(new StateWrapper(newState));

Review Comment:
   I don't think so?  StateWrapper is a simple pojo with getters/setters and no real logic, so I don't think it cares.  This method handles checking for nulls on newState and oldState, so I was happy that NPE wasn't possible.



-- 
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@nifi.apache.org

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


[GitHub] [nifi] mattyb149 closed pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mattyb149 (via GitHub)" <gi...@apache.org>.
mattyb149 closed pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval
URL: https://github.com/apache/nifi/pull/7664


-- 
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@nifi.apache.org

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


[GitHub] [nifi] mattyb149 commented on a diff in pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mattyb149 (via GitHub)" <gi...@apache.org>.
mattyb149 commented on code in PR #7664:
URL: https://github.com/apache/nifi/pull/7664#discussion_r1316681639


##########
nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/monitor/SynchronousFileWatcher.java:
##########
@@ -77,21 +77,16 @@ public boolean checkAndReset() throws IOException {
     private boolean checkForUpdate() throws IOException {
         if (resourceLock.tryLock()) {
             try {
-                final StateWrapper wrapper = lastState.get();
+                final Object oldState = lastState.get().getState();
                 final Object newState = monitor.getCurrentState(path);
-                if (newState == null && wrapper.getState() == null) {
+                if (newState == null && oldState == null) {
                     return false;
                 }
-                if (newState == null || wrapper.getState() == null) {
-                    lastState.set(new StateWrapper(newState));
+                lastState.set(new StateWrapper(newState));

Review Comment:
   Why the null checks then? Just to be defensive?



-- 
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@nifi.apache.org

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


[GitHub] [nifi] mattyb149 commented on pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mattyb149 (via GitHub)" <gi...@apache.org>.
mattyb149 commented on PR #7664:
URL: https://github.com/apache/nifi/pull/7664#issuecomment-1708744588

   +1 LGTM, thanks for the fix! Merging to support/nifi-1.x and main


-- 
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@nifi.apache.org

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


[GitHub] [nifi] mosermw commented on pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on PR #7664:
URL: https://github.com/apache/nifi/pull/7664#issuecomment-1708783191

   I appreciate you looking at this, @mattyb149.


-- 
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@nifi.apache.org

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


[GitHub] [nifi] joewitt commented on pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "joewitt (via GitHub)" <gi...@apache.org>.
joewitt commented on PR #7664:
URL: https://github.com/apache/nifi/pull/7664#issuecomment-1728323685

   @mattyb149 @mosermw I had never even heard of this class.  But today I noticed this test failure https://github.com/joewitt/nifi/actions/runs/6252186486/job/16974874215
   
   Can you please look into this?  I had never noticed this class failing before.


-- 
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@nifi.apache.org

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


[GitHub] [nifi] mattyb149 commented on a diff in pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mattyb149 (via GitHub)" <gi...@apache.org>.
mattyb149 commented on code in PR #7664:
URL: https://github.com/apache/nifi/pull/7664#discussion_r1316278797


##########
nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/monitor/SynchronousFileWatcher.java:
##########
@@ -77,21 +77,16 @@ public boolean checkAndReset() throws IOException {
     private boolean checkForUpdate() throws IOException {
         if (resourceLock.tryLock()) {
             try {
-                final StateWrapper wrapper = lastState.get();
+                final Object oldState = lastState.get().getState();
                 final Object newState = monitor.getCurrentState(path);
-                if (newState == null && wrapper.getState() == null) {
+                if (newState == null && oldState == null) {
                     return false;
                 }
-                if (newState == null || wrapper.getState() == null) {
-                    lastState.set(new StateWrapper(newState));
+                lastState.set(new StateWrapper(newState));

Review Comment:
   If newState is `null` does this cause issues creating a wrapper around it?



-- 
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@nifi.apache.org

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


[GitHub] [nifi] mosermw commented on a diff in pull request #7664: NIFI-12019 bugfix for SynchronousFileWatcher time check interval

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on code in PR #7664:
URL: https://github.com/apache/nifi/pull/7664#discussion_r1317258043


##########
nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/monitor/SynchronousFileWatcher.java:
##########
@@ -77,21 +77,16 @@ public boolean checkAndReset() throws IOException {
     private boolean checkForUpdate() throws IOException {
         if (resourceLock.tryLock()) {
             try {
-                final StateWrapper wrapper = lastState.get();
+                final Object oldState = lastState.get().getState();
                 final Object newState = monitor.getCurrentState(path);
-                if (newState == null && wrapper.getState() == null) {
+                if (newState == null && oldState == null) {
                     return false;
                 }
-                if (newState == null || wrapper.getState() == null) {
-                    lastState.set(new StateWrapper(newState));
+                lastState.set(new StateWrapper(newState));

Review Comment:
   We don't know what UpdateMonitor implementation is currently in use, and that interface doesn't guarantee that `monitor.getCurrentState(path)` returns NotNull.  So we have to check for nulls before using `newState.equals()` on line 89.



-- 
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@nifi.apache.org

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