Skip to content

Commit da79909

Browse files
sync with upstream @ 21409451
Check the NEWS file for details of what changed. git-svn-id: https://leveldb.googlecode.com/svn/trunk@28 62dab493-f737-651d-591e-8d6aee1b9529
1 parent 3c11133 commit da79909

34 files changed

+953
-406
lines changed

NEWS

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Release 1.2 2011-05-16
2+
----------------------
3+
4+
Fixes for larger databases (tested up to one billion 100-byte entries,
5+
i.e., ~100GB).
6+
7+
(1) Place hard limit on number of level-0 files. This fixes errors
8+
of the form "too many open files".
9+
10+
(2) Fixed memtable management. Before the fix, a heavy write burst
11+
could cause unbounded memory usage.
12+
13+
A fix for a logging bug where the reader would incorrectly complain
14+
about corruption.
15+
16+
Allow public access to WriteBatch contents so that users can easily
17+
wrap a DB.

db/db_bench.cc

+55-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
// overwrite -- overwrite N values in random key order in async mode
2525
// fillsync -- write N/100 values in random key order in sync mode
2626
// fill100K -- write N/1000 100K values in random order in async mode
27-
// readseq -- read N values sequentially
28-
// readreverse -- read N values in reverse order
29-
// readrandom -- read N values in random order
27+
// readseq -- read N times sequentially
28+
// readreverse -- read N times in reverse order
29+
// readrandom -- read N times in random order
30+
// readhot -- read N times in random order from 1% section of DB
3031
// crc32c -- repeated crc32c of 4K of data
3132
// Meta operations:
3233
// compact -- Compact the entire DB
@@ -54,6 +55,9 @@ static const char* FLAGS_benchmarks =
5455
// Number of key/values to place in database
5556
static int FLAGS_num = 1000000;
5657

58+
// Number of read operations to do. If negative, do FLAGS_num reads.
59+
static int FLAGS_reads = -1;
60+
5761
// Size of each value
5862
static int FLAGS_value_size = 100;
5963

@@ -72,6 +76,14 @@ static int FLAGS_write_buffer_size = 0;
7276
// Negative means use default settings.
7377
static int FLAGS_cache_size = -1;
7478

