int open_db(char *addr, int port, TCRDB **rdb) { int ecode=0; if (*rdb != NULL) { if(!tcrdbclose(*rdb)){ ecode = tcrdbecode(*rdb); fprintf(stderr, "close error: %s\n", tcrdberrmsg(ecode)); } tcrdbdel(*rdb); *rdb = NULL; } *rdb = tcrdbnew(); if(!tcrdbopen(*rdb, addr, port)){ ecode = tcrdbecode(*rdb); fprintf(stderr, "open error(%s:%d): %s\n", addr, port, tcrdberrmsg(ecode)); *rdb = NULL; } else { char *status = tcrdbstat(*rdb); printf("adding indices\n---------------------\n"); tcrdbtblsetindex(*rdb, "x", RDBITDECIMAL); tcrdbtblsetindex(*rdb, "y", RDBITDECIMAL); printf("%s---------------------\n", status); if (status) free(status); } return ecode; }
int tt_put(char * key,char * zv,int nv,value_t vt) { int ecode; int rt = 0; int nk = strlen(key); TCRDB * rdb = tcrdbnew(); int db_port = get_db_port(vt); printf("db_port -- %d\n",db_port); if(!tcrdbopen(rdb,LOCALHOST,db_port)) { ecode = tcrdbecode(rdb); fprintf(stderr,"tt_put:open %s error -- %s\n",db_port,tcrdberrmsg(ecode)); rt = 1; } else { printf("db open success!\n"); if(!tcrdbput(rdb,key,nk,zv,nv)) { ecode = tcrdbecode(rdb); fprintf(stderr,"(key=%s) tt_put error:%s\n",key,tcrdberrmsg(ecode)); rt = 2; } else { printf("(key=%s) tt_put success!\n",key); } } tcrdbdel(rdb); return rt; }
char *iod_get(char *key,int *nv) { int ecode; int nk = strlen(key); char *value; TCRDB * rdb = tcrdbnew(); int db_port = get_db_port(IO_DATA); printf("db_port -- %d\n",db_port); if(!tcrdbopen(rdb,LOCALHOST,db_port)) { ecode = tcrdbecode(rdb); fprintf(stderr,"iod_get:open %s error -- %s\n",db_port,tcrdberrmsg(ecode)); return NULL; }else{ printf("db open success!\n"); if((value = tcrdbget(rdb,key,nk,nv)) == NULL) { ecode = tcrdbecode(rdb); fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode)); return NULL; }else{ printf("(key=%s) tt_get success!\n",key); printf("%d bytes read\n",*nv); } } tcrdbdel(rdb); return value; }
static void tt_open_db (void) { char* host = NULL; int port = DEFAULT_PORT; if (rdb != NULL) return; host = ((config_host != NULL) ? config_host : DEFAULT_HOST); if (config_port != NULL) { port = parse_service_name (config_port); if (port <= 0) return; } rdb = tcrdbnew (); if (rdb == NULL) return; else if (!tcrdbopen(rdb, host, port)) { printerr (); tcrdbdel (rdb); rdb = NULL; } } /* void tt_open_db */
static VALUE mTokyoMessenger_reconnect(VALUE vself){ TCRDB *db = mTokyoMessenger_getdb(vself); if(db->fd != -1) mTokyoMessenger_close(vself); db = tcrdbnew(); rb_iv_set(vself, RDBVNDATA, Data_Wrap_Struct(rb_cObject, 0, mTokyoMessenger_free, db)); return mTokyoMessenger_connect(vself); }
/*- db_obj_remote -*/ db_obj_remote::db_obj_remote(const std::string &host, const int &port, const std::string &path) :db_obj(),_host(host),_port(port),_path(path) { #if defined(TT) _hdb = tcrdbnew(); #endif }
static int rdb_open(lua_State *L){ const char *host = luaL_optstring(L, 1, "localhost"); int port = luaL_optint(L, 2, 1978); RDBDATA *data = lua_newuserdata(L, sizeof(*data)); if(!data) return default_error(L); data->rdb = tcrdbnew(); if(!tcrdbopen(data->rdb, host, port)) return rdb_error(L, data->rdb); data->is_open = true; luaL_getmetatable(L, MT_NAME); lua_setmetatable(L, -2); return 1; }
TTClient::TTClient(string serverList){ tcrdbPtr_ = tcrdbnew(); vector<string> servers; split(servers, serverList, is_any_of(","), token_compress_on); for(size_t i = 0; i < servers.size(); i++){ string server = servers[i]; size_t p = server.find(":"); if(p != string::npos){ string ip = server.substr(0, p); string portStr = server.substr(p+1); short port = boost::lexical_cast<short>(portStr); serverList_.push_back(make_pair(ip, port)); } } LOG_INFO("TTClient::TTClient => Created : serverList = " << serverList); }
TCRDB* MemCacheServerHandler::GetDB(int id) { TCRDB* pResult = (TCRDB*) (m_xConnList[id]); if (pResult == NULL) { pResult = tcrdbnew(); std::string ip = m_xIpList[id]; int port = m_xProtList[id]; if (tcrdbopen(pResult, ip.c_str() ,port )) { m_xConnList[id] = pResult; } } return pResult; }
static VALUE mTokyoMessenger_initialize(int argc, VALUE *argv, VALUE vself){ VALUE host, port, timeout, retry; TCRDB *db; rb_scan_args(argc, argv, "04", &host, &port, &timeout, &retry); if(NIL_P(host)) host = rb_str_new2("127.0.0.1"); if(NIL_P(port)) port = INT2FIX(1978); if(NIL_P(timeout)) timeout = rb_float_new(0.0); if(NIL_P(retry)) retry = Qfalse; rb_iv_set(vself, "@host", host); rb_iv_set(vself, "@port", port); rb_iv_set(vself, "@timeout", timeout); rb_iv_set(vself, "@retry", retry); db = tcrdbnew(); rb_iv_set(vself, RDBVNDATA, Data_Wrap_Struct(rb_cObject, 0, mTokyoMessenger_free, db)); return mTokyoMessenger_connect(vself); }
int tt_get(char * key,char * zv,value_t vt) { int ecode; int nv; int rt = 0; int nk = strlen(key); char * value; TCRDB * rdb = tcrdbnew(); int db_port = get_db_port(vt); printf("db_port -- %d\n",db_port); if(!tcrdbopen(rdb,LOCALHOST,db_port)) { ecode = tcrdbecode(rdb); fprintf(stderr,"tt_get:open %s error -- %s\n",db_port,tcrdberrmsg(ecode)); rt = 1; } else { printf("db open success!\n"); if((value = tcrdbget(rdb,key,nk,&nv)) == NULL) { ecode = tcrdbecode(rdb); fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode)); rt = 2; } else { printf("(key=%s) tt_get success!\n",key); printf("%d bytes read\n",nv); memcpy(zv,value,nv); free(value); } } tcrdbdel(rdb); return rt; }
void* xtcrdb_new() { return tcrdbnew(); }
void QStore::init(bool need_url_seen_db, const std::string &url_seen_server, bool need_html_db, const std::string &html_db_server, bool need_record_db, const std::string &record_db_server, bool need_media_db, const std::string &media_db_server) { if (need_url_seen_db) { url_seen_memc = memcached_create(NULL); url_seen_servers = memcached_servers_parse(url_seen_server.c_str()); if (url_seen_servers != NULL) { memcached_return_t rc = memcached_server_push(url_seen_memc, url_seen_servers); memcached_server_list_free(url_seen_servers); if (rc != MEMCACHED_SUCCESS) { LOG(FATAL) << "open url seen db " << url_seen_server << " fail " << memcached_strerror(url_seen_memc, rc); } } else { LOG(FATAL) << "url seen servers server config error " << url_seen_server; } } /* if (need_html_db) { get_host_port_from_server(html_db_server, 9860, html_db_host, html_db_port); html_db = tcrdbnew(); if(!tcrdbopen(html_db, html_db_host.c_str(), html_db_port)){ int ecode = tcrdbecode(html_db); LOG(FATAL) << "open html db " << html_db_server << " fail " << tcrdberrmsg(ecode); } else { LOG(INFO) << "open html db " << html_db_server << " okay"; } } */ if (need_html_db) { html_memc = memcached_create(NULL); html_servers = memcached_servers_parse(html_db_server.c_str()); if (html_servers != NULL) { memcached_return_t rc = memcached_server_push(html_memc, html_servers); memcached_server_list_free(html_servers); if (rc != MEMCACHED_SUCCESS) { LOG(FATAL) << "open html db " << html_db_server << " fail " << memcached_strerror(html_memc, rc); } } else { LOG(FATAL) << "html servers server config error " << html_db_server; } } if (need_record_db) { get_host_port_from_server(record_db_server, 9870, record_db_host, record_db_port); record_db = tcrdbnew(); if(!tcrdbopen(record_db, record_db_host.c_str(), record_db_port)){ int ecode = tcrdbecode(record_db); LOG(FATAL) << "open record db " << record_db_server << " fail " << tcrdberrmsg(ecode); } else { LOG(INFO) << "open record db " << record_db_server << " okay"; } } if (need_media_db) { get_host_port_from_server(media_db_server, 9880, media_db_host, media_db_port); media_db = tcrdbnew(); if(!tcrdbopen(media_db, media_db_host.c_str(), media_db_port)){ int ecode = tcrdbecode(media_db); LOG(FATAL) << "open media db " << media_db_server << " fail " << tcrdberrmsg(ecode); } else { LOG(INFO) << "open media db " << media_db_server << " okay"; } } }
int main(int argc, char **argv) { TCXSTR *pattern, *key_root; int ecode; bool verbose, test, create, extract, optimize, resume; int o; verbose = test = create = extract = optimize = resume = false; pattern = tcxstrnew(); key_root = tcxstrnew(); db_file = tcxstrnew(); tdb_host = tcxstrnew(); tdb_port = 0; while (-1 != (o = getopt(argc, argv, "cxtvrof:p:k:H:P:"))) { switch (o) { case 'f': use_cabinet_lib = true; tcxstrcat2(db_file, optarg); /* create the object */ hdb = tchdbnew(); break; case 'H': use_cabinet_lib = false; tcxstrcat2(tdb_host, optarg); tdb = tcrdbnew(); break; case 'P': tdb_port = strtol(optarg, NULL, 0); break; case 'k': tcxstrcat2(key_root, optarg); // add trailing slash if needed char *last_c; last_c = tcxstrptr(key_root) + tcxstrsize(key_root) - 1; if (*last_c != '/') { tcxstrcat2(key_root, "/"); } break; case 'p': tcxstrcat2(pattern, optarg); break; case 'v': verbose = true; break; case 't': test = true; break; case 'c': create = true; break; case 'x': extract = true; break; case 'r': resume = true; break; case 'o': optimize = true; case '?': default: break; } } if (!create && !extract) { fprintf(stdout, "No action specifed. Use -c to create DB and -x to extract files from dbfile.tch\n"); return 1; } if ((use_cabinet_lib && NULL == hdb) || (!use_cabinet_lib && NULL == tdb)) { fprintf(stdout, "No database specifed. Use -f dbfile.tch\n"); return 1; } if (0 == tcxstrsize(pattern)) { fprintf(stdout, "No pattern is given. Using *. Use -p <glob_pattern> to override\n"); tcxstrcat2(pattern, "*"); } if (create) { glob_t gtree; glob(tcxstrptr(pattern), GLOB_NOSORT, NULL, >ree); size_t found = gtree.gl_pathc; if (use_cabinet_lib && !open_cabinet_db((int64_t) found, optimize)) return 2; if (!use_cabinet_lib && !open_tyrant_db()) return 3; int i; for (i = 0; i < found; i++) { char * fname = gtree.gl_pathv[i]; if (verbose || test) fprintf(stdout, "\n%d of %d - packing file: %s ...", i, found, fname); if (!test) pack_file(fname, key_root, resume); } fprintf(stdout, "Finished. Processed %d items\n", (int) found); globfree(>ree); } else if (extract) { if (!open_cabinet_db(0, false)) return 2; int count; count = unpack_files(NULL, verbose, test); fprintf(stdout, "Finished. Processed %d items\n", count); } /* close the database */ close_db(); /* delete the objects */ tcxstrdel(pattern); tcxstrdel(key_root); return 0; }
void TTClient::reOpen(){ close(); tcrdbPtr_ = tcrdbnew(); open(); LOG_INFO("TTClient::reOpen => finish"); }
/* initialize */ JNIEXPORT void JNICALL Java_tokyotyrant_TCRDB_initialize(JNIEnv *env, jobject self){ TCRDB *tcrdb = tcrdbnew(); (*env)->SetLongField(env, self, tcrdb_fid_ptr, (intptr_t)tcrdb); }