forked from huawei/openGauss-server
!1102 修复分区表并发访问,锁冲突导致的系统hang
Merge pull request !1102 from 杨皓/partition-lock-problem
This commit is contained in:
commit
bb74866803
|
|
@ -48,6 +48,7 @@
|
||||||
#include "parser/parsetree.h"
|
#include "parser/parsetree.h"
|
||||||
#include "rewrite/rewriteManip.h"
|
#include "rewrite/rewriteManip.h"
|
||||||
#include "storage/buf/bufmgr.h"
|
#include "storage/buf/bufmgr.h"
|
||||||
|
#include "storage/lmgr.h"
|
||||||
#include "utils/acl.h"
|
#include "utils/acl.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/partcache.h"
|
#include "utils/partcache.h"
|
||||||
|
|
@ -75,6 +76,26 @@ static List* get_relation_constraints(PlannerInfo* root, Oid relationObjectId, R
|
||||||
List* build_index_tlist(PlannerInfo* root, IndexOptInfo* index, Relation heapRelation);
|
List* build_index_tlist(PlannerInfo* root, IndexOptInfo* index, Relation heapRelation);
|
||||||
static void setRelStoreInfo(RelOptInfo* relOptInfo, Relation relation);
|
static void setRelStoreInfo(RelOptInfo* relOptInfo, Relation relation);
|
||||||
|
|
||||||
|
static BlockNumber ComputeTheTotalPages(Relation relation, int nonzeroPartitionNumber, int notAvailPartitionCnt,
|
||||||
|
int totalPartitionNumber, BlockNumber partPages)
|
||||||
|
{
|
||||||
|
BlockNumber totalPages = 0;
|
||||||
|
|
||||||
|
if (nonzeroPartitionNumber > 0 && nonzeroPartitionNumber < ESTIMATE_PARTITION_NUMBER) {
|
||||||
|
if (notAvailPartitionCnt != 0) {
|
||||||
|
totalPages = partPages * ((nonzeroPartitionNumber + notAvailPartitionCnt) / nonzeroPartitionNumber);
|
||||||
|
} else {
|
||||||
|
totalPages = partPages;
|
||||||
|
}
|
||||||
|
} else if (nonzeroPartitionNumber == ESTIMATE_PARTITION_NUMBER) {
|
||||||
|
totalPages = partPages * (totalPartitionNumber / nonzeroPartitionNumber);
|
||||||
|
} else if (nonzeroPartitionNumber == 0) {
|
||||||
|
totalPages = relation->rd_rel->relpages;
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
static void acquireSamplesForPartitionedRelation(
|
static void acquireSamplesForPartitionedRelation(
|
||||||
Relation relation, LOCKMODE lmode, RelPageType* samplePages, List** sampledPartitionOids)
|
Relation relation, LOCKMODE lmode, RelPageType* samplePages, List** sampledPartitionOids)
|
||||||
{
|
{
|
||||||
|
|
@ -94,6 +115,7 @@ static void acquireSamplesForPartitionedRelation(
|
||||||
BlockNumber partPages = 0;
|
BlockNumber partPages = 0;
|
||||||
BlockNumber currentPartPages = 0;
|
BlockNumber currentPartPages = 0;
|
||||||
Partition part = NULL;
|
Partition part = NULL;
|
||||||
|
int notAvailPartitionCnt = 0;
|
||||||
|
|
||||||
for (partitionNumber = 0; partitionNumber < totalPartitionNumber; partitionNumber++) {
|
for (partitionNumber = 0; partitionNumber < totalPartitionNumber; partitionNumber++) {
|
||||||
Oid partitionOid = InvalidOid;
|
Oid partitionOid = InvalidOid;
|
||||||
|
|
@ -127,6 +149,11 @@ static void acquireSamplesForPartitionedRelation(
|
||||||
if (!OidIsValid(partitionOid))
|
if (!OidIsValid(partitionOid))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!ConditionalLockPartition(relation->rd_id, partitionOid, lmode, PARTITION_LOCK)) {
|
||||||
|
notAvailPartitionCnt++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
part = partitionOpen(relation, partitionOid, lmode);
|
part = partitionOpen(relation, partitionOid, lmode);
|
||||||
currentPartPages = PartitionGetNumberOfBlocks(relation, part);
|
currentPartPages = PartitionGetNumberOfBlocks(relation, part);
|
||||||
partitionClose(relation, part, lmode);
|
partitionClose(relation, part, lmode);
|
||||||
|
|
@ -143,12 +170,8 @@ static void acquireSamplesForPartitionedRelation(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute the total pages */
|
*samplePages = ComputeTheTotalPages(
|
||||||
if (nonzeroPartitionNumber >= 0 && nonzeroPartitionNumber < ESTIMATE_PARTITION_NUMBER) {
|
relation, nonzeroPartitionNumber, notAvailPartitionCnt, totalPartitionNumber, partPages);
|
||||||
*samplePages = partPages;
|
|
||||||
} else if (nonzeroPartitionNumber == ESTIMATE_PARTITION_NUMBER) {
|
|
||||||
*samplePages = partPages * (totalPartitionNumber / nonzeroPartitionNumber);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue