summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-09-09 20:02:39 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-09-09 20:02:39 +0000
commit4748ce50f5a1561a4faeb5f7cbbab81d77b8eb6d (patch)
treec794402f9e437a83a7bcfc6234a5393511738330 /searchlib
parent4058c7b864ee6481703bd439ff4797041eb89018 (diff)
Add test for handling of non-compressable data, and handle it correctly.
Also do not bother compressing less than 200 bytes.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/transactionlog/chunks_test.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/transactionlog/chunks.cpp12
2 files changed, 12 insertions, 5 deletions
diff --git a/searchlib/src/tests/transactionlog/chunks_test.cpp b/searchlib/src/tests/transactionlog/chunks_test.cpp
index de530884933..fa5fe3c1006 100644
--- a/searchlib/src/tests/transactionlog/chunks_test.cpp
+++ b/searchlib/src/tests/transactionlog/chunks_test.cpp
@@ -58,4 +58,9 @@ TEST("test serialization and deserialization of future multientry xxh64 no compr
verifySerializationAndDeserialization(chunk, 100);
}
+TEST("test serialization and deserialization of uncompressable lz4") {
+ XXH64CompressedChunk chunk(CompressionConfig::Type::LZ4, 1);
+ verifySerializationAndDeserialization(chunk, 1);
+}
+
TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp b/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp
index b468c260f16..19309272c63 100644
--- a/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp
+++ b/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp
@@ -8,7 +8,7 @@
using std::runtime_error;
using std::make_unique;
-using vespalib::make_string;
+using vespalib::make_string_short::fmt;
using vespalib::compression::compress;
using vespalib::compression::decompress;
using vespalib::compression::CompressionConfig;
@@ -22,7 +22,7 @@ namespace {
void
verifyCrc(nbostream & is, Encoding::Crc crcType) {
if (is.size() < sizeof(int32_t) * 2) {
- throw runtime_error(make_string("Not even room for the crc and length. Only %zu bytes left", is.size()));
+ throw runtime_error(fmt("Not even room for the crc and length. Only %zu bytes left", is.size()));
}
size_t start = is.rp();
is.adjustReadPos(is.size() - sizeof(int32_t));
@@ -31,8 +31,7 @@ verifyCrc(nbostream & is, Encoding::Crc crcType) {
is.rp(start);
int32_t crcVerify = Encoding::calcCrc(crcType, is.data() + start, is.size() - sizeof(crc));
if (crc != crcVerify) {
- throw runtime_error(make_string("Got bad crc : crcVerify = %d, expected %d",
- static_cast<int>(crcVerify), static_cast<int>(crc)));
+ throw runtime_error(fmt("Got bad crc : crcVerify = %d, expected %d", crcVerify, crc));
}
}
@@ -108,9 +107,12 @@ XXH64CompressedChunk::compress(nbostream & os, Encoding::Crc crc) const {
nbostream org;
serializeEntries(org);
DataBuffer compressed;
- CompressionConfig cfg(_type, _level, 80);
+ CompressionConfig cfg(_type, _level, 80, 200);
ConstBufferRef uncompressed(org.data(), org.size());
Encoding::Compression actual = toCompression(::compress(cfg, uncompressed, compressed, false));
+ if (actual == Encoding::Compression::none) {
+ actual = Encoding::Compression::none_multi;
+ }
os << uint32_t(uncompressed.size());
size_t start = os.wp();
os.write(compressed.getData(), compressed.getDataLen());