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
This commit is contained in:
sanjay
2017-10-02 12:37:45 -07:00
committed by Victor Costan
parent bcd9a8ea4a
commit 7e12c00ecf
3 changed files with 156 additions and 47 deletions

View File

@@ -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,