Good day this is Cazen
Could I kindly ask about something weird situation when reading file in
hdfs with inotify polling
- Env : MacOS, EMR, Linux(standalone) - same problem
- Version : Hadoop 2.7.2
1. I would like to write down a code that read file under particular
location when it created(with using inotify)
So I modify sample code based on "hdfs-inotify-example" in github
https://github.com/onefoursix/hdfs-inotify-example/blob/master/src/main/java/com/onefoursix/HdfsINotifyExample.java
2. I've changed code with read and print line to console when it renamed
https://github.com/onefoursix/hdfs-inotify-example/commit/82485881c5da85a46dd1741c2d8420c7c4e81f93
case RENAME:
Event.RenameEvent renameEvent = (Event.RenameEvent) event;
Configuration conf = new Configuration();
conf.set("fs.defaultFS", defaultFS);
System.out.println(renameEvent.getDstPath() + " " +
inputPath.getPath());
if (renameEvent.getDstPath().startsWith(inputPath.getPath())) {
//Try to read file
try (FileSystem fs = FileSystem.get(conf)) {
Path filePath = new Path(defaultFS + renameEvent.getDstPath());
BufferedReader br = new BufferedReader(new
InputStreamReader(fs.open(filePath)));
String line;
line = br.readLine();
while (line != null) {
System.out.println(line);
line = br.readLine();
}
br.close();
}
}
3. It works. But I encountered IOException in next eventStream.take() after
file read. It doesn't happen if I do not read file on hdfs.
-------------CODE-------------
DFSInotifyEventInputStream eventStream = admin.getInotifyEventStream();
EventBatch batch = eventStream.take();
-------------LOG-------------
Cazens-MacBook-Pro:hdfs-inotify-example Cazen$ java -jar
target/hdfs-inotify-example-uber.jar hdfs://localhost:8032/cazen/
lastReadTxid = 0
log4j:WARN No appenders could be found for logger
(org.apache.hadoop.util.Shell).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
TxId = 3134
event type = CREATE
path = /cazen/test2.txt._COPYING_
owner = Cazen
ctime = 1461850245559
TxId = 3138
event type = CLOSE
TxId = 3139
event type = RENAME
/cazen/test2.txt /cazen/
--------------------File Start
Input File Text Sample LOL
--------------------File END
Exception in thread "main" java.io.IOException: The client is stopped
at org.apache.hadoop.ipc.Client.getConnection(Client.java:1507)
at org.apache.hadoop.ipc.Client.call(Client.java:1451)
at org.apache.hadoop.ipc.Client.call(Client.java:1412)
at
org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:229)
at com.sun.proxy.$Proxy9.getEditsFromTxid(Unknown Source)
at
org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getEditsFromTxid(ClientNamenodeProtocolTranslatorPB.java:1511)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at
org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191)
at
org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
at com.sun.proxy.$Proxy10.getEditsFromTxid(Unknown Source)
at
org.apache.hadoop.hdfs.DFSInotifyEventInputStream.poll(DFSInotifyEventInputStream.java:111)
at
org.apache.hadoop.hdfs.DFSInotifyEventInputStream.take(DFSInotifyEventInputStream.java:224)
at com.onefoursix.HdfsINotifyExample.main(HdfsINotifyExample.java:40)
There is possibility that I may have written the wrong code. If anyone
already know about this situation, could I ask the reason?
Any advice would be appreciated.
Thank you Have a good day :)
--
[email protected]
[email protected]
http://www.cazen.co.kr