Skip to content

Commit ae1bc29

Browse files
committed
Partition collapse now resumes properly.
Signed-off-by: Dorin Hogea <dhogea@bloomberg.net>
1 parent 2f45ce7 commit ae1bc29

20 files changed

Lines changed: 873 additions & 218 deletions

db/comdb2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,8 @@ struct ireq {
14411441
tran_type *sc_tran;
14421442
tran_type *sc_close_tran;
14431443
struct schema_change_type *sc_pending;
1444-
LISTC_T(struct schema_change_type) scs; /* all schema changes in this txn */
14451444
uuid_t scs_uuid; /* on resume, there is no sorese, but we need to know uuid for scs */
1445+
struct schema_change_type *scs; /* during resume there is no osqlsess; this points to the scs list */
14461446
double cost;
14471447
uint64_t sc_seed;
14481448
uint32_t sc_host;
@@ -3648,6 +3648,7 @@ int cmp_index_int(struct schema *oldix, struct schema *newix, char *descr,
36483648
int get_dbtable_idx_by_name(const char *tablename);
36493649
int open_temp_db_resume(struct ireq *iq, struct dbtable *db, char *tablename, int resume);
36503650
int open_temp_newdb_resume(struct ireq *iq, struct dbtable *db, int resume);
3651+
void *open_temp_db_resume_early(struct dbtable *db, char *tablename);
36513652
int find_constraint(struct dbtable *db, constraint_t *ct);
36523653

36533654
/* END OF SCHEMACHANGE DECLARATIONS*/

db/osqlblockproc.c

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,6 @@ int bplog_schemachange_run(struct ireq *iq, uuid_t uuid, void *pscs)
12921292
iq->sc = sc;
12931293
iq->sc->iq = iq;
12941294
rc = osql_process_schemachange(sc, uuid);
1295-
/* remove this from session, cleanup will be done by bp writer */
1296-
listc_rfl(scs, sc);
12971295
if (rc)
12981296
break;
12991297
}
@@ -1306,13 +1304,19 @@ int bplog_schemachange_run(struct ireq *iq, uuid_t uuid, void *pscs)
13061304
}
13071305

