int ai_btree_destroy(as_sindex_metadata *imd) { char *tname, *cname, *iname; AI_GWLOCK(); for (int i = 0; i < imd->nprts; i++) { ai_cleanup(imd->pimd[i].ibtr); } if (!(tname = create_tname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } if (!(cname = create_cname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } if (0 > ai_drop_column(tname, cname)) { cf_warning(AS_SINDEX, "Failed to drop column %s from table %s", cname, tname); } cf_free(tname); cf_free(cname); if (!(iname = get_iname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } if (0 > ai_drop_index(iname)) { cf_warning(AS_SINDEX, "Failed to drop index %s", iname); } cf_free(iname); AI_UNLOCK(); return AS_SINDEX_OK; }
/* NOTE: The creation of a secondary index is the following two commands 0.) optional: CREATE TABLE namespace (pk U160, __dummy TEXT) 1.) ALTER TABLE namespace ADD COLUMN binname columntype 2.) CREATE [UNIQUE] INDEX indexname ON namespace (binname) */ int ai_btree_create(as_sindex_metadata *imd, int simatch, int *bimatch, int nprts) { char *iname = NULL, *cname = NULL, *tname = NULL; int ret = AS_SINDEX_ERR, rv; if (1 != imd->num_bins) { cf_warning(AS_SINDEX, "Multi-bin indexes not supported"); return ret; } if (!(tname = create_tname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } if (!(cname = create_cname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } AI_GWLOCK(); int tmatch = find_table(tname); if (tmatch == -1) { if (0 > (rv = ai_create_table(tname))) { cf_warning(AS_SINDEX, "Create table %s failed (rv %d)", tname, rv); goto END; } tmatch = find_table(tname); } r_tbl_t *rt = &Tbl[tmatch]; // 1.) add entries in Aerospike Index's virtual TABLE int col_type = imd->btype[0]; icol_t *ic = find_column(tmatch, cname); if (!ic) { // COLUMN does not exist if (0 > ai_add_column(tname, cname, col_type)) { goto END; } // Add (cmatch+1) always non-zero SITRACE(imd->si, META, debug, "Added Mapping [BINNAME=%s: BINID=%d: COLID%d] [IMATCH=%d: SIMATCH=%d: INAME=%s]", imd->bnames[0], imd->binid[0], rt->col_count, Num_indx - 1, simatch, imd->iname); } //NOTE: COMMAND: CREATE PARTITIONED INDEX iname ON tname (cname) NUM = nprts if (!(iname = get_iname_from_imd(imd))) { ret = AS_SINDEX_ERR_NO_MEMORY; goto END; } if (0 > (rv = ai_create_index(iname, tname, cname, col_type, nprts))) { cf_warning(AS_SINDEX, "Create index %s failed (rv %d)", iname, rv); goto END; } *bimatch = match_partial_index_name(iname); GTRACE(META, debug, "cr8SecIndex: iname: %s bname: %s type: %d ns: %s set: %s tmatch: %d bimatch: %d", imd->iname, imd->bnames[0], imd->btype[0], imd->ns_name, imd->set, tmatch, *bimatch); ret = AS_SINDEX_OK; END: AI_UNLOCK(); cf_free(tname); cf_free(cname); cf_free(iname); return ret; }
/* NOTE: The creation of a secondary index is the following two commands 0.) optional: CREATE TABLE namespace (pk U160, __dummy TEXT) 1.) ALTER TABLE namespace ADD COLUMN binname columntype 2.) CREATE [UNIQUE] INDEX indexname ON namespace (binname) */ int ai_btree_create(as_sindex_metadata *imd, int simatch, int *bimatch, int nprts) { char *iname = NULL, *cname = NULL, *tname = NULL; int ret = AS_SINDEX_ERR, rv; if (!(tname = create_tname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } if (!(cname = create_cname_from_imd(imd))) { if (tname) { cf_free(tname); } return AS_SINDEX_ERR_NO_MEMORY; } AI_GWLOCK(); // TODO : ai_create_table has this check. So this is redundant // 3 shash_get can be reduced to 1 through ai_get_or_create_table func int tmatch = find_table(tname); if (tmatch == -1) { if (0 > (rv = ai_create_table(tname))) { cf_warning(AS_SINDEX, "Create table %s failed (rv %d)", tname, rv); goto END; } tmatch = find_table(tname); } r_tbl_t *rt = &Tbl[tmatch]; // 1.) add entries in Aerospike Index's virtual TABLE int col_type = imd->btype; icol_t *ic = find_column(tmatch, cname); if (!ic) { // COLUMN does not exist if (0 > ai_add_column(tname, cname, col_type)) { goto END; } // Add (cmatch+1) always non-zero cf_debug(AS_SINDEX, "Added Mapping [BINNAME=%s: BINID=%d: COLID%d] [IMATCH=%d: SIMATCH=%d: INAME=%s]", imd->bname, imd->binid, rt->col_count, Num_indx - 1, simatch, imd->iname); } else { cf_free(ic); } //NOTE: COMMAND: CREATE PARTITIONED INDEX iname ON tname (cname) NUM = nprts if (!(iname = get_iname_from_imd(imd))) { ret = AS_SINDEX_ERR_NO_MEMORY; goto END; } if (0 > (rv = ai_create_index(iname, tname, cname, col_type, nprts))) { cf_warning(AS_SINDEX, "Create index %s failed (rv %d)", iname, rv); goto END; } *bimatch = match_partial_index_name(iname); cf_debug(AS_SINDEX, "cr8SecIndex: iname: %s bname: %s type: %d ns: %s set: %s tmatch: %d bimatch: %d", imd->iname, imd->bname, imd->btype, imd->ns_name, imd->set, tmatch, *bimatch); ret = AS_SINDEX_OK; END: AI_UNLOCK(); if (tname) { cf_free(tname); } if (cname) { cf_free(cname); } if (iname) { cf_free(iname); } return ret; }