?? db_server_cxxproc.cpp
字號:
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2001-2002 * Sleepycat Software. All rights reserved. */#include "db_config.h"#ifdef HAVE_RPC#ifndef lintstatic const char revid[] = "$Id: db_server_cxxproc.cpp,v 1.12 2002/08/09 01:56:08 bostic Exp $";#endif /* not lint */#ifndef NO_SYSTEM_INCLUDES#include <sys/types.h>#include <rpc/rpc.h>#include <string.h>#endif#include "dbinc_auto/db_server.h"#include "db_int.h"#include "db_cxx.h"extern "C" {#include "dbinc/db_server_int.h"#include "dbinc_auto/rpc_server_ext.h"}/* BEGIN __env_cachesize_proc */extern "C" void__env_cachesize_proc( long dbenvcl_id, u_int32_t gbytes, u_int32_t bytes, u_int32_t ncache, __env_cachesize_reply *replyp)/* END __env_cachesize_proc */{ DbEnv *dbenv; ct_entry *dbenv_ctp; int ret; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; ret = dbenv->set_cachesize(gbytes, bytes, ncache); replyp->status = ret; return;}/* BEGIN __env_close_proc */extern "C" void__env_close_proc( long dbenvcl_id, u_int32_t flags, __env_close_reply *replyp)/* END __env_close_proc */{ ct_entry *dbenv_ctp; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); replyp->status = __dbenv_close_int(dbenvcl_id, flags, 0); return;}/* BEGIN __env_create_proc */extern "C" void__env_create_proc( u_int32_t timeout, __env_create_reply *replyp)/* END __env_create_proc */{ DbEnv *dbenv; ct_entry *ctp; ctp = new_ct_ent(&replyp->status); if (ctp == NULL) return; dbenv = new DbEnv(DB_CXX_NO_EXCEPTIONS); ctp->ct_envp = dbenv; ctp->ct_type = CT_ENV; ctp->ct_parent = NULL; ctp->ct_envparent = ctp; __dbsrv_settimeout(ctp, timeout); __dbsrv_active(ctp); replyp->envcl_id = ctp->ct_id; replyp->status = 0; return;}/* BEGIN __env_dbremove_proc */extern "C" void__env_dbremove_proc( long dbenvcl_id, long txnpcl_id, char *name, char *subdb, u_int32_t flags, __env_dbremove_reply *replyp)/* END __env_dbremove_proc */{ int ret; DbEnv *dbenv; DbTxn *txnp; ct_entry *dbenv_ctp, *txnp_ctp; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; if (txnpcl_id != 0) { ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DbTxn *)txnp_ctp->ct_anyp; } else txnp = NULL; ret = dbenv->dbremove(txnp, name, subdb, flags); replyp->status = ret; return;}/* BEGIN __env_dbrename_proc */void__env_dbrename_proc( long dbenvcl_id, long txnpcl_id, char *name, char *subdb, char *newname, u_int32_t flags, __env_dbrename_reply *replyp)/* END __env_dbrename_proc */{ int ret; DbEnv *dbenv; DbTxn *txnp; ct_entry *dbenv_ctp, *txnp_ctp; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; if (txnpcl_id != 0) { ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DbTxn *)txnp_ctp->ct_anyp; } else txnp = NULL; ret = dbenv->dbrename(txnp, name, subdb, newname, flags); replyp->status = ret; return;}/* BEGIN __env_encrypt_proc */extern "C" void__env_encrypt_proc( long dbenvcl_id, char *passwd, u_int32_t flags, __env_encrypt_reply *replyp)/* END __env_encrypt_proc */{ DbEnv *dbenv; ct_entry *dbenv_ctp; int ret; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; ret = dbenv->set_encrypt(passwd, flags); replyp->status = ret; return;}/* BEGIN __env_flags_proc */extern "C" void__env_flags_proc( long dbenvcl_id, u_int32_t flags, u_int32_t onoff, __env_flags_reply *replyp)/* END __env_flags_proc */{ DbEnv *dbenv; ct_entry *dbenv_ctp; int ret; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; ret = dbenv->set_flags(flags, onoff); if (onoff) dbenv_ctp->ct_envdp.onflags = flags; else dbenv_ctp->ct_envdp.offflags = flags; replyp->status = ret; return;}/* BEGIN __env_open_proc */extern "C" void__env_open_proc( long dbenvcl_id, char *home, u_int32_t flags, u_int32_t mode, __env_open_reply *replyp)/* END __env_open_proc */{ DbEnv *dbenv; ct_entry *dbenv_ctp, *new_ctp; u_int32_t newflags, shareflags; int ret; home_entry *fullhome; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; fullhome = get_home(home); if (fullhome == NULL) { ret = DB_NOSERVER_HOME; goto out; } /* * If they are using locking do deadlock detection for them, * internally. */ if ((flags & DB_INIT_LOCK) && (ret = dbenv->set_lk_detect(DB_LOCK_DEFAULT)) != 0) goto out; if (__dbsrv_verbose) { dbenv->set_errfile(stderr); dbenv->set_errpfx(fullhome->home); } /* * Mask off flags we ignore */ newflags = (flags & ~DB_SERVER_FLAGMASK); shareflags = (newflags & DB_SERVER_ENVFLAGS); /* * Check now whether we can share a handle for this env. */ replyp->envcl_id = dbenvcl_id; if ((new_ctp = __dbsrv_shareenv(dbenv_ctp, fullhome, shareflags)) != NULL) { /* * We can share, clean up old ID, set new one. */ if (__dbsrv_verbose) printf("Sharing env ID %ld\n", new_ctp->ct_id); replyp->envcl_id = new_ctp->ct_id; ret = __dbenv_close_int(dbenvcl_id, 0, 0); } else { ret = dbenv->open(fullhome->home, newflags, mode); dbenv_ctp->ct_envdp.home = fullhome; dbenv_ctp->ct_envdp.envflags = shareflags; }out: replyp->status = ret; return;}/* BEGIN __env_remove_proc */extern "C" void__env_remove_proc( long dbenvcl_id, char *home, u_int32_t flags, __env_remove_reply *replyp)/* END __env_remove_proc */{ DbEnv *dbenv; ct_entry *dbenv_ctp; int ret; home_entry *fullhome; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; fullhome = get_home(home); if (fullhome == NULL) { replyp->status = DB_NOSERVER_HOME; return; } ret = dbenv->remove(fullhome->home, flags); __dbdel_ctp(dbenv_ctp); replyp->status = ret; return;}/* BEGIN __txn_abort_proc */extern "C" void__txn_abort_proc( long txnpcl_id, __txn_abort_reply *replyp)/* END __txn_abort_proc */{ DbTxn *txnp; ct_entry *txnp_ctp; int ret; ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DbTxn *)txnp_ctp->ct_anyp; ret = txnp->abort(); __dbdel_ctp(txnp_ctp); replyp->status = ret; return;}/* BEGIN __txn_begin_proc */extern "C" void__txn_begin_proc( long dbenvcl_id, long parentcl_id, u_int32_t flags, __txn_begin_reply *replyp)/* END __txn_begin_proc */{ DbEnv *dbenv; DbTxn *parent, *txnp; ct_entry *ctp, *dbenv_ctp, *parent_ctp; int ret; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; parent_ctp = NULL; ctp = new_ct_ent(&replyp->status); if (ctp == NULL) return; if (parentcl_id != 0) { ACTIVATE_CTP(parent_ctp, parentcl_id, CT_TXN); parent = (DbTxn *)parent_ctp->ct_anyp; ctp->ct_activep = parent_ctp->ct_activep; } else parent = NULL; ret = dbenv->txn_begin(parent, &txnp, flags); if (ret == 0) { ctp->ct_txnp = txnp; ctp->ct_type = CT_TXN; ctp->ct_parent = parent_ctp; ctp->ct_envparent = dbenv_ctp; replyp->txnidcl_id = ctp->ct_id; __dbsrv_settimeout(ctp, dbenv_ctp->ct_timeout); __dbsrv_active(ctp); } else __dbclear_ctp(ctp); replyp->status = ret; return;}/* BEGIN __txn_commit_proc */extern "C" void__txn_commit_proc( long txnpcl_id, u_int32_t flags, __txn_commit_reply *replyp)/* END __txn_commit_proc */{ DbTxn *txnp; ct_entry *txnp_ctp; int ret; ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DbTxn *)txnp_ctp->ct_anyp; ret = txnp->commit(flags); __dbdel_ctp(txnp_ctp); replyp->status = ret; return;}/* BEGIN __txn_discard_proc */extern "C" void__txn_discard_proc( long txnpcl_id, u_int32_t flags, __txn_discard_reply *replyp)/* END __txn_discard_proc */{ DbTxn *txnp; ct_entry *txnp_ctp; int ret; ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DbTxn *)txnp_ctp->ct_anyp; ret = txnp->discard(flags); __dbdel_ctp(txnp_ctp); replyp->status = ret; return;}/* BEGIN __txn_prepare_proc */extern "C" void__txn_prepare_proc( long txnpcl_id, u_int8_t *gid, __txn_prepare_reply *replyp)/* END __txn_prepare_proc */{ DbTxn *txnp; ct_entry *txnp_ctp; int ret; ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DbTxn *)txnp_ctp->ct_anyp; ret = txnp->prepare(gid); replyp->status = ret; return;}/* BEGIN __txn_recover_proc */extern "C" void__txn_recover_proc( long dbenvcl_id, u_int32_t count, u_int32_t flags, __txn_recover_reply *replyp, int * freep)/* END __txn_recover_proc */{ DbEnv *dbenv; DbPreplist *dbprep, *p; ct_entry *dbenv_ctp, *ctp; long erri, i, retcount; u_int32_t *txnidp; int ret; char *gid; ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV); dbenv = (DbEnv *)dbenv_ctp->ct_anyp; *freep = 0; if ((ret = __os_malloc(dbenv->get_DB_ENV(), count * sizeof(DbPreplist), &dbprep)) != 0) goto out; if ((ret = dbenv->txn_recover(dbprep, count, &retcount, flags)) != 0) goto out; /* * If there is nothing, success, but it's easy. */ replyp->retcount = retcount; // TODO: fix C++ txn_recover if (retcount == 0) { replyp->txn.txn_val = NULL; replyp->txn.txn_len = 0; replyp->gid.gid_val = NULL; replyp->gid.gid_len = 0; } /* * We have our txn list. Now we need to allocate the space for * the txn ID array and the GID array and set them up. */ if ((ret = __os_calloc(dbenv->get_DB_ENV(), retcount, sizeof(u_int32_t), &replyp->txn.txn_val)) != 0) goto out; replyp->txn.txn_len = retcount * sizeof(u_int32_t); if ((ret = __os_calloc(dbenv->get_DB_ENV(), retcount, DB_XIDDATASIZE, &replyp->gid.gid_val)) != 0) { __os_free(dbenv->get_DB_ENV(), replyp->txn.txn_val); goto out; } replyp->gid.gid_len = retcount * DB_XIDDATASIZE; /* * Now walk through our results, creating parallel arrays * to send back. For each entry we need to create a new * txn ctp and then fill in the array info. */ i = 0; p = dbprep; gid = replyp->gid.gid_val; txnidp = replyp->txn.txn_val; while (i++ < retcount) { ctp = new_ct_ent(&ret); if (ret != 0) { i--; goto out2; } ctp->ct_txnp = p->txn; ctp->ct_type = CT_TXN; ctp->ct_parent = NULL; ctp->ct_envparent = dbenv_ctp; __dbsrv_settimeout(ctp, dbenv_ctp->ct_timeout); __dbsrv_active(ctp); *txnidp = ctp->ct_id; memcpy(gid, p->gid, DB_XIDDATASIZE); p++; txnidp++; gid += DB_XIDDATASIZE; } /* * If we get here, we have success and we have to set freep * so it'll get properly freed next time. */ *freep = 1;out: if (dbprep != NULL) __os_free(dbenv->get_DB_ENV(), dbprep); replyp->status = ret; return;out2: /* * We had an error in the middle of creating our new txn * ct entries. We have to unwind all that we have done. Ugh. */ for (txnidp = replyp->txn.txn_val, erri = 0; erri < i; erri++, txnidp++) { ctp = get_tableent(*txnidp); __dbclear_ctp(ctp); } __os_free(dbenv->get_DB_ENV(), replyp->txn.txn_val); __os_free(dbenv->get_DB_ENV(), replyp->gid.gid_val); __os_free(dbenv->get_DB_ENV(), dbprep); replyp->status = ret; return;}/* BEGIN __db_bt_maxkey_proc */extern "C" void__db_bt_maxkey_proc( long dbpcl_id, u_int32_t maxkey, __db_bt_maxkey_reply *replyp)/* END __db_bt_maxkey_proc */{ Db *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (Db *)dbp_ctp->ct_anyp;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -