google / google/leveldb

leveldb crashes when putting larger value string

Open
#718 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
39.4k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Description

Recently I began to learn how to use leveldb, and I need to store very very long string in leveldb, for example, 5 billion. But I failed when I try to insert a string of 4.3 billion Byte, the entire code is shown below.
```c++
#include
#include
#include
#include
#include

using namespace std;

int main(void)
{
leveldb::DB *db = nullptr;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "./testdb", &db);
assert(status.ok());
cout<Put(leveldb::WriteOptions(), key, value);
if (s.ok())
s = db->Get(leveldb::ReadOptions(), "A", &get_value);
if (s.ok())
cout << get_value.size() << endl;
else
cout << s.ToString() << endl;
delete db;
return 0;
}

```
And here is the output of shell is

```sh
[zhou@localhost test_leveldb]$ make
g++ hello_leveldb.cc -o hello_leveldb -lpthread -lleveldb -std=c++11
[zhou@localhost test_leveldb]$ ./hello_leveldb
8
Corruption: unknown WriteBatch tag
```

I have made another attempts like inserting strings of 42 billion, it works well.When I look up the source code, I found Slice can have a length of 'size_t', and I'm sure it is equal to 'unsigned long long'. But leveldb works like it can only contain strings with length no more that unsigned int. I download leveldb using git clone today(Aug 18,2019). I cannot find where the question is. How can I do?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.