Closed
Description
I found strange bug, for some keys unqlite lost some key-value pair after commit, I write code for reproduce it:
#include <string>
#include <ctime>
#include <cstdint>
extern "C" {
#include "../UnQLite-kv/unqlite.h"
}
struct TestStruct
{
double d1;
double d2;
};
int main(int argc, char **argv)
{
std::string filename("TEST." + std::to_string(time(nullptr)));
TestStruct test = { 1.0, 1.1 };
// Fill database
{
unqlite *db = nullptr;
int res = unqlite_open(&db, filename.c_str(), UNQLITE_OPEN_CREATE);
if (res != UNQLITE_OK)
{
return res;
}
for (int64_t i = 0; i < 165; ++i)
{
int res = unqlite_kv_store(db, &i, sizeof(int64_t), &test, sizeof(TestStruct));
if (res != UNQLITE_OK)
{
return res;
}
}
res = unqlite_close(db);
if (res != UNQLITE_OK)
{
return res;
}
}
// Reopen
{
unqlite *db = nullptr;
int res = unqlite_open(&db, filename.c_str(), UNQLITE_OPEN_CREATE);
if (res != UNQLITE_OK)
{
return res;
}
// Write pair with key 162 again
int64_t i_bug = 162;
res = unqlite_kv_store(db, &i_bug, sizeof(int64_t), &test, sizeof(TestStruct));
if (res != UNQLITE_OK)
{
return res;
}
// Force commit
res = unqlite_commit(db);
if (res != UNQLITE_OK)
{
return res;
}
// Test pair with key 164, it lost
int64_t i = 164;
TestStruct test1= {};
unqlite_int64 buf_size = sizeof(TestStruct);
res = unqlite_kv_fetch(db, &i, sizeof(int64_t), &test1, &buf_size);
if (res != UNQLITE_OK)
{
printf("%d", res); //Yep, print -6 there
return res;
}
res = unqlite_close(db);
if (res != UNQLITE_OK)
{
return res;
}
}
return 0;
}
For this types of key and value, after reopen database and write pair with key 162 and force commit unqlite lost pair with key 164.
I check it with last unqlite, unqlite-kv and vedis sources on msvc2013, clang 3.8.1 and gcc 6.2.0
Metadata
Metadata
Assignees
Labels
No labels