提交 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 {
/**
* 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
* retention time (in case it is referenced in older versions).
* created. After this, the chunk is kept alive a bit longer (in case it is
* referenced in older versions).
*/
public long unused;
......
......@@ -42,6 +42,7 @@ TransactionStore:
if there is only one connection
MVStore:
- make sure serialization / deserialization errors don't corrupt the file
- FileStore: don't open and close when set using MVStore.Builder.fileStore
- test and possibly improve compact operation (for large dbs)
- is data kept in the stream store if the transaction is not committed?
......@@ -115,6 +116,7 @@ MVStore:
- rollback of removeMap should restore the data -
which has big consequences, as the metadata map
would probably need references to the root nodes of all maps
- combine MVMap and MVMapConcurrent
*/
......@@ -335,12 +337,7 @@ public class MVStore {
readFileHeader();
}
} catch (IllegalStateException e) {
try {
closeStore(false);
} catch (Exception e2) {
// ignore
}
throw e;
panic(e);
} finally {
if (encryptionKey != null) {
Arrays.fill(encryptionKey, (char) 0);
......@@ -355,6 +352,15 @@ public class MVStore {
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
* directory must already exist.
......@@ -1145,6 +1151,7 @@ public class MVStore {
shrinkFileIfPossible(1);
}
try {
for (MVMap<?, ?> m : changed) {
Page p = m.getRoot();
if (p.getTotalCount() > 0) {
......@@ -1152,6 +1159,9 @@ public class MVStore {
}
}
metaRoot.writeEnd();
} catch (IllegalStateException e) {
panic(e);
}
// some pages might have been changed in the meantime (in the newest
// version)
......
......@@ -133,6 +133,8 @@ public class MVStoreTool {
int p = block.position();
pos += length;
int remaining = c.pageCount;
TreeMap<Integer, Integer> mapSizes = new TreeMap<Integer, Integer>();
int totalSize = 0;
while (remaining > 0) {
chunk.position(p);
int pageSize = chunk.getInt();
......@@ -153,6 +155,12 @@ public class MVStoreTool {
node ? entries + 1 : entries,
pageSize);
p += pageSize;
Integer mapSize = mapSizes.get(mapId);
if (mapSize == null) {
mapSize = 0;
}
mapSizes.put(mapId, mapSize + pageSize);
totalSize += pageSize;
remaining--;
long[] children = null;
long[] counts = null;
......@@ -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;
chunk.position(footerPos);
pw.printf(
......
......@@ -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
* @return the id (potentially an empty array)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论