79+
// Maximum number of files to keep open at the same time (use default if == 0)
80+
static int FLAGS_open_files = 0;
81+
82+
// If true, do not destroy the existing database. If you set this
83+
// flag and also specify a benchmark that wants a fresh database, that
84+
// benchmark will fail.
85+
static bool FLAGS_use_existing_db = false;
86+
7587
namespace leveldb {
7688

7789
// Helper for quickly generating random data.
@@ -126,6 +138,7 @@ class Benchmark {
126138
Cache* cache_;
127139
DB* db_;
128140
int num_;
141+
int reads_;
129142
int heap_counter_;
130143
double start_;
131144
double last_op_finish_;
@@ -298,6 +311,7 @@ class Benchmark {
298311
: cache_(FLAGS_cache_size >= 0 ? NewLRUCache(FLAGS_cache_size) : NULL),
299312
db_(NULL),
300313
num_(FLAGS_num),
314+
reads_(FLAGS_reads < 0 ? FLAGS_num : FLAGS_reads),
301315
heap_counter_(0),
302316
bytes_(0),
303317
rand_(301) {
@@ -308,7 +322,9 @@ class Benchmark {
308322
Env::Default()->DeleteFile("/tmp/dbbench/" + files[i]);
309323
}
310324
}
311-
DestroyDB("/tmp/dbbench", Options());
325+
if (!FLAGS_use_existing_db) {
326+
DestroyDB("/tmp/dbbench", Options());
327+
}
312328
}
313329

314330
~Benchmark() {
@@ -355,11 +371,13 @@ class Benchmark {
355371
ReadReverse();
356372
} else if (name == Slice("readrandom")) {
357373
ReadRandom();
374+
} else if (name == Slice("readhot")) {
375+
ReadHot();
358376
} else if (name == Slice("readrandomsmall")) {
359-
int n = num_;
360-
num_ /= 1000;
377+
int n = reads_;
378+
reads_ /= 1000;
361379
ReadRandom();
362-
num_ = n;
380+
reads_ = n;
363381
} else if (name == Slice("compact")) {
364382
Compact();
365383
} else if (name == Slice("crc32c")) {
@@ -449,7 +467,7 @@ class Benchmark {
449467
void Open() {
450468
assert(db_ == NULL);
451469
Options options;
452-
options.create_if_missing = true;
470+
options.create_if_missing = !FLAGS_use_existing_db;
453471
options.block_cache = cache_;
454472
options.write_buffer_size = FLAGS_write_buffer_size;
455473
Status s = DB::Open(options, "/tmp/dbbench", &db_);
@@ -462,6 +480,10 @@ class Benchmark {
462480
void Write(const WriteOptions& options, Order order, DBState state,
463481
int num_entries, int value_size, int entries_per_batch) {
464482
if (state == FRESH) {
483+
if (FLAGS_use_existing_db) {
484+
message_ = "skipping (--use_existing_db is true)";
485+
return;
486+
}
465487
delete db_;
466488
db_ = NULL;
467489
DestroyDB("/tmp/dbbench", Options());
@@ -499,7 +521,7 @@ class Benchmark {
499521
void ReadSequential() {
500522
Iterator* iter = db_->NewIterator(ReadOptions());
501523
int i = 0;
502-
for (iter->SeekToFirst(); i < num_ && iter->Valid(); iter->Next()) {
524+
for (iter->SeekToFirst(); i < reads_ && iter->Valid(); iter->Next()) {
503525
bytes_ += iter->key().size() + iter->value().size();
504526
FinishedSingleOp();
505527
++i;
@@ -510,7 +532,7 @@ class Benchmark {
510532
void ReadReverse() {
511533
Iterator* iter = db_->NewIterator(ReadOptions());
512534
int i = 0;
513-
for (iter->SeekToLast(); i < num_ && iter->Valid(); iter->Prev()) {
535+
for (iter->SeekToLast(); i < reads_ && iter->Valid(); iter->Prev()) {
514536
bytes_ += iter->key().size() + iter->value().size();
515537
FinishedSingleOp();
516538
++i;
@@ -521,7 +543,7 @@ class Benchmark {
521543
void ReadRandom() {
522544
ReadOptions options;
523545
std::string value;
524-
for (int i = 0; i < num_; i++) {
546+
for (int i = 0; i < reads_; i++) {
525547
char key[100];
526548
const int k = rand_.Next() % FLAGS_num;
527549
snprintf(key, sizeof(key), "%016d", k);
@@ -530,6 +552,19 @@ class Benchmark {
530552
}
531553
}
532554

555+
void ReadHot() {
556+
ReadOptions options;
557+
std::string value;
558+
const int range = (FLAGS_num + 99) / 100;
559+
for (int i = 0; i < reads_; i++) {
560+
char key[100];
561+
const int k = rand_.Next() % range;
562+
snprintf(key, sizeof(key), "%016d", k);
563+
db_->Get(options, key, &value);
564+
FinishedSingleOp();
565+
}
566+
}
567+
533568
void Compact() {
534569
DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
535570
dbi->TEST_CompactMemTable();
@@ -582,6 +617,8 @@ class Benchmark {
582617

583618
int main(int argc, char** argv) {
584619
FLAGS_write_buffer_size = leveldb::Options().write_buffer_size;
620+
FLAGS_open_files = leveldb::Options().max_open_files;
621+
585622
for (int i = 1; i < argc; i++) {
586623
double d;
587624
int n;
@@ -593,14 +630,21 @@ int main(int argc, char** argv) {
593630
} else if (sscanf(argv[i], "--histogram=%d%c", &n, &junk) == 1 &&
594631
(n == 0 || n == 1)) {
595632
FLAGS_histogram = n;
633+
} else if (sscanf(argv[i], "--use_existing_db=%d%c", &n, &junk) == 1 &&
634+
(n == 0 || n == 1)) {
635+
FLAGS_use_existing_db = n;
596636
} else if (sscanf(argv[i], "--num=%d%c", &n, &junk) == 1) {
597637
FLAGS_num = n;
638+
} else if (sscanf(argv[i], "--reads=%d%c", &n, &junk) == 1) {
639+
FLAGS_reads = n;
598640
} else if (sscanf(argv[i], "--value_size=%d%c", &n, &junk) == 1) {
599641
FLAGS_value_size = n;
600642
} else if (sscanf(argv[i], "--write_buffer_size=%d%c", &n, &junk) == 1) {
601643
FLAGS_write_buffer_size = n;
602644
} else if (sscanf(argv[i], "--cache_size=%d%c", &n, &junk) == 1) {
603645
FLAGS_cache_size = n;
646+
} else if (sscanf(argv[i], "--open_files=%d%c", &n, &junk) == 1) {
647+
FLAGS_open_files = n;
604648
} else {
605649
fprintf(stderr, "Invalid flag '%s'\n", argv[i]);
606650
exit(1);

0 commit comments

Comments
 (0)