@@ -84,6 +84,14 @@ static bool FLAGS_histogram = false;
8484// (initialized to default value by "main")
8585static int FLAGS_write_buffer_size = 0 ;
8686
87+ // Number of bytes written to each file.
88+ // (initialized to default value by "main")
89+ static int FLAGS_max_file_size = 0 ;
90+
91+ // Approximate size of user data packed per block (before compression.
92+ // (initialized to default value by "main")
93+ static int FLAGS_block_size = 0 ;
94+
8795// Number of bytes to use as a cache of uncompressed data.
8896// Negative means use default settings.
8997static int FLAGS_cache_size = -1 ;
@@ -109,6 +117,7 @@ static const char* FLAGS_db = NULL;
109117namespace leveldb {
110118
111119namespace {
120+ leveldb::Env* g_env = NULL ;
112121
113122// Helper for quickly generating random data.
114123class RandomGenerator {
@@ -186,7 +195,7 @@ class Stats {
186195 done_ = 0 ;
187196 bytes_ = 0 ;
188197 seconds_ = 0 ;
189- start_ = Env::Default () ->NowMicros ();
198+ start_ = g_env ->NowMicros ();
190199 finish_ = start_;
191200 message_.clear ();
192201 }
@@ -204,7 +213,7 @@ class Stats {
204213 }
205214
206215 void Stop () {
207- finish_ = Env::Default () ->NowMicros ();
216+ finish_ = g_env ->NowMicros ();
208217 seconds_ = (finish_ - start_) * 1e-6 ;
209218 }
210219
@@ -214,7 +223,7 @@ class Stats {
214223
215224 void FinishedSingleOp () {
216225 if (FLAGS_histogram) {
217- double now = Env::Default () ->NowMicros ();
226+ double now = g_env ->NowMicros ();
218227 double micros = now - last_op_finish_;
219228 hist_.Add (micros);
220229 if (micros > 20000 ) {
@@ -404,10 +413,10 @@ class Benchmark {
404413 reads_(FLAGS_reads < 0 ? FLAGS_num : FLAGS_reads),
405414 heap_counter_(0 ) {
406415 std::vector<std::string> files;
407- Env::Default () ->GetChildren (FLAGS_db, &files);
416+ g_env ->GetChildren (FLAGS_db, &files);
408417 for (size_t i = 0 ; i < files.size (); i++) {
409418 if (Slice (files[i]).starts_with (" heap-" )) {
410- Env::Default () ->DeleteFile (std::string (FLAGS_db) + " /" + files[i]);
419+ g_env ->DeleteFile (std::string (FLAGS_db) + " /" + files[i]);
411420 }
412421 }
413422 if (!FLAGS_use_existing_db) {
@@ -589,7 +598,7 @@ class Benchmark {
589598 arg[i].shared = &shared;
590599 arg[i].thread = new ThreadState (i);
591600 arg[i].thread ->shared = &shared;
592- Env::Default () ->StartThread (ThreadBody, &arg[i]);
601+ g_env ->StartThread (ThreadBody, &arg[i]);
593602 }
594603
595604 shared.mu .Lock ();
@@ -700,9 +709,12 @@ class Benchmark {
700709 void Open () {
701710 assert (db_ == NULL );
702711 Options options;
712+ options.env = g_env;
703713 options.create_if_missing = !FLAGS_use_existing_db;
704714 options.block_cache = cache_;
705715 options.write_buffer_size = FLAGS_write_buffer_size;
716+ options.max_file_size = FLAGS_max_file_size;
717+ options.block_size = FLAGS_block_size;
706718 options.max_open_files = FLAGS_open_files;
707719 options.filter_policy = filter_policy_;
708720 options.reuse_logs = FLAGS_reuse_logs;
@@ -925,7 +937,7 @@ class Benchmark {
925937 char fname[100 ];
926938 snprintf (fname, sizeof (fname), " %s/heap-%04d" , FLAGS_db, ++heap_counter_);
927939 WritableFile* file;
928- Status s = Env::Default () ->NewWritableFile (fname, &file);
940+ Status s = g_env ->NewWritableFile (fname, &file);
929941 if (!s.ok ()) {
930942 fprintf (stderr, " %s\n " , s.ToString ().c_str ());
931943 return ;
@@ -934,7 +946,7 @@ class Benchmark {
934946 delete file;
935947 if (!ok) {
936948 fprintf (stderr, " heap profiling not supported\n " );
937- Env::Default () ->DeleteFile (fname);
949+ g_env ->DeleteFile (fname);
938950 }
939951 }
940952};
@@ -943,6 +955,8 @@ class Benchmark {
943955
944956int main (int argc, char ** argv) {
945957 FLAGS_write_buffer_size = leveldb::Options ().write_buffer_size ;
958+ FLAGS_max_file_size = leveldb::Options ().max_file_size ;
959+ FLAGS_block_size = leveldb::Options ().block_size ;
946960 FLAGS_open_files = leveldb::Options ().max_open_files ;
947961 std::string default_db_path;
948962
@@ -973,6 +987,10 @@ int main(int argc, char** argv) {
973987 FLAGS_value_size = n;
974988 } else if (sscanf (argv[i], " --write_buffer_size=%d%c" , &n, &junk) == 1 ) {
975989 FLAGS_write_buffer_size = n;
990+ } else if (sscanf (argv[i], " --max_file_size=%d%c" , &n, &junk) == 1 ) {
991+ FLAGS_max_file_size = n;
992+ } else if (sscanf (argv[i], " --block_size=%d%c" , &n, &junk) == 1 ) {
993+ FLAGS_block_size = n;
976994 } else if (sscanf (argv[i], " --cache_size=%d%c" , &n, &junk) == 1 ) {
977995 FLAGS_cache_size = n;
978996 } else if (sscanf (argv[i], " --bloom_bits=%d%c" , &n, &junk) == 1 ) {
@@ -987,9 +1005,11 @@ int main(int argc, char** argv) {
9871005 }
9881006 }
9891007
1008+ leveldb::g_env = leveldb::Env::Default ();
1009+
9901010 // Choose a location for the test database if none given with --db=<path>
9911011 if (FLAGS_db == NULL ) {
992- leveldb::Env::Default () ->GetTestDirectory (&default_db_path);
1012+ leveldb::g_env ->GetTestDirectory (&default_db_path);
9931013 default_db_path += " /dbbench" ;
9941014 FLAGS_db = default_db_path.c_str ();
9951015 }
0 commit comments