Skip to content

Commit

Permalink
Split initializer plugin to take pre and post-recovery callbacks (blo…
Browse files Browse the repository at this point in the history
  • Loading branch information
mponomar authored Apr 10, 2019
1 parent 6daac8f commit c708eec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bbinc/comdb2_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#define __INCLUDED_COMDB2_INITIALIZER_H

struct comdb2_initializer {
int (*initializer_handler)();
int (*pre_recovery)();
int (*post_recovery)();
};
typedef struct comdb2_initializer comdb2_initializer_t;

Expand Down
5 changes: 5 additions & 0 deletions bbinc/comdb2_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ enum comdb2_plugin_type {
COMDB2_PLUGIN_LAST
};

enum {
COMDB2_PLUGIN_INITIALIZER_PRE,
COMDB2_PLUGIN_INITIALIZER_POST
};

enum comdb2_plugin_flag {
/* Flag to indicate whether the plugin is static. */
COMDB2_PLUGIN_STATIC = 1,
Expand Down
6 changes: 4 additions & 2 deletions db/comdb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ int register_db_tunables(struct dbenv *tbl);
int destroy_plugins(void);
void register_plugin_tunables(void);
int install_static_plugins(void);
int run_init_plugins(void);
int run_init_plugins(int phase);

inline int getkeyrecnums(const struct dbtable *tbl, int ixnum)
{
Expand Down Expand Up @@ -3375,6 +3375,8 @@ static int init(int argc, char **argv)
if (rc)
return -1;

run_init_plugins(COMDB2_PLUGIN_INITIALIZER_PRE);

/* open database environment, and all dbs */
thedb = newdbenv(dbname, lrlname);
if (thedb == 0)
Expand Down Expand Up @@ -5315,7 +5317,7 @@ int main(int argc, char **argv)
// new schemachanges won't allow broken size.
gbl_broken_max_rec_sz = 0;

if (run_init_plugins()) {
if (run_init_plugins(COMDB2_PLUGIN_INITIALIZER_POST)) {
logmsg(LOGMSG_FATAL, "Initializer plugin failed\n");
exit(1);
}
Expand Down
17 changes: 14 additions & 3 deletions db/plugin_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,25 @@ const char *comdb2_plugin_type_to_str(int type)
return "unknown";
}

int run_init_plugins()
int run_init_plugins(int phase)
{
for (int i = 0; gbl_plugins[i]; ++i) {
struct comdb2_initializer *initer;
int rc;
int rc = 0;
if (gbl_plugins[i]->type == COMDB2_PLUGIN_INITIALIZER) {
initer = gbl_plugins[i]->data;
rc = initer->initializer_handler();
rc = 0;
switch (phase) {
case COMDB2_PLUGIN_INITIALIZER_PRE:
if (initer->pre_recovery)
rc = initer->pre_recovery();
break;
case COMDB2_PLUGIN_INITIALIZER_POST:
if (initer->post_recovery)
rc = initer->post_recovery();
break;

}
if (rc) {
return 1;
}
Expand Down

0 comments on commit c708eec

Please sign in to comment.