/* ** 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 testPagesize(lsm_db *db, int nPgsz, int nBlksz, int *pRc){ if( *pRc==0 ){ int n1 = 0; int n2 = 0; lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1); lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2); testCompareInt(n1, nPgsz, pRc); testCompareInt(n2, nBlksz, pRc); } }
static lsm_db *newLsmConnection( const char *zDb, int nPgsz, int nBlksz, int *pRc ){ lsm_db *db = 0; if( *pRc==0 ){ int n1 = nPgsz; int n2 = nBlksz; *pRc = lsm_new(tdb_lsm_env(), &db); if( *pRc==0 ){ if( n1 ) lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1); if( n2 ) lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2); *pRc = lsm_open(db, "testdb.lsm"); } } return db; }
static int testConfigureSetFactory( Tcl_Interp *interp, lsm_db *db, Tcl_Obj *pArg ){ lsm_compress_factory aFactory[2] = { { 0, 0, 0 }, { 0, testCompressFactory, 0 }, }; int bArg = 0; int rc; rc = Tcl_GetBooleanFromObj(interp, pArg, &bArg); if( rc!=TCL_OK ) return rc; assert( bArg==1 || bArg==0 ); rc = lsm_config(db, LSM_CONFIG_SET_COMPRESSION_FACTORY, &aFactory[bArg]); return rc; }
static int testConfigureSetCompression( Tcl_Interp *interp, lsm_db *db, Tcl_Obj *pCmp, unsigned int iId ){ struct CompressionScheme { const char *zName; lsm_compress cmp; } aCmp[] = { { "encrypt", { 0, 43, testCompressEncBound, testCompressEncCompress, testCompressEncUncompress, testCompressEncFree } }, { "rle", { 0, 44, testCompressRleBound, testCompressRleCompress, testCompressRleUncompress, testCompressRleFree } }, { "noop", { 0, 45, testCompressNoopBound, testCompressNoopCompress, testCompressNoopUncompress, testCompressNoopFree } }, { 0, {0, 0, 0, 0, 0, 0} } }; int iOpt; int rc; if( interp ){ rc = Tcl_GetIndexFromObjStruct( interp, pCmp, aCmp, sizeof(aCmp[0]), "scheme", 0, &iOpt ); if( rc!=TCL_OK ) return rc; }else{ int nOpt = sizeof(aCmp)/sizeof(aCmp[0]); for(iOpt=0; iOpt<nOpt; iOpt++){ if( iId==aCmp[iOpt].cmp.iId ) break; } if( iOpt==nOpt ) return 0; } rc = lsm_config(db, LSM_CONFIG_SET_COMPRESSION, &aCmp[iOpt].cmp); return rc; }
/* ** Array apObj[] is an array of nObj Tcl objects intended to be transformed ** into lsm_config() calls on database db. ** ** Each pair of objects in the array is treated as a key/value pair used ** as arguments to a single lsm_config() call. If there are an even number ** of objects in the array, then the interpreter result is set to the output ** value of the final lsm_config() call. Or, if there are an odd number of ** objects in the array, the final object is treated as the key for a ** read-only call to lsm_config(), the return value of which is used as ** the interpreter result. For example, the following: ** ** { safety 1 mmap 0 use_log } ** ** Results in a sequence of calls similar to: ** ** iVal = 1; lsm_config(db, LSM_CONFIG_SAFETY, &iVal); ** iVal = 0; lsm_config(db, LSM_CONFIG_MMAP, &iVal); ** iVal = -1; lsm_config(db, LSM_CONFIG_USE_LOG, &iVal); ** Tcl_SetObjResult(interp, Tcl_NewIntObj(iVal)); */ static int testConfigureLsm( Tcl_Interp *interp, lsm_db *db, int nObj, Tcl_Obj *const* apObj ){ struct Lsmconfig { const char *zOpt; int eOpt; int bInteger; } aConfig[] = { { "autoflush", LSM_CONFIG_AUTOFLUSH, 1 }, { "page_size", LSM_CONFIG_PAGE_SIZE, 1 }, { "block_size", LSM_CONFIG_BLOCK_SIZE, 1 }, { "safety", LSM_CONFIG_SAFETY, 1 }, { "autowork", LSM_CONFIG_AUTOWORK, 1 }, { "autocheckpoint", LSM_CONFIG_AUTOCHECKPOINT, 1 }, { "mmap", LSM_CONFIG_MMAP, 1 }, { "use_log", LSM_CONFIG_USE_LOG, 1 }, { "automerge", LSM_CONFIG_AUTOMERGE, 1 }, { "max_freelist", LSM_CONFIG_MAX_FREELIST, 1 }, { "multi_proc", LSM_CONFIG_MULTIPLE_PROCESSES, 1 }, { "set_compression", LSM_CONFIG_SET_COMPRESSION, 0 }, { "set_compression_factory", LSM_CONFIG_SET_COMPRESSION_FACTORY, 0 }, { "readonly", LSM_CONFIG_READONLY, 1 }, { 0, 0, 0 } }; int i; int rc = TCL_OK; for(i=0; rc==TCL_OK && i<nObj; i+=2){ int iOpt; rc = Tcl_GetIndexFromObjStruct( interp, apObj[i], aConfig, sizeof(aConfig[0]), "option", 0, &iOpt ); if( rc==TCL_OK ){ if( i==(nObj-1) ){ Tcl_ResetResult(interp); if( aConfig[iOpt].bInteger ){ int iVal = -1; lsm_config(db, aConfig[iOpt].eOpt, &iVal); Tcl_SetObjResult(interp, Tcl_NewIntObj(iVal)); } }else{ if( aConfig[iOpt].eOpt==LSM_CONFIG_SET_COMPRESSION ){ rc = testConfigureSetCompression(interp, db, apObj[i+1], 0); } else if( aConfig[iOpt].eOpt==LSM_CONFIG_SET_COMPRESSION_FACTORY ){ rc = testConfigureSetFactory(interp, db, apObj[i+1]); } else { int iVal; rc = Tcl_GetIntFromObj(interp, apObj[i+1], &iVal); if( rc==TCL_OK ){ lsm_config(db, aConfig[iOpt].eOpt, &iVal); } Tcl_SetObjResult(interp, Tcl_NewIntObj(iVal)); } } } } return rc; }