/* * Return 0 in case of success * -1 in case of failure */ static int btree_addsinglerec(as_sindex_metadata *imd, cf_digest *dig, cf_ll *recl, uint64_t *n_bdigs) { if (!as_sindex_partition_isactive(imd->si->ns, dig)) { return 0; } bool create = (cf_ll_size(recl) == 0) ? true : false; dig_arr_t *dt; if (!create) { cf_ll_element * ele = cf_ll_get_tail(recl); dt = ((ll_recl_element*)ele)->dig_arr; if (dt->num == NUM_DIGS_PER_ARR) { create = true; } } if (create) { dt = getDigestArray(); if (!dt) { return -1; } ll_recl_element * node; node = cf_malloc(sizeof(ll_recl_element)); node->dig_arr = dt; cf_ll_append(recl, (cf_ll_element *)node); } memcpy(&dt->digs[dt->num], dig, CF_DIGEST_KEY_SZ); dt->num++; *n_bdigs = *n_bdigs + 1; return 0; }
/* * Internal function which adds digests to the defrag_list * Mallocs the nodes of defrag_list * Returns : * -1 : Error * number of digests found : success * */ static long build_defrag_list_from_nbtr(as_namespace *ns, ai_obj *acol, bt *nbtr, ulong nofst, ulong *limit, uint64_t * tot_found, cf_ll *gc_list) { int error = -1; btEntry *nbe; // STEP 1: go thru a portion of the nbtr and find to-be-deleted-PKs // TODO: a range query may be smarter then using the Xth Iterator btSIter *nbi = (nofst ? btGetFullXthIter(nbtr, nofst, 1, NULL, 0) : btGetFullRangeIter(nbtr, 1, NULL)); if (!nbi) { return error; } long found = 0; long processed = 0; while ((nbe = btRangeNext(nbi, 1))) { ai_obj *akey = nbe->key; int ret = as_sindex_can_defrag_record(ns, (cf_digest *) (&akey->y)); if (ret == AS_SINDEX_GC_SKIP_ITERATION) { *limit = 0; break; } else if (ret == AS_SINDEX_GC_OK) { bool create = (cf_ll_size(gc_list) == 0) ? true : false; objs_to_defrag_arr *dt; if (!create) { cf_ll_element * ele = cf_ll_get_tail(gc_list); dt = ((ll_sindex_gc_element*)ele)->objs_to_defrag; if (dt->num == SINDEX_GC_NUM_OBJS_PER_ARR) { create = true; } } if (create) { dt = as_sindex_gc_get_defrag_arr(); if (!dt) { *tot_found += found; return -1; } ll_sindex_gc_element * node; node = cf_malloc(sizeof(ll_sindex_gc_element)); node->objs_to_defrag = dt; cf_ll_append(gc_list, (cf_ll_element *)node); } cloneDigestFromai_obj(&(dt->acol_digs[dt->num].dig), akey); ai_objClone(&(dt->acol_digs[dt->num].acol), acol); dt->num += 1; found++; } processed++; (*limit)--; if (*limit == 0) break; } btReleaseRangeIterator(nbi); *tot_found += found; return processed; }
/* * Return 0 in case of success * -1 in case of failure */ static int btree_addsinglerec(as_sindex_metadata *imd, ai_obj * key, cf_digest *dig, cf_ll *recl, uint64_t *n_bdigs, bool * can_partition_query, bool partitions_pre_reserved) { // The digests which belongs to one of the query-able partitions are elligible to go into recl uint32_t pid = as_partition_getid(dig); as_namespace * ns = imd->si->ns; if (partitions_pre_reserved) { if (!can_partition_query[pid]) { return 0; } } else { if (! client_replica_maps_is_partition_queryable(ns, pid)) { return 0; } } bool create = (cf_ll_size(recl) == 0) ? true : false; as_index_keys_arr * keys_arr = NULL; if (!create) { cf_ll_element * ele = cf_ll_get_tail(recl); keys_arr = ((as_index_keys_ll_element*)ele)->keys_arr; if (keys_arr->num == AS_INDEX_KEYS_PER_ARR) { create = true; } } if (create) { keys_arr = as_index_get_keys_arr(); if (!keys_arr) { cf_warning(AS_SINDEX, "Fail to allocate sindex key value array"); return -1; } as_index_keys_ll_element * node = cf_malloc(sizeof(as_index_keys_ll_element)); node->keys_arr = keys_arr; cf_ll_append(recl, (cf_ll_element *)node); } // Copy the digest (value) memcpy(&keys_arr->pindex_digs[keys_arr->num], dig, CF_DIGEST_KEY_SZ); // Copy the key if (C_IS_DG(imd->sktype)) { memcpy(&keys_arr->sindex_keys[keys_arr->num].key.str_key, &key->y, CF_DIGEST_KEY_SZ); } else { keys_arr->sindex_keys[keys_arr->num].key.int_key = key->l; } keys_arr->num++; *n_bdigs = *n_bdigs + 1; return 0; }
static long build_defrag_list_from_arr(as_namespace *ns, ai_obj *acol, ai_arr *arr, long nofst, long *limit, uint64_t * tot_found, cf_ll *gc_list) { long found = 0; long processed = 0; uint64_t validation_time_ns = 0; for (int i = nofst; i < arr->used; i++) { SET_TIME_FOR_SINDEX_GC_HIST(validation_time_ns); int ret = as_sindex_can_defrag_record(ns, (cf_digest *) &arr->data[i * CF_DIGEST_KEY_SZ]); SINDEX_GC_HIST_INSERT_DATA_POINT(sindex_gc_validate_obj_hist, validation_time_ns); validation_time_ns = 0; if (ret == AS_SINDEX_GC_SKIP_ITERATION) { *limit = 0; break; } else if (ret == AS_SINDEX_GC_OK) { bool create = (cf_ll_size(gc_list) == 0) ? true : false; objs_to_defrag_arr *dt; if (!create) { cf_ll_element * ele = cf_ll_get_tail(gc_list); dt = ((ll_sindex_gc_element*)ele)->objs_to_defrag; if (dt->num == SINDEX_GC_NUM_OBJS_PER_ARR) { create = true; } } if (create) { dt = as_sindex_gc_get_defrag_arr(); if (!dt) { *tot_found += found; return -1; } ll_sindex_gc_element * node; node = cf_malloc(sizeof(ll_sindex_gc_element)); node->objs_to_defrag = dt; cf_ll_append(gc_list, (cf_ll_element *)node); } memcpy(&(dt->acol_digs[dt->num].dig), (cf_digest *) &arr->data[i * CF_DIGEST_KEY_SZ], CF_DIGEST_KEY_SZ); ai_objClone(&(dt->acol_digs[dt->num].acol), acol); dt->num += 1; found++; } processed++; (*limit)--; if (*limit == 0) { break; } } *tot_found += found; return processed; }