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

MVStore: error compressing an empty page

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