📄 db_server_proc.c
字号:
u_int32_t keysize; u_int32_t datadlen; u_int32_t datadoff; u_int32_t dataulen; u_int32_t dataflags; void *datadata; u_int32_t datasize; u_int32_t flags; __db_put_reply *replyp; int * freep;{ DB *dbp; DBT key, data; DB_TXN *txnp; ct_entry *dbp_ctp, *txnp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; if (txnpcl_id != 0) { ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DB_TXN *)txnp_ctp->ct_anyp; } else txnp = NULL; replyp->keydata.keydata_val = NULL; *freep = 0; memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); /* Set up key and data DBT */ key.dlen = keydlen; key.ulen = keyulen; key.doff = keydoff; /* * Ignore memory related flags on server. */ key.flags = DB_DBT_MALLOC; if (keyflags & DB_DBT_PARTIAL) key.flags |= DB_DBT_PARTIAL; key.size = keysize; key.data = keydata; data.dlen = datadlen; data.ulen = dataulen; data.doff = datadoff; data.flags = dataflags; data.size = datasize; data.data = datadata; /* Got all our stuff, now do the put */ ret = dbp->put(dbp, txnp, &key, &data, flags); /* * If the client did a DB_APPEND, set up key in reply. * Otherwise just status. */ if (ret == 0 && (flags == DB_APPEND)) { /* * XXX * We need to xdr_free whatever we are returning, next time. * However, DB does not allocate a new key if one was given * and we'd be free'ing up space allocated in the request. * So, allocate a new key/data pointer if it is the same one * as in the request. */ *freep = 1; /* * Key */ if (key.data == keydata) { ret = __os_umalloc(dbp->dbenv, key.size, &replyp->keydata.keydata_val); if (ret != 0) goto err; memcpy(replyp->keydata.keydata_val, key.data, key.size); } else replyp->keydata.keydata_val = key.data; replyp->keydata.keydata_len = key.size; } else {err: FREE_IF_CHANGED(dbp->dbenv, key.data, keydata); FREE_IF_CHANGED(dbp->dbenv, replyp->keydata.keydata_val, key.data); replyp->keydata.keydata_val = NULL; replyp->keydata.keydata_len = 0; *freep = 0; } replyp->status = ret; return;}/* * PUBLIC: void __db_get_priority_proc __P((u_int, __db_get_priority_reply *)); */void__db_get_priority_proc(dbpcl_id, replyp) u_int dbpcl_id; __db_get_priority_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; replyp->status = dbp->get_priority(dbp, (DB_CACHE_PRIORITY *)&replyp->priority);}/* * PUBLIC: void __db_set_priority_proc __P((u_int, u_int32_t, * PUBLIC: __db_set_priority_reply *)); */void__db_set_priority_proc(dbpcl_id, priority, replyp) u_int dbpcl_id; u_int32_t priority; __db_set_priority_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->set_priority(dbp, (DB_CACHE_PRIORITY)priority); replyp->status = ret; return;}/* * PUBLIC: void __db_get_re_delim_proc __P((u_int, __db_get_re_delim_reply *)); */void__db_get_re_delim_proc(dbpcl_id, replyp) u_int dbpcl_id; __db_get_re_delim_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; replyp->status = dbp->get_re_delim(dbp, (int *)&replyp->delim);}/* * PUBLIC: void __db_set_re_delim_proc __P((u_int, u_int32_t, * PUBLIC: __db_set_re_delim_reply *)); */void__db_set_re_delim_proc(dbpcl_id, delim, replyp) u_int dbpcl_id; u_int32_t delim; __db_set_re_delim_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->set_re_delim(dbp, delim); replyp->status = ret; return;}/* * PUBLIC: void __db_get_re_len_proc __P((u_int, __db_get_re_len_reply *)); */void__db_get_re_len_proc(dbpcl_id, replyp) u_int dbpcl_id; __db_get_re_len_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; replyp->status = dbp->get_re_len(dbp, &replyp->len);}/* * PUBLIC: void __db_set_re_len_proc * PUBLIC: __P((u_int, u_int32_t, __db_set_re_len_reply *)); */void__db_set_re_len_proc(dbpcl_id, len, replyp) u_int dbpcl_id; u_int32_t len; __db_set_re_len_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->set_re_len(dbp, len); replyp->status = ret; return;}/* * PUBLIC: void __db_get_re_pad_proc __P((u_int, __db_get_re_pad_reply *)); */void__db_get_re_pad_proc(dbpcl_id, replyp) u_int dbpcl_id; __db_get_re_pad_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; replyp->status = dbp->get_re_pad(dbp, (int *)&replyp->pad);}/* * PUBLIC: void __db_set_re_pad_proc * PUBLIC: __P((u_int, u_int32_t, __db_set_re_pad_reply *)); */void__db_set_re_pad_proc(dbpcl_id, pad, replyp) u_int dbpcl_id; u_int32_t pad; __db_set_re_pad_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->set_re_pad(dbp, pad); replyp->status = ret; return;}/* * PUBLIC: void __db_remove_proc __P((u_int, char *, char *, u_int32_t, * PUBLIC: __db_remove_reply *)); */void__db_remove_proc(dbpcl_id, name, subdb, flags, replyp) u_int dbpcl_id; char *name; char *subdb; u_int32_t flags; __db_remove_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->remove(dbp, name, subdb, flags); __dbdel_ctp(dbp_ctp); replyp->status = ret; return;}/* * PUBLIC: void __db_rename_proc __P((u_int, char *, char *, char *, u_int32_t, * PUBLIC: __db_rename_reply *)); */void__db_rename_proc(dbpcl_id, name, subdb, newname, flags, replyp) u_int dbpcl_id; char *name; char *subdb; char *newname; u_int32_t flags; __db_rename_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->rename(dbp, name, subdb, newname, flags); __dbdel_ctp(dbp_ctp); replyp->status = ret; return;}/* * PUBLIC: void __db_stat_proc __P((u_int, u_int, u_int32_t, __db_stat_reply *, * PUBLIC: int *)); */void__db_stat_proc(dbpcl_id, txnpcl_id, flags, replyp, freep) u_int dbpcl_id; u_int txnpcl_id; u_int32_t flags; __db_stat_reply *replyp; int * freep;{ DB *dbp; DB_TXN *txnp; DBTYPE type; ct_entry *dbp_ctp, *txnp_ctp; u_int32_t *q, *p, *retsp; int i, len, ret; void *sp; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; if (txnpcl_id != 0) { ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DB_TXN *)txnp_ctp->ct_anyp; } else txnp = NULL; ret = dbp->stat(dbp, txnp, &sp, flags); replyp->status = ret; if (ret != 0) return; /* * We get here, we have success. Allocate an array so that * we can use the list generator. Generate the reply, free * up the space. */ /* * XXX This assumes that all elements of all stat structures * are u_int32_t fields. They are, currently. */ (void)dbp->get_type(dbp, &type); if (type == DB_HASH) len = sizeof(DB_HASH_STAT); else if (type == DB_QUEUE) len = sizeof(DB_QUEUE_STAT); else /* BTREE or RECNO are same stats */ len = sizeof(DB_BTREE_STAT); replyp->stats.stats_len = len / sizeof(u_int32_t); if ((ret = __os_umalloc(dbp->dbenv, len * replyp->stats.stats_len, &retsp)) != 0) goto out; for (i = 0, q = retsp, p = sp; i < len; i++, q++, p++) *q = *p; replyp->stats.stats_val = retsp; __os_ufree(dbp->dbenv, sp); if (ret == 0) *freep = 1;out: replyp->status = ret; return;}/* * PUBLIC: void __db_sync_proc __P((u_int, u_int32_t, __db_sync_reply *)); */void__db_sync_proc(dbpcl_id, flags, replyp) u_int dbpcl_id; u_int32_t flags; __db_sync_reply *replyp;{ DB *dbp; ct_entry *dbp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; ret = dbp->sync(dbp, flags); replyp->status = ret; return;}/* * PUBLIC: void __db_truncate_proc __P((u_int, u_int, u_int32_t, * PUBLIC: __db_truncate_reply *)); */void__db_truncate_proc(dbpcl_id, txnpcl_id, flags, replyp) u_int dbpcl_id; u_int txnpcl_id; u_int32_t flags; __db_truncate_reply *replyp;{ DB *dbp; DB_TXN *txnp; ct_entry *dbp_ctp, *txnp_ctp; u_int32_t count; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; if (txnpcl_id != 0) { ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DB_TXN *)txnp_ctp->ct_anyp; } else txnp = NULL; ret = dbp->truncate(dbp, txnp, &count, flags); replyp->status = ret; if (ret == 0) replyp->count = count; return;}/* * PUBLIC: void __db_cursor_proc __P((u_int, u_int, u_int32_t, * PUBLIC: __db_cursor_reply *)); */void__db_cursor_proc(dbpcl_id, txnpcl_id, flags, replyp) u_int dbpcl_id; u_int txnpcl_id; u_int32_t flags; __db_cursor_reply *replyp;{ DB *dbp; DBC *dbc; DB_TXN *txnp; ct_entry *dbc_ctp, *env_ctp, *dbp_ctp, *txnp_ctp; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; dbc_ctp = new_ct_ent(&replyp->status); if (dbc_ctp == NULL) return; if (txnpcl_id != 0) { ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN); txnp = (DB_TXN *)txnp_ctp->ct_anyp; dbc_ctp->ct_activep = txnp_ctp->ct_activep; } else txnp = NULL; if ((ret = dbp->cursor(dbp, txnp, &dbc, flags)) == 0) { dbc_ctp->ct_dbc = dbc; dbc_ctp->ct_type = CT_CURSOR; dbc_ctp->ct_parent = dbp_ctp; env_ctp = dbp_ctp->ct_envparent; dbc_ctp->ct_envparent = env_ctp; __dbsrv_settimeout(dbc_ctp, env_ctp->ct_timeout); __dbsrv_active(dbc_ctp); replyp->dbcidcl_id = dbc_ctp->ct_id; } else __dbclear_ctp(dbc_ctp); replyp->status = ret; return;}/* * PUBLIC: void __db_join_proc __P((u_int, u_int32_t *, u_int32_t, u_int32_t, * PUBLIC: __db_join_reply *)); */void__db_join_proc(dbpcl_id, curs, curslen, flags, replyp) u_int dbpcl_id; u_int32_t * curs; u_int32_t curslen; u_int32_t flags; __db_join_reply *replyp;{ DB_ENV *dbenv; DB *dbp; DBC **jcurs, **c; DBC *dbc; ct_entry *dbc_ctp, *ctp, *dbp_ctp; size_t size; u_int32_t *cl, i; int ret; ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB); dbp = (DB *)dbp_ctp->ct_anyp; dbenv = dbp->dbenv; dbc_ctp = new_ct_ent(&replyp->status); if (dbc_ctp == NULL) return; size = (curslen + 1) * sizeof(DBC *); if ((ret = __os_calloc( dbenv, curslen + 1, sizeof(DBC *), &jcurs)) != 0) { replyp->status = ret; __dbclear_ctp(dbc_ctp); return; } /* * If our curslist has a parent txn, we need to use it too * for the activity timeout. All cursors must be part of * the same transaction, so just check the first. */ ctp = get_tableent(*curs); DB_ASSERT(dbenv, ctp->ct_type == CT_CURSOR); /* * If we are using a transaction, set the join activity timer * to point to the parent transaction. */ if (ctp->ct_activep != &ctp->ct_active) dbc_ctp->ct_activep = ctp->ct_activep; for (i = 0, cl = curs, c = jcurs; i < curslen; i++, cl++, c++) { ctp = get_tableent(*cl); if (ctp == NULL) { replyp->status = DB_NOSERVER_ID; goto out; } /* * If we are using a txn, the join cursor points to the * transaction timeout. If we are not using a transaction, * then all the curslist cursors must point to the join * cursor's timeout so that we do not timeout any of the * curlist cursors while the join cursor is active. * Change the type of the curslist ctps to CT_JOIN so that * we know they are part of a join list and we can distinguish * them and later restore them when the join cursor is closed. */ DB_ASSERT(dbenv, ctp->ct_type == CT_CURSOR); ctp->ct_type |= CT_JOIN; ctp->ct_origp = ctp->ct_activep; /* * Setting this to the ct_active field of the dbc_ctp is * really just a way to distinguish which join dbc this * cursor is part of. The ct_activep of this cursor is * not used at all during its lifetime as part of a join * cursor. */ ctp->ct_activep = &dbc_ctp->ct_active; *c = ctp->ct_dbc; } *c = NULL; if ((ret = dbp->join(dbp, jcurs, &dbc, flags)) == 0) { dbc_ctp->ct_dbc = dbc; dbc_ctp->ct_type = (CT_JOINCUR | CT_CURSOR); dbc_ctp->ct_parent = dbp_ctp; dbc_ctp->ct_envparent = dbp_ctp->ct_envparent; __dbsrv_settimeout(dbc_ctp, dbp_ctp->ct_envparent->ct_timeout);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -