[Mod-auth-devel] DB Pool mods
Brought to you by:
firechipmunk,
honx
From: Nick K. <ni...@we...> - 2004-01-06 01:58:38
|
Just to let you know, I've added an additional feature that's rather more powerful than what we already have. sql_acquire gets a handle that remains valid and guaranteed unique through the lifetime of a request. It can be called any number of times in different phases of a request, or (most powerfully) in different modules, by the simple expedient of storing the request's handle in the request_config. (not yet ported to pg_pool and mysql_pool) typedef struct { SQL* sql ; unsigned int flags ; apr_reslist_t* dbpool ; } sql_request ; static apr_status_t pool_release(void* x) { sql_request* req = (sql_request*)x ; if ( req->flags & SQL_TRANSACTION_ENABLED ) req->sql->rollback() ; if ( req->flags & SQL_LOCK_ENABLED ) req->sql->unlock(NULL) ; apr_reslist_release(req->dbpool, req->sql) ; return APR_SUCCESS ; } SQL* sql_acquire(request_rec* r, unsigned int flags) { sql_request* req = (sql_request*) ap_get_module_config(r->request_config, &valet_sql_module) ; if ( ! req ) { svr_cfg* svr = (svr_cfg*) ap_get_module_config(r->server->module_config, &valet_sql_module) ; req = (sql_request*) apr_palloc(r->pool, sizeof(sql_request) ) ; req->flags = flags ; req->dbpool = svr->dbpool ; if ( apr_reslist_acquire(svr->dbpool, (void**)&req->sql) != APR_SUCCESS ) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Failed to acquire SQL connection from pool") ; return NULL ; } const char* err = req->sql->verify(r->pool) ; if ( err ) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "SQL: %s", err) ; apr_reslist_release(svr->dbpool, req->sql) ; return NULL ; } ap_set_module_config(r->request_config, &valet_sql_module, req) ; apr_pool_cleanup_register(r->pool, req, pool_release, apr_pool_cleanup_null) ; } else { req->flags |= flags ; // ensure all required cleanups happen } return req->sql ; } -- Nick Kew |