Skip to content

Commit

Permalink
Add more debugging information when decompression fails, #116
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Dec 24, 2021
1 parent 7030fae commit 5b6f6f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void Compression::decompress(MDB_val& data, bool &isValid, bool canAllocate) {
dictionary, decompressTarget - dictionary);
//fprintf(stdout, "first uncompressed byte %X %X %X %X %X %X\n", uncompressedData[0], uncompressedData[1], uncompressedData[2], uncompressedData[3], uncompressedData[4], uncompressedData[5]);
if (written < 0) {
//fprintf(stderr, "Failed to decompress data %u %u %u %u\n", charData[0], data.mv_size, compressionHeaderSize, uncompressedLength);
fprintf(stderr, "Failed to decompress data %u %u %u %u %u %u %u %u\n", compressionHeaderSize, uncompressedLength, charData[0], charData[1], charData[2], charData[3], charData[4], charData[5]);
if (canAllocate)
Nan::ThrowError("Failed to decompress data");
isValid = false;
Expand Down Expand Up @@ -247,4 +247,4 @@ extern "C" EXTERN uint64_t newCompression(char* dictionary, uint32_t dictSize, u
compression->acceleration = 1;
compression->compressionThreshold = threshold;
return (uint64_t) compression;
}
}
23 changes: 23 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,29 @@ describe('lmdb-js', function() {
console.log(dbBinary.getBinaryLocation(3))
console.log(dbBinary.getBinaryLocation(4))
});
it('open and close with compression', async function() {
let data = ''
for (let i = 0; i < 100; i++) {
data += Math.random()
}
for (let i = 0; i < 100; i++) {
let db = open(testDirPath + '/test-close.mdb', {
// name: 'test-close',
compression: true,
overlappingSync: true,
});
let v = db.get('key')
v = db.get('key1')
v = db.get('key2')
v = db.get('key3')
db.put('key', data);
let promise = db.close();
db.put('key1', data);
await db.put('key2', data);
db.put('key3', data);
await promise;
}
})
after(function(done) {
db.get('key1');
let iterator = db.getRange({})[Symbol.iterator]()
Expand Down

0 comments on commit 5b6f6f4

Please sign in to comment.