diff --git a/src/backend/storage/buffer/buf_init_ext.c b/src/backend/storage/buffer/buf_init_ext.c index 3696a3c3a630ff1851473e59dcca561a3d263635..3171f73b7457839ec87565f2c30f7c7f615d0503 100644 --- a/src/backend/storage/buffer/buf_init_ext.c +++ b/src/backend/storage/buffer/buf_init_ext.c @@ -71,7 +71,7 @@ void KPHCPciBufInitCtx() KPHCPciPageCtrl *ctrl = PCI_GET_CTRL_BY_ID(gPciBufCtx, i); memset((void*)ctrl, 0, sizeof(KPHCPciPageCtrl)); ctrl->ctrlId = i; - ctrl->pciPage = (CfsExtentHeader *)(void *)(gPciBufCtx->pageBuf + (Size)((Size)(i - 1) * BLCKSZ)); + ctrl->pciPage = (KPHCCfsExtentHeader *)(void *)(gPciBufCtx->pageBuf + (Size)((Size)(i - 1) * BLCKSZ)); LWLockInitialize(&ctrl->contentLock, (int)LWTRANCHE_PCI_BUFFER_CONTENT); KPHCPciLruPushNoLock(&gPciBufCtx->freeLru[ctrl->ctrlId % PCI_PART_LIST_NUM], ctrl, CTRL_STATE_FREE); diff --git a/src/backend/storage/smgr/Makefile b/src/backend/storage/smgr/Makefile index cc02a8a0c22aafd373e8e28523bcce56f30e2664..3131b776eacf4fa051620d31d90a7d53b84029c4 100644 --- a/src/backend/storage/smgr/Makefile +++ b/src/backend/storage/smgr/Makefile @@ -14,8 +14,7 @@ include $(top_builddir)/src/Makefile.global OBJS = \ md.o \ - smgr.o \ - cfs_buffers.o + smgr.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/storage/smgr/cfs_buffers.c b/src/backend/storage/smgr/cfs_buffers.c deleted file mode 100644 index d288b9912203d879a21e7cec5805da59612b8f8b..0000000000000000000000000000000000000000 --- a/src/backend/storage/smgr/cfs_buffers.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "storage/cfs_buffers.h" - -void KPHCPciBufInitCtx(void) -{ -} -KPHCPciPageCtrl *KPHCPciBufReadPage(const KPHCExtentLocation location, LWLockMode lockMode, KPHCPciBufferReadMode readMode) -{ - return NULL; -} - -void KPHCPciBufFreePage(KPHCPciPageCtrl *ctrl, const KPHCExtentLocation location, bool need_write) -{ -} - diff --git a/src/include/storage/buf_ext.h b/src/include/storage/buf_ext.h index e358caa49526843d0e2ab617194df0f219cf3225..10d4884b40e24d68af864b81e475cf23e8baf564 100644 --- a/src/include/storage/buf_ext.h +++ b/src/include/storage/buf_ext.h @@ -31,22 +31,26 @@ #define PCI_SET_NO_READ(ctrl) (ctrl->loadStatus = CTRL_PAGE_NO_LOAD) +typedef struct CfsExtentAddress { + uint32 checksum; + volatile uint8 nchunks; + volatile uint8 allocated_chunks; + uint16 chunknos[FLEXIBLE_ARRAY_MEMBER]; +}KPHCCfsExtentAddress; typedef struct CfsExtentHeader { - void *exHeader; -} CfsExtentHeader; - - -typedef struct RelFileNodeKp { - Oid spcNode; - Oid dbNode; - Oid relNode; - uint8 bucketNode; -} RelFileNodeKp; + pg_atomic_uint32 nblocks; + pg_atomic_uint32 allocated_chunks; + uint16 chunk_size; + uint8 algorithm : 7; + uint8 recycleInOrder : 1; + uint8 recv; + KPHCCfsExtentAddress cfsExtentAddress[FLEXIBLE_ARRAY_MEMBER]; +}KPHCCfsExtentHeader; typedef struct KPHCExtentLocation { int fd; - RelFileNodeKp relFileNode; + RelFileNode relFileNode; BlockNumber extentNumber; BlockNumber extentStart; BlockNumber extentOffset; @@ -64,7 +68,7 @@ typedef struct stPciHashBucket { } KPHCPciHashBucket; typedef struct stPciPageHashtbl { - HashValueFunc hash; + HashValueFunc hash; HashCompareFunc match; uint32 bucketNum; KPHCPciHashBucket *buckets; @@ -77,9 +81,8 @@ typedef struct stPciLruList { volatile uint32 last; } KPHCPciLruList; - typedef struct KPHCCfsBufferKey { - RelFileNodeKp relFileNode; + RelFileNode relFileNode; uint32 extentCount; } KPHCCfsBufferKey; @@ -95,7 +98,6 @@ typedef enum enCtrlLoadStatus { CTRL_PAGE_LOADED_ERROR } KPHCCtrlLoadStatus; - typedef struct __attribute__((aligned(128))) stPciPageCtrl { uint32 ctrlId; @@ -111,7 +113,7 @@ typedef struct __attribute__((aligned(128))) stPciPageCtrl LWLock contentLock; KPHCCtrlLoadStatus loadStatus; KPHCCfsBufferKey pciKey; - CfsExtentHeader *pciPage; + KPHCCfsExtentHeader *pciPage; } KPHCPciPageCtrl; typedef struct __attribute__((aligned(128))) stPciPageBuffCtx @@ -129,7 +131,6 @@ typedef enum pciBufferReadMode { PCI_BUF_NO_READ } KPHCPciBufferReadMode; - extern KPHCPciPageBuffCtx *gPciBufCtx; void KPHCPciBufInitCtx(); @@ -139,5 +140,5 @@ void KPHCPciBufFreePage(KPHCPciPageCtrl *ctrl, const KPHCExtentLocation location void KPHCPciLruPushNoLock(KPHCPciLruList *lru, KPHCPciPageCtrl *item, KPHCCtrlState state); KPHCPciPageCtrl *KPHCPciBufReadPage(const KPHCExtentLocation location, LWLockMode lockMode, KPHCPciBufferReadMode readMode); - +typedef KPHCExtentLocation (*KPHCCfsLocationConvert)(SMgrRelation sRel, ForkNumber forknum, BlockNumber logicBlockNumber, bool skipSync, int type); #endif \ No newline at end of file diff --git a/src/include/storage/cfs_buffers.h b/src/include/storage/cfs_buffers.h deleted file mode 100644 index 2f46383994d1b0ac0bc015fbdd71f2775fa2f1cb..0000000000000000000000000000000000000000 --- a/src/include/storage/cfs_buffers.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef CFS_BUFFERS_H -#define CFS_BUFFERS_H - -#include "postgres.h" -#include "postgres_ext.h" -#include "storage/block.h" -#include "port/atomics.h" -#include "storage/lwlock.h" -#include "utils/wait_event.h" -#include "storage/fd.h" -#include "utils/elog.h" -#include "storage/shmem.h" -#include "utils/hsearch.h" -#include "storage/relfilenode.h" -#include "storage/smgr.h" - -typedef struct ExtentLocation { - int fd; - RelFileNode relFileNode; - BlockNumber extentNumber; - BlockNumber extentStart; - BlockNumber extentOffset; - BlockNumber headerNum; - uint16 chrunkSize; - uint8 algorithm; -}KPHCExtentLocation; - -typedef struct CfsBufferKey { - RelFileNode relFileNode; - uint32 extentCount; -}KPHCCfsBufferKey; - -typedef enum enCtrlState { - CTRL_STATE_INIT = 0, - CTRL_STATE_USED = 1, - CTRL_STATE_FREE = 2, -} KPHCCtrlState; - -typedef enum enCtrlLoadStatus { - CTRL_PAGE_NO_LOAD, - CTRL_PAGE_IS_LOADED, - CTRL_PAGE_LOADED_ERROR -} KPHCCtrlLoadStatus; - -typedef struct CfsExtentAddress { - uint32 checksum; - volatile uint8 nchunks; - volatile uint8 allocated_chunks; - uint16 chunknos[FLEXIBLE_ARRAY_MEMBER]; -}KPHCCfsExtentAddress; - -typedef struct CfsExtentHeader { - pg_atomic_uint32 nblocks; - pg_atomic_uint32 allocated_chunks; - uint16 chunk_size; - uint8 algorithm : 7; - uint8 recycleInOrder : 1; - uint8 recv; - KPHCCfsExtentAddress cfsExtentAddress[FLEXIBLE_ARRAY_MEMBER]; -}KPHCCfsExtentHeader; - -typedef struct __attribute__((aligned(128))) stPciPageCtrl -{ - uint32 ctrlId; - KPHCCtrlState state; - volatile uint32 lruPrev; - volatile uint32 lruNext; - volatile uint32 bckPrev; - volatile uint32 bckNext; - volatile uint32 bckId; - pg_atomic_uint32 touchNum; - pg_atomic_uint32 refNum; - - LWLock *contentLock; - KPHCCtrlLoadStatus loadStatus; - - KPHCCfsBufferKey pciKey; - KPHCCfsExtentHeader *pciPage; -} KPHCPciPageCtrl; - -typedef struct stPciHashBucket { - LWLock *lock; - uint32 bckId; - uint32 ctrlCount; - uint32 firstCtrlId; -} KPHCPciHashBucket; - -typedef struct stPciPageHashtbl { - HashValueFunc hash; - HashCompareFunc match; - - uint32 bucketNum; - KPHCPciHashBucket *buckets; -} KPHCPciPageHashtbl; - -typedef struct stPciLruList { - LWLock *lock; - volatile uint32 count; - volatile uint32 first; - volatile uint32 last; -} KPHCPciLruList; - -#define PCI_PART_LIST_NUM (8) -#define PCI_LRU_LIST_NUM (PCI_PART_LIST_NUM * 2) - -typedef struct __attribute__((aligned(128))) stPciPageBuffCtx -{ - KPHCPciPageCtrl *ctrlBuf; - char *pageBuf; - KPHCPciPageHashtbl hashtbl; - - uint32 maxCount; - KPHCPciLruList mainLru[PCI_PART_LIST_NUM]; - KPHCPciLruList freeLru[PCI_PART_LIST_NUM]; -} KPHCPciPageBuffCtx; - -#define PCI_INVALID_ID (0) -#define PCI_GET_CTRL_BY_ID(ctx, ctrlId) ((KPHCPciPageCtrl *)(&(ctx->ctrlBuf[(ctrlId) - 1]))) -#define PCI_GET_BUCKET_BY_ID(ctx, bckId) ((KPHCPciHashBucket *)(&(ctx->hashtbl.buckets[(bckId) - 1]))) -#define PCI_GET_BUCKET_BY_HASH(ctx, hashcode) (PCI_GET_BUCKET_BY_ID(ctx, (((hashcode) % ctx->hashtbl.bucketNum) + 1))) - -#define PCI_SET_NO_READ(ctrl) (ctrl->loadStatus = CTRL_PAGE_NO_LOAD) - -typedef enum pciBufferReadMode { - PCI_BUF_NORMAL_READ, - PCI_BUF_NO_READ -} KPHCPciBufferReadMode; - -typedef KPHCExtentLocation (*KPHCCfsLocationConvert)(SMgrRelation sRel, ForkNumber forknum, BlockNumber logicBlockNumber, bool skipSync, int type); - -extern KPHCPciPageBuffCtx *gPciBufCtx; - -extern void KPHCPciBufInitCtx(void); - -extern KPHCPciPageCtrl *KPHCPciBufReadPage(const KPHCExtentLocation location, LWLockMode lockMode, KPHCPciBufferReadMode readMode); - -extern void KPHCPciBufFreePage(KPHCPciPageCtrl *ctrl, const KPHCExtentLocation location, bool need_write); -#endif // CFS_BUFFERS_H diff --git a/src/include/storage/page_compression.h b/src/include/storage/page_compression.h index 22b3422c536174bbfb217a1a759c28a6a4177f30..c31f6996bf2d33b33850d9f1ef32cf20d781fe72 100644 --- a/src/include/storage/page_compression.h +++ b/src/include/storage/page_compression.h @@ -5,7 +5,7 @@ #include "storage/relfilenode.h" #include "storage/bufpage.h" #include "utils/rel.h" -#include "storage/cfs_buffers.h" +#include "storage/buf_ext.h" #define KPHC_CMP_BYTE_CONVERT_LEN 1 #define KPHC_CMP_DIFF_CONVERT_LEN 1 diff --git a/src/include/storage/relfilenode.h b/src/include/storage/relfilenode.h index 1a66dde36d97b5a0a054c1b8d7268cff53dbfda6..cd4b8a41309e0ce74458c7c9ca1ecda5c99f6701 100644 --- a/src/include/storage/relfilenode.h +++ b/src/include/storage/relfilenode.h @@ -59,6 +59,7 @@ typedef struct RelFileNode Oid spcNode; /* tablespace */ Oid dbNode; /* database */ Oid relNode; /* relation */ + uint16 bucketNode; uint16 opt; /* 2 bytes for compress options */ } RelFileNode;