mp.h
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:8k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996, 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  *
  7.  * $Id: mp.h,v 11.16 2001/01/10 04:50:53 ubell Exp $
  8.  */
  9. struct __bh; typedef struct __bh BH;
  10. struct __db_mpool; typedef struct __db_mpool DB_MPOOL;
  11. struct __db_mpreg; typedef struct __db_mpreg DB_MPREG;
  12. struct __mpool; typedef struct __mpool MPOOL;
  13. struct __mpoolfile; typedef struct __mpoolfile MPOOLFILE;
  14. /* We require at least 40K of cache. */
  15. #define DB_CACHESIZE_MIN (20 * 1024)
  16. /*
  17.  * DB_MPOOL --
  18.  * Per-process memory pool structure.
  19.  */
  20. struct __db_mpool {
  21. /* These fields need to be protected for multi-threaded support. */
  22. MUTEX    *mutexp; /* Structure thread lock. */
  23. /* List of pgin/pgout routines. */
  24. LIST_HEAD(__db_mpregh, __db_mpreg) dbregq;
  25. /* List of DB_MPOOLFILE's. */
  26. TAILQ_HEAD(__db_mpoolfileh, __db_mpoolfile) dbmfq;
  27. /* These fields are not thread-protected. */
  28. DB_ENV     *dbenv; /* Reference to error information. */
  29. u_int32_t   nreg; /* N underlying cache regions. */
  30. REGINFO    *reginfo; /* Underlying cache regions. */
  31. };
  32. /*
  33.  * DB_MPREG --
  34.  * DB_MPOOL registry of pgin/pgout functions.
  35.  */
  36. struct __db_mpreg {
  37. LIST_ENTRY(__db_mpreg) q; /* Linked list. */
  38. int ftype; /* File type. */
  39. /* Pgin, pgout routines. */
  40. int (*pgin) __P((DB_ENV *, db_pgno_t, void *, DBT *));
  41. int (*pgout) __P((DB_ENV *, db_pgno_t, void *, DBT *));
  42. };
  43. /*
  44.  * DB_MPOOLFILE --
  45.  * Per-process DB_MPOOLFILE information.
  46.  */
  47. struct __db_mpoolfile {
  48. /* These fields need to be protected for multi-threaded support. */
  49. MUTEX   *mutexp; /* Structure thread lock. */
  50. DB_FH    fh; /* Underlying file handle. */
  51. u_int32_t ref; /* Reference count. */
  52. /*
  53.  * !!!
  54.  * This field is a special case -- it's protected by the region lock
  55.  * NOT the thread lock.  The reason for this is that we always have
  56.  * the region lock immediately before or after we modify the field,
  57.  * and we don't want to use the structure lock to protect it because
  58.  * then I/O (which is done with the structure lock held because of
  59.  * the race between the seek and write of the file descriptor) will
  60.  * block any other put/get calls using this DB_MPOOLFILE structure.
  61.  */
  62. u_int32_t pinref; /* Pinned block reference count. */
  63. /*
  64.  * !!!
  65.  * This field is a special case -- it's protected by the region lock
  66.  * since it's manipulated only when new files are added to the list.
  67.  */
  68. TAILQ_ENTRY(__db_mpoolfile) q; /* Linked list of DB_MPOOLFILE's. */
  69. /* These fields are not thread-protected. */
  70. DB_MPOOL  *dbmp; /* Overlying DB_MPOOL. */
  71. MPOOLFILE *mfp; /* Underlying MPOOLFILE. */
  72. void   *addr; /* Address of mmap'd region. */
  73. size_t    len; /* Length of mmap'd region. */
  74. /* These fields need to be protected for multi-threaded support. */
  75. #define MP_READONLY 0x01 /* File is readonly. */
  76. #define MP_UPGRADE 0x02 /* File descriptor is readwrite. */
  77. #define MP_UPGRADE_FAIL 0x04 /* Upgrade wasn't possible. */
  78. u_int32_t  flags;
  79. };
  80. /*
  81.  * NCACHE --
  82.  * Select a cache based on the page number.  This assumes accesses are
  83.  * uniform across pages, which is probably OK -- what we really want to
  84.  * avoid is anything that puts all the pages for any single file in the
  85.  * same cache, as we expect that file access will be bursty.
  86.  */
  87. #define NCACHE(mp, pgno)
  88. ((pgno) % ((MPOOL *)mp)->nreg)
  89. /*
  90.  * NBUCKET --
  91.  *  We make the assumption that early pages of the file are more likely
  92.  *  to be retrieved than the later pages, which means the top bits will
  93.  *  be more interesting for hashing as they're less likely to collide.
  94.  *  That said, as 512 8K pages represents a 4MB file, so only reasonably
  95.  *  large files will have page numbers with any other than the bottom 9
  96.  *  bits set.  We XOR in the MPOOL offset of the MPOOLFILE that backs the
  97.  *  page, since that should also be unique for the page.  We don't want
  98.  *  to do anything very fancy -- speed is more important to us than using
  99.  *  good hashing.
  100.  */
  101. #define NBUCKET(mc, mf_offset, pgno)
  102. (((pgno) ^ ((mf_offset) << 9)) % (mc)->htab_buckets)
  103. /*
  104.  * MPOOL --
  105.  * Shared memory pool region.
  106.  */
  107. struct __mpool {
  108. /*
  109.  * The memory pool can be broken up into individual pieces/files.
  110.  * Not what we would have liked, but on Solaris you can allocate
  111.  * only a little more than 2GB of memory in a contiguous chunk,
  112.  * and I expect to see more systems with similar issues.
  113.  *
  114.  * The first of these pieces/files describes the entire pool, all
  115.  * subsequent ones only describe a part of the cache.
  116.  *
  117.  * We single-thread memp_sync and memp_fsync calls.
  118.  *
  119.  * This mutex is intended *only* to single-thread access to the call,
  120.  * it is not used to protect the lsn and lsn_cnt fields, the region
  121.  * lock is used to protect them.
  122.  */
  123. MUTEX   sync_mutex; /* Checkpoint lock. */
  124. DB_LSN   lsn; /* Maximum checkpoint LSN. */
  125. u_int32_t lsn_cnt; /* Checkpoint buffers left to write. */
  126. SH_TAILQ_HEAD(__mpfq) mpfq; /* List of MPOOLFILEs. */
  127. u_int32_t nreg; /* Number of underlying REGIONS. */
  128. roff_t   regids; /* Array of underlying REGION Ids. */
  129. #define MP_LSN_RETRY 0x01 /* Retry all BH_WRITE buffers. */
  130. u_int32_t  flags;
  131. /*
  132.  * The following structure fields only describe the cache portion of
  133.  * the region.
  134.  */
  135. SH_TAILQ_HEAD(__bhq) bhq; /* LRU list of buffer headers. */
  136. int     htab_buckets; /* Number of hash table entries. */
  137. roff_t     htab; /* Hash table offset. */
  138. DB_MPOOL_STAT stat; /* Per-cache mpool statistics. */
  139. #ifdef MUTEX_SYSTEM_RESOURCES
  140. roff_t     maint_off; /* Maintenance information offset */
  141. #endif
  142. };
  143. /*
  144.  * MPOOLFILE --
  145.  * Shared DB_MPOOLFILE information.
  146.  */
  147. struct __mpoolfile {
  148. SH_TAILQ_ENTRY  q; /* List of MPOOLFILEs */
  149. db_pgno_t mpf_cnt; /* Ref count: DB_MPOOLFILEs. */
  150. db_pgno_t block_cnt; /* Ref count: blocks in cache. */
  151. db_pgno_t lsn_cnt; /* Checkpoint buffers left to write. */
  152. int   ftype; /* File type. */
  153. int32_t   lsn_off; /* Page's LSN offset. */
  154. u_int32_t clear_len; /* Bytes to clear on page create. */
  155. roff_t   path_off; /* File name location. */
  156. roff_t   fileid_off; /* File identification location. */
  157. roff_t   pgcookie_len; /* Pgin/pgout cookie length. */
  158. roff_t   pgcookie_off; /* Pgin/pgout cookie location. */
  159. db_pgno_t last_pgno; /* Last page in the file. */
  160. db_pgno_t orig_last_pgno; /* Original last page in the file. */
  161. DB_MPOOL_FSTAT stat; /* Per-file mpool statistics. */
  162. #define MP_CAN_MMAP 0x01 /* If the file can be mmap'd. */
  163. #define MP_DEADFILE 0x02 /* Dirty pages can simply be trashed. */
  164. #define MP_TEMP 0x04 /* Backing file is a temporary. */
  165. #define MP_UNLINK 0x08 /* Unlink file on last close. */
  166. u_int32_t  flags;
  167. };
  168. /*
  169.  * BH_TO_CACHE --
  170.  * Return the cache where we can find the specified buffer header.
  171.  */
  172. #define BH_TO_CACHE(dbmp, bhp)
  173. (dbmp)->reginfo[NCACHE((dbmp)->reginfo[0].primary, (bhp)->pgno)].primary
  174. /*
  175.  * BH --
  176.  * Buffer header.
  177.  */
  178. struct __bh {
  179. MUTEX         mutex; /* Buffer thread/process lock. */
  180. u_int16_t ref; /* Reference count. */
  181. #define BH_CALLPGIN 0x001 /* Page needs to be reworked... */
  182. #define BH_DIRTY 0x002 /* Page was modified. */
  183. #define BH_DISCARD 0x004 /* Page is useless. */
  184. #define BH_LOCKED 0x008 /* Page is locked (I/O in progress). */
  185. #define BH_SYNC 0x010 /* memp sync: write the page */
  186. #define BH_SYNC_LOGFLSH 0x020 /* memp sync: also flush the log */
  187. #define BH_TRASH 0x040 /* Page is garbage. */
  188. u_int16_t  flags;
  189. SH_TAILQ_ENTRY q; /* LRU queue. */
  190. SH_TAILQ_ENTRY hq; /* MPOOL hash bucket queue. */
  191. db_pgno_t pgno; /* Underlying MPOOLFILE page number. */
  192. roff_t   mf_offset; /* Associated MPOOLFILE offset. */
  193. /*
  194.  * !!!
  195.  * This array must be at least size_t aligned -- the DB access methods
  196.  * put PAGE and other structures into it, and then access them directly.
  197.  * (We guarantee size_t alignment to applications in the documentation,
  198.  * too.)
  199.  */
  200. u_int8_t   buf[1]; /* Variable length data. */
  201. };
  202. #include "mp_ext.h"