/*
** 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 );
}
예제 #2
0
void TestLsmMainWindow::on_actionTest1_triggered()
{
    int rc;
    lsm_db *db;

    /* Allocate a new database handle */
    rc = lsm_new(0, &db);
    if( rc!=LSM_OK ) return;

//	rc = lsm_config(db, LSM_CONFIG_PAGE_SIZE,);
//	rc = lsm_config(db, LSM_CONFIG_BLOCK_SIZE, 1024);

    /* Connect the database handle to database "test.db" */
    rc = lsm_open(db, "d:\\test.db");
    if( rc!=LSM_OK ) return;

    lsm_insert(db, "testkey", 7, "testval", 7);
    lsm_insert(db, "testkey", 7, "testval", 7);
    lsm_insert(db, "testkey", 7, "testval", 7);
    lsm_insert(db, "testkey", 7, "testval", 7);

    lsm_cursor* csr;
    rc = lsm_csr_open(db, &csr);

    rc = lsm_csr_seek(csr, "testkey", 7, LSM_SEEK_EQ);
    if( lsm_csr_valid(csr) ) {
        const char *pVal;
        int nVal;

        rc = lsm_csr_value(csr, (const void **)&pVal, &nVal);
        if( rc==LSM_OK ) {
            QString test = QString::fromLatin1(pVal, nVal);
            qDebug(test.toLatin1().constData());
            /* pVal now points to a buffer nVal bytes in size containing the
            ** value associated with database key "b".  */
        }
    }

    lsm_csr_close(csr);

    rc = lsm_close(db);
}
static void testOomWrite(
  OomTest *pOom,
  lsm_db *pDb,
  void *pKey, int nKey,
  void *pVal, int nVal,
  int *pRc
){
  testOomAssertRc(pOom, *pRc);
  if( *pRc==LSM_OK ){
    int rc;

    rc = lsm_insert(pDb, pKey, nKey, pVal, nVal);
    testOomAssertRc(pOom, rc);

    *pRc = rc;
  }
}
static int lsmWriteStr(lsm_db *pDb, const char *zKey, const char *zVal){
  int nKey = strlen(zKey);
  int nVal = strlen(zVal);
  return lsm_insert(pDb, (void *)zKey, nKey, (void *)zVal, nVal);
}