Assertion failed: (Valid()), function key, file block_based_table_reader.h, line 522
- Dominant language
- C++
- Stars
- 32.1k
- Forks
- 6.9k
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
> Note: Please use Issues only for bug reports. For questions, discussions, feature requests, etc. post to dev group: https://groups.google.com/forum/#!forum/rocksdb or https://www.facebook.com/groups/rocksdb.dev
### Expected behavior
Works fine
### Actual behavior
Bug
### Steps to reproduce the behavior
```
#ifndef ROCKSDB_ENDIANNSESS_H
#define ROCKSDB_ENDIANNSESS_H
bool isBigEndian() {
static unsigned long x(1);
static bool result(reinterpret_cast(&x)[0] == 0);
return result;
}
template
T toBigEndian(T u) {
if (isBigEndian()) {
return u;
}
union {
T u;
unsigned char u8[sizeof(T)];
} source, dest;
source.u = u;
for (size_t k = 0; k < sizeof(T); k++)
dest.u8[k] = source.u8[sizeof(T) - k - 1];
return dest.u;
}
u_int64_t readLongB(const char *data) {
u_int64_t byte7 = ((u_int64_t) * (data)) << 56;
u_int64_t byte6 = (u_int64_t)(*(data + 1) & 0xFF) << 48;
u_int64_t byte5 = (u_int64_t)(*(data + 2) & 0xFF) << 40;
u_int64_t byte4 = (u_int64_t)(*(data + 3) & 0xFF) << 32;
u_int64_t byte3 = (u_int64_t)(*(data + 4) & 0xFF) << 24;
u_int64_t byte2 = (u_int64_t)(*(data + 5) & 0xFF) << 16;
u_int64_t byte1 = (u_int64_t)(*(data + 6) & 0xFF) << 8;
u_int64_t byte0 = (u_int64_t)(*(data + 7) & 0xFF);
return byte7 | byte6 | byte5 | byte4 | byte3 | byte2 | byte1 | byte0;
}
u_int64_t from64BigEndian(const char *thePointer) {
if (isBigEndian()) {
return *(reinterpret_cast(thePointer));
}
return readLongB(thePointer);
}
#endif // ROCKSDB_ENDIANNSESS_H
```
```
#include
#include
#include
#include "endiannsess.h"
#include "rocksdb/db.h"
#include "rocksdb/table.h"
using namespace std;
using namespace rocksdb;
std::string kDBPath = "/opt/repos/rocksdata";
rocksdb::TableFactory *makeBlockTableFactory() {
BlockBasedTableOptions blockOpts{};
blockOpts.index_type =
rocksdb::BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch;
blockOpts.block_size = 4096;
blockOpts.metadata_block_size = 4096;
blockOpts.partition_filters = true;
blockOpts.block_cache = NewLRUCache(4 * 1024 * 1024, 2, true);
blockOpts.cache_index_and_filter_blocks = true;
blockOpts.cache_index_and_filter_blocks_with_high_priority = true;
return rocksdb::NewBlockBasedTableFactory(blockOpts);
}
int main() {
system("exec rm -r /opt/repos/rocksdata/*");
DB *aDb;
Options aOptions;
aOptions.IncreaseParallelism();
aOptions.create_if_missing = true;
aOptions.OptimizeLevelStyleCompaction();
aOptions.compression = rocksdb::CompressionType::kNoCompression;
std::vector aVector{};
aVector.emplace_back(rocksdb::CompressionType::kNoCompression);
aOptions.compression_per_level = aVector;
// open DB
Status aStatus = DB::Open(aOptions, kDBPath, &aDb);
if (!aStatus.ok()) {
printf("%s\n", aStatus.ToString().c_str());
assert(aStatus.ok());
}
ColumnFamilyOptions columnFamilyOptions1{};
auto *tf = makeBlockTableFactory();
columnFamilyOptions1.table_factory =
std::shared_ptr(tf);
ColumnFamilyHandle *aHandle;
aStatus = aDb->CreateColumnFamily(columnFamilyOptions1, "new_cf1", &aHandle);
if (!aStatus.ok()) {
printf("%s\n", aStatus.ToString().c_str());
assert(aStatus.ok());
}
u_int64_t buffer[1]{};
char *pointer = reinterpret_cast(&buffer);
Options options{};
SstFileWriter sst_file_writer(EnvOptions(), options);
Status s = sst_file_writer.Open("/opt/repos/rocksdata/file.sst");
for (u_int64_t aIndex = 0; aIndex < 10000000; aIndex++) {
buffer[0] = toBigEndian(aIndex);
Slice aKey(pointer, 8);
Slice aValue("value");
Status aStatus1 = sst_file_writer.Put(aKey, aValue);
assert(aStatus1.ok());
}
auto *opts = new ExternalSstFileInfo();
sst_file_writer.Finish(opts);
IngestExternalFileOptions option{};
std::vector external_file = {"/opt/repos/rocksdata/file.sst"};
assert(aDb->IngestExternalFile(aHandle, external_file, option).ok());
delete aHandle;
delete aDb;
return 0;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.