QDTA *pull_unsorted_from_dtaq() { unsigned char *kdata; unsigned char *vdata; QDTA *qdta = NULL; QDTA *dta = NULL; int ksize; int vsize; FUNC; get_moddb_lock(); tcmdbiterinit(dbdtaq); if ((kdata = tcmdbiternext(dbdtaq, &ksize)) != NULL) { vdata = tcmdbget(dbdtaq, kdata, ksize, &vsize); qdta = (QDTA *) vdata; if (NULL != qdta) { dta = s_malloc(sizeof(QDTA)); memcpy(dta, qdta, sizeof(QDTA)); mdelete_key(dbdtaq, kdata, config->hashlen); free(vdata); } free(kdata); } EFUNC; release_moddb_lock(); return dta; }
/* thread the read function */ static void *threadread(void *targ){ TCMDB *mdb = ((TARGCOMBO *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGCOMBO *)targ)->rnum; bool rnd = ((TARGCOMBO *)targ)->rnd; int id = ((TARGCOMBO *)targ)->id; double stime = tctime(); if(id == 0) iprintf("reading:\n"); int base = id * rnum; for(int i = 1; i <= rnum; i++){ char kbuf[RECBUFSIZ]; int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i) : i)); int vsiz; char *vbuf = ndb ? tcndbget(ndb, kbuf, ksiz, &vsiz) : tcmdbget(mdb, kbuf, ksiz, &vsiz); if(vbuf) tcfree(vbuf); if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(id == 0) iprintf("time: %.3f\n", tctime() - stime); return NULL; }
/* thread the typical function */ static void *threadtypical(void *targ){ TCMDB *mdb = ((TARGTYPICAL *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGTYPICAL *)targ)->rnum; bool nc = ((TARGTYPICAL *)targ)->nc; int rratio = ((TARGTYPICAL *)targ)->rratio; int id = ((TARGTYPICAL *)targ)->id; bool err = false; TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL; int base = id * rnum; int mrange = tclmax(50 + rratio, 100); for(int i = 1; !err && i <= rnum; i++){ char buf[RECBUFSIZ]; int len = sprintf(buf, "%08d", base + myrandnd(i)); int rnd = myrand(mrange); if(rnd < 10){ if(ndb){ tcndbput(ndb, buf, len, buf, len); } else { tcmdbput(mdb, buf, len, buf, len); } if(map) tcmapput(map, buf, len, buf, len); } else if(rnd < 15){ if(ndb){ tcndbputkeep(ndb, buf, len, buf, len); } else { tcmdbputkeep(mdb, buf, len, buf, len); } if(map) tcmapputkeep(map, buf, len, buf, len); } else if(rnd < 20){ if(ndb){ tcndbputcat(ndb, buf, len, buf, len); } else { tcmdbputcat(mdb, buf, len, buf, len); } if(map) tcmapputcat(map, buf, len, buf, len); } else if(rnd < 30){ if(ndb){ tcndbout(ndb, buf, len); } else { tcmdbout(mdb, buf, len); } if(map) tcmapout(map, buf, len); } else if(rnd < 31){ if(myrand(10) == 0) tcmdbiterinit(mdb); for(int j = 0; !err && j < 10; j++){ int ksiz; char *kbuf = ndb ? tcndbiternext(ndb, &ksiz) : tcmdbiternext(mdb, &ksiz); if(kbuf) tcfree(kbuf); } } else { int vsiz; char *vbuf = ndb ? tcndbget(ndb, buf, len, &vsiz) : tcmdbget(mdb, buf, len, &vsiz); if(vbuf){ if(map){ int msiz; const char *mbuf = tcmapget(map, buf, len, &msiz); if(msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint(__LINE__, "(validation)"); err = true; } } tcfree(vbuf); } else { if(map && tcmapget(map, buf, len, &vsiz)){ eprint(__LINE__, "(validation)"); err = true; } } } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(map){ tcmapiterinit(map); int ksiz; const char *kbuf; while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){ int vsiz; char *vbuf = ndb ? tcndbget(ndb, kbuf, ksiz, &vsiz) : tcmdbget(mdb, kbuf, ksiz, &vsiz); if(vbuf){ int msiz; const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz); if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint(__LINE__, "(validation)"); err = true; } tcfree(vbuf); } else { eprint(__LINE__, "(validation)"); err = true; } } tcmapdel(map); } return err ? "error" : NULL; }