1 | /* -*- c-basic-offset: 2 -*- */ |
2 | /* |
3 | Copyright(C) 2015-2017 Kouhei Sutou <kou@clear-code.com> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #ifndef MRN_DATABASE_REPAIRER_HPP_ |
21 | #define MRN_DATABASE_REPAIRER_HPP_ |
22 | |
23 | #include <groonga.h> |
24 | |
25 | namespace mrn { |
26 | class DatabaseRepairer { |
27 | public: |
28 | DatabaseRepairer(grn_ctx *ctx, THD *thd); |
29 | ~DatabaseRepairer(void); |
30 | bool is_crashed(void); |
31 | bool is_corrupt(void); |
32 | bool repair(void); |
33 | |
34 | private: |
35 | grn_ctx *ctx_; |
36 | THD *thd_; |
37 | const char *base_directory_; |
38 | char base_directory_buffer_[MRN_MAX_PATH_SIZE]; |
39 | const char *path_prefix_; |
40 | char path_prefix_buffer_[MRN_MAX_PATH_SIZE]; |
41 | size_t path_prefix_length_; |
42 | size_t mrn_db_file_suffix_length_; |
43 | |
44 | typedef void (DatabaseRepairer::*EachBodyFunc)(grn_ctx *ctx, |
45 | grn_obj *db, |
46 | const char *db_path, |
47 | void *user_data); |
48 | |
49 | void each_database(EachBodyFunc each_body_func, void *user_data); |
50 | void each_database_body(const char *base_path, |
51 | grn_ctx *ctx, |
52 | EachBodyFunc each_body_func, |
53 | void *user_data); |
54 | void detect_paths(void); |
55 | |
56 | void check_body(grn_ctx *ctx, |
57 | grn_obj *db, |
58 | const char *db_path, |
59 | void *user_data); |
60 | void repair_body(grn_ctx *ctx, |
61 | grn_obj *db, |
62 | const char *db_path, |
63 | void *user_data); |
64 | }; |
65 | } |
66 | |
67 | #endif /* MRN_DATABASE_REPAIRER_HPP_ */ |
68 | |