use of com.bonree.brfs.disknode.data.write.record.RecordCollection in project BRFS by zhangnianli.
the class MetadataFetchMessageHandler method getRecordElements.
private List<RecordElement> getRecordElements(String filePath) {
List<RecordElement> recordInfo = null;
Pair<RecordFileWriter, WriteWorker> binding = writerManager.getBinding(filePath, false);
if (binding != null) {
RecordElementReader recordReader = null;
try {
binding.first().flush();
writerManager.adjustFileWriter(filePath);
RecordCollection recordSet = binding.first().getRecordCollection();
recordReader = recordSet.getRecordElementReader();
recordInfo = new ArrayList<RecordElement>();
for (RecordElement element : recordReader) {
recordInfo.add(element);
}
} catch (Exception e) {
LOG.error("getSequnceNumbers from file[{}] error", filePath, e);
} finally {
CloseUtils.closeQuietly(recordReader);
}
} else {
// 到这有两种情况:
// 1、文件打开操作未成功后进行同步;
// 2、文件关闭成功后进行文件同步;
recordInfo = new ArrayList<RecordElement>();
File dataFile = new File(filePath);
if (dataFile.exists()) {
// 到这的唯一机会是,多副本文件关闭时只有部分关闭成功,当磁盘节点恢复正常
// 后,需要再次进行同步流程让所有副本文件关闭,因为没有日志文件,所以只能
// 通过解析数据文件生成序列号列表
byte[] bytes = DataFileReader.readFile(dataFile);
List<String> offsetInfos = FileDecoder.getDataFileOffsets(fileFormater.fileHeader().length(), bytes);
for (String info : offsetInfos) {
List<String> parts = Splitter.on('|').splitToList(info);
int offset = Integer.parseInt(parts.get(0));
int size = Integer.parseInt(parts.get(1));
recordInfo.add(new RecordElement(offset, size, 0));
}
}
}
return recordInfo;
}
use of com.bonree.brfs.disknode.data.write.record.RecordCollection in project BRFS by zhangnianli.
the class FileLengthMessageHandler method getRecordElements.
private List<RecordElement> getRecordElements(String filePath) {
List<RecordElement> recordInfo = null;
try {
Pair<RecordFileWriter, WriteWorker> binding = writerManager.getBinding(filePath, false);
if (binding != null) {
RecordElementReader recordReader = null;
try {
binding.first().flush();
writerManager.adjustFileWriter(filePath);
RecordCollection recordSet = binding.first().getRecordCollection();
recordReader = recordSet.getRecordElementReader();
recordInfo = new ArrayList<RecordElement>();
for (RecordElement element : recordReader) {
recordInfo.add(element);
}
} catch (Exception e) {
LOG.error("getSequnceNumbers from file[{}] error", filePath, e);
} finally {
CloseUtils.closeQuietly(recordReader);
}
} else {
// 到这有两种情况:
// 1、文件打开操作未成功后进行同步;
// 2、文件关闭操作未成功进行再次关闭;
recordInfo = new ArrayList<RecordElement>();
File dataFile = new File(filePath);
if (dataFile.exists()) {
// 到这的唯一机会是,多副本文件关闭时只有部分关闭成功,当磁盘节点恢复正常
// 后,需要再次进行同步流程让所有副本文件关闭,因为没有日志文件,所以只能
// 通过解析数据文件生成序列号列表
byte[] bytes = DataFileReader.readFile(dataFile);
List<String> offsetInfos = FileDecoder.getDataFileOffsets(fileFormater.fileHeader().length(), bytes);
for (String info : offsetInfos) {
List<String> parts = Splitter.on('|').splitToList(info);
int offset = Integer.parseInt(parts.get(0));
int size = Integer.parseInt(parts.get(1));
recordInfo.add(new RecordElement(offset, size, 0));
}
}
}
} catch (Exception e) {
LOG.error("get record element error", e);
}
return recordInfo;
}
Aggregations