Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

qam.h

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: qam.h,v 12.3 2005/10/16 18:42:40 bostic Exp $
00008  */
00009 
00010 #ifndef _DB_QAM_H_
00011 #define _DB_QAM_H_
00012 
00013 /*
00014  * QAM data elements: a status field and the data.
00015  */
00016 typedef struct _qamdata {
00017         u_int8_t  flags;        /* 00: delete bit. */
00018 #define QAM_VALID       0x01
00019 #define QAM_SET         0x02
00020         u_int8_t  data[1];      /* Record. */
00021 } QAMDATA;
00022 
00023 struct __queue;         typedef struct __queue QUEUE;
00024 struct __qcursor;       typedef struct __qcursor QUEUE_CURSOR;
00025 
00026 struct __qcursor {
00027         /* struct __dbc_internal */
00028         __DBC_INTERNAL
00029 
00030         /* Queue private part */
00031 
00032         /* Per-thread information: queue private. */
00033         db_recno_t       recno;         /* Current record number. */
00034 
00035         u_int32_t        flags;
00036 };
00037 
00038 typedef struct __mpfarray {
00039         u_int32_t n_extent;             /* Number of extents in table. */
00040         u_int32_t low_extent;           /* First extent open. */
00041         u_int32_t hi_extent;            /* Last extent open. */
00042         struct __qmpf {
00043                 int pinref;
00044                 DB_MPOOLFILE *mpf;
00045         } *mpfarray;                     /* Array of open extents. */
00046 } MPFARRAY;
00047 
00048 /*
00049  * The in-memory, per-tree queue data structure.
00050  */
00051 struct __queue {
00052         db_pgno_t q_meta;               /* Database meta-data page. */
00053         db_pgno_t q_root;               /* Database root page. */
00054 
00055         int       re_pad;               /* Fixed-length padding byte. */
00056         u_int32_t re_len;               /* Length for fixed-length records. */
00057         u_int32_t rec_page;             /* records per page */
00058         u_int32_t page_ext;             /* Pages per extent */
00059         MPFARRAY array1, array2;        /* File arrays. */
00060 
00061                                         /* Extent file configuration: */
00062         DBT pgcookie;                   /* Initialized pgcookie. */
00063         DB_PGINFO pginfo;               /* Initialized pginfo struct. */
00064 
00065         char *path;                     /* Space allocated to file pathname. */
00066         char *name;                     /* The name of the file. */
00067         char *dir;                      /* The dir of the file. */
00068         int mode;                       /* Mode to open extents. */
00069 };
00070 
00071 /* Format for queue extent names. */
00072 #define QUEUE_EXTENT            "%s%c__dbq.%s.%d"
00073 #define QUEUE_EXTENT_HEAD       "__dbq.%s."
00074 
00075 typedef struct __qam_filelist {
00076         DB_MPOOLFILE *mpf;
00077         u_int32_t id;
00078 } QUEUE_FILELIST;
00079 
00080 /*
00081  * Calculate the page number of a recno.
00082  *
00083  * Number of records per page =
00084  *      Divide the available space on the page by the record len + header.
00085  *
00086  * Page number for record =
00087  *      divide the physical record number by the records per page
00088  *      add the root page number
00089  *      For now the root page will always be 1, but we might want to change
00090  *      in the future (e.g. multiple fixed len queues per file).
00091  *
00092  * Index of record on page =
00093  *      physical record number, less the logical pno times records/page
00094  */
00095 #define CALC_QAM_RECNO_PER_PAGE(dbp)                                    \
00096     (((dbp)->pgsize - QPAGE_SZ(dbp)) /                                  \
00097     (u_int32_t)DB_ALIGN((uintmax_t)SSZA(QAMDATA, data) +                \
00098     ((QUEUE *)(dbp)->q_internal)->re_len, sizeof(u_int32_t)))
00099 
00100 #define QAM_RECNO_PER_PAGE(dbp) (((QUEUE*)(dbp)->q_internal)->rec_page)
00101 
00102 #define QAM_RECNO_PAGE(dbp, recno)                                      \
00103     (((QUEUE *)(dbp)->q_internal)->q_root                               \
00104     + (((recno) - 1) / QAM_RECNO_PER_PAGE(dbp)))
00105 
00106 #define QAM_PAGE_EXTENT(dbp, pgno)                                      \
00107     (((pgno) - 1) / ((QUEUE *)(dbp)->q_internal)->page_ext)
00108 
00109 #define QAM_RECNO_EXTENT(dbp, recno)                                    \
00110     QAM_PAGE_EXTENT(dbp, QAM_RECNO_PAGE(dbp, recno))
00111 
00112 #define QAM_RECNO_INDEX(dbp, pgno, recno)                               \
00113     (((recno) - 1) - (QAM_RECNO_PER_PAGE(dbp)                           \
00114     * (pgno - ((QUEUE *)(dbp)->q_internal)->q_root)))
00115 
00116 #define QAM_GET_RECORD(dbp, page, index)                                \
00117     ((QAMDATA *)((u_int8_t *)(page) + (QPAGE_SZ(dbp) +                  \
00118     (DB_ALIGN((uintmax_t)SSZA(QAMDATA, data) +                          \
00119     ((QUEUE *)(dbp)->q_internal)->re_len, sizeof(u_int32_t)) * index))))
00120 
00121 #define QAM_AFTER_CURRENT(meta, recno)                                  \
00122     ((recno) > (meta)->cur_recno &&                                     \
00123     ((meta)->first_recno <= (meta)->cur_recno ||                        \
00124     ((recno) < (meta)->first_recno &&                                   \
00125     (recno) - (meta)->cur_recno < (meta)->first_recno - (recno))))
00126 
00127 #define QAM_BEFORE_FIRST(meta, recno)                                   \
00128     ((recno) < (meta)->first_recno &&                                   \
00129     ((meta->first_recno <= (meta)->cur_recno ||                         \
00130     ((recno) > (meta)->cur_recno &&                                     \
00131     (recno) - (meta)->cur_recno > (meta)->first_recno - (recno)))))
00132 
00133 #define QAM_NOT_VALID(meta, recno)                                      \
00134     (recno == RECNO_OOB ||                                              \
00135         QAM_BEFORE_FIRST(meta, recno) || QAM_AFTER_CURRENT(meta, recno))
00136 
00137 /*
00138  * Log opcodes for the mvptr routine.
00139  */
00140 #define QAM_SETFIRST            0x01
00141 #define QAM_SETCUR              0x02
00142 #define QAM_TRUNCATE            0x04
00143 
00144 /*
00145  * Parameter to __qam_position.
00146  */
00147 typedef enum {
00148         QAM_READ,
00149         QAM_WRITE,
00150         QAM_CONSUME
00151 } qam_position_mode;
00152 
00153 typedef enum {
00154         QAM_PROBE_GET,
00155         QAM_PROBE_PUT,
00156         QAM_PROBE_MPF
00157 } qam_probe_mode;
00158 
00159 /*
00160  * Ops for __qam_nameop.
00161  */
00162 typedef enum {
00163         QAM_NAME_DISCARD,
00164         QAM_NAME_RENAME,
00165         QAM_NAME_REMOVE
00166 } qam_name_op;
00167 
00168 #define __qam_fget(dbp, pgnoaddr, flags, addrp) \
00169         __qam_fprobe(dbp, *pgnoaddr, addrp, QAM_PROBE_GET, flags)
00170 
00171 #define __qam_fput(dbp, pageno, addrp, flags) \
00172         __qam_fprobe(dbp, pageno, addrp, QAM_PROBE_PUT, flags)
00173 
00174 #include "dbinc_auto/qam_auto.h"
00175 #include "dbinc_auto/qam_ext.h"
00176 #endif /* !_DB_QAM_H_ */

Generated on Sun Dec 25 12:14:22 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2