提交 57863eee authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: improved error messages and logging; improved behavior if there is an…

MVStore: improved error messages and logging; improved behavior if there is an error when serializing objects.
上级 8615b43b
...@@ -92,8 +92,8 @@ public class Chunk { ...@@ -92,8 +92,8 @@ public class Chunk {
/** /**
* When this chunk was no longer needed, in milliseconds after the store was * When this chunk was no longer needed, in milliseconds after the store was
* created. After this, the chunk is kept alive for at least half the * created. After this, the chunk is kept alive a bit longer (in case it is
* retention time (in case it is referenced in older versions). * referenced in older versions).
*/ */
public long unused; public long unused;
......
...@@ -42,6 +42,7 @@ TransactionStore: ...@@ -42,6 +42,7 @@ TransactionStore:
if there is only one connection if there is only one connection
MVStore: MVStore:
- make sure serialization / deserialization errors don't corrupt the file
- FileStore: don't open and close when set using MVStore.Builder.fileStore - FileStore: don't open and close when set using MVStore.Builder.fileStore
- test and possibly improve compact operation (for large dbs) - test and possibly improve compact operation (for large dbs)
- is data kept in the stream store if the transaction is not committed? - is data kept in the stream store if the transaction is not committed?
...@@ -115,6 +116,7 @@ MVStore: ...@@ -115,6 +116,7 @@ MVStore:
- rollback of removeMap should restore the data - - rollback of removeMap should restore the data -
which has big consequences, as the metadata map which has big consequences, as the metadata map
would probably need references to the root nodes of all maps would probably need references to the root nodes of all maps
- combine MVMap and MVMapConcurrent
*/ */
...@@ -335,12 +337,7 @@ public class MVStore { ...@@ -335,12 +337,7 @@ public class MVStore {
readFileHeader(); readFileHeader();
} }
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
try { panic(e);
closeStore(false);
} catch (Exception e2) {
// ignore
}
throw e;
} finally { } finally {
if (encryptionKey != null) { if (encryptionKey != null) {
Arrays.fill(encryptionKey, (char) 0); Arrays.fill(encryptionKey, (char) 0);
...@@ -354,6 +351,15 @@ public class MVStore { ...@@ -354,6 +351,15 @@ public class MVStore {
int delay = o == null ? 1000 : (Integer) o; int delay = o == null ? 1000 : (Integer) o;
setAutoCommitDelay(delay); setAutoCommitDelay(delay);
} }
private void panic(IllegalStateException e) {
try {
closeStore(false);
} catch (Exception e2) {
// ignore
}
throw e;
}
/** /**
* Open a store in exclusive mode. For a file-based store, the parent * Open a store in exclusive mode. For a file-based store, the parent
...@@ -1145,13 +1151,17 @@ public class MVStore { ...@@ -1145,13 +1151,17 @@ public class MVStore {
shrinkFileIfPossible(1); shrinkFileIfPossible(1);
} }
for (MVMap<?, ?> m : changed) { try {
Page p = m.getRoot(); for (MVMap<?, ?> m : changed) {
if (p.getTotalCount() > 0) { Page p = m.getRoot();
p.writeEnd(); if (p.getTotalCount() > 0) {
p.writeEnd();
}
} }
metaRoot.writeEnd();
} catch (IllegalStateException e) {
panic(e);
} }
metaRoot.writeEnd();
// some pages might have been changed in the meantime (in the newest // some pages might have been changed in the meantime (in the newest
// version) // version)
......
...@@ -133,6 +133,8 @@ public class MVStoreTool { ...@@ -133,6 +133,8 @@ public class MVStoreTool {
int p = block.position(); int p = block.position();
pos += length; pos += length;
int remaining = c.pageCount; int remaining = c.pageCount;
TreeMap<Integer, Integer> mapSizes = new TreeMap<Integer, Integer>();
int totalSize = 0;
while (remaining > 0) { while (remaining > 0) {
chunk.position(p); chunk.position(p);
int pageSize = chunk.getInt(); int pageSize = chunk.getInt();
...@@ -153,6 +155,12 @@ public class MVStoreTool { ...@@ -153,6 +155,12 @@ public class MVStoreTool {
node ? entries + 1 : entries, node ? entries + 1 : entries,
pageSize); pageSize);
p += pageSize; p += pageSize;
Integer mapSize = mapSizes.get(mapId);
if (mapSize == null) {
mapSize = 0;
}
mapSizes.put(mapId, mapSize + pageSize);
totalSize += pageSize;
remaining--; remaining--;
long[] children = null; long[] children = null;
long[] counts = null; long[] counts = null;
...@@ -219,6 +227,10 @@ public class MVStoreTool { ...@@ -219,6 +227,10 @@ public class MVStoreTool {
} }
} }
} }
for (Integer mapId : mapSizes.keySet()) {
int percent = 100 * mapSizes.get(mapId) / totalSize;
pw.printf("map %x: %d%%%n", mapId, percent);
}
int footerPos = chunk.limit() - Chunk.FOOTER_LENGTH; int footerPos = chunk.limit() - Chunk.FOOTER_LENGTH;
chunk.position(footerPos); chunk.position(footerPos);
pw.printf( pw.printf(
......
...@@ -91,7 +91,7 @@ public class StreamStore { ...@@ -91,7 +91,7 @@ public class StreamStore {
} }
/** /**
* Store the stream, and return the id. * Store the stream, and return the id. The stream is not closed.
* *
* @param in the stream * @param in the stream
* @return the id (potentially an empty array) * @return the id (potentially an empty array)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论