나는 Hadoop
을 배우고 있으며,이 문제는 당황 스럽습니다. 기본적으로 디스크에 SequenceFile
을 쓰고 다시 읽습니다. 그러나, 읽을 때마다 EOFException
을 얻을 때마다. 자세히 살펴보면 시퀀스 파일을 작성할 때이 파일은 조기에 잘 리며 인덱스 962를 작성한 후에 항상 발생하며 파일의 크기는 항상 45056 바이트로 고정되어 있습니다.SequenceFile이 잘리는 이유는 무엇입니까?
MacBook Pro에서 Java 8 및 Hadoop 2.5.1을 사용하고 있습니다. 사실, 자바 7에서 다른 리눅스 머신에서 같은 코드를 시도했지만 똑같은 일이 일어납니다.
작가/리더가 제대로 닫히지 않을 수 있습니다. 이전 스타일의 try/catch 코드를 명시 적으로 writer.close() 함께 사용하여 시도했다 및 또한 최신 try-with-resource 방식을 사용하십시오. 둘 다 작동하지 않습니다.
도움이 될 것입니다.
public class SequenceFileDemo {
private static final String[] DATA = { "One, two, buckle my shoe",
"Three, four, shut the door",
"Five, six, pick up sticks",
"Seven, eight, lay them straight",
"Nine, ten, a big fat hen" };
public static void main(String[] args) throws Exception {
String uri = "file:///Users/andy/Downloads/puzzling.seq";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
Path path = new Path(uri);
IntWritable key = new IntWritable();
Text value = new Text();
//API change
try {
SequenceFile.Writer writer = SequenceFile.createWriter(conf,
stream(fs.create(path)),
keyClass(IntWritable.class),
valueClass(Text.class));
for (int i = 0; i < 1024; i++) {
key.set(i);
value.clear();
value.set(DATA[i % DATA.length]);
writer.append(key, value);
if ((i-1) %100 == 0) writer.hflush();
System.out.printf("[%s]\t%s\t%s\n", writer.getLength(), key, value);
}
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
SequenceFile.Reader reader = new SequenceFile.Reader(conf,
SequenceFile.Reader.file(path));
Class<?> keyClass = reader.getKeyClass();
Class<?> valueClass = reader.getValueClass();
boolean isWritableSerilization = false;
try {
keyClass.asSubclass(WritableComparable.class);
isWritableSerilization = true;
} catch (ClassCastException e) {
}
if (isWritableSerilization) {
WritableComparable<?> rKey = (WritableComparable<?>) ReflectionUtils.newInstance(keyClass, conf);
Writable rValue = (Writable) ReflectionUtils.newInstance(valueClass, conf);
while(reader.next(rKey, rValue)) {
System.out.printf("[%s] %d %s=%s\n",reader.syncSeen(), reader.getPosition(), rKey, rValue);
}
} else {
//make sure io.seraizliatons has the serialization in use when write the sequence file
}
reader.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
실제로 정수를 쓰는 경우에도 Windows 8, Java 8 및 Hadoop 2.2에서도이를 재현 할 수 있습니다. 그곳에서 발견 된 흥미로운 버그. 그리고 실제로 어떤 이유로 파일을 끝으로 자르는 것처럼 보입니다. –