/* * Return 0 in case of success * -1 in case of failure */ static int add_recs_from_nbtr(as_sindex_metadata *imd, ai_obj *ikey, bt *nbtr, as_sindex_qctx *qctx, bool fullrng) { int ret = 0; ai_obj sfk, efk; init_ai_obj(&sfk); init_ai_obj(&efk); btSIter *nbi; btEntry *nbe; btSIter stack_nbi; if (fullrng) { nbi = btSetFullRangeIter(&stack_nbi, nbtr, 1, NULL); } else { // search from LAST batches end-point init_ai_objFromDigest(&sfk, &qctx->bdig); assignMaxKey(nbtr, &efk); nbi = btSetRangeIter(&stack_nbi, nbtr, &sfk, &efk, 1); } if (nbi) { while ((nbe = btRangeNext(nbi, 1))) { ai_obj *akey = nbe->key; // FIRST can be REPEAT (last batch) if (!fullrng && ai_objEQ(&sfk, akey)) { continue; } if (btree_addsinglerec(imd, ikey, (cf_digest *)&akey->y, qctx->recl, &qctx->n_bdigs, qctx->can_partition_query, qctx->partitions_pre_reserved)) { ret = -1; break; } if (qctx->n_bdigs == qctx->bsize) { if (ikey) { ai_objClone(qctx->bkey, ikey); } cloneDigestFromai_obj(&qctx->bdig, akey); break; } } btReleaseRangeIterator(nbi); } else { cf_warning(AS_QUERY, "Could not find nbtr iterator.. skipping !!"); } return ret; }
static int add_recs_from_arr(as_sindex_metadata *imd, ai_obj *ikey, ai_arr *arr, as_sindex_qctx *qctx) { bool ret = 0; for (int i = 0; i < arr->used; i++) { if (btree_addsinglerec(imd, (cf_digest *)&arr->data[i * CF_DIGEST_KEY_SZ], qctx->recl, &qctx->n_bdigs)) { ret = -1; break; } // do not break on hitting batch limit, if the tree converts to // bt from arr, there is no way to know which digest were already // returned when attempting subsequent batch. Return the entire // thing. } // mark nbtr as finished and copy the offset qctx->nbtr_done = true; if (ikey) { ai_objClone(qctx->bkey, ikey); } return ret; }