提交 96079ea4 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

MVStore tool now supports info for compressed pages

上级 a743a1d7
...@@ -15,6 +15,9 @@ import java.util.Map; ...@@ -15,6 +15,9 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import org.h2.compress.CompressDeflate;
import org.h2.compress.CompressLZF;
import org.h2.compress.Compressor;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.mvstore.type.DataType; import org.h2.mvstore.type.DataType;
...@@ -149,6 +152,7 @@ public class MVStoreTool { ...@@ -149,6 +152,7 @@ public class MVStoreTool {
new TreeMap<Integer, Integer>(); new TreeMap<Integer, Integer>();
int pageSizeSum = 0; int pageSizeSum = 0;
while (remaining > 0) { while (remaining > 0) {
int start = p;
try { try {
chunk.position(p); chunk.position(p);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
...@@ -162,7 +166,7 @@ public class MVStoreTool { ...@@ -162,7 +166,7 @@ public class MVStoreTool {
int mapId = DataUtils.readVarInt(chunk); int mapId = DataUtils.readVarInt(chunk);
int entries = DataUtils.readVarInt(chunk); int entries = DataUtils.readVarInt(chunk);
int type = chunk.get(); int type = chunk.get();
boolean compressed = (type & 2) != 0; boolean compressed = (type & DataUtils.PAGE_COMPRESSED) != 0;
boolean node = (type & 1) != 0; boolean node = (type & 1) != 0;
if (details) { if (details) {
pw.printf( pw.printf(
...@@ -206,11 +210,24 @@ public class MVStoreTool { ...@@ -206,11 +210,24 @@ public class MVStoreTool {
} }
String[] keys = new String[entries]; String[] keys = new String[entries];
if (mapId == 0 && details) { if (mapId == 0 && details) {
if (!compressed) { ByteBuffer data;
for (int i = 0; i < entries; i++) { if (compressed) {
String k = StringDataType.INSTANCE.read(chunk); boolean fast = !((type & DataUtils.PAGE_COMPRESSED_HIGH) ==
keys[i] = k; DataUtils.PAGE_COMPRESSED_HIGH);
} Compressor compressor = getCompressor(fast);
int lenAdd = DataUtils.readVarInt(chunk);
int compLen = pageSize + start - chunk.position();
byte[] comp = DataUtils.newBytes(compLen);
chunk.get(comp);
int l = compLen + lenAdd;
data = ByteBuffer.allocate(l);
compressor.expand(comp, 0, compLen, data.array(), 0, l);
} else {
data = chunk;
}
for (int i = 0; i < entries; i++) {
String k = StringDataType.INSTANCE.read(data);
keys[i] = k;
} }
if (node) { if (node) {
// meta map node // meta map node
...@@ -231,11 +248,11 @@ public class MVStoreTool { ...@@ -231,11 +248,11 @@ public class MVStoreTool {
keys.length >= entries ? null : keys[entries], keys.length >= entries ? null : keys[entries],
DataUtils.getPageChunkId(cp), DataUtils.getPageChunkId(cp),
DataUtils.getPageOffset(cp)); DataUtils.getPageOffset(cp));
} else if (!compressed) { } else {
// meta map leaf // meta map leaf
String[] values = new String[entries]; String[] values = new String[entries];
for (int i = 0; i < entries; i++) { for (int i = 0; i < entries; i++) {
String v = StringDataType.INSTANCE.read(chunk); String v = StringDataType.INSTANCE.read(data);
values[i] = v; values[i] = v;
} }
for (int i = 0; i < entries; i++) { for (int i = 0; i < entries; i++) {
...@@ -299,6 +316,10 @@ public class MVStoreTool { ...@@ -299,6 +316,10 @@ public class MVStoreTool {
pw.flush(); pw.flush();
} }
private static Compressor getCompressor(boolean fast) {
return fast ? new CompressLZF() : new CompressDeflate();
}
/** /**
* Read the summary information of the file and write them to system out. * Read the summary information of the file and write them to system out.
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论