Skip to content

Commit abbad76

Browse files
committed
Use user from multimaster connstrings in bgwpool
1 parent d941a6a commit abbad76

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-
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)

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

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
bool MtmDoReplication;
198198
char* MtmDatabaseName;
199+
char* MtmDatabaseUser;
199200
char* MtmUtilityStmt = NULL;
200201

201202
int MtmNodes;
@@ -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_t len;
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
case T_LockStmt:
34723485
case T_CheckPointStmt:
34733486
case T_ReindexStmt:
3487+
case T_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=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