📄 testblobs.cpp
字号:
{ DBG("--- deletePk ---"); unsigned n = 0; CHK((g_con = g_ndb->startTransaction()) != 0); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("deletePk pk1=" << hex << tup.m_pk1); CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0); CHK(g_opr->deleteTuple() == 0); CHK(g_opr->equal("PK1", tup.m_pk1) == 0); if (g_opt.m_pk2len != 0) CHK(g_opr->equal("PK2", tup.m_pk2) == 0); if (++n == g_opt.m_batch) { CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); CHK((g_con = g_ndb->startTransaction()) != 0); n = 0; } g_opr = 0; tup.m_exists = false; } if (n != 0) { CHK(g_con->execute(Commit) == 0); n = 0; } g_ndb->closeTransaction(g_con); g_con = 0; return 0;}// hash index opsstatic intreadIdx(int style){ DBG("--- readIdx " << stylename[style] << " ---"); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("readIdx pk1=" << hex << tup.m_pk1); CHK((g_con = g_ndb->startTransaction()) != 0); CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0); CHK(g_opx->readTuple() == 0); CHK(g_opx->equal("PK2", tup.m_pk2) == 0); CHK(getBlobHandles(g_opx) == 0); if (style == 0) { CHK(getBlobValue(tup) == 0); } else if (style == 1) { CHK(setBlobReadHook(tup) == 0); } else { CHK(g_con->execute(NoCommit) == 0); CHK(readBlobData(tup) == 0); } CHK(g_con->execute(Commit) == 0); if (style == 0 || style == 1) { CHK(verifyBlobValue(tup) == 0); } g_ndb->closeTransaction(g_con); g_opx = 0; g_con = 0; } return 0;}static intupdateIdx(int style){ DBG("--- updateIdx " << stylename[style] << " ---"); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("updateIdx pk1=" << hex << tup.m_pk1); CHK((g_con = g_ndb->startTransaction()) != 0); CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0); CHK(g_opx->updateTuple() == 0); CHK(g_opx->equal("PK2", tup.m_pk2) == 0); CHK(getBlobHandles(g_opx) == 0); if (style == 0) { CHK(setBlobValue(tup) == 0); } else if (style == 1) { CHK(setBlobWriteHook(tup) == 0); } else { CHK(g_con->execute(NoCommit) == 0); CHK(writeBlobData(tup) == 0); } CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); g_opx = 0; g_con = 0; tup.m_exists = true; } return 0;}static intwriteIdx(int style){ DBG("--- writeIdx " << stylename[style] << " ---"); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("writeIdx pk1=" << hex << tup.m_pk1); CHK((g_con = g_ndb->startTransaction()) != 0); CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0); CHK(g_opx->writeTuple() == 0); CHK(g_opx->equal("PK2", tup.m_pk2) == 0); CHK(getBlobHandles(g_opx) == 0); if (style == 0) { CHK(setBlobValue(tup) == 0); } else if (style == 1) { // non-nullable must be set CHK(g_bh1->setValue("", 0) == 0); CHK(setBlobWriteHook(tup) == 0); } else { // non-nullable must be set CHK(g_bh1->setValue("", 0) == 0); CHK(g_con->execute(NoCommit) == 0); CHK(writeBlobData(tup) == 0); } CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); g_opx = 0; g_con = 0; tup.m_exists = true; } return 0;}static intdeleteIdx(){ DBG("--- deleteIdx ---"); unsigned n = 0; CHK((g_con = g_ndb->startTransaction()) != 0); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("deleteIdx pk1=" << hex << tup.m_pk1); CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0); CHK(g_opx->deleteTuple() == 0); CHK(g_opx->equal("PK2", tup.m_pk2) == 0); if (++n == g_opt.m_batch) { CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); CHK((g_con = g_ndb->startTransaction()) != 0); n = 0; } g_opx = 0; tup.m_exists = false; } if (n != 0) { CHK(g_con->execute(Commit) == 0); n = 0; } return 0;}// scan ops table and indexstatic intreadScan(int style, bool idx){ DBG("--- " << "readScan" << (idx ? "Idx" : "") << " " << stylename[style] << " ---"); Tup tup; tup.alloc(); // allocate buffers CHK((g_con = g_ndb->startTransaction()) != 0); if (! idx) { CHK((g_ops = g_con->getNdbScanOperation(g_opt.m_tname)) != 0); } else { CHK((g_ops = g_con->getNdbIndexScanOperation(g_opt.m_x2name, g_opt.m_tname)) != 0); } CHK(g_ops->readTuples(NdbScanOperation::LM_Read) == 0); CHK(g_ops->getValue("PK1", (char*)&tup.m_pk1) != 0); if (g_opt.m_pk2len != 0) CHK(g_ops->getValue("PK2", tup.m_pk2) != 0); CHK(getBlobHandles(g_ops) == 0); if (style == 0) { CHK(getBlobValue(tup) == 0); } else if (style == 1) { CHK(setBlobReadHook(tup) == 0); } CHK(g_con->execute(NoCommit) == 0); unsigned rows = 0; while (1) { int ret; tup.m_pk1 = (Uint32)-1; memset(tup.m_pk2, 'x', g_opt.m_pk2len); CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1); if (ret == 1) break; DBG("readScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1); Uint32 k = tup.m_pk1 - g_opt.m_pk1off; CHK(k < g_opt.m_rows && g_tups[k].m_exists); tup.copyfrom(g_tups[k]); if (style == 0) { CHK(verifyBlobValue(tup) == 0); } else if (style == 1) { // execute ops generated by callbacks, if any CHK(verifyBlobValue(tup) == 0); } else { CHK(readBlobData(tup) == 0); } rows++; } g_ndb->closeTransaction(g_con); g_con = 0; g_ops = 0; CHK(g_opt.m_rows == rows); return 0;}static intupdateScan(int style, bool idx){ DBG("--- " << "updateScan" << (idx ? "Idx" : "") << " " << stylename[style] << " ---"); Tup tup; tup.alloc(); // allocate buffers CHK((g_con = g_ndb->startTransaction()) != 0); if (! idx) { CHK((g_ops = g_con->getNdbScanOperation(g_opt.m_tname)) != 0); } else { CHK((g_ops = g_con->getNdbIndexScanOperation(g_opt.m_x2name, g_opt.m_tname)) != 0); } CHK(g_ops->readTuples(NdbScanOperation::LM_Exclusive) == 0); CHK(g_ops->getValue("PK1", (char*)&tup.m_pk1) != 0); if (g_opt.m_pk2len != 0) CHK(g_ops->getValue("PK2", tup.m_pk2) != 0); CHK(g_con->execute(NoCommit) == 0); unsigned rows = 0; while (1) { int ret; tup.m_pk1 = (Uint32)-1; memset(tup.m_pk2, 'x', g_opt.m_pk2len); CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1); if (ret == 1) break; DBG("updateScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1); Uint32 k = tup.m_pk1 - g_opt.m_pk1off; CHK(k < g_opt.m_rows && g_tups[k].m_exists); // calculate new blob values calcBval(g_tups[k], false); tup.copyfrom(g_tups[k]); CHK((g_opr = g_ops->updateCurrentTuple()) != 0); CHK(getBlobHandles(g_opr) == 0); if (style == 0) { CHK(setBlobValue(tup) == 0); } else if (style == 1) { CHK(setBlobWriteHook(tup) == 0); } else { CHK(g_con->execute(NoCommit) == 0); CHK(writeBlobData(tup) == 0); } CHK(g_con->execute(NoCommit) == 0); g_opr = 0; rows++; } CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); g_con = 0; g_ops = 0; CHK(g_opt.m_rows == rows); return 0;}static intdeleteScan(bool idx){ DBG("--- " << "deleteScan" << (idx ? "Idx" : "") << " ---"); Tup tup; CHK((g_con = g_ndb->startTransaction()) != 0); if (! idx) { CHK((g_ops = g_con->getNdbScanOperation(g_opt.m_tname)) != 0); } else { CHK((g_ops = g_con->getNdbIndexScanOperation(g_opt.m_x2name, g_opt.m_tname)) != 0); } CHK(g_ops->readTuples(NdbScanOperation::LM_Exclusive) == 0); CHK(g_ops->getValue("PK1", (char*)&tup.m_pk1) != 0); if (g_opt.m_pk2len != 0) CHK(g_ops->getValue("PK2", tup.m_pk2) != 0); CHK(g_con->execute(NoCommit) == 0); unsigned rows = 0; unsigned n = 0; while (1) { int ret; tup.m_pk1 = (Uint32)-1; memset(tup.m_pk2, 'x', g_opt.m_pk2len); CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1); if (ret == 1) break; while (1) { DBG("deleteScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1); Uint32 k = tup.m_pk1 - g_opt.m_pk1off; CHK(k < g_opt.m_rows && g_tups[k].m_exists); g_tups[k].m_exists = false; CHK(g_ops->deleteCurrentTuple() == 0); rows++; tup.m_pk1 = (Uint32)-1; memset(tup.m_pk2, 'x', g_opt.m_pk2len); CHK((ret = g_ops->nextResult(false)) == 0 || ret == 1 || ret == 2); if (++n == g_opt.m_batch || ret == 2) { DBG("execute batch: n=" << n << " ret=" << ret); switch (0) { case 0: // works normally CHK(g_con->execute(NoCommit) == 0); CHK(true || g_con->restart() == 0); break; case 1: // nonsense - g_con is invalid for 2nd batch CHK(g_con->execute(Commit) == 0); CHK(true || g_con->restart() == 0); break; case 2: // DBTC sendSignalErrorRefuseLab CHK(g_con->execute(NoCommit) == 0); CHK(g_con->restart() == 0); break; case 3: // 266 time-out CHK(g_con->execute(Commit) == 0); CHK(g_con->restart() == 0); break; } n = 0; } if (ret == 2) break; } } CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); g_con = 0; g_ops = 0; CHK(g_opt.m_rows == rows); return 0;}// main// from here on print always#undef DBG#define DBG(x) \ do { \ ndbout << "line " << __LINE__ << " " << x << endl; \ } while (0)static inttestmain(){ g_ndb = new Ndb(g_ncc, "TEST_DB"); CHK(g_ndb->init(20) == 0); CHK(g_ndb->waitUntilReady() == 0); g_dic = g_ndb->getDictionary(); g_tups = new Tup [g_opt.m_rows]; CHK(dropTable() == 0); CHK(createTable() == 0); if (g_opt.m_bugtest != 0) { // test a general bug instead of blobs CHK((*g_opt.m_bugtest)() == 0); return 0; } Bcol& b1 = g_opt.m_blob1; CHK(NdbBlob::getBlobTableName(b1.m_btname, g_ndb, g_opt.m_tname, "BL1") == 0); DBG("BL1: inline=" << b1.m_inline << " part=" << b1.m_partsize << " table=" << b1.m_btname); if (! g_opt.m_oneblob) { Bcol& b2 = g_opt.m_blob2; CHK(NdbBlob::getBlobTableName(b2.m_btname, g_ndb, g_opt.m_tname, "BL2") == 0); DBG("BL2: inline=" << b2.m_inline << " part=" << b2.m_partsize << " table=" << b2.m_btname); } if (g_opt.m_seed != 0) srandom(g_opt.m_seed); for (g_loop = 0; g_opt.m_loop == 0 || g_loop < g_opt.m_loop; g_loop++) { int style; DBG("=== loop " << g_loop << " ==="); if (g_opt.m_seed == 0) srandom(g_loop); // pk for (style = 0; style <= 2; style++) { if (! testcase('k') || ! testcase(style)) continue; DBG("--- pk ops " << stylename[style] << " ---"); if (testcase('n')) { calcTups(false); CHK(insertPk(style) == 0); CHK(verifyBlob() == 0); CHK(readPk(style) == 0); if (testcase('u')) { calcTups(style); CHK(updatePk(style) == 0); CHK(verifyBlob() == 0); CHK(readPk(style) == 0); } CHK(deletePk() == 0); CHK(verifyBlob() == 0); } if (testcase('w')) { calcTups(false); CHK(writePk(style) == 0); CHK(verifyBlob() == 0); CHK(readPk(style) == 0); if (testcase('u')) { calcTups(style); CHK(writePk(style) == 0); CHK(verifyBlob() == 0); CHK(readPk(style) == 0); } CHK(deletePk() == 0); CHK(verifyBlob() == 0); } } // hash index for (style = 0; style <= 2; style++) { if (! testcase('i') || ! testcase(style)) continue; DBG("--- idx ops " << stylename[style] << " ---"); if (testcase('n')) { calcTups(false); CHK(insertPk(style) == 0); CHK(verifyBlob() == 0); CHK(readIdx(style) == 0); if (testcase('u')) { calcTups(style); CHK(updateIdx(style) == 0); CHK(verifyBlob() == 0); CHK(readIdx(style) == 0); } CHK(deleteIdx() == 0); CHK(verifyBlob() == 0); } if (testcase('w')) { calcTups(false); CHK(writePk(style) == 0); CHK(verifyBlob() == 0); CHK(readIdx(style) == 0); if (testcase('u')) { calcTups(style); CHK(writeIdx(style) == 0); CHK(verifyBlob() == 0); CHK(readIdx(style) == 0); } CHK(deleteIdx() == 0); CHK(verifyBlob() == 0); } } // scan table for (style = 0; style <= 2; style++) { if (! testcase('s') || ! testcase(style)) continue; DBG("--- table scan " << stylename[style] << " ---"); calcTups(false); CHK(insertPk(style) == 0); CHK(verifyBlob() == 0); CHK(readScan(style, false) == 0); if (testcase('u')) { CHK(updateScan(style, false) == 0); CHK(verifyBlob() == 0); } CHK(deleteScan(false) == 0); CHK(verifyBlob() == 0); } // scan index for (style = 0; style <= 2; style++) { if (! testcase('r') || ! testcase(style)) continue; DBG("--- index scan " << stylename[style] << " ---"); calcTups(false); CHK(insertPk(style) == 0); CHK(verifyBlob() == 0); CHK(readScan(style, true) == 0); if (testcase('u')) { CHK(updateScan(style, true) == 0); CHK(verifyBlob() == 0); } CHK(deleteScan(true) == 0); CHK(verifyBlob() == 0); } } delete g_ndb; return 0;}// separate performance teststruct Tmr { // stolen from testOIBasic Tmr() { clr(); } void clr() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -