Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions contrib/zenith/libpagestore.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ zenith_connect()
}

/* Ask the Page Server to connect to us, and stream WAL from us. */
if (callmemaybe_connstring && callmemaybe_connstring[0])
if (callmemaybe_connstring && callmemaybe_connstring[0]
&& zenith_tenant
&& zenith_timeline)
{
PGresult *res;

query = psprintf("callmemaybe %s %s", zenith_timeline, callmemaybe_connstring);
query = psprintf("callmemaybe %s %s %s", zenith_tenant, zenith_timeline, callmemaybe_connstring);
res = PQexec(pageserver_conn, query);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
Expand All @@ -81,7 +83,7 @@ zenith_connect()
PQclear(res);
}

query = psprintf("pagestream %s", zenith_timeline);
query = psprintf("pagestream %s %s", zenith_tenant, zenith_timeline);
ret = PQsendQuery(pageserver_conn, query);
if (ret != 1)
zenith_log(ERROR,
Expand Down Expand Up @@ -185,11 +187,11 @@ zenith_call(ZenithRequest request)


static bool
check_zenith_timeline(char **newval, void **extra, GucSource source)
check_zenith_id(char **newval, void **extra, GucSource source)
{
uint8 ztimelineid[16];
uint8 zid[16];

return **newval == '\0' || HexDecodeString(ztimelineid, *newval, 16);
return **newval == '\0' || HexDecodeString(zid, *newval, 16);
}

/*
Expand Down Expand Up @@ -223,7 +225,16 @@ _PG_init(void)
"",
PGC_POSTMASTER,
0, /* no flags required */
check_zenith_timeline, NULL, NULL);
check_zenith_id, NULL, NULL);

DefineCustomStringVariable("zenith.zenith_tenant",
"Zenith tenantid the server is running on",
NULL,
&zenith_tenant,
"",
PGC_POSTMASTER,
0, /* no flags required */
check_zenith_id, NULL, NULL);

DefineCustomBoolVariable("zenith.wal_redo",
"start in wal-redo mode",
Expand All @@ -242,6 +253,7 @@ _PG_init(void)

/* Is there more correct way to pass CustomGUC to postgres code? */
zenith_timeline_walproposer = zenith_timeline;
zenith_tenant_walproposer = zenith_tenant;

if (wal_redo)
{
Expand Down
1 change: 1 addition & 0 deletions contrib/zenith/pagestore_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extern page_server_api * page_server;
extern char *page_server_connstring;
extern char *callmemaybe_connstring;
extern char *zenith_timeline;
extern char *zenith_tenant;
extern bool wal_redo;

extern const f_smgr *smgr_zenith(BackendId backend, RelFileNode rnode);
Expand Down
1 change: 1 addition & 0 deletions contrib/zenith/pagestore_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ page_server_api *page_server;
char *page_server_connstring;
char *callmemaybe_connstring;
char *zenith_timeline;
char *zenith_tenant;
bool wal_redo = false;

char const *const ZenithMessageStr[] =
Expand Down
8 changes: 8 additions & 0 deletions src/backend/replication/walproposer.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ HandleWalKeeperResponse(void)
}

char *zenith_timeline_walproposer = NULL;
char *zenith_tenant_walproposer = NULL;

/*
* WAL proposer bgworeker entry point
Expand Down Expand Up @@ -285,6 +286,13 @@ WalProposerMain(Datum main_arg)
if (*zenith_timeline_walproposer != '\0' &&
!HexDecodeString(serverInfo.ztimelineid, zenith_timeline_walproposer, 16))
elog(FATAL, "Could not parse zenith.zenith_timeline, %s", zenith_timeline_walproposer);

if (!zenith_tenant_walproposer)
elog(FATAL, "zenith.zenith_tenant is not provided");
if (*zenith_tenant_walproposer != '\0' &&
!HexDecodeString(serverInfo.ztenantid, zenith_tenant_walproposer, 16))
elog(FATAL, "Could not parse zenith.zenith_tenant, %s", zenith_tenant_walproposer);

serverInfo.protocolVersion = SK_PROTOCOL_VERSION;
pg_strong_random(&serverInfo.nodeId.uuid, sizeof(serverInfo.nodeId.uuid));
serverInfo.systemId = GetSystemIdentifier();
Expand Down
2 changes: 2 additions & 0 deletions src/include/replication/walproposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct WalMessage;
typedef struct WalMessage WalMessage;

extern char *zenith_timeline_walproposer;
extern char *zenith_tenant_walproposer;

/* WAL safekeeper state */
typedef enum
Expand Down Expand Up @@ -59,6 +60,7 @@ typedef struct ServerInfo
XLogRecPtr walEnd;
TimeLineID timeline;
int walSegSize;
uint8 ztenantid[16];
} ServerInfo;

/*
Expand Down