Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 03ec403

Browse files
committed
Port multimaster sequence AM to pg-10
1 parent 8abb06b commit 03ec403

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

multimaster.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static ExecutorStart_hook_type PreviousExecutorStartHook;
290290
static ExecutorFinish_hook_type PreviousExecutorFinishHook;
291291
static ProcessUtility_hook_type PreviousProcessUtilityHook;
292292
static shmem_startup_hook_type PreviousShmemStartupHook;
293-
// static seq_nextval_hook_t PreviousSeqNextvalHook;
293+
static seq_nextval_hook_t PreviousSeqNextvalHook;
294294

295295
static void MtmExecutorStart(QueryDesc *queryDesc, int eflags);
296296
static void MtmExecutorFinish(QueryDesc *queryDesc);
@@ -3390,8 +3390,8 @@ _PG_init(void)
33903390
PreviousProcessUtilityHook = ProcessUtility_hook;
33913391
ProcessUtility_hook = MtmProcessUtility;
33923392

3393-
// PreviousSeqNextvalHook = SeqNextvalHook;
3394-
// SeqNextvalHook = MtmSeqNextvalHook;
3393+
PreviousSeqNextvalHook = SeqNextvalHook;
3394+
SeqNextvalHook = MtmSeqNextvalHook;
33953395
}
33963396

33973397
/*
@@ -3403,7 +3403,7 @@ _PG_fini(void)
34033403
shmem_startup_hook = PreviousShmemStartupHook;
34043404
ExecutorFinish_hook = PreviousExecutorFinishHook;
34053405
ProcessUtility_hook = PreviousProcessUtilityHook;
3406-
// SeqNextvalHook = PreviousSeqNextvalHook;
3406+
SeqNextvalHook = PreviousSeqNextvalHook;
34073407
}
34083408

34093409

@@ -5089,7 +5089,33 @@ static bool MtmFunctionProfileDependsOnTempTable(CreateFunctionStmt* func)
50895089
return false;
50905090
}
50915091

5092+
static void
5093+
AdjustCreateSequence(List *options)
5094+
{
5095+
bool has_increment = false, has_start = false;
5096+
ListCell *option;
5097+
5098+
foreach(option, options)
5099+
{
5100+
DefElem *defel = (DefElem *) lfirst(option);
5101+
if (strcmp(defel->defname, "increment") == 0)
5102+
has_increment = true;
5103+
else if (strcmp(defel->defname, "start") == 0)
5104+
has_start = true;
5105+
}
50925106

5107+
if (!has_increment)
5108+
{
5109+
DefElem *defel = makeDefElem("increment", (Node *) makeInteger(MtmMaxNodes), -1);
5110+
options = lappend(options, defel);
5111+
}
5112+
5113+
if (!has_start)
5114+
{
5115+
DefElem *defel = makeDefElem("start", (Node *) makeInteger(MtmNodeId), -1);
5116+
options = lappend(options, defel);
5117+
}
5118+
}
50935119

50945120
static void MtmProcessUtility(PlannedStmt *pstmt,
50955121
const char *queryString, ProcessUtilityContext context,
@@ -5162,6 +5188,13 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
51625188
elog(ERROR, "Multimaster doesn't support creating and dropping databases");
51635189
break;
51645190

5191+
case T_CreateSeqStmt:
5192+
{
5193+
CreateSeqStmt *stmt = (CreateSeqStmt *) parsetree;
5194+
AdjustCreateSequence(stmt->options);
5195+
}
5196+
break;
5197+
51655198
case T_CreateTableSpaceStmt:
51665199
case T_DropTableSpaceStmt:
51675200
{

pglogical_apply.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,18 +1274,18 @@ void MtmExecutor(void* work, size_t size)
12741274
s.len = save_len;
12751275
break;
12761276
}
1277-
// case 'N':
1278-
// {
1279-
// int64 next;
1280-
// Oid relid;
1281-
// Assert(rel != NULL);
1282-
// relid = RelationGetRelid(rel);
1283-
// close_rel(rel);
1284-
// rel = NULL;
1285-
// next = pq_getmsgint64(&s);
1286-
// AdjustSequence(relid, next);
1287-
// break;
1288-
// }
1277+
case 'N':
1278+
{
1279+
int64 next;
1280+
Oid relid;
1281+
Assert(rel != NULL);
1282+
relid = RelationGetRelid(rel);
1283+
close_rel(rel);
1284+
rel = NULL;
1285+
next = pq_getmsgint64(&s);
1286+
AdjustSequence(relid, next);
1287+
break;
1288+
}
12891289
case '0':
12901290
Assert(rel != NULL);
12911291
heap_truncate_one_rel(rel);

tests/reinit-mm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ do
7777
multimaster.arbiter_port = $arbiter_port
7878
multimaster.max_recovery_lag = 30GB
7979
multimaster.referee_connstring = 'dbname=$USER host=127.0.0.1 port=5440 sslmode=disable'
80+
multimaster.monotonic_sequences = on
8081
SQL
8182

8283
cat <<CONF >> tmp_check/node$i/pg_hba.conf

0 commit comments

Comments
 (0)