From 1c5654cd23fd887ffab90a806781ecf81313fdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=94=A6=E9=BE=99?= <15822173373@163.com> Date: Mon, 28 Nov 2022 19:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E7=9B=B8=E5=85=B3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/pagehack/pagehack.cpp | 2 +- src/bin/pg_probackup/data.cpp | 20 +++++++++---------- src/bin/pg_probackup/file.cpp | 2 +- src/common/backend/utils/cache/partcache.cpp | 3 +++ src/common/backend/utils/cache/relcache.cpp | 3 +++ .../optimizer/commands/indexcmds.cpp | 15 ++++++++++++-- .../optimizer/commands/verifyrepair.cpp | 10 +++++----- .../process/postmaster/pagewriter.cpp | 2 +- .../storage/access/transam/twophase.cpp | 2 +- src/gausskernel/storage/buffer/bufmgr.cpp | 2 +- .../storage/smgr/cfs/cfs_tools.cpp | 12 +---------- src/include/storage/page_compression_impl.h | 10 +++++----- 12 files changed, 45 insertions(+), 38 deletions(-) diff --git a/contrib/pagehack/pagehack.cpp b/contrib/pagehack/pagehack.cpp index fb353e68e..f9b32e6a7 100644 --- a/contrib/pagehack/pagehack.cpp +++ b/contrib/pagehack/pagehack.cpp @@ -3135,7 +3135,7 @@ static void MarkBufferDirty(char *buffer, size_t len) static int parse_page_file(const char *filename, SegmentType type, const uint32 start_point, const uint32 number_read) { - if (type != SEG_HEAP && type != SEG_INDEX_BTREE) { + if (!IsCompressedFile(filename, strlen(filename))) { return parse_uncompressed_page_file(filename, type, start_point, number_read); } diff --git a/src/bin/pg_probackup/data.cpp b/src/bin/pg_probackup/data.cpp index adb6962bf..f8738d5ad 100644 --- a/src/bin/pg_probackup/data.cpp +++ b/src/bin/pg_probackup/data.cpp @@ -460,13 +460,13 @@ get_checksum_errormsg(Page page, char **errormsg, BlockNumber absolute_blkno) */ static int32 prepare_page(ConnectionArgs *conn_arg, - pgFile *file, XLogRecPtr prev_backup_start_lsn, - BlockNumber blknum, FILE *in, - BackupMode backup_mode, - Page page, bool strict, - uint32 checksum_version, - const char *from_fullpath, - PageState *page_st, PageCompression *pageCompression, int &read_len) + pgFile *file, XLogRecPtr prev_backup_start_lsn, + BlockNumber blknum, FILE *in, + BackupMode backup_mode, + Page page, bool strict, + uint32 checksum_version, + const char *from_fullpath, + PageState *page_st, PageCompression *pageCompression, int &read_len) { int try_again = PAGE_READ_ATTEMPTS; bool page_is_valid = false; @@ -2221,9 +2221,9 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f PageState page_st; int read_len = -1; int rc = prepare_page(conn_arg, file, prev_backup_start_lsn, - blknum, in, backup_mode, curr_page, - true, checksum_version, - from_fullpath, &page_st, pageCompression, read_len); + blknum, in, backup_mode, curr_page, + true, checksum_version, + from_fullpath, &page_st, pageCompression, read_len); if (rc == PageIsTruncated) break; diff --git a/src/bin/pg_probackup/file.cpp b/src/bin/pg_probackup/file.cpp index 436212932..b69483424 100644 --- a/src/bin/pg_probackup/file.cpp +++ b/src/bin/pg_probackup/file.cpp @@ -1427,7 +1427,7 @@ static void fio_send_pages_impl(int out, char* buf) * Optimize stdio buffer usage, fseek only when current position * does not match the position of requested block. */ - if (current_pos != (int)(blknum*BLCKSZ)) + if (current_pos != (int)(blknum * BLCKSZ)) { current_pos = blknum*BLCKSZ; if (fseek(in, current_pos, SEEK_SET) != 0) diff --git a/src/common/backend/utils/cache/partcache.cpp b/src/common/backend/utils/cache/partcache.cpp index a1f45020f..d05cbc726 100644 --- a/src/common/backend/utils/cache/partcache.cpp +++ b/src/common/backend/utils/cache/partcache.cpp @@ -501,8 +501,11 @@ Partition PartitionBuildLocalPartition(const char *relname, Oid partid, Oid part PartitionInitPhysicalAddr(part); /* compressed option was set by PartitionInitPhysicalAddr if part->rd_options != NULL */ if (part->rd_options == NULL && reloptions) { + (void)MemoryContextSwitchTo(oldcxt); StdRdOptions* options = (StdRdOptions*)(void *)default_reloptions(reloptions, false, RELOPT_KIND_HEAP); SetupPageCompressForRelation(&part->pd_node, &options->compress, PartitionGetPartitionName(part)); + (void)MemoryContextSwitchTo(LocalMyDBCacheMemCxt()); + pfree(options); } } diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index b9fbd429b..a473457cb 100644 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -4604,8 +4604,11 @@ Relation RelationBuildLocalRelation(const char* relname, Oid relnamespace, Tuple /* compressed option was set by RelationInitPhysicalAddr if rel->rd_options != NULL */ if (rel->rd_options == NULL && reloptions && SUPPORT_COMPRESSED(relkind, rel->rd_rel->relam)) { + (void)MemoryContextSwitchTo(oldcxt); StdRdOptions *options = (StdRdOptions *)(void*)default_reloptions(reloptions, false, RELOPT_KIND_HEAP); SetupPageCompressForRelation(&rel->rd_node, &options->compress, RelationGetRelationName(rel)); + (void)MemoryContextSwitchTo(LocalMyDBCacheMemCxt()); + pfree(options); } diff --git a/src/gausskernel/optimizer/commands/indexcmds.cpp b/src/gausskernel/optimizer/commands/indexcmds.cpp index 3ef18d56b..a13f758a9 100755 --- a/src/gausskernel/optimizer/commands/indexcmds.cpp +++ b/src/gausskernel/optimizer/commands/indexcmds.cpp @@ -566,6 +566,16 @@ static void WaitForOlderSnapshots(TransactionId limitXmin) } } +inline bool get_rel_segment(Relation rel) +{ + if (rel == NULL || rel->rd_options == NULL) { + return false; + } + + StdRdOptions *opt = (StdRdOptions*)(rel->rd_options); + return opt->segment; +} + /* * DefineIndex * Creates a new index. @@ -672,6 +682,7 @@ Oid DefineIndex(Oid relationId, IndexStmt* stmt, Oid indexRelationId, bool is_al lockmode = concurrent ? ShareUpdateExclusiveLock : ShareLock; rel = heap_open(relationId, lockmode); + bool segment = get_rel_segment(rel); TableCreateSupport indexCreateSupport{(int)COMPRESS_TYPE_NONE, false, false, false, false, false, true, false}; ListCell *cell = NULL; foreach (cell, stmt->options) { @@ -683,9 +694,9 @@ Oid DefineIndex(Oid relationId, IndexStmt* stmt, Oid indexRelationId, bool is_al /* do not suppport to create compressed index for temp table. */ if ((indexCreateSupport.compressType != (int)COMPRESS_TYPE_NONE) && (relPersistence == RELPERSISTENCE_TEMP || relPersistence == RELPERSISTENCE_GLOBAL_TEMP || - relPersistence == RELPERSISTENCE_UNLOGGED)) { + relPersistence == RELPERSISTENCE_UNLOGGED || segment)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("compressed index \"%s\" is not supported for temporary table and unlogged table," + errmsg("compressed index \"%s\" is not supported for temporary table, unlogged table and segment table," " please use uncompressed one instead", stmt->idxname))); } diff --git a/src/gausskernel/optimizer/commands/verifyrepair.cpp b/src/gausskernel/optimizer/commands/verifyrepair.cpp index 7fec15e4f..4d17f6ba4 100644 --- a/src/gausskernel/optimizer/commands/verifyrepair.cpp +++ b/src/gausskernel/optimizer/commands/verifyrepair.cpp @@ -1613,8 +1613,8 @@ static bool PrimaryRepairSegFile_NonSegment(const RelFileNode &rd_node, RemoteRe int64 segpathlen = strlen(path) + SEGLEN + strlen(COMPRESS_STR); char *segpath = (char *)palloc0((Size)segpathlen); BlockNumber relSegSize = IS_COMPRESSED_RNODE(rd_node, MAIN_FORKNUM) ? CFS_LOGIC_BLOCKS_PER_FILE: RELSEG_SIZE; - uint32 seg_size = (uint32)((seg_no < maxSegno || ((uint32)size % (relSegSize * BLCKSZ)) == 0) ? - (relSegSize * BLCKSZ) : ((uint32)size % (relSegSize * BLCKSZ))); + uint32 seg_size = (uint32)((seg_no < maxSegno || (size % (relSegSize * BLCKSZ)) == 0) ? + (relSegSize * BLCKSZ) : (size % (relSegSize * BLCKSZ))); if (seg_no == 0) { rc = sprintf_s(segpath, (uint64)segpathlen, "%s%s", path, @@ -1831,9 +1831,9 @@ bool gsRepairFile(Oid tableOid, char* path, int timeout) } else { BlockNumber relSegSize = IS_COMPRESSED_RNODE(relation->rd_node, MAIN_FORKNUM) ? CFS_LOGIC_BLOCKS_PER_FILE: RELSEG_SIZE; - int32 maxSegno = ((int32)size % ((int64)relSegSize * BLCKSZ)) != 0 - ? (int32)size / ((int64)relSegSize * BLCKSZ) - : ((int32)size / ((int64)relSegSize * BLCKSZ)) - 1; + int32 maxSegno = (int32)((size % ((int64)relSegSize * BLCKSZ)) != 0 + ? (size / ((int64)relSegSize * BLCKSZ)) + : (size / ((int64)relSegSize * BLCKSZ)) - 1); for (int32 i = 0; i <= maxSegno; i++) { bool repair = PrimaryRepairSegFile_NonSegment(relation->rd_node, &repairFileKey, firstPath, i, maxSegno, diff --git a/src/gausskernel/process/postmaster/pagewriter.cpp b/src/gausskernel/process/postmaster/pagewriter.cpp index 14b502c3b..a5c0c7053 100755 --- a/src/gausskernel/process/postmaster/pagewriter.cpp +++ b/src/gausskernel/process/postmaster/pagewriter.cpp @@ -2342,7 +2342,7 @@ PUSH_DIRTY: item->bucketNode = buf_desc->tag.rnode.bucketNode; item->forkNum = buf_desc->tag.forkNum; item->blockNum = buf_desc->tag.blockNum; - if (IsSegmentFileNode(buf_desc->tag.rnode)) { + if (IsSegmentFileNode(buf_desc->tag.rnode) || IS_COMPRESSED_RNODE(buf_desc->tag.rnode, buf_desc->tag.forkNum)) { *contain_hashbucket = true; } diff --git a/src/gausskernel/storage/access/transam/twophase.cpp b/src/gausskernel/storage/access/transam/twophase.cpp index 2f334aee9..104002d76 100644 --- a/src/gausskernel/storage/access/transam/twophase.cpp +++ b/src/gausskernel/storage/access/transam/twophase.cpp @@ -1854,7 +1854,7 @@ void StartPrepare(GlobalTransaction gxact) uint32 size = (uint32)(hdr_new.hdr.nabortrels * sizeof(ColFileNode)); if (unlikely((long)(t_thrd.proc->workingVersionNum < PAGE_COMPRESSION_VERSION))) { /* commitrels will be free in ConvertToOldColFileNode */ - registerData = (void *)ConvertToOldColFileNode(abortrels, hdr_new.hdr.ncommitrels); + registerData = (void *)ConvertToOldColFileNode(abortrels, hdr_new.hdr.nabortrels); size = hdr_new.hdr.nabortrels * sizeof(ColFileNodeRel); } save_state_data(registerData, size); diff --git a/src/gausskernel/storage/buffer/bufmgr.cpp b/src/gausskernel/storage/buffer/bufmgr.cpp index 864a7297f..57facb2de 100644 --- a/src/gausskernel/storage/buffer/bufmgr.cpp +++ b/src/gausskernel/storage/buffer/bufmgr.cpp @@ -6498,7 +6498,7 @@ void shared_buffer_write_error_callback(void *arg) if (buf_desc != NULL) { char *path = relpathperm(((BufferDesc *)buf_desc)->tag.rnode, ((BufferDesc *)buf_desc)->tag.forkNum); if (buf_desc->tag.rnode.opt) { - (void)errcontext("writing block %u of relation %s_pcd", buf_desc->tag.blockNum, path); + (void)errcontext("writing block %u of relation %s_compress", buf_desc->tag.blockNum, path); } else { (void)errcontext("writing block %u of relation %s", buf_desc->tag.blockNum, path); } diff --git a/src/gausskernel/storage/smgr/cfs/cfs_tools.cpp b/src/gausskernel/storage/smgr/cfs/cfs_tools.cpp index 5e0f7d739..2fc23c729 100644 --- a/src/gausskernel/storage/smgr/cfs/cfs_tools.cpp +++ b/src/gausskernel/storage/smgr/cfs/cfs_tools.cpp @@ -63,12 +63,10 @@ size_t CfsReadCompressedPage(char *dst, size_t destLen, BlockNumber extent_offse } decltype(CfsExtentHeader::chunk_size) chunkSize = cfsExtentHeader->chunk_size; auto extentStart = (cfsReadStruct->extentCount * CFS_EXTENT_SIZE) * BLCKSZ; - uint8 allocatedChunks; uint8 nchunks; size_t tryCount = 0; do { CfsExtentAddress *cfsExtentAddress = GetExtentAddress(cfsExtentHeader, (uint16)extent_offset_blkno); - allocatedChunks = cfsExtentAddress->allocated_chunks; nchunks = cfsExtentAddress->nchunks; for (uint8 i = 0; i < nchunks; i++) { @@ -107,15 +105,7 @@ size_t CfsReadCompressedPage(char *dst, size_t destLen, BlockNumber extent_offse } } while (true); - if (allocatedChunks > nchunks) { - auto currentWriteSize = nchunks * chunkSize; - errno_t rc = memset_s(dst + (uint32)currentWriteSize, - destLen - (uint32)currentWriteSize, - 0, - (uint32)(allocatedChunks - nchunks) * (uint32)chunkSize); - securec_check(rc, "", ""); - } - return allocatedChunks * chunkSize; + return nchunks * chunkSize; } const size_t CUR_PAGE_SIZE = (uint32)getpagesize(); diff --git a/src/include/storage/page_compression_impl.h b/src/include/storage/page_compression_impl.h index c077fff93..3925cc4f4 100644 --- a/src/include/storage/page_compression_impl.h +++ b/src/include/storage/page_compression_impl.h @@ -158,11 +158,11 @@ void Transpose8x16U(uint8 **src, uint8 **dst) matLine4x2.val[3] = vld1q_u8(src[7]); vst4q_u8(sptr4x2, matLine4x2); - matLine4x2.val[0] = vld1q_u8(src[4]); - matLine4x2.val[1] = vld1q_u8(src[5]); - matLine4x2.val[2] = vld1q_u8(src[6]); - matLine4x2.val[3] = vld1q_u8(src[7]); - vst4q_u8(sptr4x2, matLine4x2); + uint32x4x2_t dstLine04; + uint32x4x2_t dstLine15; + uint32x4x2_t dstLine26; + uint32x4x2_t dstLine37; + uint8 dstPtr[128]; dstLine04.val[0] = vld1q_u32((uint32_t *)sptr4x1); dstLine04.val[1] = vld1q_u32((uint32_t *)sptr4x2);