int se_reqread(sereq *r) { sereqarg *arg = &r->arg; sedb *db = (sedb*)r->db; uint32_t keysize; void *key; if (sslikely(arg->v.v)) { keysize = sv_size(&arg->v); key = sv_pointer(&arg->v); } else { keysize = 0; key = NULL; } char *prefix; uint32_t prefixsize; if (arg->vprefix.v) { void *vptr = sv_vpointer(arg->vprefix.v); prefix = sf_key(vptr, 0); prefixsize = sf_keysize(vptr, 0); } else { prefix = NULL; prefixsize = 0; } if (sslikely(arg->vlsn_generate)) arg->vlsn = sr_seq(db->r.seq, SR_LSN); sitx x; si_begin(&x, &db->index, 1); siread q; si_readopen(&q, &x, arg->cache, arg->order, arg->vlsn, prefix, prefixsize, key, keysize); if (arg->update) si_readupdate(&q, &arg->vup, arg->update_eq); if (arg->cache_only) si_readcache_only(&q); if (arg->has) si_readhas(&q); r->rc = si_read(&q); r->read_disk = q.read_disk; r->read_cache = q.read_cache; r->v = q.result.v; si_readclose(&q); si_commit(&x); return r->rc; }
so *se_read(sedb *db, sedocument *o, sx *x, uint64_t vlsn, sicache *cache) { se *e = se_of(&db->o); uint64_t start = ss_utime(); /* prepare the key */ int auto_close = o->created <= 1; int rc = se_document_createkey(o); if (ssunlikely(rc == -1)) goto error; rc = se_document_validate_ro(o, &db->o); if (ssunlikely(rc == -1)) goto error; if (ssunlikely(! se_active(e))) goto error; sv vup; sv_init(&vup, &sv_vif, NULL, NULL); sedocument *ret = NULL; /* concurrent */ if (x && o->order == SS_EQ) { /* note: prefix is ignored during concurrent * index search */ int rc = sx_get(x, &db->coindex, &o->v, &vup); if (ssunlikely(rc == -1 || rc == 2 /* delete */)) goto error; if (rc == 1 && !sv_is(&vup, SVUPSERT)) { ret = (sedocument*)se_document_new(e, &db->o, &vup); if (sslikely(ret)) { ret->cold_only = o->cold_only; ret->created = 1; ret->orderset = 1; ret->flagset = 1; } else { sv_vunref(db->r, vup.v); } if (auto_close) so_destroy(&o->o); return &ret->o; } } else { sx_get_autocommit(&e->xm, &db->coindex); } /* prepare read cache */ int cachegc = 0; if (cache == NULL) { cachegc = 1; cache = si_cachepool_pop(&e->cachepool); if (ssunlikely(cache == NULL)) { if (vup.v) sv_vunref(db->r, vup.v); sr_oom(&e->error); goto error; } } sv_vref(o->v.v); /* do read */ siread rq; si_readopen(&rq, db->index, cache, o->order, vlsn, sv_pointer(&o->v), vup.v, o->prefix_copy, o->prefix_size, o->cold_only, 0, start); rc = si_read(&rq); si_readclose(&rq); /* prepare result */ if (rc == 1) { ret = (sedocument*)se_readresult(e, &rq); if (ret) o->prefix_copy = NULL; } /* cleanup */ if (o->v.v) sv_vunref(db->r, o->v.v); if (vup.v) sv_vunref(db->r, vup.v); if (ret == NULL && rq.result.v) sv_vunref(db->r, rq.result.v); if (cachegc && cache) si_cachepool_push(cache); if (auto_close) so_destroy(&o->o); return &ret->o; error: if (auto_close) so_destroy(&o->o); return NULL; }