asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xikui Wang (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (ASTERIXDB-1690) FileSystemWatcher.close() is blocked by FileSystemWatcher.take() when monitoring directory.
Date Wed, 12 Oct 2016 05:20:20 GMT

     [ https://issues.apache.org/jira/browse/ASTERIXDB-1690?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Xikui Wang updated ASTERIXDB-1690:
----------------------------------
    Description: 
When create feed for directory monitoring, disconnect feed can be blocked by the FileSystemWatcher.
When FileSystemWatcher is waiting for new files, the whole object is locked by current thread.
So when another thread trying to close the watcher, it will be blocked. Here is the take()
method from FileSystemWatcher: 

 public synchronized File take() throws IOException {
        File next = poll();
        if (next != null) {
            return next;
        }
        if (done || !isFeed) {
            return null;
        }
        // No file was found, wait for the filesystem to push events
        WatchKey key = null;
        lock.lock();
        try {
            while (!it.hasNext()) {
                try {
                    key = watcher.take();
                } catch (InterruptedException x) {
                    if (LOGGER.isEnabledFor(Level.WARN)) {
                        LOGGER.warn("Feed Closed");
                    }
                    if (watcher == null) {
                        return null;
                    }
                    continue;
                } catch (ClosedWatchServiceException e) {
                    if (LOGGER.isEnabledFor(Level.WARN)) {
                        LOGGER.warn("The watcher has exited");
                    }
                    if (watcher == null) {
                        return null;
                    }
                    continue;
                }
                handleEvents(key);
                if (endOfEvents(key)) {
                    return null;
                }
            }
        } finally {
            lock.unlock();
        }
        // files were found, re-create the iterator and move it one step
        return it.next();
    }

  was:
When create feed for directory monitoring, disconnect feed can be blocked by the FileSystemWatcher.
When FileSystemWatcher is waiting for new files, the whole object is locked by current thread.
So when another thread trying to close the watcher, it will be blocked. Here is the take()
method from FileSystemWatcher: 

{quote}
 public synchronized File take() throws IOException {
        File next = poll();
        if (next != null) {
            return next;
        }
        if (done || !isFeed) {
            return null;
        }
        // No file was found, wait for the filesystem to push events
        WatchKey key = null;
        lock.lock();
        try {
            while (!it.hasNext()) {
                try {
                    key = watcher.take();
                } catch (InterruptedException x) {
                    if (LOGGER.isEnabledFor(Level.WARN)) {
                        LOGGER.warn("Feed Closed");
                    }
                    if (watcher == null) {
                        return null;
                    }
                    continue;
                } catch (ClosedWatchServiceException e) {
                    if (LOGGER.isEnabledFor(Level.WARN)) {
                        LOGGER.warn("The watcher has exited");
                    }
                    if (watcher == null) {
                        return null;
                    }
                    continue;
                }
                handleEvents(key);
                if (endOfEvents(key)) {
                    return null;
                }
            }
        } finally {
            lock.unlock();
        }
        // files were found, re-create the iterator and move it one step
        return it.next();
    }
{quote}


> FileSystemWatcher.close() is blocked by FileSystemWatcher.take() when monitoring directory.
> -------------------------------------------------------------------------------------------
>
>                 Key: ASTERIXDB-1690
>                 URL: https://issues.apache.org/jira/browse/ASTERIXDB-1690
>             Project: Apache AsterixDB
>          Issue Type: Bug
>          Components: Feeds
>            Reporter: Xikui Wang
>
> When create feed for directory monitoring, disconnect feed can be blocked by the FileSystemWatcher.
When FileSystemWatcher is waiting for new files, the whole object is locked by current thread.
So when another thread trying to close the watcher, it will be blocked. Here is the take()
method from FileSystemWatcher: 
>  public synchronized File take() throws IOException {
>         File next = poll();
>         if (next != null) {
>             return next;
>         }
>         if (done || !isFeed) {
>             return null;
>         }
>         // No file was found, wait for the filesystem to push events
>         WatchKey key = null;
>         lock.lock();
>         try {
>             while (!it.hasNext()) {
>                 try {
>                     key = watcher.take();
>                 } catch (InterruptedException x) {
>                     if (LOGGER.isEnabledFor(Level.WARN)) {
>                         LOGGER.warn("Feed Closed");
>                     }
>                     if (watcher == null) {
>                         return null;
>                     }
>                     continue;
>                 } catch (ClosedWatchServiceException e) {
>                     if (LOGGER.isEnabledFor(Level.WARN)) {
>                         LOGGER.warn("The watcher has exited");
>                     }
>                     if (watcher == null) {
>                         return null;
>                     }
>                     continue;
>                 }
>                 handleEvents(key);
>                 if (endOfEvents(key)) {
>                     return null;
>                 }
>             }
>         } finally {
>             lock.unlock();
>         }
>         // files were found, re-create the iterator and move it one step
>         return it.next();
>     }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message