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

📄 readme

📁 postgresql8.3.4源码,开源数据库
💻
字号:
$PostgreSQL: pgsql/src/backend/utils/resowner/README,v 1.5 2007/03/13 00:33:42 tgl Exp $Notes about resource owners---------------------------ResourceOwner objects are a concept invented to simplify management ofquery-related resources, such as buffer pins and table locks.  Theseresources need to be tracked in a reliable way to ensure that they willbe released at query end, even if the query fails due to an error.Rather than expecting the entire executor to have bulletproof datastructures, we localize the tracking of such resources into a singlemodule.The design of the ResourceOwner API is modeled on our MemoryContext API,which has proven very flexible and successful in preventing memory leaks.In particular we allow ResourceOwners to have child ResourceOwner objectsso that there can be forests of the things; releasing a parentResourceOwner acts on all its direct and indirect children as well.(It is tempting to consider unifying ResourceOwners and MemoryContextsinto a single object type, but their usage patterns are sufficientlydifferent that this is probably not really a helpful thing to do.)We create a ResourceOwner for each transaction or subtransaction aswell as one for each Portal.  During execution of a Portal, the globalvariable CurrentResourceOwner points to the Portal's ResourceOwner.This causes operations such as ReadBuffer and LockAcquire to recordownership of the acquired resources in that ResourceOwner object.When a Portal is closed, any remaining resources (typically only locks)become the responsibility of the current transaction.  This is representedby making the Portal's ResourceOwner a child of the current transaction'sResourceOwner.  resowner.c automatically transfers the resources to theparent object when releasing the child.  Similarly, subtransactionResourceOwners are children of their immediate parent.We need transaction-related ResourceOwners as well as Portal-related onesbecause transactions may initiate operations that require resources (suchas query parsing) when no associated Portal exists yet.API overview------------The basic operations on a ResourceOwner are:* create a ResourceOwner* associate or deassociate some resource with a ResourceOwner* release a ResourceOwner's assets (free all owned resources, but not the  owner object itself)* delete a ResourceOwner (including child owner objects); all resources  must have been released beforehandLocks are handled specially because in non-error situations a lock shouldbe held until end of transaction, even if it was originally taken by asubtransaction or portal.  Therefore, the "release" operation on a childResourceOwner transfers lock ownership to the parent instead of actuallyreleasing the lock, if isCommit is true.Currently, ResourceOwners contain direct support for recording ownership ofbuffer pins, lmgr locks, and catcache, relcache, plancache, and tupdescreferences.  Other objects can be associated with a ResourceOwner by recordingthe address of the owning ResourceOwner in such an object.  There is an APIfor other modules to get control during ResourceOwner release, so that theycan scan their own data structures to find the objects that need to bedeleted.Whenever we are inside a transaction, the global variableCurrentResourceOwner shows which resource owner should be assignedownership of acquired resources.  Note however that CurrentResourceOwneris NULL when not inside any transaction (or when inside a failedtransaction).  In this case it is not valid to acquire query-lifespanresources.When unpinning a buffer or releasing a lock or cache reference,CurrentResourceOwner must point to the same resource owner that was currentwhen the buffer, lock, or cache reference was acquired.  It would be possibleto relax this restriction given additional bookkeeping effort, but at presentthere seems no need.Code that transiently changes CurrentResourceOwner should generally use aPG_TRY construct to ensure that the previous value of CurrentResourceOwneris restored if control is lost during an error exit.

⌨️ 快捷键说明

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