Skip to content

Commit 2f8bcb9

Browse files
committed
Use user from multimaster connstrings in bgwpool
1 parent cb33add commit 2f8bcb9

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

contrib/mmts/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-
void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, size_t queueSize, size_t nWorkers)
66+
void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, char const* dbuser, size_t queueSize, size_t nWorkers)
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_t BgwGetLastPeekTime(BgwPool* pool)

contrib/mmts/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
typedef uint64 timestamp_t;
1111

1212
#define MAX_DBNAME_LEN 30
13+
#define MAX_DBUSER_LEN 30
1314
#define MULTIMASTER_BGW_RESTART_TIMEOUT 1 /* seconds */
1415

1516
extern timestamp_t MtmGetSystemTime(void); /* non-adjusted current system time */
@@ -30,14 +31,15 @@ typedef struct
3031
time_t lastPeakTime;
3132
bool producerBlocked;
3233
char dbname[MAX_DBNAME_LEN];
34+
char dbuser[MAX_DBUSER_LEN];
3335
char* queue;
3436
} BgwPool;
3537

3638
typedef BgwPool*(*BgwPoolConstructor)(void);
3739

3840
extern void BgwPoolStart(int nWorkers, BgwPoolConstructor constructor);
3941

40-
extern void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, size_t queueSize, size_t nWorkers);
42+
extern void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, char const* dbuser, size_t queueSize, size_t nWorkers);
4143

4244
extern void BgwPoolExecute(BgwPool* pool, void* work, size_t size);
4345

contrib/mmts/multimaster.c

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

198198
bool MtmDoReplication;
199199
char* MtmDatabaseName;
200+
char* MtmDatabaseUser;
200201
char* MtmUtilityStmt = NULL;
201202

202203
int MtmNodes;
@@ -1718,7 +1719,7 @@ static void MtmInitialize()
17181719
PGSemaphoreCreate(&Mtm->votingSemaphore);
17191720
PGSemaphoreReset(&Mtm->votingSemaphore);
17201721
SpinLockInit(&Mtm->spinlock);
1721-
BgwPoolInit(&Mtm->pool, MtmExecutor, MtmDatabaseName, MtmQueueSize, MtmWorkers);
1722+
BgwPoolInit(&Mtm->pool, MtmExecutor, MtmDatabaseName, MtmDatabaseUser, MtmQueueSize, MtmWorkers);
17221723
RegisterXactCallback(MtmXactCallback, NULL);
17231724
MtmTx.snapshot = INVALID_CSN;
17241725
MtmTx.xid = InvalidTransactionId;
@@ -1805,19 +1806,31 @@ static void MtmSplitConnStrs(void)
18051806

18061807
MtmUpdateNodeConnectionInfo(&MtmConnections[i], connStr);
18071808

1808-
if (i+1 == MtmNodeId) {
1809-
char* dbName = strstr(connStr, "dbname=");
1809+
if (i+1 == MtmNodeId) {
1810+
char* dbName = strstr(connStr, "dbname="); // XXX: shoud we care about string 'itisnotdbname=xxx'?
1811+
char* dbUser = strstr(connStr, "user=");
18101812
char* end;
18111813
size_t len;
1812-
if (dbName == NULL) {
1813-
elog(ERROR, "Database not specified in connection string: '%s'", connStr);
1814-
}
1814+
1815+
if (dbName == NULL)
1816+
elog(ERROR, "Database is not specified in connection string: '%s'", connStr);
1817+
1818+
if (dbUser == NULL)
1819+
elog(ERROR, "Database user is not specified in connection string: '%s'", connStr);
1820+
18151821
dbName += 7;
18161822
for (end = dbName; *end != ' ' && *end != '\0'; end++);
18171823
len = end - dbName;
18181824
MtmDatabaseName = (char*)palloc(len + 1);
18191825
memcpy(MtmDatabaseName, dbName, len);
18201826
MtmDatabaseName[len] = '\0';
1827+
1828+
dbUser += 5;
1829+
for (end = dbUser; *end != ' ' && *end != '\0'; end++);
1830+
len = end - dbUser;
1831+
MtmDatabaseUser = (char*)palloc(len + 1);
1832+
memcpy(MtmDatabaseUser, dbUser, len);
1833+
MtmDatabaseUser[len] = '\0';
18211834
}
18221835
connStr = p + 1;
18231836
}
@@ -3287,6 +3300,7 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
32873300
case T_LockStmt:
32883301
case T_CheckPointStmt:
32893302
case T_ReindexStmt:
3303+
case T_RefreshMatViewStmt:
32903304
skipCommand = true;
32913305
break;
32923306

contrib/mmts/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=regression user=stas host=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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy