10 #include <sys/types.h> 57 return DB::Open(options_, dbname_, &db_);
71 std::string key_space, value_space;
73 for (
int i = 0; i < n; i++) {
77 batch.
Put(key,
Value(i, &value_space));
88 void Check(
int min_expected,
int max_expected) {
89 int next_expected = 0;
94 std::string value_space;
99 if (in ==
"" || in ==
"~") {
105 key < next_expected) {
109 missed += (key - next_expected);
110 next_expected = key + 1;
111 if (iter->
value() !=
Value(key, &value_space)) {
120 "expected=%d..%d; got=%d; bad_keys=%d; bad_values=%d; missed=%d\n",
121 min_expected, max_expected, correct, bad_keys, bad_values, missed);
128 std::vector<std::string> filenames;
133 int picked_number = -1;
134 for (
size_t i = 0; i < filenames.size(); i++) {
137 int(number) > picked_number) {
138 fname = dbname_ +
"/" + filenames[i];
139 picked_number = number;
145 if (stat(fname.c_str(), &sbuf) != 0) {
146 const char* msg = strerror(errno);
152 if (-offset > sbuf.st_size) {
155 offset = sbuf.st_size + offset;
158 if (offset > sbuf.st_size) {
159 offset = sbuf.st_size;
161 if (offset + bytes_to_corrupt > sbuf.st_size) {
162 bytes_to_corrupt = sbuf.st_size - offset;
166 std::string contents;
169 for (
int i = 0; i < bytes_to_corrupt; i++) {
170 contents[i + offset] ^= 0x80;
177 std::string property;
180 sscanf(property.c_str(),
"%d", &result) == 1) {
190 snprintf(buf,
sizeof(buf),
"%016d", i);
191 storage->assign(buf, strlen(buf));
192 return Slice(*storage);
223 std::string value_storage;
225 for (
int i = 0; s.
ok() && i < num; i++) {
227 batch.
Put(
"a",
Value(100, &value_storage));
305 dbi->TEST_CompactRange(0, NULL, NULL);
340 for (
int i = 0; i < 2; i++) {
349 std::string tmp1, tmp2;
351 ASSERT_TRUE(!s.
ok()) <<
"write did not fail in corrupted paranoid db";
360 std::string tmp1, tmp2;
372 int main(
int argc,
char** argv) {
void TEST_CompactRange(int level, const Slice *begin, const Slice *end)
Status WriteStringToFile(Env *env, const Slice &data, const std::string &fname)
bool ParseFileName(const std::string &fname, uint64_t *number, FileType *type)
int main(int argc, char **argv)
void Corrupt(FileType filetype, int offset, int bytes_to_corrupt)
virtual Slice key() const =0
virtual Slice value() const =0
void SleepForMicroseconds(int micros)
virtual void SeekToFirst()=0
bool writable_file_error_
static const int kValueSize
static const int kBlockSize
virtual Status Put(const WriteOptions &options, const Slice &key, const Slice &value)=0
Status RepairDB(const std::string &dbname, const Options &options)
Status DestroyDB(const std::string &dbname, const Options &options)
Slice Key(int i, std::string *storage)
bool ConsumeDecimalNumber(Slice *in, uint64_t *val)
virtual bool GetProperty(const Slice &property, std::string *value)=0
std::string ToString() const
int Property(const std::string &name)
virtual Status Get(const ReadOptions &options, const Slice &key, std::string *value)=0
static Status Open(const Options &options, const std::string &name, DB **dbptr)
virtual void CompactRange(const Slice *begin, const Slice *end)
static const int kMaxMemCompactLevel
Status TEST_CompactMemTable()
TEST(AutoCompactTest, ReadAll)
Slice Value(int k, std::string *storage)
virtual Status Write(const WriteOptions &options, WriteBatch *updates)=0
Cache * NewLRUCache(size_t capacity)
int num_writable_file_errors_
virtual Iterator * NewIterator(const ReadOptions &options)=0
Slice RandomString(Random *rnd, int len, std::string *dst)
Status GetChildren(const std::string &dir, std::vector< std::string > *r)
virtual bool Valid() const =0
void Put(const Slice &key, const Slice &value)
std::string NumberToString(uint64_t num)
void Check(int min_expected, int max_expected)
Status ReadFileToString(Env *env, const std::string &fname, std::string *data)