我讀了hadoop-1.0.4源代碼中的SequenceFile.java。我發現sync(long)
方法 它被用於在SequenceFile中將SequenceFile拆分爲MapReduce中的文件拆分時,在SequenceFile中查找「同步標記」(在文件創建時生成時爲16字節的MD5)。Hadoop SequenceFile是否安全?
/** Seek to the next sync mark past a given position.*/
public synchronized void sync(long position) throws IOException {
if (position+SYNC_SIZE >= end) {
seek(end);
return;
}
try {
seek(position+4); // skip escape
in.readFully(syncCheck);
int syncLen = sync.length;
for (int i = 0; in.getPos() < end; i++) {
int j = 0;
for (; j < syncLen; j++) {
if (sync[j] != syncCheck[(i+j)%syncLen])
break;
}
if (j == syncLen) {
in.seek(in.getPos() - SYNC_SIZE); // position before sync
return;
}
syncCheck[i%syncLen] = in.readByte();
}
} catch (ChecksumException e) { // checksum failure
handleChecksumException(e);
}
}
這些代碼只是查找包含與「同步標記」相同數據的數據序列。
我的疑問:
考慮一個情況:在SequenceFile數據會包含一個16個字節的數據序列一樣的「同步標記」,代碼上面會誤把那16字節的數據「同步標記「然後SequenceFile將不會被正確解析?
我沒有發現有關數據或同步標記的任何「轉義」操作。 SequenceFile如何可以二進制安全?我錯過了什麼嗎?