Skip to content

Commit

Permalink
need to disable live sc upon error before freeing stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Dorin Hogea <dhogea@bloomberg.net>
  • Loading branch information
dorinhogea committed Dec 13, 2023
1 parent 3b55cca commit b725e57
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
78 changes: 37 additions & 41 deletions db/osqlblockproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,52 +1263,48 @@ int bplog_schemachange(struct ireq *iq, blocksql_tran_t *tran, void *err)


if (rc) {
if (rc == ERR_NOMASTER) {
/* IFF the schema changes are NOT aborted, clean in-mem structures but
* leave persistent and replicated changes (llmeta, new btree-s) so
* that a new master/resume will pick it up later
* NOTE: this clears iq->sc_pending, obviously (sc-s are freed), so
* the rest of schema change code -finalize, callback hooks- do NOT
* trigger anymore (they should not, they will do it when future resume
* finishes)
* NOTE2: if sc_should_abort is set, the bplog writer will call
* backout_schema_change and sc_abort callback, which they will
* clear any persistent and in-mem structures
*/
struct schema_change_type *next;
sc = iq->sc_pending;
while (sc != NULL) {
next = sc->sc_next;
if (sc->newdb && sc->newdb->handle) {
int bdberr = 0;
live_sc_off(sc->db);
while (sc->logical_livesc) {
usleep(200);
}
if (sc->db->sc_live_logical) {
bdb_clear_logical_live_sc(sc->db->handle, 1);
sc->db->sc_live_logical = 0;
}
if (rc == ERR_NOMASTER)
sc_set_downgrading(sc);
bdb_close_only(sc->newdb->handle, &bdberr);
freedb(sc->newdb);
sc->newdb = NULL;
/* IFF the schema changes are NOT aborted, clean in-mem structures but
* leave persistent and replicated changes (llmeta, new btree-s) so
* that a new master/resume will pick it up later
* NOTE: this clears iq->sc_pending, obviously (sc-s are freed), so
* the rest of schema change code -finalize, callback hooks- do NOT
* trigger anymore (they should not, they will do it when future resume
* finishes)
* NOTE2: if sc_should_abort is set, the bplog writer will call
* backout_schema_change and sc_abort callback, which they will
* clear any persistent and in-mem structures
*/
struct schema_change_type *next;
sc = iq->sc_pending;
while (sc != NULL) {
next = sc->sc_next;
if (sc->newdb && sc->newdb->handle) {
int bdberr = 0;
live_sc_off(sc->db);
while (sc->logical_livesc) {
usleep(200);
}
if (sc->db->sc_live_logical) {
bdb_clear_logical_live_sc(sc->db->handle, 1);
sc->db->sc_live_logical = 0;
}
sc_set_running(iq, sc, sc->tablename, 0, NULL, 0, 0, __func__,
__LINE__);
free_schema_change_type(sc);
sc = next;
}
iq->sc_pending = NULL;
} else {
sc = iq->sc_pending;
while (sc != NULL) {
__LINE__);
if (rc == ERR_NOMASTER) {
sc_set_downgrading(sc);
bdb_close_only(sc->newdb->handle, &bdberr);
freedb(sc->newdb);
sc->newdb = NULL;
free_schema_change_type(sc);
}
} else {
sc_set_running(iq, sc, sc->tablename, 0, NULL, 0, 0, __func__,
__LINE__);
sc = sc->sc_next;
__LINE__);
}
sc = next;
}
if (rc == ERR_NOMASTER)
iq->sc_pending = NULL;
}
logmsg(LOGMSG_INFO, ">>> DDL SCHEMA CHANGE RC %d <<<\n", rc);

Expand Down
1 change: 0 additions & 1 deletion db/toblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,6 @@ void handle_postabort_bpfunc(struct ireq *iq)
}
}

int backout_schema_changes(struct ireq *iq, tran_type *tran);
static void backout_and_abort_tranddl(struct ireq *iq, tran_type *parent,
int rowlocks)
{
Expand Down

0 comments on commit b725e57

Please sign in to comment.