Skip to content

Commit 0bb319a

Browse files
committed
2 parents 0b46b4c + c0d6021 commit 0bb319a

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

contrib/multimaster/dtmd/include/limits.h renamed to contrib/multimaster/dtmd/include/dtmdlimits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef LIMITS_H
2-
#define LIMITS_H
1+
#ifndef DTMD_LIMITS_H
2+
#define DTMD_LIMITS_H
33

44
#define MAX_TRANSACTIONS 4096
55

contrib/multimaster/dtmd/include/snapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define SNAPSHOT_H
33

44
#include "int.h"
5-
#include "limits.h"
5+
#include "dtmdlimits.h"
66

77
typedef struct Snapshot {
88
xid_t xmin;

contrib/multimaster/dtmd/include/transaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "int.h"
66
#include "clog.h"
77
#include "snapshot.h"
8-
#include "limits.h"
8+
#include "dtmdlimits.h"
99

1010
#define MAX_SNAPSHOTS_PER_TRANS 8
1111

contrib/multimaster/dtmd/src/server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#endif
2222

2323
#include "server.h"
24-
#include "limits.h"
24+
#include "dtmdlimits.h"
2525
#include "util.h"
2626
#include "sockhub.h"
2727

contrib/pg_dtm/dtmd/include/limits.h

Lines changed: 0 additions & 10 deletions
This file was deleted.

contrib/pg_shard/src/prune_shard_list.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
127127
List *restrictInfoList = NIL;
128128
Node *baseConstraint = NULL;
129129
int shardHashCode = -1;
130+
int shardCount = shardIntervalList->length;
131+
uint32 hashTokenIncrement = (uint32)(HASH_TOKEN_COUNT / shardCount);
130132
Var *partitionColumn = PartitionColumn(relationId);
131133
char partitionMethod = PartitionType(relationId);
132134

@@ -168,8 +170,6 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
168170
if (OidIsValid(hashFunction->fn_oid))
169171
{
170172
int hashedValue = DatumGetInt32(FunctionCall1(hashFunction, constant->constvalue));
171-
int shardCount = shardIntervalList->length;
172-
uint32 hashTokenIncrement = (uint32)(HASH_TOKEN_COUNT / shardCount);
173173
shardHashCode = (int)((uint32)(hashedValue - INT32_MIN) / hashTokenIncrement);
174174
remainingShardList = LookupShardPlacementCache(relationId, shardHashCode);
175175
if (remainingShardList != NULL)
@@ -229,7 +229,19 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
229229
}
230230
if (shardHashCode >= 0)
231231
{
232-
AddToShardPlacementCache(relationId, shardHashCode, shardIntervalList->length, remainingShardList);
232+
ShardInterval* shardInterval = (ShardInterval *) linitial(remainingShardList);
233+
int64 shardId = shardInterval->id;
234+
int32 shardMinHashToken = INT32_MIN + (shardId * hashTokenIncrement);
235+
int32 shardMaxHashToken = shardMinHashToken + (hashTokenIncrement - 1);
236+
if (shardId == (shardCount - 1))
237+
{
238+
shardMaxHashToken = INT32_MAX;
239+
}
240+
if (DatumGetInt32(shardInterval->minValue) == shardMinHashToken &&
241+
DatumGetInt32(shardInterval->maxValue) == shardMaxHashToken)
242+
{
243+
AddToShardPlacementCache(relationId, shardHashCode, shardIntervalList->length, remainingShardList);
244+
}
233245
}
234246
return remainingShardList;
235247
}

0 commit comments

Comments
 (0)