int index = mapedFiles.size() - 3;
if (index < 0)
index = 0;
int mapedFileSizeLogics = this.tranStateTable.getMapedFileSize();
MapedFile mapedFile = mapedFiles.get(index);
ByteBuffer byteBuffer = mapedFile.sliceByteBuffer();
long processOffset = mapedFile.getFileFromOffset();
long mapedFileOffset = 0;
while (true) {
for (int i = 0; i < mapedFileSizeLogics; i += TSStoreUnitSize) {
final long clOffset_read = byteBuffer.getLong();
final int size_read = byteBuffer.getInt();
final int timestamp_read = byteBuffer.getInt();
final int groupHashCode_read = byteBuffer.getInt();
final int state_read = byteBuffer.getInt();
boolean stateOK = false;
switch (state_read) {
case MessageSysFlag.TransactionPreparedType:
case MessageSysFlag.TransactionCommitType:
case MessageSysFlag.TransactionRollbackType:
stateOK = true;
break;
default:
break;
}
// 说明当前存储单元有效
// TODO 这样判断有效是否合理?
if (clOffset_read >= 0 && size_read > 0 && stateOK) {
mapedFileOffset = i + TSStoreUnitSize;
}
else {
log.info("recover current transaction state table file over, "
+ mapedFile.getFileName() + " " + clOffset_read + " " + size_read + " "
+ timestamp_read);
break;
}
}
// 走到文件末尾,切换至下一个文件
if (mapedFileOffset == mapedFileSizeLogics) {
index++;
if (index >= mapedFiles.size()) {
// 当前条件分支不可能发生
log.info("recover last transaction state table file over, last maped file "
+ mapedFile.getFileName());
break;
}
else {
mapedFile = mapedFiles.get(index);
byteBuffer = mapedFile.sliceByteBuffer();
processOffset = mapedFile.getFileFromOffset();
mapedFileOffset = 0;
log.info("recover next transaction state table file, " + mapedFile.getFileName());
}
}
else {
log.info("recover current transaction state table queue over " + mapedFile.getFileName()
+ " " + (processOffset + mapedFileOffset));
break;
}
}