|
|
@ -20,22 +20,22 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace leveldb { |
|
|
|
namespace leveldb { |
|
|
|
|
|
|
|
|
|
|
|
static bool SnappyCompressionSupported() {
|
|
|
|
static bool SnappyCompressionSupported(const CompressionOptions& options) { |
|
|
|
std::string out; |
|
|
|
std::string out; |
|
|
|
Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
|
|
|
Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
|
|
|
return port::Snappy_Compress(in.data(), in.size(), &out);
|
|
|
|
return port::Snappy_Compress(options, in.data(), in.size(), &out); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool ZlibCompressionSupported() {
|
|
|
|
static bool ZlibCompressionSupported(const CompressionOptions& options) { |
|
|
|
std::string out; |
|
|
|
std::string out; |
|
|
|
Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
|
|
|
Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
|
|
|
return port::Zlib_Compress(in.data(), in.size(), &out);
|
|
|
|
return port::Zlib_Compress(options, in.data(), in.size(), &out); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool BZip2CompressionSupported() {
|
|
|
|
static bool BZip2CompressionSupported(const CompressionOptions& options) { |
|
|
|
std::string out; |
|
|
|
std::string out; |
|
|
|
Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
|
|
|
Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
|
|
|
return port::BZip2_Compress(in.data(), in.size(), &out);
|
|
|
|
return port::BZip2_Compress(options, in.data(), in.size(), &out); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static std::string RandomString(Random* rnd, int len) { |
|
|
|
static std::string RandomString(Random* rnd, int len) { |
|
|
@ -1105,22 +1105,24 @@ void MinLevelHelper(DBTest* self, Options& options) { |
|
|
|
ASSERT_EQ(self->NumTableFilesAtLevel(1), 1); |
|
|
|
ASSERT_EQ(self->NumTableFilesAtLevel(1), 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(DBTest, MinLevelToCompress) {
|
|
|
|
void MinLevelToCompress(CompressionType& type, Options& options, int wbits, |
|
|
|
Options options = CurrentOptions();
|
|
|
|
int lev, int strategy) { |
|
|
|
|
|
|
|
fprintf(stderr, "Test with compression options : window_bits = %d, level = %d, strategy = %d}\n", wbits, lev, strategy); |
|
|
|
options.write_buffer_size = 100<<10; //100KB
|
|
|
|
options.write_buffer_size = 100<<10; //100KB
|
|
|
|
options.num_levels = 3; |
|
|
|
options.num_levels = 3; |
|
|
|
options.max_mem_compaction_level = 0; |
|
|
|
options.max_mem_compaction_level = 0; |
|
|
|
options.level0_file_num_compaction_trigger = 3; |
|
|
|
options.level0_file_num_compaction_trigger = 3; |
|
|
|
options.create_if_missing = true; |
|
|
|
options.create_if_missing = true; |
|
|
|
CompressionType type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SnappyCompressionSupported()) {
|
|
|
|
if (SnappyCompressionSupported(CompressionOptions(wbits, lev, strategy))) { |
|
|
|
type = kSnappyCompression; |
|
|
|
type = kSnappyCompression; |
|
|
|
fprintf(stderr, "using snappy\n"); |
|
|
|
fprintf(stderr, "using snappy\n"); |
|
|
|
} else if (ZlibCompressionSupported()) {
|
|
|
|
} else if (ZlibCompressionSupported( |
|
|
|
|
|
|
|
CompressionOptions(wbits, lev, strategy))) { |
|
|
|
type = kZlibCompression; |
|
|
|
type = kZlibCompression; |
|
|
|
fprintf(stderr, "using zlib\n"); |
|
|
|
fprintf(stderr, "using zlib\n"); |
|
|
|
} else if (BZip2CompressionSupported()) {
|
|
|
|
} else if (BZip2CompressionSupported( |
|
|
|
|
|
|
|
CompressionOptions(wbits, lev, strategy))) { |
|
|
|
type = kBZip2Compression; |
|
|
|
type = kBZip2Compression; |
|
|
|
fprintf(stderr, "using bzip2\n"); |
|
|
|
fprintf(stderr, "using bzip2\n"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -1136,6 +1138,29 @@ TEST(DBTest, MinLevelToCompress) { |
|
|
|
for (int i = 1; i < options.num_levels; i++) { |
|
|
|
for (int i = 1; i < options.num_levels; i++) { |
|
|
|
options.compression_per_level[i] = type; |
|
|
|
options.compression_per_level[i] = type; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
TEST(DBTest, MinLevelToCompress1) { |
|
|
|
|
|
|
|
Options options = CurrentOptions(); |
|
|
|
|
|
|
|
CompressionType type; |
|
|
|
|
|
|
|
MinLevelToCompress(type, options, -14, -1, 0); |
|
|
|
|
|
|
|
Reopen(&options); |
|
|
|
|
|
|
|
MinLevelHelper(this, options); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// do not compress L0 and L1
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) { |
|
|
|
|
|
|
|
options.compression_per_level[i] = kNoCompression; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 2; i < options.num_levels; i++) { |
|
|
|
|
|
|
|
options.compression_per_level[i] = type; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DestroyAndReopen(&options); |
|
|
|
|
|
|
|
MinLevelHelper(this, options); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DBTest, MinLevelToCompress2) { |
|
|
|
|
|
|
|
Options options = CurrentOptions(); |
|
|
|
|
|
|
|
CompressionType type; |
|
|
|
|
|
|
|
MinLevelToCompress(type, options, 15, -1, 0); |
|
|
|
Reopen(&options); |
|
|
|
Reopen(&options); |
|
|
|
MinLevelHelper(this, options); |
|
|
|
MinLevelHelper(this, options); |
|
|
|
|
|
|
|
|
|
|
@ -1682,6 +1707,29 @@ TEST(DBTest, DBOpen_Options) { |
|
|
|
db = NULL; |
|
|
|
db = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DBTest, DBOpen_Change_NumLevels) { |
|
|
|
|
|
|
|
std::string dbname = test::TmpDir() + "/db_change_num_levels"; |
|
|
|
|
|
|
|
DestroyDB(dbname, Options()); |
|
|
|
|
|
|
|
Options opts; |
|
|
|
|
|
|
|
Status s; |
|
|
|
|
|
|
|
DB* db = NULL; |
|
|
|
|
|
|
|
opts.create_if_missing = true; |
|
|
|
|
|
|
|
s = DB::Open(opts, dbname, &db); |
|
|
|
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
ASSERT_TRUE(db != NULL); |
|
|
|
|
|
|
|
db->Put(WriteOptions(), "a", "123"); |
|
|
|
|
|
|
|
db->Put(WriteOptions(), "b", "234"); |
|
|
|
|
|
|
|
db->CompactRange(NULL, NULL); |
|
|
|
|
|
|
|
delete db; |
|
|
|
|
|
|
|
db = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts.create_if_missing = false; |
|
|
|
|
|
|
|
opts.num_levels = 2; |
|
|
|
|
|
|
|
s = DB::Open(opts, dbname, &db); |
|
|
|
|
|
|
|
ASSERT_TRUE(strstr(s.ToString().c_str(), "Corruption") != NULL); |
|
|
|
|
|
|
|
ASSERT_TRUE(db == NULL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check that number of files does not grow when we are out of space
|
|
|
|
// Check that number of files does not grow when we are out of space
|
|
|
|
TEST(DBTest, NoSpace) { |
|
|
|
TEST(DBTest, NoSpace) { |
|
|
|
Options options = CurrentOptions(); |
|
|
|
Options options = CurrentOptions(); |
|
|
|