-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepair_if_failed.cpp
47 lines (38 loc) · 1.08 KB
/
repair_if_failed.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <leveldb/db.h>
#include "util.h"
leveldb::DB *g_db;
std::string g_data_dir = "./data/simple_demo";
int init() {
leveldb::Options init_options;
init_options.create_if_missing = true;
leveldb::Status s = leveldb::DB::Open(init_options, g_data_dir.c_str(), &g_db);
if (s.ok()) {
notice("db open succeed:%s\n", g_data_dir.c_str());
return 0;
}
warning("db open failed:%s\n", s.ToString().c_str());
s = leveldb::RepairDB(g_data_dir.c_str(), init_options);
if (!s.ok()) {
warning("db repair failed:%s\n", s.ToString().c_str());
return -1;
}
s = leveldb::DB::Open(init_options, g_data_dir.c_str(), &g_db);
if (s.ok()) {
notice("db open succeed after repair:%s\n", g_data_dir.c_str());
return 0;
}
warning("db open failed after repair:%s\n", s.ToString().c_str());
return 0;
}
int main(int argc, char **argv) {
if (argc > 1) {
g_data_dir = argv[1];
}
if (init()) {
warning("init failed");
return -1;
}
delete g_db;
return 0;
}