⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_server_proc.c

📁 mysql数据库源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2000-2002 *      Sleepycat Software.  All rights reserved. */#include "db_config.h"#ifdef HAVE_RPC#ifndef lintstatic const char revid[] = "$Id: db_server_proc.c,v 1.92 2002/07/29 15:21:20 sue 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 "dbinc/db_server_int.h"#include "dbinc_auto/rpc_server_ext.h"/* BEGIN __env_cachesize_proc *//* * PUBLIC: void __env_cachesize_proc __P((long, u_int32_t, u_int32_t, * PUBLIC:      u_int32_t, __env_cachesize_reply *)); */void__env_cachesize_proc(dbenvcl_id, gbytes, bytes,		ncache, replyp)	long dbenvcl_id;	u_int32_t gbytes;	u_int32_t bytes;	u_int32_t ncache;	__env_cachesize_reply *replyp;/* END __env_cachesize_proc */{	DB_ENV *dbenv;	ct_entry *dbenv_ctp;	int ret;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_ctp->ct_anyp;	ret = dbenv->set_cachesize(dbenv, gbytes, bytes, ncache);	replyp->status = ret;	return;}/* BEGIN __env_close_proc *//* * PUBLIC: void __env_close_proc __P((long, u_int32_t, __env_close_reply *)); */void__env_close_proc(dbenvcl_id, flags, replyp)	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 *//* * PUBLIC: void __env_create_proc __P((u_int32_t, __env_create_reply *)); */void__env_create_proc(timeout, replyp)	u_int32_t timeout;	__env_create_reply *replyp;/* END __env_create_proc */{	DB_ENV *dbenv;	ct_entry *ctp;	int ret;	ctp = new_ct_ent(&replyp->status);	if (ctp == NULL)		return;	if ((ret = db_env_create(&dbenv, 0)) == 0) {		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;	} else		__dbclear_ctp(ctp);	replyp->status = ret;	return;}/* BEGIN __env_dbremove_proc *//* * PUBLIC: void __env_dbremove_proc __P((long, long, char *, char *, u_int32_t, * PUBLIC:      __env_dbremove_reply *)); */void__env_dbremove_proc(dbenvcl_id, txnpcl_id, name,		subdb, flags, replyp)	long dbenvcl_id;	long txnpcl_id;	char *name;	char *subdb;	u_int32_t flags;	__env_dbremove_reply *replyp;/* END __env_dbremove_proc */{	int ret;	DB_ENV * dbenv;	ct_entry *dbenv_ctp;	DB_TXN * txnp;	ct_entry *txnp_ctp;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_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 = dbenv->dbremove(dbenv, txnp, name, subdb, flags);	replyp->status = ret;	return;}/* BEGIN __env_dbrename_proc *//* * PUBLIC: void __env_dbrename_proc __P((long, long, char *, char *, char *, * PUBLIC:      u_int32_t, __env_dbrename_reply *)); */void__env_dbrename_proc(dbenvcl_id, txnpcl_id, name,		subdb, newname, flags, replyp)	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;	DB_ENV * dbenv;	ct_entry *dbenv_ctp;	DB_TXN * txnp;	ct_entry *txnp_ctp;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_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 = dbenv->dbrename(dbenv, txnp, name, subdb, newname, flags);	replyp->status = ret;	return;}/* BEGIN __env_encrypt_proc *//* * PUBLIC: void __env_encrypt_proc __P((long, char *, u_int32_t, * PUBLIC:      __env_encrypt_reply *)); */void__env_encrypt_proc(dbenvcl_id, passwd, flags, replyp)	long dbenvcl_id;	char *passwd;	u_int32_t flags;	__env_encrypt_reply *replyp;/* END __env_encrypt_proc */{	int ret;	DB_ENV * dbenv;	ct_entry *dbenv_ctp;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_ctp->ct_anyp;	ret = dbenv->set_encrypt(dbenv, passwd, flags);	replyp->status = ret;	return;}/* BEGIN __env_flags_proc *//* * PUBLIC: void __env_flags_proc __P((long, u_int32_t, u_int32_t, * PUBLIC:      __env_flags_reply *)); */void__env_flags_proc(dbenvcl_id, flags, onoff, replyp)	long dbenvcl_id;	u_int32_t flags;	u_int32_t onoff;	__env_flags_reply *replyp;/* END __env_flags_proc */{	DB_ENV *dbenv;	ct_entry *dbenv_ctp;	int ret;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_ctp->ct_anyp;	ret = dbenv->set_flags(dbenv, 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 *//* * PUBLIC: void __env_open_proc __P((long, char *, u_int32_t, u_int32_t, * PUBLIC:      __env_open_reply *)); */void__env_open_proc(dbenvcl_id, home, flags,		mode, replyp)	long dbenvcl_id;	char *home;	u_int32_t flags;	u_int32_t mode;	__env_open_reply *replyp;/* END __env_open_proc */{	DB_ENV *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 = (DB_ENV *)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(dbenv, DB_LOCK_DEFAULT)) != 0)		goto out;	if (__dbsrv_verbose) {		dbenv->set_errfile(dbenv, stderr);		dbenv->set_errpfx(dbenv, 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(dbenv, 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 *//* * PUBLIC: void __env_remove_proc __P((long, char *, u_int32_t, * PUBLIC:      __env_remove_reply *)); */void__env_remove_proc(dbenvcl_id, home, flags, replyp)	long dbenvcl_id;	char *home;	u_int32_t flags;	__env_remove_reply *replyp;/* END __env_remove_proc */{	DB_ENV *dbenv;	ct_entry *dbenv_ctp;	int ret;	home_entry *fullhome;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_ctp->ct_anyp;	fullhome = get_home(home);	if (fullhome == NULL) {		replyp->status = DB_NOSERVER_HOME;		return;	}	ret = dbenv->remove(dbenv, fullhome->home, flags);	__dbdel_ctp(dbenv_ctp);	replyp->status = ret;	return;}/* BEGIN __txn_abort_proc *//* * PUBLIC: void __txn_abort_proc __P((long, __txn_abort_reply *)); */void__txn_abort_proc(txnpcl_id, replyp)	long txnpcl_id;	__txn_abort_reply *replyp;/* END __txn_abort_proc */{	DB_TXN *txnp;	ct_entry *txnp_ctp;	int ret;	ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN);	txnp = (DB_TXN *)txnp_ctp->ct_anyp;	ret = txnp->abort(txnp);	__dbdel_ctp(txnp_ctp);	replyp->status = ret;	return;}/* BEGIN __txn_begin_proc *//* * PUBLIC: void __txn_begin_proc __P((long, long, u_int32_t, * PUBLIC:      __txn_begin_reply *)); */void__txn_begin_proc(dbenvcl_id, parentcl_id,		flags, replyp)	long dbenvcl_id;	long parentcl_id;	u_int32_t flags;	__txn_begin_reply *replyp;/* END __txn_begin_proc */{	DB_ENV *dbenv;	DB_TXN *parent, *txnp;	ct_entry *ctp, *dbenv_ctp, *parent_ctp;	int ret;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)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 = (DB_TXN *)parent_ctp->ct_anyp;		ctp->ct_activep = parent_ctp->ct_activep;	} else		parent = NULL;	ret = dbenv->txn_begin(dbenv, 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 *//* * PUBLIC: void __txn_commit_proc __P((long, u_int32_t, * PUBLIC:      __txn_commit_reply *)); */void__txn_commit_proc(txnpcl_id, flags, replyp)	long txnpcl_id;	u_int32_t flags;	__txn_commit_reply *replyp;/* END __txn_commit_proc */{	DB_TXN *txnp;	ct_entry *txnp_ctp;	int ret;	ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN);	txnp = (DB_TXN *)txnp_ctp->ct_anyp;	ret = txnp->commit(txnp, flags);	__dbdel_ctp(txnp_ctp);	replyp->status = ret;	return;}/* BEGIN __txn_discard_proc *//* * PUBLIC: void __txn_discard_proc __P((long, u_int32_t, * PUBLIC:      __txn_discard_reply *)); */void__txn_discard_proc(txnpcl_id, flags, replyp)	long txnpcl_id;	u_int32_t flags;	__txn_discard_reply *replyp;/* END __txn_discard_proc */{	DB_TXN *txnp;	ct_entry *txnp_ctp;	int ret;	ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN);	txnp = (DB_TXN *)txnp_ctp->ct_anyp;	ret = txnp->discard(txnp, flags);	__dbdel_ctp(txnp_ctp);	replyp->status = ret;	return;}/* BEGIN __txn_prepare_proc *//* * PUBLIC: void __txn_prepare_proc __P((long, u_int8_t *, * PUBLIC:      __txn_prepare_reply *)); */void__txn_prepare_proc(txnpcl_id, gid, replyp)	long txnpcl_id;	u_int8_t *gid;	__txn_prepare_reply *replyp;/* END __txn_prepare_proc */{	DB_TXN *txnp;	ct_entry *txnp_ctp;	int ret;	ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN);	txnp = (DB_TXN *)txnp_ctp->ct_anyp;	ret = txnp->prepare(txnp, gid);	replyp->status = ret;	return;}/* BEGIN __txn_recover_proc *//* * PUBLIC: void __txn_recover_proc __P((long, u_int32_t, u_int32_t, * PUBLIC:      __txn_recover_reply *, int *)); */void__txn_recover_proc(dbenvcl_id, count,		flags, replyp, freep)	long dbenvcl_id;	u_int32_t count;	u_int32_t flags;	__txn_recover_reply *replyp;	int * freep;/* END __txn_recover_proc */{	DB_ENV *dbenv;	DB_PREPLIST *dbprep, *p;	ct_entry *dbenv_ctp, *ctp;	long erri, i, retcount;	u_int32_t *txnidp;	int ret;	u_int8_t *gid;	ACTIVATE_CTP(dbenv_ctp, dbenvcl_id, CT_ENV);	dbenv = (DB_ENV *)dbenv_ctp->ct_anyp;	dbprep = NULL;	*freep = 0;	if ((ret =	    __os_malloc(dbenv, count * sizeof(DB_PREPLIST), &dbprep)) != 0)		goto out;	if ((ret =	    dbenv->txn_recover(dbenv, dbprep, count, &retcount, flags)) != 0)		goto out;	/*	 * If there is nothing, success, but it's easy.	 */	replyp->retcount = retcount;	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, 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, retcount, DB_XIDDATASIZE,	    &replyp->gid.gid_val)) != 0) {		__os_free(dbenv, 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, 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, replyp->txn.txn_val);	__os_free(dbenv, replyp->gid.gid_val);	__os_free(dbenv, dbprep);	replyp->status = ret;	return;}/* BEGIN __db_bt_maxkey_proc *//* * PUBLIC: void __db_bt_maxkey_proc __P((long, u_int32_t, * PUBLIC:      __db_bt_maxkey_reply *)); */void__db_bt_maxkey_proc(dbpcl_id, maxkey, replyp)	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;	ret = dbp->set_bt_maxkey(dbp, maxkey);	replyp->status = ret;	return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -