Fix for the weird behaviour encountered by ldb Get where it could read only the second-latest value

Summary:
Changed the Get and Scan options with openForReadOnly mode to have access to the memtable.
Changed the visibility of NewInternalIterator in db_impl from private to protected so that
the derived class db_impl_read_only can call that in its NewIterator function for the
scan case. The previous approach which changed the default for flush_on_destroy_ from false to true
caused many problems in the unit tests due to empty sst files that it created. All
unit tests pass now.

Test Plan: make clean; make all check; ldb put and get and scans

Reviewers: dhruba, heyongqiang, sheki

Reviewed By: dhruba

CC: kosievdmerwe, zshao, dilipj, kailiu

Differential Revision: https://reviews.facebook.net/D8697
This commit is contained in:
amayank
2013-02-15 15:28:24 -08:00
parent fe10200ddc
commit b2c50f1c3f
3 changed files with 29 additions and 26 deletions

View File

@@ -61,9 +61,9 @@ public:
}
virtual ~LDBCommand() {
if (db_ != NULL) {
if (db_ != nullptr) {
delete db_;
db_ = NULL;
db_ = nullptr;
}
}
@@ -73,7 +73,7 @@ public:
return;
}
if (db_ == NULL && !NoDBOpen()) {
if (db_ == nullptr && !NoDBOpen()) {
OpenDB();
if (!exec_state_.IsNotStarted()) {
return;
@@ -85,7 +85,7 @@ public:
exec_state_ = LDBCommandExecuteResult::SUCCEED("");
}
if (db_ != NULL) {
if (db_ != nullptr) {
CloseDB ();
}
}
@@ -165,7 +165,7 @@ protected:
LDBCommand(const map<string, string>& options, const vector<string>& flags,
bool is_read_only, const vector<string>& valid_cmd_line_options) :
db_(NULL),
db_(nullptr),
is_read_only_(is_read_only),
is_key_hex_(false),
is_value_hex_(false),
@@ -190,9 +190,7 @@ protected:
// Open the DB.
leveldb::Status st;
if (is_read_only_) {
//st = leveldb::DB::OpenForReadOnly(opt, db_path_, &db_);
// Could not get this to work
st = leveldb::DB::Open(opt, db_path_, &db_);
st = leveldb::DB::OpenForReadOnly(opt, db_path_, &db_);
} else {
st = leveldb::DB::Open(opt, db_path_, &db_);
}
@@ -203,9 +201,9 @@ protected:
}
void CloseDB () {
if (db_ != NULL) {
if (db_ != nullptr) {
delete db_;
db_ = NULL;
db_ = nullptr;
}
}