int sc_ctl_call(sc *s, uint64_t vlsn) { int rc = sr_statusactive(s->r->status); if (ssunlikely(rc == 0)) return 0; scworker *w = sc_workerpool_pop(&s->wp, s->r); if (ssunlikely(w == NULL)) return -1; rc = sc_step(s, w, vlsn); sc_workerpool_push(&s->wp, w); return rc; }
static void* se_worker(void *arg) { ssthread *self = arg; se *e = self->arg; ss_thread_setname(self, "worker"); ss_vfsioprio_low(&e->vfs); scworker *w = sc_workerpool_pop(&e->scheduler.wp, &e->r); if (ssunlikely(w == NULL)) return NULL; for (;;) { int rc = se_active(e); if (ssunlikely(rc == 0)) break; rc = sc_step(&e->scheduler, w, sx_vlsn(&e->xm)); if (ssunlikely(rc == -1)) break; if (ssunlikely(rc == 0)) ss_sleep(10000000); /* 10ms */ } sc_workerpool_push(&e->scheduler.wp, w); return NULL; }
int sc_ctl_branch(sc *s, uint64_t vlsn, si *index) { sr *r = s->r; int rc = sr_statusactive(r->status); if (ssunlikely(rc == 0)) return 0; srzone *z = sr_zoneof(r); scworker *w = sc_workerpool_pop(&s->wp, r); if (ssunlikely(w == NULL)) return -1; while (1) { uint64_t vlsn_lru = si_lru_vlsn(index); siplan plan = { .explain = SI_ENONE, .plan = SI_BRANCH, .a = z->branch_wm, .b = 0, .c = 0, .node = NULL }; rc = si_plan(index, &plan); if (rc == 0) break; rc = si_execute(index, &w->dc, &plan, vlsn, vlsn_lru); if (ssunlikely(rc == -1)) break; } sc_workerpool_push(&s->wp, w); return rc; } int sc_ctl_compact(sc *s, uint64_t vlsn, si *index) { sr *r = s->r; int rc = sr_statusactive(r->status); if (ssunlikely(rc == 0)) return 0; srzone *z = sr_zoneof(r); scworker *w = sc_workerpool_pop(&s->wp, r); if (ssunlikely(w == NULL)) return -1; while (1) { uint64_t vlsn_lru = si_lru_vlsn(index); siplan plan = { .explain = SI_ENONE, .plan = SI_COMPACT, .a = z->compact_wm, .b = z->compact_mode, .c = 0, .node = NULL }; rc = si_plan(index, &plan); if (rc == 0) break; rc = si_execute(index, &w->dc, &plan, vlsn, vlsn_lru); if (ssunlikely(rc == -1)) break; } sc_workerpool_push(&s->wp, w); return rc; } int sc_ctl_compact_index(sc *s, uint64_t vlsn, si *index) { sr *r = s->r; int rc = sr_statusactive(r->status); if (ssunlikely(rc == 0)) return 0; srzone *z = sr_zoneof(r); scworker *w = sc_workerpool_pop(&s->wp, r); if (ssunlikely(w == NULL)) return -1; while (1) { uint64_t vlsn_lru = si_lru_vlsn(index); siplan plan = { .explain = SI_ENONE, .plan = SI_COMPACT_INDEX, .a = z->branch_wm, .b = 0, .c = 0, .node = NULL }; rc = si_plan(index, &plan); if (rc == 0) break; rc = si_execute(index, &w->dc, &plan, vlsn, vlsn_lru); if (ssunlikely(rc == -1)) break; } sc_workerpool_push(&s->wp, w); return rc; } int sc_ctl_anticache(sc *s) { uint64_t asn = sr_seq(s->r->seq, SR_ASNNEXT); ss_mutexlock(&s->lock); s->anticache_asn = asn; s->anticache_storage = s->anticache_limit; s->anticache = 1; ss_mutexunlock(&s->lock); return 0; }