Changeset 217

Show
Ignore:
Timestamp:
02/07/07 21:35:35 (1 year ago)
Author:
ug
Message:

Split up database into 3 files to allow for faster start-up.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/cpptest.cpp

    r214 r217  
    2929    gl.start_processing(); 
    3030    directory_iterator end_itr; 
    31     string path = "/home/ug/go/kombilo/06/libkombilo"; 
     31    // string path = "/home/ug/go/kombilo/06/libkombilo"; 
    3232    // string path = "/home/ug/go/gtl/reviews"; 
    33     // string path = "/home/ug/go/gogod06/1999"; 
     33    string path = "/home/ug/go/gogod06/2000"; 
    3434    for(directory_iterator it(path); it != end_itr; ++it) { 
    3535      string n = it->string(); 
  • 06/libkombilo/process.py

    r212 r217  
    1010 
    1111try:  
    12     os.system('rm t1.db') 
     12    os.system('rm t1.db*') 
    1313except:  
    1414    pass 
     
    4545    print 'Processed %d games in %.2f seconds' % (counter, time.time()-starttime) 
    4646 
    47 filelist = glob.glob('./*.sgf') 
    48 # filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 
     47# filelist = glob.glob('./*.sgf') 
     48filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 
    4949# filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 
    5050 
  • 06/libkombilo/search.cpp

    r216 r217  
    969969 
    970970void Algo_finalpos::initialize_process(sqlite3* DB) throw(DBError) { 
     971  // printf("init Algo_finalpos\n"); 
    971972  db = DB; 
    972973  char sql[100]; 
    973974  sprintf(sql, "create table if not exists algo_finalpos_%d ( id integer primary key, data blob );", boardsize); 
    974975  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    975   if (rc != SQLITE_OK) throw DBError(); 
     976  if (rc != SQLITE_OK) { 
     977    printf("error %d\n", rc); 
     978    throw DBError(); 
     979  } 
     980  // printf("init Algo_finalpos\n"); 
    976981} 
    977982 
     
    10301035  } 
    10311036  data = new vector<char* >; 
     1037  int rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 
     1038  if (rc) throw DBError(); 
    10321039  sqlite3_stmt *ppStmt=0; 
    10331040  char sql[100]; 
    10341041  sprintf(sql, "select data from algo_finalpos_%d order by id", boardsize); 
    1035   int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
     1042  rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    10361043  if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 
    10371044  while (sqlite3_step(ppStmt) == SQLITE_ROW) { 
     
    10481055  rc = sqlite3_finalize(ppStmt); 
    10491056  if (rc != SQLITE_OK) return rc; 
     1057  rc = sqlite3_exec(db, "commit;", 0, 0, 0); 
     1058  if (rc != SQLITE_OK) throw DBError(); 
    10501059  return 0; 
    10511060} 
     
    12071216 
    12081217void Algo_movelist::initialize_process(sqlite3* DB) throw(DBError) { 
     1218  // printf("init Algo_movelist\n"); 
    12091219  db = DB; 
    12101220  char sql[100]; 
     
    12121222  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    12131223  if (rc != SQLITE_OK) throw DBError(); 
     1224  // printf("init Algo_movelist\n"); 
    12141225}                                          
    12151226 
     
    13221333  db = DB; 
    13231334 
     1335  int rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 
     1336  if (rc) throw DBError(); 
     1337 
    13241338  sqlite3_stmt *ppStmt=0; 
    13251339  char sql[100]; 
    13261340  sprintf(sql, "select movelist,fpC from algo_movelist_%d order by id", boardsize); 
    1327   int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
     1341  rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    13281342  if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 
    13291343  while (sqlite3_step(ppStmt) == SQLITE_ROW) { 
     
    13491363  if (rc != SQLITE_OK) return rc; 
    13501364 
     1365  rc = sqlite3_exec(db, "commit;", 0, 0, 0); 
     1366  if (rc != SQLITE_OK) throw DBError(); 
    13511367  // printf("data sizes %d, %d, %d\n", data1->size(), data1l->size(), data2->size()); 
    13521368  return 0; 
     
    33653381  labels = 0; 
    33663382  continuations = 0; 
    3367   dbname = new char[strlen(DBNAME)+1]; 
     3383  dbname = new char[strlen(DBNAME)+2]; 
    33683384  strcpy(dbname, DBNAME); 
     3385  db = algo_db1 = algo_db2 = 0; 
     3386 
     3387  dbname[strlen(DBNAME)] = '1'; 
     3388  dbname[strlen(DBNAME)+1] = 0; 
     3389  int rc = sqlite3_open(dbname, &algo_db1);  
     3390  if (rc) { 
     3391    sqlite3_close(algo_db1); 
     3392    algo_db1 = 0; 
     3393    throw DBError(); 
     3394  } 
     3395  rc = sqlite3_busy_timeout(algo_db1, 200); 
     3396  if (rc) throw DBError(); 
     3397  rc = sqlite3_exec(algo_db1, "pragma synchronous = off;", 0, 0, 0); 
     3398  if (rc) throw DBError(); 
     3399  rc = sqlite3_exec(algo_db1, "pragma cache_size = 100000;", 0, 0, 0); 
     3400  if (rc) throw DBError(); 
     3401  dbname[strlen(DBNAME)] = '2'; 
     3402  dbname[strlen(DBNAME)+1] = 0; 
     3403  rc = sqlite3_open(dbname, &algo_db2);  
     3404  if (rc) { 
     3405    sqlite3_close(algo_db2); 
     3406    algo_db2 = 0; 
     3407    throw DBError(); 
     3408  } 
     3409  rc = sqlite3_busy_timeout(algo_db2, 200); 
     3410  if (rc) throw DBError(); 
     3411  rc = sqlite3_exec(algo_db2, "pragma synchronous = off;", 0, 0, 0); 
     3412  if (rc) throw DBError(); 
     3413  rc = sqlite3_exec(algo_db2, "pragma cache_size = 700000;", 0, 0, 0); 
     3414  if (rc) throw DBError(); 
    33693415 
    33703416  // try to retrieve basic options from database 
    3371   int rc = sqlite3_open(dbname, &db);  
     3417  dbname[strlen(DBNAME)] = 0; 
     3418  rc = sqlite3_open(dbname, &db);  
    33723419  if (rc) { 
    33733420    sqlite3_close(db); 
     
    33793426  rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
    33803427  if (rc) throw DBError(); 
    3381   rc = sqlite3_exec(db, "pragma cache_size = 700000;", 0, 0, 0); 
     3428  rc = sqlite3_exec(db, "pragma cache_size = 100000;", 0, 0, 0); 
    33823429  if (rc) throw DBError(); 
    33833430 
     
    34233470    if (rc != SQLITE_OK) throw DBError(); 
    34243471  } 
    3425   // rc = sqlite3_close(db); 
    3426   // if (rc != SQLITE_OK) throw DBError(); 
    3427   // db = 0; 
    3428  
    34293472 
    34303473  // printf("set up Algorithm instances\n"); 
     
    34823525  int ctr = algo_ps.size()/20; 
    34833526  // printf("add algos %d %d %d\n", bs, ctr, p_op->algos); 
    3484   for(int i=0; i<20; i++) algo_ps.push_back(0); 
     3527  for(int i=0; i<20; i++) { 
     3528    algo_ps.push_back(0); 
     3529    algo_dbs.push_back(0); 
     3530  } 
    34853531 
    34863532  algo_ps[20*ctr] = new Algo_signature(bs); 
    3487   if (p_op->algos & ALGO_FINALPOS)  
     3533  algo_dbs[20*ctr] = db; 
     3534  if (p_op->algos & ALGO_FINALPOS) { 
    34883535    algo_ps[algo_finalpos+20*ctr] = new Algo_finalpos(bs); 
    3489   if (p_op->algos & ALGO_MOVELIST)  
     3536    algo_dbs[algo_finalpos+20*ctr] = algo_db1; 
     3537  } 
     3538  if (p_op->algos & ALGO_MOVELIST) { 
    34903539    algo_ps[algo_movelist+20*ctr] = new Algo_movelist(bs); 
    3491   if (p_op->algos & ALGO_HASH_FULL)  
     3540    algo_dbs[algo_movelist+20*ctr] = algo_db1; 
     3541  } 
     3542  if (p_op->algos & ALGO_HASH_FULL) { 
    34923543    algo_ps[algo_hash_full+20*ctr] = new Algo_hash_full(bs, p_op->algo_hash_corner_maxNumStones); 
    3493   if (p_op->algos & ALGO_HASH_CORNER)  
     3544    algo_dbs[algo_hash_full+20*ctr] = algo_db2; 
     3545  } 
     3546  if (p_op->algos & ALGO_HASH_CORNER) { 
    34943547    algo_ps[algo_hash_corner+20*ctr] = new Algo_hash_corner(bs, 7, p_op->algo_hash_corner_maxNumStones); 
     3548    algo_dbs[algo_hash_corner+20*ctr] = algo_db2; 
     3549  } 
    34953550  // for(int a=20*ctr; a<20*(ctr+1); a++) printf("aa %d %p\n", a, algo_ps[a]); 
    34963551  // if (algos & ALGO_HASH_SIDE)  
     
    35133568   
    35143569  int rc; 
    3515   // db = 0; 
    3516   // rc = sqlite3_open(dbname, &db); 
    3517   // if (rc) { 
    3518   //   fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); 
    3519   //   sqlite3_close(db); 
    3520   //   db = 0; 
    3521   //   throw DBError(); 
    3522   // } 
    35233570  rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 
    35243571  if (rc) throw DBError(); 
     
    35383585   
    35393586  readPlayersList(); 
     3587  rc = sqlite3_exec(db, "commit;", 0, 0, 0); 
     3588  if (rc != SQLITE_OK) throw DBError(); 
    35403589 
    35413590  if (rc == SQLITE_OK && !readDBs) { 
    35423591    for(unsigned int a=0; a < 20*boardsizes.size(); a++) { 
    3543       if (algo_ps[a]) algo_ps[a]->readDB(db); 
     3592      if (algo_ps[a]) algo_ps[a]->readDB(algo_dbs[a]); 
    35443593    } 
    35453594    readDBs = 1; 
    35463595  } 
    3547   rc = sqlite3_exec(db, "commit;", 0, 0, 0); 
    3548   if (rc != SQLITE_OK) throw DBError(); 
    35493596  // printf("read.\n"); 
    35503597 
    3551   // rc = sqlite3_close(db); 
    3552   // if (rc != SQLITE_OK) throw DBError(); 
    3553   // db = 0; 
    35543598  reset(); 
    35553599  // printf("leave readDB\n"); 
     
    37933837 
    37943838void GameList::gisearch(char* sql, int complete) throw(DBError) { 
    3795   bool dbWasOpen = false; 
    3796   if (!db) { 
    3797     int rc = sqlite3_open(dbname, &db); 
    3798     if (rc) { 
    3799       sqlite3_close(db); 
    3800       db = 0; 
    3801       throw DBError(); 
    3802     } 
    3803   } else dbWasOpen = true; 
    38043839  if (start_sorted() == 0) {  
    3805     if (!dbWasOpen) { 
    3806       int rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
    3807       if (rc) throw DBError(); 
    3808       rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0); 
    3809       if (rc) throw DBError(); 
    3810     } 
    38113840    string query; 
    38123841    if (!complete) query = "select id from games where "; 
     
    38173846    if( rc!=SQLITE_OK ) throw DBError(); 
    38183847 
    3819     if (!dbWasOpen) { 
    3820       rc = sqlite3_close(db); 
    3821       if( rc!=SQLITE_OK ) throw DBError(); 
    3822       db = 0; 
    3823     } 
    38243848    end_sorted(); 
    38253849  } 
     
    38973921  } 
    38983922  int index = (*all)[(*currentList)[i].second]->id; 
    3899   // int rc = sqlite3_open(dbname, &db);  
    3900   // if (rc) { 
    3901   //   sqlite3_close(db); 
    3902   //   db = 0; 
    3903   //   throw DBError(); 
    3904   // } 
    39053923  char* prop = 0; 
    39063924  char sql[200]; 
     
    39093927  int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 
    39103928  if (rc != SQLITE_OK) throw DBError(); 
    3911   // sqlite3_close(db); 
    3912   // db = 0; 
    39133929 
    39143930  if (!prop) return ""; 
     
    39293945  } 
    39303946  int index = (*all)[(*currentList)[i].second]->id; 
    3931   // int rc = sqlite3_open(dbname, &db);  
    3932   // if (rc) { 
    3933   //   sqlite3_close(db); 
    3934   //   db = 0; 
    3935   //   throw DBError(); 
    3936   // } 
    39373947  char* prop = 0; 
    39383948  char sql[200]; 
     
    39413951  int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 
    39423952  if (rc != SQLITE_OK) throw DBError(); 
    3943   // sqlite3_close(db); 
    3944   // db = 0; 
    39453953 
    39463954  if (!prop) return ""; 
     
    39563964  sizeX = pattern.sizeX; // need this in lookupLabel 
    39573965  PatternList pl(pattern, searchOptions->fixedColor, searchOptions->nextMove); 
    3958   // int rc = sqlite3_open(dbname, &db);  
    3959   // if (rc) { 
    3960   //   sqlite3_close(db); 
    3961   //   db = 0; 
    3962   //   throw DBError(); 
    3963   // } 
    3964   // rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
    3965   // if (rc) throw DBError(); 
    3966   // rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0); 
    3967   // if (rc) throw DBError(); 
    39683966 
    39693967  if (boardsizes.size() != 1 || boardsizes[0] != pattern.boardsize) { 
     
    39733971  } 
    39743972  if (!readDBs) { 
    3975     for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->readDB(db); 
     3973    for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->readDB(algo_dbs[a]); 
    39763974    readDBs = 1; 
    39773975  } 
     
    39803978  // FULL BOARD PATTERN? 
    39813979  if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX == pattern.boardsize && pattern.sizeY == pattern.boardsize && algo_ps[algo_hash_full]) { 
    3982     hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full])->search(pl, *this, *searchOptions, db); 
     3980    hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_full]); 
    39833981    if (hash_result == 1) { 
    39843982    } else if (hash_result == 0) { 
     
    39913989    // CORNER PATTERN? 
    39923990    if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX >= 7 && pattern.sizeY >= 7 && algo_ps[algo_hash_corner]) { 
    3993       hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner])->search(pl, *this, *searchOptions, db); 
     3991      hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_corner]); 
    39943992      if (hash_result == 0) { 
    39953993        if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist]) 
     
    40054003    } 
    40064004  } 
    4007   // sqlite3_close(db); 
    4008   // db = 0; 
    40094005  if (labels) delete [] labels; 
    40104006  labels = pl.sortContinuations(); 
     
    41204116 
    41214117  int rc; 
    4122   // rc = sqlite3_open(dbname, &db);  
    4123   // if (rc) { 
    4124   //   sqlite3_close(db); 
    4125   //   db = 0; 
    4126   //   throw DBError(); 
    4127   // } 
    4128   // rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
    4129   // if (rc) throw DBError(); 
    4130   // rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0); 
    4131   // if (rc) throw DBError(); 
    41324118 
    41334119  createGamesDB(); 
     
    41354121  char* sql = "begin transaction;"; 
    41364122  rc = sqlite3_exec(db, sql, 0, 0, 0); 
    4137   if (rc) throw DBError(); 
     4123  if (rc) { throw DBError(); } 
     4124  rc = sqlite3_exec(algo_db1, sql, 0, 0, 0); 
     4125  if (rc) { throw DBError(); } 
     4126  rc = sqlite3_exec(algo_db2, sql, 0, 0, 0); 
     4127  if (rc) { throw DBError(); } 
    41384128  current = 0; 
    4139   for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->initialize_process(db); 
     4129  for(unsigned int a=0; a < 20*boardsizes.size(); a++) { 
     4130    if (algo_ps[a]) algo_ps[a]->initialize_process(algo_dbs[a]); 
     4131  } 
    41404132} 
    41414133 
     
    41474139    sqlite3_close(db); 
    41484140    db = 0; 
     4141    throw DBError(); 
     4142  } 
     4143  rc = sqlite3_exec(algo_db1, "commit;", 0, 0, 0); 
     4144  if (rc != SQLITE_OK) { 
     4145    sqlite3_close(algo_db1); 
     4146    algo_db1 = 0; 
     4147    throw DBError(); 
     4148  } 
     4149  rc = sqlite3_exec(algo_db2, "commit;", 0, 0, 0); 
     4150  if (rc != SQLITE_OK) { 
     4151    sqlite3_close(algo_db2); 
     4152    algo_db2 = 0; 
    41494153    throw DBError(); 
    41504154  } 
     
    42234227        // printf("a %d\n", a); 
    42244228        // printf("%p\n", algo_ps[a]); 
    4225         if (algo_ps[a]) algo_ps[a]->initialize_process(db); 
     4229        if (algo_ps[a]) algo_ps[a]->initialize_process(algo_dbs[a]); 
    42264230      } 
    42274231    } 
  • 06/libkombilo/search.h

    r211 r217  
    574574    std::vector<int> boardsizes; 
    575575    std::vector<algo_p> algo_ps; 
     576    std::vector<sqlite3*> algo_dbs; 
    576577    std::vector<GameListEntry* > * all; 
    577578    std::vector<std::pair<int,int> > * currentList; // pair of game id and position within all 
     
    655656    int SGFtagsSize; 
    656657    int sizeX; // keeps track of width of search pattern during search 
     658    sqlite3* algo_db1; 
     659    sqlite3* algo_db2; 
    657660    ProcessOptions* p_op; 
    658661    std::vector<std::string>* SGFtags; 
  • 06/libkombilo/testsearch.py

    r216 r217  
    1414# print gl.size(), 'games in the database' 
    1515 
    16 p = Pattern(CORNER_SW_PATTERN, 19, 7, 7, '........................X........................') 
     16# p = Pattern(CENTER_PATTERN, 19, 3,4,"..O.....OX..") 
     17# p = Pattern(CORNER_SW_PATTERN, 19, 7, 7, '........................X........................') 
    1718# p = Pattern(CENTER_PATTERN, 19, 3, 3, '.X.XXXXOX') 
    18 # p = Pattern(CENTER_PATTERN, 19, 3, 5, '.X.' + '.OX' + '.OX' + '.OX' + 'OXO')  
     19p = Pattern(CENTER_PATTERN, 19, 3, 5, '.X.' + '.OX' + '.OX' + '.OX' + 'OXO')  
    1920# p = Pattern(CENTER_PATTERN, 19, 5, 4, '..XOO'+ '...XX'+ '.....'+ '..X..')  
    2021so = SearchOptions()