Postgresql存储引擎源码分析六(转载,不断更新)

    最近看到了一个很好的博客,里面给出了Postgresql缓冲管理部分源码的整体结构,现转载给大家分享:

 

1pgsql/src/include/storage/buf_internals.h

宏定义:

CLEAR_BUFFERTAG(a)

LockBufHdr(bufHdr)

UnlockBufHdr(bufHdr)

BufferDescriptorGetBuffer(bdesc)

INIT_BUFFERTAG(a,xx_rnode,xx_forkNum,xx_blockNum)

BufMappingPartitionLock(hashcode)

BUFFERTAGS_EQUAL(a,b)

结构体:

BufferDesc

BufferTag

2pgsql/src/backend/storage/ipc/shmem.c

函数体:

void *ShmemInitStruct(const char *name, Size size, bool *foundPtr)

void *ShmemAlloc(Size size)

bool ShmemAddrIsValid(void *addr)

Size add_size(Size s1, Size s2)

3pgsql/src/include/storage/shmem.h

结构体:ShmemIndexEnt

4pgsql/src/backend/storage/lmgr/lwlock.c

函数体:

void LWLockAcquire(LWLockId lockid, LWLockMode mode)

void LWLockRelease(LWLockId lockid)

LWLockId LWLockAssign(void)

bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)

5pgsql/src/include/storage/pg_shmem.h

结构体:

PGShmemHeader

6pgsql/src/backend/utils/hash/dynahash.c

宏定义:

MOD(x,y)

ELEMENTKEY(helem)

IS_PARTITIONED(hctl)

类型定义:

HASHSEGMENT

HASHBUCKET

结构体:

HASHHDR

HTAB

函数体:

void *hash_search(HTAB *hashp,const void *keyPtr,HASHACTION action,bool *foundPtr)

long hash_select_dirsize(long num_entries)

Size hash_estimate_size(long num_entries, Size entrysize)

static int choose_nelem_alloc(Size entrysize)

uint32 get_hash_value(HTAB *hashp, const void *keyPtr)

void *hash_search_with_hash_value(HTAB *hashp,const void *keyPtr,uint32 hashvalue,HASHACTION action,bool *foundPtr)

static inline uint32 calc_bucket(HASHHDR *hctl, uint32 hash_val)

static void hash_corrupted(HTAB *hashp)

static HASHBUCKET get_hash_entry(HTAB *hashp)

static bool element_alloc(HTAB *hashp, int nelem)

static bool has_seq_scans(HTAB *hashp)

static bool expand_table(HTAB *hashp)

static bool dir_realloc(HTAB *hashp)

static HASHSEGMENT seg_alloc(HTAB *hashp)

static inline uint32 calc_bucket(HASHHDR *hctl, uint32 hash_val)

HTAB *hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)

static void *DynaHashAlloc(Size size)

7pgsql/src/include/utils/elog.h

宏定义:

elog

结构体:

ErrorContextCallback

8pgsql/src/include/storage/spin.h

宏定义:

SpinLockInit(lock)

SpinLockAcquire(lock)

SpinLockRelease(lock)

9pgsql/src/include/storage/s_lock.h

宏定义:

S_INIT_LOCK(lock)

S_UNLOCK(lock)

S_LOCK(lock)

TAS(lock)

10pgsql/src/include/storage/lwlock.h

类型定义:

LWLockId

 

11pgsql/src/include/utils/hsearch.h

类型定义

HashValueFunc

HashCompareFunc

HashCopyFunc

HashAllocFunc

结构体:

HASHELEMENT

HASHCTL

12pgsql/src/include/utils/palloc.h

类型定义:

MemoryContext

13pgsql/src/include/nodes/memnodes.h

结构体

MemoryContextData

MemoryContextMethods

14pgsql/src/backend/storage/ipc/shmem.c

函数体:

HTAB *ShmemInitHash(const char *name, long init_size,long max_size,HASHCTL *infoP,int hash_flags)

Size mul_size(Size s1, Size s2)

15pgsql/src/backend/storage/buffer/freelist.c

结构体:

BufferStrategyControl

BufferAccessStrategyData

函数体:

volatile BufferDesc *StrategyGetBuffer(BufferAccessStrategy strategy, bool *lock_held)

void StrategyFreeBuffer(volatile BufferDesc *buf)

int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc)

Size StrategyShmemSize(void)

void StrategyInitialize(bool init)

BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)

void FreeAccessStrategy(BufferAccessStrategy strategy)

static volatile BufferDesc *GetBufferFromRing(BufferAccessStrategy strategy)

static void AddBufferToRing(BufferAccessStrategy strategy, volatile BufferDesc *buf)

bool StrategyRejectBuffer(BufferAccessStrategy strategy, volatile BufferDesc *buf)

16pgsql/src/backend/storage/buffer/buf_init.c

函数体:

void InitBufferPool(void)

void InitBufferPoolAccess(void)

Size BufferShmemSize(void)

17pgsql/src/backend/storage/buffer/buf_table.c

结构体:

BufferLookupEnt

函数体:

Size BufTableShmemSize(int size)

void InitBufTable(int size)

uint32 BufTableHashCode(BufferTag *tagPtr)

int BufTableLookup(BufferTag *tagPtr, uint32 hashcode)

int BufTableInsert(BufferTag *tagPtr, uint32 hashcode, int buf_id)

void BufTableDelete(BufferTag *tagPtr, uint32 hashcode)

18pgsql/src/backend/storage/buffer/bufmgr.c

宏定义:

BufHdrGetBlock(bufHdr)

BufferGetLSN(bufHdr)

LocalBufHdrGetBlock(bufHdr)

BUF_WRITTEN

BUF_REUSABLE

    下一步,我们将分析存储管理里面最重要的缓冲管理部分的源码了。

鲁笛

posted @ 2010-03-06 14:45  电信415实验室  阅读(981)  评论(0编辑  收藏  举报