/* * 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; }
/* * Return 0 in case of success * -1 in case of failure */ static int get_numeric_range_recl(as_sindex_metadata *imd, uint64_t begk, uint64_t endk, as_sindex_qctx *qctx) { ai_obj sfk; init_ai_objLong(&sfk, qctx->new_ibtr ? begk : qctx->bkey->l); ai_obj efk; init_ai_objLong(&efk, endk); as_sindex_pmetadata *pimd = &imd->pimd[qctx->pimd_idx]; bool fullrng = qctx->new_ibtr; int ret = 0; btSIter *bi = btGetRangeIter(pimd->ibtr, &sfk, &efk, 1); btEntry *be; if (bi) { while ((be = btRangeNext(bi, 1))) { ai_obj *ikey = be->key; ai_nbtr *anbtr = be->val; if (!anbtr) { ret = -1; break; } // figure out nbtr to deal with. If the key which was // used last time vanishes work with next key. If the // key exist but 'last' entry made to list in the last // iteration; Move to next nbtr if (!fullrng) { if (!ai_objEQ(&sfk, ikey)) { fullrng = 1; // bkey disappeared } else if (qctx->nbtr_done) { qctx->nbtr_done = false; // If we are moving to the next key, we need // to search the full range. fullrng = 1; continue; } } if (anbtr->is_btree) { if (add_recs_from_nbtr(imd, ikey, anbtr->u.nbtr, qctx, fullrng)) { ret = -1; break; } } else { if (add_recs_from_arr(imd, ikey, anbtr->u.arr, qctx)) { ret = -1; break; } } // Since add_recs_from_arr() returns entire thing and do not support the batch limit, // >= operator is needed here. if (qctx->n_bdigs >= qctx->bsize) { break; } // If it reaches here, this means last key could not fill the batch. // So if we are to start a new key, search should be done on full range // and the new nbtr is obviously not done. fullrng = 1; qctx->nbtr_done = false; } btReleaseRangeIterator(bi); } return ret; }