Skip to content

Commit

Permalink
async phase also needs write locks, and a txn
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 7, 2023
1 parent b3de000 commit b0f6177
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions db/comdb2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3550,8 +3550,8 @@ int cmp_index_int(struct schema *oldix, struct schema *newix, char *descr,
size_t descrlen);
int getdbidxbyname_ll(const char *p_name);
int get_dbtable_idx_by_name(const char *tablename);
int open_temp_db_resume(struct dbtable *db, char *prefix, int resume, int temp,
tran_type *tran);
int open_temp_db_resume(struct ireq *iq, struct dbtable *db, char *prefix, int resume,
int temp, tran_type *tran);
int find_constraint(struct dbtable *db, constraint_t *ct);

/* END OF SCHEMACHANGE DECLARATIONS*/
Expand Down
2 changes: 1 addition & 1 deletion schemachange/sc_alter_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ int do_alter_table(struct ireq *iq, struct schema_change_type *s,
* truncated prefix anyway */
bdb_get_new_prefix(new_prefix, sizeof(new_prefix), &bdberr);

rc = open_temp_db_resume(newdb, new_prefix, s->resume, 0, tran);
rc = open_temp_db_resume(iq, newdb, new_prefix, s->resume, 0, tran);
if (rc) {
/* todo: clean up db */
sc_errf(s, "failed opening new db\n");
Expand Down
2 changes: 1 addition & 1 deletion schemachange/sc_fastinit_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int do_fastinit(struct ireq *iq, struct schema_change_type *s, tran_type *tran)
local_lock = 1;
wrlock_schema_lk();
}
rc = open_temp_db_resume(newdb, new_prefix, 0, 0, tran);
rc = open_temp_db_resume(iq, newdb, new_prefix, 0, 0, tran);
if (local_lock)
unlock_schema_lk();
if (rc) {
Expand Down
23 changes: 20 additions & 3 deletions schemachange/sc_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@ int resume_schema_change(void)
/****************** Functions down here will likely be moved elsewhere *****/

/* this assumes threads are not active in db */
int open_temp_db_resume(struct dbtable *db, char *prefix, int resume, int temp,
tran_type *tran)
int open_temp_db_resume(struct ireq *iq, struct dbtable *db, char *prefix, int resume,
int temp, tran_type *tran)
{
char *tmpname;
int bdberr;
Expand Down Expand Up @@ -1207,18 +1207,35 @@ int open_temp_db_resume(struct dbtable *db, char *prefix, int resume, int temp,

if (!db->handle) /* did not/could not open existing one, creating new one */
{
int rc;
tran_type * tmp_tran = tran;
if (!tmp_tran) {
rc = trans_start(iq, NULL, &tmp_tran);
if (rc)
return -1;
}

db->handle = bdb_create_tran(
tmpname, db->dbenv->basedir, db->lrl, db->nix,
(short *)db->ix_keylen, db->ix_dupes, db->ix_recnums,
db->ix_datacopy, db->ix_datacopylen, db->ix_collattr, db->ix_nullsallowed,
db->numblobs + 1, /* one main record + the blobs blobs */
db->dbenv->bdb_env, temp, &bdberr, tran);
db->dbenv->bdb_env, temp, &bdberr, tmp_tran);
if (db->handle == NULL) {
if (tmp_tran != tran)
trans_abort(iq, tmp_tran);

logmsg(LOGMSG_ERROR, "%s: failed to open %s, rcode %d\n", __func__,
tmpname, bdberr);
free(tmpname);
return -1;
}

if (tmp_tran != tran) {
rc = trans_commit(iq, tmp_tran, gbl_myhostname);
if (rc)
return -1;
}
}

/* clone the blobstripe genid. this will definately be needed in the
Expand Down
2 changes: 1 addition & 1 deletion schemachange/schemachange.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ static int add_table_for_recovery(struct ireq *iq, struct schema_change_type *s)

bdb_get_new_prefix(new_prefix, sizeof(new_prefix), &bdberr);

rc = open_temp_db_resume(newdb, new_prefix, 1, 0, NULL);
rc = open_temp_db_resume(iq, newdb, new_prefix, 1, 0, NULL);
if (rc) {
backout_schemas(newdb->tablename);
abort();
Expand Down

0 comments on commit b0f6177

Please sign in to comment.