825
/* perform compare command */
826
static int proccompare(const char *name, int tnum, int rnum){
827
iprintf("<Comparison Test>\n name=%s tnum=%d rnum=%d\n\n", name, tnum, rnum);
829
double stime = tctime();
831
TCMDB *mdb = tcmdbnew2(rnum / 2);
832
TCNDB *ndb = tcndbnew();
833
TCHDB *hdb = tchdbnew();
835
if(myrand(2) == 1) hopts |= HDBTLARGE;
836
if(myrand(2) == 1) hopts |= HDBTBZIP;
837
if(!tchdbtune(hdb, rnum / 2, -1, -1, hopts)){
838
eprint(NULL, "tchdbtune");
841
sprintf(path, "%s.tch", name);
842
int homode = HDBOWRITER | HDBOCREAT | HDBOTRUNC;
843
if(myrand(2) == 1) homode |= HDBOTSYNC;
844
if(!tchdbopen(hdb, path, homode)){
845
eprint(NULL, "tchdbopen");
848
TCBDB *bdb = tcbdbnew();
850
if(myrand(2) == 1) bopts |= BDBTLARGE;
851
if(myrand(2) == 1) bopts |= BDBTBZIP;
852
if(!tcbdbtune(bdb, 5, 5, rnum / 10, -1, -1, bopts)){
853
eprint(NULL, "tcbdbtune");
856
sprintf(path, "%s.tcb", name);
857
int bomode = BDBOWRITER | BDBOCREAT | BDBOTRUNC;
858
if(myrand(2) == 1) bomode |= BDBOTSYNC;
859
if(!tcbdbopen(bdb, path, bomode)){
860
eprint(NULL, "tcbdbopen");
863
for(int t = 1; !err && t <= tnum; t++){
864
bool commit = myrand(2) == 0;
865
iprintf("transaction %d (%s):\n", t, commit ? "commit" : "abort");
866
if(!tchdbtranbegin(hdb)){
867
eprint(NULL, "tchdbtranbegin");
870
if(!tcbdbtranbegin(bdb)){
871
eprint(NULL, "tcbdbtranbegin");
875
for(int i = 1; !err && i <= rnum; i++){
876
if(myrand(10) == 0) act = myrand(7);
877
char kbuf[RECBUFSIZ];
878
int ksiz = sprintf(kbuf, "%d", myrand(i) + 1);
879
char vbuf[RECBUFSIZ];
880
int vsiz = sprintf(vbuf, "%d:%d:%d", t, i, myrand(i));
883
if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
884
eprint(NULL, "tchdbput");
887
if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
888
eprint(NULL, "tcbdbput");
892
tcmdbput(mdb, kbuf, ksiz, vbuf, vsiz);
893
tcndbput(ndb, kbuf, ksiz, vbuf, vsiz);
897
if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
898
eprint(NULL, "tchdbputkeep");
901
if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
902
eprint(NULL, "tcbdbputkeep");
906
tcmdbputkeep(mdb, kbuf, ksiz, vbuf, vsiz);
907
tcndbputkeep(ndb, kbuf, ksiz, vbuf, vsiz);
911
if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
912
eprint(NULL, "tchdbputcat");
915
if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
916
eprint(NULL, "tcbdbputcat");
920
tcmdbputcat(mdb, kbuf, ksiz, vbuf, vsiz);
921
tcndbputcat(ndb, kbuf, ksiz, vbuf, vsiz);
925
if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
926
eprint(NULL, "tchdbaddint");
929
if(tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP){
930
eprint(NULL, "tchdbaddint");
934
tcmdbaddint(mdb, kbuf, ksiz, 1);
935
tcndbaddint(ndb, kbuf, ksiz, 1);
939
if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
940
eprint(NULL, "tchdbadddouble");
943
if(isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP){
944
eprint(NULL, "tchdbadddouble");
948
tcmdbadddouble(mdb, kbuf, ksiz, 1.0);
949
tcndbadddouble(ndb, kbuf, ksiz, 1.0);
953
if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
954
eprint(NULL, "tchdbout");
957
if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
958
eprint(NULL, "tcbdbout");
962
tcmdbout(mdb, kbuf, ksiz);
963
tcndbout(ndb, kbuf, ksiz);
967
if(rnum > 250 && i % (rnum / 250) == 0){
969
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
973
if(!tchdbtrancommit(hdb)){
974
eprint(NULL, "tchdbcommit");
977
if(!tcbdbtrancommit(bdb)){
978
eprint(NULL, "tcbdbcommit");
983
if(!tchdbclose(hdb)){
984
eprint(NULL, "tchdbclose");
987
sprintf(path, "%s.tch", name);
988
if(!tchdbopen(hdb, path, HDBOWRITER)){
989
eprint(NULL, "tchdbopen");
992
if(!tcbdbclose(bdb)){
993
eprint(NULL, "tcbdbclose");
996
sprintf(path, "%s.tcb", name);
997
if(!tcbdbopen(bdb, path, BDBOWRITER)){
998
eprint(NULL, "tcbdbopen");
1002
if(!tchdbtranabort(hdb)){
1003
eprint(NULL, "tchdbtranabort");
1006
if(!tcbdbtranabort(bdb)){
1007
eprint(NULL, "tcbdbtranabort");
1013
iprintf("checking consistency of all:\n");
1014
if(tchdbrnum(hdb) != tcbdbrnum(bdb)){
1015
eprint(NULL, "(validation)");
1022
for(int i = 1; (kbuf = tcmdbiternext(mdb, &ksiz)) != NULL; i++, inum++){
1024
char *vbuf = tcmdbget(mdb, kbuf, ksiz, &vsiz);
1026
char *rbuf = tcndbget(ndb, kbuf, ksiz, &rsiz);
1027
if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1028
eprint(NULL, "tcndbget");
1032
rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
1033
if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1034
eprint(NULL, "tchdbget");
1038
rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
1039
if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1040
eprint(NULL, "tcbdbget");
1046
if(rnum > 250 && i % (rnum / 250) == 0){
1048
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1051
if(rnum > 250) iprintf(" (%08d)\n", inum);
1052
iprintf("checking consistency of hash:\n");
1054
if(!tchdbiterinit(hdb)){
1055
eprint(NULL, "tchdbiterinit");
1058
for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
1060
char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
1062
char *rbuf = tcmdbget(mdb, kbuf, ksiz, &rsiz);
1063
if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1064
eprint(NULL, "(validation)");
1070
if(rnum > 250 && i % (rnum / 250) == 0){
1072
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1075
if(rnum > 250) iprintf(" (%08d)\n", inum);
1076
iprintf("checking consistency of tree:\n");
1077
BDBCUR *cur = tcbdbcurnew(bdb);
1078
if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
1079
eprint(NULL, "tcbdbcurfirst");
1082
for(int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++){
1084
char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
1086
char *rbuf = tcndbget(ndb, kbuf, ksiz, &rsiz);
1087
if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1088
eprint(NULL, "(validation)");
1094
if(rnum > 250 && i % (rnum / 250) == 0){
1096
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1100
if(rnum > 250) iprintf(" (%08d)\n", inum);
1102
if(!tchdbclose(hdb)){
1103
eprint(NULL, "tcbdbclose");
1106
if(!tcbdbclose(bdb)){
1107
eprint(NULL, "tcbdbclose");
1114
iprintf("time: %.3f\n", tctime() - stime);
1115
iprintf("%s\n\n", err ? "error" : "ok");