/* ** Set up a database file with the following properties: ** ** * Page size is 1024 bytes. ** * Block size is 64 KB. ** * Contains 5000 key-value pairs starting at 0 from the ** datasource returned getDatasource(). */ static void setup_populate_db2(){ Datasource *pData; int ii; int rc; int nBlocksize = 64*1024; int nPagesize = 1024; int nWritebuffer = 4*1024; lsm_db *pDb; testDeleteLsmdb(LSMTEST6_TESTDB); rc = lsm_new(tdb_lsm_env(), &pDb); if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB); lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &nBlocksize); lsm_config(pDb, LSM_CONFIG_PAGE_SIZE, &nPagesize); lsm_config(pDb, LSM_CONFIG_AUTOFLUSH, &nWritebuffer); pData = getDatasource(); for(ii=0; rc==LSM_OK && ii<5000; ii++){ void *pKey; int nKey; void *pVal; int nVal; testDatasourceEntry(pData, ii, &pKey, &nKey, &pVal, &nVal); lsm_insert(pDb, pKey, nKey, pVal, nVal); } testDatasourceFree(pData); lsm_close(pDb); testSaveDb(LSMTEST6_TESTDB, "log"); assert( rc==LSM_OK ); }
static void simple_oom_8(OomTest *pOom){ Datasource *pData = getDatasource(); int rc = LSM_OK; lsm_db *pDb; testRestoreDb(LSMTEST6_TESTDB, "log"); testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc); testOomScan(pOom, pDb, 1, "xyz", 3, 20, &rc); lsm_close(pDb); testDatasourceFree(pData); }
static void simple_oom_5(OomTest *pOom){ Datasource *pData = getDatasource(); int rc = LSM_OK; lsm_db *pDb; testRestoreDb(LSMTEST6_TESTDB, "log"); testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc); testOomFetchData(pOom, pDb, pData, 3333, &rc); testOomFetchData(pOom, pDb, pData, 0, &rc); testOomFetchData(pOom, pDb, pData, 4999, &rc); lsm_close(pDb); testDatasourceFree(pData); }
static void simple_oom_6(OomTest *pOom){ Datasource *pData = getDatasource(); int rc = LSM_OK; lsm_db *pDb; testRestoreDb(LSMTEST6_TESTDB, "log"); testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc); testOomWriteData(pOom, pDb, pData, 5000, &rc); testOomWriteData(pOom, pDb, pData, 5001, &rc); testOomWriteData(pOom, pDb, pData, 5002, &rc); testOomFetchData(pOom, pDb, pData, 5001, &rc); testOomFetchData(pOom, pDb, pData, 1234, &rc); lsm_close(pDb); testDatasourceFree(pData); }
/* ** This test case has two clients connected to a database. The first client ** hits an OOM while writing to the database. Check that the second ** connection is still able to query the db following the OOM. */ static void simple_oom2_1(OomTest *pOom){ const int nRecord = 100; /* Number of records initially in db */ const int nIns = 10; /* Number of records inserted with OOM */ Datasource *pData = getDatasource(); int rc = LSM_OK; lsm_db *pDb1; lsm_db *pDb2; int i; testDeleteLsmdb(LSMTEST6_TESTDB); /* Open the two connections. Initialize the in-memory tree so that it ** contains 100 records. Do all this with OOM injection disabled. */ testOomEnable(pOom, 0); testOomOpen(pOom, LSMTEST6_TESTDB, &pDb1, &rc); testOomOpen(pOom, LSMTEST6_TESTDB, &pDb2, &rc); for(i=0; i<nRecord; i++){ testOomWriteData(pOom, pDb1, pData, i, &rc); } testOomEnable(pOom, 1); assert( rc==0 ); /* Insert 10 more records using pDb1. Stop when an OOM is encountered. */ for(i=nRecord; i<nRecord+nIns; i++){ testOomWriteData(pOom, pDb1, pData, i, &rc); if( rc ) break; } testOomAssertRc(pOom, rc); /* Switch off OOM injection. Write a few rows using pDb2. Then check ** that the database may be successfully queried. */ testOomEnable(pOom, 0); rc = 0; for(; i<nRecord+nIns && rc==0; i++){ testOomWriteData(pOom, pDb2, pData, i, &rc); } for(i=0; i<nRecord+nIns; i++) testOomFetchData(pOom, pDb2, pData, i, &rc); testOomEnable(pOom, 1); lsm_close(pDb1); lsm_close(pDb2); testDatasourceFree(pData); }
static void do_test_api1(const char *zPattern, int *pRc){ if( testCaseBegin(pRc, zPattern, "api1.lsm") ){ const DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 200, 250 }; Datasource *pData; TestDb *pDb; int rc = 0; pDb = testOpen("lsm_lomem", 1, &rc); pData = testDatasourceNew(&defn); testWriteDatasourceRange(pDb, pData, 0, 1000, pRc); do_test_api1_lsm(tdb_lsm(pDb), pRc); testDatasourceFree(pData); testClose(&pDb); testCaseFinish(*pRc); } }
static void doDataTest4( const char *zSystem, /* Database system to test */ Datatest4 *p, /* Structure containing test parameters */ int *pRc /* OUT: Error code */ ){ lsm_db *db = 0; TestDb *pDb; TestDb *pControl; Datasource *pData; int i; int rc = 0; int iDot = 0; int bMultiThreaded = 0; /* True for MT LSM database */ int nRecOn3 = (p->nRec / 3); int iData = 0; /* Start the test case, open a database and allocate the datasource. */ rc = testControlDb(&pControl); pDb = testOpen(zSystem, 1, &rc); pData = testDatasourceNew(&p->defn); if( rc==0 ){ db = tdb_lsm(pDb); bMultiThreaded = tdb_lsm_multithread(pDb); } testWriteDatasourceRange(pControl, pData, iData, nRecOn3*3, &rc); testWriteDatasourceRange(pDb, pData, iData, nRecOn3*3, &rc); for(i=0; rc==0 && i<p->nRepeat; i++){ testDeleteDatasourceRange(pControl, pData, iData, nRecOn3*2, &rc); testDeleteDatasourceRange(pDb, pData, iData, nRecOn3*2, &rc); if( db ){ int nDone; #if 0 fprintf(stderr, "lsm_work() start...\n"); fflush(stderr); #endif do { nDone = 0; rc = lsm_work(db, 1, (1<<30), &nDone); }while( rc==0 && nDone>0 ); if( bMultiThreaded && rc==LSM_BUSY ) rc = LSM_OK; #if 0 fprintf(stderr, "lsm_work() done...\n"); fflush(stderr); #endif } if( i+1<p->nRepeat ){ iData += (nRecOn3*2); testWriteDatasourceRange(pControl, pData, iData+nRecOn3, nRecOn3*2, &rc); testWriteDatasourceRange(pDb, pData, iData+nRecOn3, nRecOn3*2, &rc); testCompareDb(pData, nRecOn3*3, iData, pControl, pDb, &rc); /* If Datatest4.bReopen is true, close and reopen the database */ if( p->bReopen ){ testReopen(&pDb, &rc); if( rc==0 ) db = tdb_lsm(pDb); } } /* Update the progress dots... */ testCaseProgress(i, p->nRepeat, testCaseNDot(), &iDot); } testClose(&pDb); testClose(&pControl); testDatasourceFree(pData); testCaseFinish(rc); *pRc = rc; }