Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabbad76

Browse files
committed
Use user from multimaster connstrings in bgwpool
1 parentd941a6a commitabbad76

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

‎bgwpool.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void BgwPoolMainLoop(Datum arg)
2525
void*work;
2626

2727
BackgroundWorkerUnblockSignals();
28-
BackgroundWorkerInitializeConnection(pool->dbname,"stas");
28+
BackgroundWorkerInitializeConnection(pool->dbname,pool->dbuser);
2929

3030
while(true) {
3131
PGSemaphoreLock(&pool->available);
@@ -63,7 +63,7 @@ static void BgwPoolMainLoop(Datum arg)
6363
}
6464
}
6565

66-
voidBgwPoolInit(BgwPool*pool,BgwPoolExecutorexecutor,charconst*dbname,size_tqueueSize,size_tnWorkers)
66+
voidBgwPoolInit(BgwPool*pool,BgwPoolExecutorexecutor,charconst*dbname,charconst*dbuser,size_tqueueSize,size_tnWorkers)
6767
{
6868
pool->queue= (char*)ShmemAlloc(queueSize);
6969
pool->executor=executor;
@@ -80,7 +80,8 @@ void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, si
8080
pool->pending=0;
8181
pool->nWorkers=nWorkers;
8282
pool->lastPeakTime=0;
83-
strcpy(pool->dbname,dbname);
83+
strncpy(pool->dbname,dbname,MAX_DBNAME_LEN);
84+
strncpy(pool->dbuser,dbuser,MAX_DBUSER_LEN);
8485
}
8586

8687
timestamp_tBgwGetLastPeekTime(BgwPool*pool)

‎bgwpool.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef void(*BgwPoolExecutor)(int id, void* work, size_t size);
1010
typedefuint64timestamp_t;
1111

1212
#defineMAX_DBNAME_LEN 30
13+
#defineMAX_DBUSER_LEN 30
1314
#defineMULTIMASTER_BGW_RESTART_TIMEOUT 1/* seconds */
1415

1516
externtimestamp_tMtmGetSystemTime(void);/* non-adjusted current system time */
@@ -30,14 +31,15 @@ typedef struct
3031
time_tlastPeakTime;
3132
boolproducerBlocked;
3233
chardbname[MAX_DBNAME_LEN];
34+
chardbuser[MAX_DBUSER_LEN];
3335
char*queue;
3436
}BgwPool;
3537

3638
typedefBgwPool*(*BgwPoolConstructor)(void);
3739

3840
externvoidBgwPoolStart(intnWorkers,BgwPoolConstructorconstructor);
3941

40-
externvoidBgwPoolInit(BgwPool*pool,BgwPoolExecutorexecutor,charconst*dbname,size_tqueueSize,size_tnWorkers);
42+
externvoidBgwPoolInit(BgwPool*pool,BgwPoolExecutorexecutor,charconst*dbname,charconst*dbuser,size_tqueueSize,size_tnWorkers);
4143

4244
externvoidBgwPoolExecute(BgwPool*pool,void*work,size_tsize);
4345

‎multimaster.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ char const* const MtmNodeStatusMnem[] =
196196

197197
boolMtmDoReplication;
198198
char*MtmDatabaseName;
199+
char*MtmDatabaseUser;
199200
char*MtmUtilityStmt=NULL;
200201

201202
intMtmNodes;
@@ -1804,7 +1805,7 @@ static void MtmInitialize()
18041805
PGSemaphoreCreate(&Mtm->votingSemaphore);
18051806
PGSemaphoreReset(&Mtm->votingSemaphore);
18061807
SpinLockInit(&Mtm->spinlock);
1807-
BgwPoolInit(&Mtm->pool,MtmExecutor,MtmDatabaseName,MtmQueueSize,MtmWorkers);
1808+
BgwPoolInit(&Mtm->pool,MtmExecutor,MtmDatabaseName,MtmDatabaseUser,MtmQueueSize,MtmWorkers);
18081809
RegisterXactCallback(MtmXactCallback,NULL);
18091810
MtmTx.snapshot=INVALID_CSN;
18101811
MtmTx.xid=InvalidTransactionId;
@@ -1918,19 +1919,31 @@ static void MtmSplitConnStrs(void)
19181919

19191920
MtmUpdateNodeConnectionInfo(&MtmConnections[i],connStr);
19201921

1921-
if (i+1==MtmNodeId) {
1922-
char*dbName=strstr(connStr,"dbname=");
1922+
if (i+1==MtmNodeId) {
1923+
char*dbName=strstr(connStr,"dbname=");// XXX: shoud we care about string 'itisnotdbname=xxx'?
1924+
char*dbUser=strstr(connStr,"user=");
19231925
char*end;
19241926
size_tlen;
1925-
if (dbName==NULL) {
1926-
elog(ERROR,"Database not specified in connection string: '%s'",connStr);
1927-
}
1927+
1928+
if (dbName==NULL)
1929+
elog(ERROR,"Database is not specified in connection string: '%s'",connStr);
1930+
1931+
if (dbUser==NULL)
1932+
elog(ERROR,"Database user is not specified in connection string: '%s'",connStr);
1933+
19281934
dbName+=7;
19291935
for (end=dbName;*end!=' '&&*end!='\0';end++);
19301936
len=end-dbName;
19311937
MtmDatabaseName= (char*)palloc(len+1);
19321938
memcpy(MtmDatabaseName,dbName,len);
19331939
MtmDatabaseName[len]='\0';
1940+
1941+
dbUser+=5;
1942+
for (end=dbUser;*end!=' '&&*end!='\0';end++);
1943+
len=end-dbUser;
1944+
MtmDatabaseUser= (char*)palloc(len+1);
1945+
memcpy(MtmDatabaseUser,dbUser,len);
1946+
MtmDatabaseUser[len]='\0';
19341947
}
19351948
connStr=p+1;
19361949
}
@@ -3471,6 +3484,7 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
34713484
caseT_LockStmt:
34723485
caseT_CheckPointStmt:
34733486
caseT_ReindexStmt:
3487+
caseT_RefreshMatViewStmt:
34743488
skipCommand= true;
34753489
break;
34763490

‎tests/reinit-mm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ for ((i=1;i<=n_nodes;i++))
1818
do
1919
port=$((5431+ i))
2020
raft_port=$((6665+ i))
21-
conn_str="$conn_str${sep}dbname=regression host=localhost port=$port sslmode=disable"
21+
conn_str="$conn_str${sep}dbname=regressionuser=stashost=localhost port=$port sslmode=disable"
2222
raft_conn_str="$raft_conn_str${sep}${i}:localhost:$raft_port"
2323
sep=","
2424
initdb node$i

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp