postgresql共享内存的三个结构体

本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/16105797

postgresql的共享内存维护主要依靠以下三个结构体:

HHDR:

typedef struct hashhdr {
long bsize; /* Bucket/Page Size */
long bshift; /* Bucket shift */
long dsize; /* Directory Size */
long ssize; /* Segment Size */
long sshift; /* Segment shift */
long max_bucket; /* ID of Maximum bucket in use */
long high_mask; /* Mask to modulo into entire table */
long low_mask; /* Mask to modulo into lower half of table */
long ffactor; /* Fill factor */
long nkeys; /* Number of keys in hash table */
long nsegs; /* Number of allocated segments */
long keysize; /* hash key length in bytes */
long datasize; /* elem data length in bytes */
long max_dsize; /* 'dsize' limit if directory is fixed size */
BUCKET_INDEX freeBucketIndex;
/* index of first free bucket */
#ifdef HASH_STATISTICS
long accesses;
long collisions;
#endif
} HHDR;

这个结构体定义了hash结构的目录。

HTAB:

typedef struct htab {
HHDR *hctl; /* shared control information */
long (*hash)(); /* Hash Function */
char *segbase; /* segment base address for
* calculating pointer values
*/
SEG_OFFSET *dir; /* 'directory' of segm starts */
long *(*alloc)(); /* memory allocator
* (long * for alignment reasons)
*/ } HTAB;

这个结构体定义了hash table(动态、静态属性)。

HASHCTL:

typedef struct hashctl {
long bsize; /* Bucket Size */
long ssize; /* Segment Size */
long dsize; /* Dirsize Size */
long ffactor; /* Fill factor */
long (*hash)(); /* Hash Function */
long keysize; /* hash key length in bytes */
long datasize; /* elem data length in bytes */
long max_size; /* limit to dsize if directory size is limited */
long *segbase; /* base for calculating bucket + seg ptrs */
long * (*alloc)(); /* memory allocation function */
long *dir; /* directory if allocated already */
long *hctl; /* location of header information in shd mem */
} HASHCTL;

其中,HHDR是HTAB的一个元素。

上一篇:PostgreSQL 务实应用(三/5)分表复制


下一篇:首只科创板基金募集金额超百亿!