]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #include <gtest/gtest.h> |
2 | #include "include/Context.h" | |
3 | #include "rocksdb/db.h" | |
4 | #include "rocksdb/env.h" | |
5 | #include "rocksdb/thread_status.h" | |
6 | #include "kv/RocksDBStore.h" | |
7 | #include <iostream> | |
8 | ||
9 | using namespace std; | |
10 | ||
11 | const string dir("rocksdb.test_temp_dir"); | |
12 | ||
13 | TEST(RocksDBOption, simple) { | |
14 | rocksdb::Options options; | |
15 | rocksdb::Status status; | |
11fdf7f2 TL |
16 | map<string,string> kvoptions; |
17 | RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, kvoptions, NULL); | |
7c673cae FG |
18 | string options_string = "" |
19 | "write_buffer_size=536870912;" | |
20 | "create_if_missing=true;" | |
21 | "max_write_buffer_number=4;" | |
22 | "max_background_compactions=4;" | |
23 | "stats_dump_period_sec = 5;" | |
24 | "min_write_buffer_number_to_merge = 2;" | |
25 | "level0_file_num_compaction_trigger = 4;" | |
26 | "max_bytes_for_level_base = 104857600;" | |
27 | "target_file_size_base = 10485760;" | |
28 | "num_levels = 3;" | |
f67539c2 TL |
29 | "compression = kNoCompression;" |
30 | "compaction_options_universal = {min_merge_width=4;size_ratio=2;max_size_amplification_percent=500}"; | |
7c673cae FG |
31 | int r = db->ParseOptionsFromString(options_string, options); |
32 | ASSERT_EQ(0, r); | |
33 | ASSERT_EQ(536870912u, options.write_buffer_size); | |
34 | ASSERT_EQ(4, options.max_write_buffer_number); | |
35 | ASSERT_EQ(4, options.max_background_compactions); | |
36 | ASSERT_EQ(5u, options.stats_dump_period_sec); | |
37 | ASSERT_EQ(2, options.min_write_buffer_number_to_merge); | |
38 | ASSERT_EQ(4, options.level0_file_num_compaction_trigger); | |
39 | ASSERT_EQ(104857600u, options.max_bytes_for_level_base); | |
40 | ASSERT_EQ(10485760u, options.target_file_size_base); | |
41 | ASSERT_EQ(3, options.num_levels); | |
42 | ASSERT_EQ(rocksdb::kNoCompression, options.compression); | |
f67539c2 TL |
43 | ASSERT_EQ(2, options.compaction_options_universal.size_ratio); |
44 | ASSERT_EQ(4, options.compaction_options_universal.min_merge_width); | |
45 | ASSERT_EQ(500, options.compaction_options_universal.max_size_amplification_percent); | |
7c673cae FG |
46 | } |
47 | TEST(RocksDBOption, interpret) { | |
48 | rocksdb::Options options; | |
49 | rocksdb::Status status; | |
11fdf7f2 TL |
50 | map<string,string> kvoptions; |
51 | RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, kvoptions, NULL); | |
7c673cae FG |
52 | string options_string = "compact_on_mount = true; compaction_threads=10;flusher_threads=5;"; |
53 | ||
54 | int r = db->ParseOptionsFromString(options_string, options); | |
55 | ASSERT_EQ(0, r); | |
56 | ASSERT_TRUE(db->compact_on_mount); | |
57 | //check thread pool setting | |
58 | options.env->SleepForMicroseconds(100000); | |
59 | std::vector<rocksdb::ThreadStatus> thread_list; | |
60 | status = options.env->GetThreadList(&thread_list); | |
61 | ASSERT_TRUE(status.ok()); | |
62 | ||
63 | int num_high_pri_threads = 0; | |
64 | int num_low_pri_threads = 0; | |
65 | for (vector<rocksdb::ThreadStatus>::iterator it = thread_list.begin(); | |
66 | it!= thread_list.end(); | |
67 | ++it) { | |
68 | if (it->thread_type == rocksdb::ThreadStatus::HIGH_PRIORITY) | |
69 | num_high_pri_threads++; | |
70 | if (it->thread_type == rocksdb::ThreadStatus::LOW_PRIORITY) | |
71 | num_low_pri_threads++; | |
72 | } | |
73 | ASSERT_EQ(15u, thread_list.size()); | |
74 | //low pri threads is compaction_threads | |
75 | ASSERT_EQ(10, num_low_pri_threads); | |
76 | //high pri threads is flusher_threads | |
77 | ASSERT_EQ(5, num_high_pri_threads); | |
78 | } |