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

MVStore: error compressing an empty page

上级 b6bbf419
...@@ -814,13 +814,13 @@ public class Page { ...@@ -814,13 +814,13 @@ public class Page {
map.getValueType().write(buff, values, len, false); map.getValueType().write(buff, values, len, false);
} }
MVStore store = map.getStore(); MVStore store = map.getStore();
if (store.getCompress()) {
Compressor compressor = map.getStore().getCompressor();
int expLen = buff.position() - compressStart; int expLen = buff.position() - compressStart;
if (expLen > 16 && store.getCompress()) {
Compressor compressor = map.getStore().getCompressor();
byte[] exp = new byte[expLen]; byte[] exp = new byte[expLen];
buff.position(compressStart).get(exp); buff.position(compressStart).get(exp);
byte[] comp = new byte[exp.length * 2]; byte[] comp = new byte[expLen * 2];
int compLen = compressor.compress(exp, exp.length, comp, 0); int compLen = compressor.compress(exp, expLen, comp, 0);
if (compLen + DataUtils.getVarIntLen(compLen - expLen) < expLen) { if (compLen + DataUtils.getVarIntLen(compLen - expLen) < expLen) {
buff.position(typePos). buff.position(typePos).
put((byte) (type + DataUtils.PAGE_COMPRESSED)); put((byte) (type + DataUtils.PAGE_COMPRESSED));
......
...@@ -50,6 +50,7 @@ public class TestMVStore extends TestBase { ...@@ -50,6 +50,7 @@ public class TestMVStore extends TestBase {
public void test() throws Exception { public void test() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir()); FileUtils.createDirectories(getBaseDir());
testCompressEmptyPage();
testCompressed(); testCompressed();
testFileFormatExample(); testFileFormatExample();
testMaxChunkLength(); testMaxChunkLength();
...@@ -106,6 +107,23 @@ public class TestMVStore extends TestBase { ...@@ -106,6 +107,23 @@ public class TestMVStore extends TestBase {
testLargerThan2G(); testLargerThan2G();
} }
private void testCompressEmptyPage() {
String fileName = getBaseDir() + "/testDeletedMap.h3";
MVStore store = new MVStore.Builder().
cacheSize(100).fileName(fileName).
compressData().
autoCommitBufferSize(10 * 1024).
open();
MVMap<String, String> map = store.openMap("test");
store.removeMap(map);
store.commit();
store.close();
store = new MVStore.Builder().
compressData().
open();
store.close();
}
private void testCompressed() { private void testCompressed() {
String fileName = getBaseDir() + "/testCompressed.h3"; String fileName = getBaseDir() + "/testCompressed.h3";
MVStore s = new MVStore.Builder().fileName(fileName).compressData().open(); MVStore s = new MVStore.Builder().fileName(fileName).compressData().open();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论