13081306
/* wait for all schema changes to finish */
1309-
int bplog_schemachange_wait(struct ireq *iq, int rc)
1307+
int bplog_schemachange_wait(struct ireq *iq, void *pscs, int rc)
13101308
{
1311-
struct schema_change_type *sc;
1309+
LISTC_T(struct schema_change_type) *scs = pscs;
1310+
struct schema_change_type *sc, *tmp;
1311+
1312+
/* unlink sclists from iq->sorese */
1313+
LISTC_FOR_EACH_SAFE(scs, sc, tmp, scs_lnk)
1314+
{
1315+
listc_rfl(scs, sc);
1316+
}
13121317

13131318
iq->sc = sc = iq->sc_pending;
13141319
iq->sc_pending = NULL;
1315-
13161320
while (sc != NULL) {
13171321
Pthread_mutex_lock(&sc->mtx);
13181322
sc->nothrevent = 1;
@@ -1430,7 +1434,7 @@ int bplog_schemachange(struct ireq *iq)
14301434

14311435
rc = bplog_schemachange_run(iq, iq->sorese->uuid, &iq->sorese->scs);
14321436

1433-
return bplog_schemachange_wait(iq, rc);
1437+
return bplog_schemachange_wait(iq, &iq->sorese->scs, rc);
14341438
}
14351439

14361440
int get_schema_change_txns(struct ireq *iq, tran_type **logi,
@@ -1457,16 +1461,13 @@ int get_schema_change_txns(struct ireq *iq, tran_type **logi,
14571461
return 0;
14581462
}
14591463

1460-
void *resume_sc_multiddl_txn_finalize(void *p)
1464+
int resume_sc_multiddl_txn_finalize(struct ireq *iq)
14611465
{
1462-
comdb2_name_thread(__func__);
1463-
bdb_thread_event(thedb->bdb_env, BDBTHR_EVENT_START_RDWR);
1464-
1465-
struct ireq *iq = (struct ireq*)p;
14661466
struct schema_change_type *sc;
14671467
tran_type *parent_trans = NULL;
14681468
int error = 0;
14691469
uuid_t uuid;
1470+
int rc = 0;
14701471

14711472
comdb2uuidcpy(uuid, iq->sc_pending->uuid);
14721473

@@ -1500,16 +1501,14 @@ void *resume_sc_multiddl_txn_finalize(void *p)
15001501
if (error) {
15011502
logmsg(LOGMSG_ERROR, "%s: Aborting schema change because of errors\n",
15021503
__func__);
1504+
rc = ERR_SC;
15031505
goto abort_sc;
15041506
}
15051507

1506-
int rc;
15071508
if ((rc = get_schema_change_txns(iq, &iq->sc_logical_tran, &parent_trans,
15081509
&iq->sc_tran))) {
1509-
logmsg(LOGMSG_ERROR,
1510-
"%s:%d failed to start schema change transaction\n", __func__,
1511-
-rc);
1512-
rc = -1;
1510+
logmsg(LOGMSG_ERROR, "%s:%d failed to start schema change transaction\n", __func__, rc);
1511+
rc = ERR_SC;
15131512
goto abort_sc;
15141513
}
15151514

@@ -1538,9 +1537,8 @@ void *resume_sc_multiddl_txn_finalize(void *p)
15381537
iq->sc_logical_tran = NULL;
15391538

15401539
osql_postcommit_handle(iq);
1541-
bdb_thread_event(thedb->bdb_env, BDBTHR_EVENT_DONE_RDWR);
15421540

1543-
return NULL;
1541+
return 0;
15441542

15451543
abort_sc:
15461544
logmsg(LOGMSG_ERROR, "%s: aborting schema change\n", __func__);
@@ -1561,7 +1559,42 @@ void *resume_sc_multiddl_txn_finalize(void *p)
15611559
}
15621560

15631561
osql_postabort_handle(iq);
1564-
bdb_thread_event(thedb->bdb_env, BDBTHR_EVENT_DONE_RDWR);
1562+
1563+
return rc;
1564+
}
1565+
1566+
void *resume_sc_multiddl_txn_finalize_thd(void *arg)
1567+
{
1568+
struct ireq *iq = (struct ireq *)arg;
1569+
struct schema_change_type *sc;
1570+
1571+
comdb2_name_thread(__func__);
1572+
backend_thread_event(thedb, COMDB2_THR_EVENT_START_RDWR);
1573+
1574+
if (!(sc = iq->scs)) {
1575+
logmsg(LOGMSG_ERROR, "%s NULL sc list?\n", __func__);
1576+
backend_thread_event(thedb, COMDB2_THR_EVENT_DONE_RDWR);
1577+
return NULL;
1578+
}
1579+
1580+
/* the schemas are async resumed; wait here for them
1581+
* to finish
1582+
*/
1583+
while (sc) {
1584+
/* wait for this scs to finish */
1585+
wait_for_schema_change_start(sc, ASYNC_SC_END);
1586+
sc = sc->scs_lnk.next;
1587+
}
1588+
1589+
/* at this point, the schema changes have ran and are linked in sc_pending;
1590+
* run the regular finalize routine
1591+
*/
1592+
int rc = resume_sc_multiddl_txn_finalize(iq);
1593+
if (rc) {
1594+
logmsg(LOGMSG_ERROR, "%s failed to finalize rc %d\n", __func__, rc);
1595+
}
1596+
1597+
backend_thread_event(thedb, COMDB2_THR_EVENT_DONE_RDWR);
15651598

15661599
return NULL;
15671600
}
@@ -1608,22 +1641,23 @@ int resume_sc_multiddl_txn(sc_list_t *scl)
16081641
struct ireq *iq = calloc(1, sizeof(struct ireq));
16091642
init_fake_ireq(thedb, iq);
16101643

1611-
/* this starts schema changeas;
1644+
/* this starts schema changes;
16121645
* the alters have to register themselves inline,
1613-
* but the rest of the execution is done in parallel
1614-
* waiting is done by a separate thread that will finalize
1615-
* the schema change
1616-
* NOTE: schema changes will be queued in iq->sc_pending
1646+
* but the rest of the execution is done in a parallel thread,
1647+
* which is also responsible for finalizing the transaction
16171648
*
16181649
*/
16191650
rc = bplog_schemachange_run(iq, scl->uuid, &scs);
16201651
if (rc) {
1652+
/* TODO: free the scs */
16211653
free(iq);
16221654
return -1;
16231655
}
16241656

1657+
/* prepare the wait for scs */
1658+
iq->scs = scs.top;
1659+
16251660
pthread_t tid;
1626-
Pthread_create(&tid, &gbl_pthread_attr_detached,
1627-
resume_sc_multiddl_txn_finalize, iq);
1661+
Pthread_create(&tid, &gbl_pthread_attr_detached, resume_sc_multiddl_txn_finalize_thd, iq);
16281662
return 0;
16291663
}

db/osqlblockproc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,10 @@ void osql_bplog_set_blkseq(osql_sess_t *sess, struct ireq *iq);
115115
*/
116116
void osql_bplog_time_done(osql_bp_timings_t *tms);
117117

118+
/**
119+
* Finalize a multiddl txn
120+
*
121+
*/
122+
int resume_sc_multiddl_txn_finalize(struct ireq *iq);
123+
118124
#endif

0 commit comments

Comments
 (0)