diff options
author | sanjay <sanjay@google.com> | 2017-10-02 12:37:45 -0700 |
---|---|---|
committer | Victor Costan <pwnall@chromium.org> | 2017-10-03 11:27:09 -0700 |
commit | 7e12c00ecf1bb725e212618e7026e4d34d6cd3bb (patch) | |
tree | 819404ec53dbf474593146bd59ab29e4177b5f8d /db | |
parent | bcd9a8ea4a8aad23a3e101a23c61615bab2a093f (diff) | |
download | leveldb-7e12c00ecf1bb725e212618e7026e4d34d6cd3bb.tar.gz |
Fix issue 474: a race between the f*_unlocked() STDIO calls in
env_posix.cc and concurrent application calls to fflush(NULL).
The fix is to avoid using stdio in env_posix.cc but add our own
buffering where we need it.
Added a test to reproduce the bug.
Added a test for Env reads/writes.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170738066
Diffstat (limited to 'db')
-rw-r--r-- | db/db_test.cc | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/db/db_test.cc b/db/db_test.cc index a0b08bc..edc3916 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -25,6 +25,13 @@ static std::string RandomString(Random* rnd, int len) { return r; } +static std::string RandomKey(Random* rnd) { + int len = (rnd->OneIn(3) + ? 1 // Short sometimes to encourage collisions + : (rnd->OneIn(100) ? rnd->Skewed(10) : rnd->Uniform(10))); + return test::RandomKey(rnd, len); +} + namespace { class AtomicCounter { private: @@ -1394,6 +1401,15 @@ TEST(DBTest, L0_CompactionBug_Issue44_b) { ASSERT_EQ("(->)(c->cv)", Contents()); } +TEST(DBTest, Fflush_Issue474) { + static const int kNum = 100000; + Random rnd(test::RandomSeed()); + for (int i = 0; i < kNum; i++) { + fflush(NULL); + ASSERT_OK(Put(RandomKey(&rnd), RandomString(&rnd, 100))); + } +} + TEST(DBTest, ComparatorCheck) { class NewComparator : public Comparator { public: @@ -1959,13 +1975,6 @@ class ModelDB: public DB { KVMap map_; }; -static std::string RandomKey(Random* rnd) { - int len = (rnd->OneIn(3) - ? 1 // Short sometimes to encourage collisions - : (rnd->OneIn(100) ? rnd->Skewed(10) : rnd->Uniform(10))); - return test::RandomKey(rnd, len); -} - static bool CompareIterators(int step, DB* model, DB* db, |