Fix valgrind errors in rocksdb tests: auto_roll_logger_test, reduce_levels_test

Summary: Fix for memory leaks in rocksdb tests. Also modified the variable NUM_FAILED_TESTS to print the actual number of failed tests.

Test Plan: make <test>; valgrind --leak-check=full ./<test>

Reviewers: sheki, dhruba

Reviewed By: sheki

CC: leveldb

Differential Revision: https://reviews.facebook.net/D9333
main
Mayank Agarwal 12 years ago
parent ebf16f57c9
commit 5b278b53ae
  1. 3
      db/version_set_reduce_num_levels.cc
  2. 20
      util/auto_roll_logger_test.cc
  3. 29
      util/ldb_cmd.cc
  4. 2
      valgrind_test.sh

@ -67,7 +67,8 @@ Status VersionSet::ReduceNumberOfLevels(int new_levels, port::Mutex* mu) {
num_levels_ = new_levels; num_levels_ = new_levels;
compact_pointer_ = new std::string[new_levels]; compact_pointer_ = new std::string[new_levels];
Init(new_levels); Init(new_levels);
st = LogAndApply(new VersionEdit(new_levels), mu, true); VersionEdit ve(new_levels);
st = LogAndApply(&ve , mu, true);
return st; return st;
} }

@ -122,13 +122,11 @@ TEST(AutoRollLoggerTest, RollLogFileBySize) {
InitTestDb(); InitTestDb();
size_t log_max_size = 1024 * 5; size_t log_max_size = 1024 * 5;
AutoRollLogger* logger = new AutoRollLogger( AutoRollLogger logger(Env::Default(), kTestDir, "", log_max_size, 0);
Env::Default(), kTestDir, "", log_max_size, 0);
RollLogFileBySizeTest(logger, log_max_size, RollLogFileBySizeTest(&logger, log_max_size,
kSampleMessage + ":RollLogFileBySize"); kSampleMessage + ":RollLogFileBySize");
delete logger;
} }
TEST(AutoRollLoggerTest, RollLogFileByTime) { TEST(AutoRollLoggerTest, RollLogFileByTime) {
@ -138,13 +136,10 @@ TEST(AutoRollLoggerTest, RollLogFileByTime) {
InitTestDb(); InitTestDb();
// -- Test the existence of file during the server restart. // -- Test the existence of file during the server restart.
ASSERT_TRUE(!env->FileExists(kLogFile)); ASSERT_TRUE(!env->FileExists(kLogFile));
AutoRollLogger* logger = new AutoRollLogger( AutoRollLogger logger(Env::Default(), kTestDir, "", log_size, 1);
Env::Default(), kTestDir, "", log_size, 1);
ASSERT_TRUE(env->FileExists(kLogFile)); ASSERT_TRUE(env->FileExists(kLogFile));
RollLogFileByTimeTest(logger, time, kSampleMessage + ":RollLogFileByTime"); RollLogFileByTimeTest(&logger, time, kSampleMessage + ":RollLogFileByTime");
delete logger;
} }
TEST(AutoRollLoggerTest, TEST(AutoRollLoggerTest,
@ -178,16 +173,15 @@ TEST(AutoRollLoggerTest, CompositeRollByTimeAndSizeLogger) {
InitTestDb(); InitTestDb();
AutoRollLogger* logger = new AutoRollLogger( AutoRollLogger logger(Env::Default(), kTestDir, "", log_max_size, time);
Env::Default(), kTestDir, "", log_max_size, time);
// Test the ability to roll by size // Test the ability to roll by size
RollLogFileBySizeTest( RollLogFileBySizeTest(
logger, log_max_size, &logger, log_max_size,
kSampleMessage + ":CompositeRollByTimeAndSizeLogger"); kSampleMessage + ":CompositeRollByTimeAndSizeLogger");
// Test the ability to roll by Time // Test the ability to roll by Time
RollLogFileByTimeTest( logger, time, RollLogFileByTimeTest( &logger, time,
kSampleMessage + ":CompositeRollByTimeAndSizeLogger"); kSampleMessage + ":CompositeRollByTimeAndSizeLogger");
} }

@ -392,7 +392,7 @@ void DBLoaderCommand::DoCommand() {
std::cout << "Warning: " << bad_lines << " bad lines ignored." << std::endl; std::cout << "Warning: " << bad_lines << " bad lines ignored." << std::endl;
} }
if (compact_) { if (compact_) {
db_->CompactRange(NULL, NULL); db_->CompactRange(nullptr, nullptr);
} }
} }
@ -560,27 +560,24 @@ leveldb::Options ReduceDBLevelsCommand::PrepareOptionsForOpenDB() {
Status ReduceDBLevelsCommand::GetOldNumOfLevels(leveldb::Options& opt, Status ReduceDBLevelsCommand::GetOldNumOfLevels(leveldb::Options& opt,
int* levels) { int* levels) {
TableCache* tc = new TableCache(db_path_, &opt, 10); TableCache tc(db_path_, &opt, 10);
const InternalKeyComparator* cmp = new InternalKeyComparator( const InternalKeyComparator cmp(opt.comparator);
opt.comparator); VersionSet versions(db_path_, &opt, &tc, &cmp);
VersionSet* versions = new VersionSet(db_path_, &opt,
tc, cmp);
// We rely the VersionSet::Recover to tell us the internal data structures // We rely the VersionSet::Recover to tell us the internal data structures
// in the db. And the Recover() should never do any change // in the db. And the Recover() should never do any change
// (like LogAndApply) to the manifest file. // (like LogAndApply) to the manifest file.
Status st = versions->Recover(); Status st = versions.Recover();
if (!st.ok()) { if (!st.ok()) {
return st; return st;
} }
int max = -1; int max = -1;
for (int i = 0; i < versions->NumberLevels(); i++) { for (int i = 0; i < versions.NumberLevels(); i++) {
if (versions->NumLevelFiles(i)) { if (versions.NumLevelFiles(i)) {
max = i; max = i;
} }
} }
*levels = max + 1; *levels = max + 1;
delete versions;
return st; return st;
} }
@ -619,15 +616,13 @@ void ReduceDBLevelsCommand::DoCommand() {
db_->CompactRange(nullptr, nullptr); db_->CompactRange(nullptr, nullptr);
CloseDB(); CloseDB();
TableCache* tc = new TableCache(db_path_, &opt, 10); TableCache tc(db_path_, &opt, 10);
const InternalKeyComparator* cmp = new InternalKeyComparator( const InternalKeyComparator cmp(opt.comparator);
opt.comparator); VersionSet versions(db_path_, &opt, &tc, &cmp);
VersionSet* versions = new VersionSet(db_path_, &opt,
tc, cmp);
// We rely the VersionSet::Recover to tell us the internal data structures // We rely the VersionSet::Recover to tell us the internal data structures
// in the db. And the Recover() should never do any change (like LogAndApply) // in the db. And the Recover() should never do any change (like LogAndApply)
// to the manifest file. // to the manifest file.
st = versions->Recover(); st = versions.Recover();
if (!st.ok()) { if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString()); exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
return; return;
@ -635,7 +630,7 @@ void ReduceDBLevelsCommand::DoCommand() {
port::Mutex mu; port::Mutex mu;
mu.Lock(); mu.Lock();
st = versions->ReduceNumberOfLevels(new_levels_, &mu); st = versions.ReduceNumberOfLevels(new_levels_, &mu);
mu.Unlock(); mu.Unlock();
if (!st.ok()) { if (!st.ok()) {

@ -4,7 +4,7 @@
VALGRIND_DIR=VALGRIND_LOGS VALGRIND_DIR=VALGRIND_LOGS
make -j$(nproc) valgrind_check make -j$(nproc) valgrind_check
NUM_FAILED_TESTS=`wc -l $VALGRIND_DIR/valgrind_failed_tests | awk '{print $1}'` NUM_FAILED_TESTS=$((`wc -l $VALGRIND_DIR/valgrind_failed_tests | awk '{print $1}'` - 1))
if [ $NUM_FAILED_TESTS -le 1 ]; then if [ $NUM_FAILED_TESTS -le 1 ]; then
echo No tests have valgrind errors echo No tests have valgrind errors
exit 0 exit 0

Loading…
Cancel
Save