提交 0cc4689e authored 作者: Thomas Mueller's avatar Thomas Mueller

Recover: more detailed trace output.

上级 5a9f3926
...@@ -413,12 +413,11 @@ public class Recover extends Tool implements DataHandler { ...@@ -413,12 +413,11 @@ public class Recover extends Tool implements DataHandler {
} }
writer.println("-- head " + i + writer.println("-- head " + i +
": writeCounter: " + writeCounter + ": writeCounter: " + writeCounter +
" log key: " + key + " trunk: " + firstTrunkPage + "/" + firstDataPage + " log " + key + ":" + firstTrunkPage + "/" + firstDataPage +
" crc expected " + expected + " crc " + got + " (" + (expected == got ? "ok" : ("expected: " + expected)) + ")");
" got " + got + " (" + (expected == got ? "ok" : "different") + ")");
} }
writer.println("-- firstTrunkPage: " + logFirstTrunkPage + writer.println("-- log " + logKey + ":" + logFirstTrunkPage +
" firstDataPage: " + logFirstDataPage); "/" + logFirstDataPage);
PrintWriter devNull = new PrintWriter(new OutputStream() { PrintWriter devNull = new PrintWriter(new OutputStream() {
public void write(int b) { public void write(int b) {
...@@ -432,7 +431,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -432,7 +431,7 @@ public class Recover extends Tool implements DataHandler {
dumpPageStore(writer, pageCount); dumpPageStore(writer, pageCount);
writeSchema(writer); writeSchema(writer);
try { try {
dumpPageLogStream(writer, logKey, logFirstTrunkPage, logFirstDataPage); dumpPageLogStream(writer, logKey, logFirstTrunkPage, logFirstDataPage, pageCount);
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
...@@ -488,11 +487,17 @@ public class Recover extends Tool implements DataHandler { ...@@ -488,11 +487,17 @@ public class Recover extends Tool implements DataHandler {
s = Data.create(this, pageSize); s = Data.create(this, pageSize);
seek(page); seek(page);
store.readFully(s.getBytes(), 0, pageSize); store.readFully(s.getBytes(), 0, pageSize);
dumpPage(writer, s, page, pageCount);
}
}
private void dumpPage(PrintWriter writer, Data s, long page, long pageCount) {
try {
int type = s.readByte(); int type = s.readByte();
switch (type) { switch (type) {
case Page.TYPE_EMPTY: case Page.TYPE_EMPTY:
stat.pageTypeCount[type]++; stat.pageTypeCount[type]++;
continue; return;
} }
boolean last = (type & Page.FLAG_LAST) != 0; boolean last = (type & Page.FLAG_LAST) != 0;
type &= ~Page.FLAG_LAST; type &= ~Page.FLAG_LAST;
...@@ -572,11 +577,13 @@ public class Recover extends Tool implements DataHandler { ...@@ -572,11 +577,13 @@ public class Recover extends Tool implements DataHandler {
writer.println("-- ERROR page " + page + " unknown type " + type); writer.println("-- ERROR page " + page + " unknown type " + type);
break; break;
} }
} catch (Exception e) {
writeError(writer, e);
} }
} }
private void dumpPageLogStream(PrintWriter writer, int logKey, private void dumpPageLogStream(PrintWriter writer, int logKey,
int logFirstTrunkPage, int logFirstDataPage) throws IOException { int logFirstTrunkPage, int logFirstDataPage, long pageCount) throws IOException {
Data s = Data.create(this, pageSize); Data s = Data.create(this, pageSize);
DataReader in = new DataReader( DataReader in = new DataReader(
new PageInputStream(writer, this, store, logKey, logFirstTrunkPage, logFirstDataPage, pageSize) new PageInputStream(writer, this, store, logKey, logFirstTrunkPage, logFirstDataPage, pageSize)
...@@ -644,13 +651,17 @@ public class Recover extends Tool implements DataHandler { ...@@ -644,13 +651,17 @@ public class Recover extends Tool implements DataHandler {
break; break;
} }
writer.println("-- undo page " + pageId + " " + typeName); writer.println("-- undo page " + pageId + " " + typeName);
if (trace) {
Data d = Data.create(null, data);
dumpPage(writer, d, pageId, pageCount);
}
} else if (x == PageLog.ADD) { } else if (x == PageLog.ADD) {
int sessionId = in.readVarInt(); int sessionId = in.readVarInt();
setStorage(in.readVarInt()); setStorage(in.readVarInt());
Row row = PageLog.readRow(in, s); Row row = PageLog.readRow(in, s);
writer.println("-- session " + sessionId + writer.println("-- session " + sessionId +
" table " + storageId + " table " + storageId +
" add " + row.toString()); " + " + row.toString());
if (transactionLog) { if (transactionLog) {
if (storageId == 0 && row.getColumnCount() >= 4) { if (storageId == 0 && row.getColumnCount() >= 4) {
int tableId = (int) row.getKey(); int tableId = (int) row.getKey();
...@@ -680,7 +691,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -680,7 +691,7 @@ public class Recover extends Tool implements DataHandler {
long key = in.readVarLong(); long key = in.readVarLong();
writer.println("-- session " + sessionId + writer.println("-- session " + sessionId +
" table " + storageId + " table " + storageId +
" remove " + key); " - " + key);
if (transactionLog) { if (transactionLog) {
if (storageId == 0) { if (storageId == 0) {
int tableId = (int) key; int tableId = (int) key;
...@@ -749,6 +760,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -749,6 +760,7 @@ public class Recover extends Tool implements DataHandler {
private final Data page; private final Data page;
private final int pageSize; private final int pageSize;
private long trunkPage; private long trunkPage;
private long nextTrunkPage;
private long dataPage; private long dataPage;
private IntArray dataPages = new IntArray(); private IntArray dataPages = new IntArray();
private boolean endOfFile; private boolean endOfFile;
...@@ -761,7 +773,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -761,7 +773,7 @@ public class Recover extends Tool implements DataHandler {
this.store = store; this.store = store;
this.pageSize = pageSize; this.pageSize = pageSize;
this.logKey = logKey - 1; this.logKey = logKey - 1;
this.trunkPage = firstTrunkPage; this.nextTrunkPage = firstTrunkPage;
this.dataPage = firstDataPage; this.dataPage = firstDataPage;
page = Data.create(handler, pageSize); page = Data.create(handler, pageSize);
} }
...@@ -809,10 +821,11 @@ public class Recover extends Tool implements DataHandler { ...@@ -809,10 +821,11 @@ public class Recover extends Tool implements DataHandler {
return; return;
} }
while (dataPages.size() == 0) { while (dataPages.size() == 0) {
if (trunkPage == 0) { if (nextTrunkPage == 0) {
endOfFile = true; endOfFile = true;
return; return;
} }
trunkPage = nextTrunkPage;
store.seek(trunkPage * pageSize); store.seek(trunkPage * pageSize);
store.readFully(page.getBytes(), 0, pageSize); store.readFully(page.getBytes(), 0, pageSize);
page.reset(); page.reset();
...@@ -824,7 +837,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -824,7 +837,7 @@ public class Recover extends Tool implements DataHandler {
int t = page.readByte(); int t = page.readByte();
page.readShortInt(); page.readShortInt();
if (t != Page.TYPE_STREAM_TRUNK) { if (t != Page.TYPE_STREAM_TRUNK) {
writer.println("-- eof page: " + trunkPage + " type: " + t + " expected type: " + Page.TYPE_STREAM_TRUNK); writer.println("-- log eof " + trunkPage + " type: " + t + " expected type: " + Page.TYPE_STREAM_TRUNK);
endOfFile = true; endOfFile = true;
return; return;
} }
...@@ -832,9 +845,10 @@ public class Recover extends Tool implements DataHandler { ...@@ -832,9 +845,10 @@ public class Recover extends Tool implements DataHandler {
int key = page.readInt(); int key = page.readInt();
logKey++; logKey++;
if (key != logKey) { if (key != logKey) {
writer.println("-- eof page: " + trunkPage + " type: " + t + " expected key: " + logKey + " got: " + key); writer.println("-- log eof " + trunkPage + " type: " + t + " expected key: " + logKey + " got: " + key);
} }
trunkPage = page.readInt(); nextTrunkPage = page.readInt();
writer.println("-- log " + key + ":" + trunkPage + " next: " + nextTrunkPage);
int pageCount = page.readShortInt(); int pageCount = page.readShortInt();
for (int i = 0; i < pageCount; i++) { for (int i = 0; i < pageCount; i++) {
int d = page.readInt(); int d = page.readInt();
...@@ -865,13 +879,14 @@ public class Recover extends Tool implements DataHandler { ...@@ -865,13 +879,14 @@ public class Recover extends Tool implements DataHandler {
page.readShortInt(); page.readShortInt();
int p = page.readInt(); int p = page.readInt();
int k = page.readInt(); int k = page.readInt();
writer.println("-- log " + k + ":" + trunkPage + "/" + nextPage);
if (t != Page.TYPE_STREAM_DATA) { if (t != Page.TYPE_STREAM_DATA) {
writer.println("-- eof page: " +nextPage+ " type: " + t + " parent: " + p + writer.println("-- log eof " +nextPage+ " type: " + t + " parent: " + p +
" expected type: " + Page.TYPE_STREAM_DATA); " expected type: " + Page.TYPE_STREAM_DATA);
endOfFile = true; endOfFile = true;
return; return;
} else if (k != logKey) { } else if (k != logKey) {
writer.println("-- eof page: " +nextPage+ " type: " + t + " parent: " + p + writer.println("-- log eof " +nextPage+ " type: " + t + " parent: " + p +
" expected key: " + logKey + " got: " + k); " expected key: " + logKey + " got: " + k);
endOfFile = true; endOfFile = true;
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论