-
Notifications
You must be signed in to change notification settings - Fork 2
/
connection.h
58 lines (43 loc) · 1.6 KB
/
connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*-------------------------------------------------------------------------
*
* connection.h
*
* Declarations for public functions and types related to connection hash
* functionality.
*
* Copyright (c) 2014, Citus Data, Inc.
*
*-------------------------------------------------------------------------
*/
#ifndef PG_SHARD_CONNECTION_H
#define PG_SHARD_CONNECTION_H
#include "c.h"
#include "libpq-fe.h"
/* maximum duration to wait for connection */
#define CLIENT_CONNECT_TIMEOUT_SECONDS "5"
/* maximum (textual) lengths of hostname */
#define MAX_NODE_LENGTH 255
/* times to attempt connection (or reconnection) */
#define MAX_CONNECT_ATTEMPTS 2
/* SQL statement for testing */
#define TEST_SQL "DO $$ BEGIN RAISE EXCEPTION 'Raised remotely!'; END $$"
/*
* NodeConnectionKey acts as the key to index into the (process-local) hash
* keeping track of open connections. Node name and port are sufficient.
*/
typedef struct NodeConnectionKey
{
char nodeName[MAX_NODE_LENGTH + 1]; /* hostname of host to connect to */
int32 nodePort; /* port of host to connect to */
} NodeConnectionKey;
/* NodeConnectionEntry keeps track of connections themselves. */
typedef struct NodeConnectionEntry
{
NodeConnectionKey cacheKey; /* hash entry key */
PGconn *connection; /* connection to remote server, if any */
} NodeConnectionEntry;
/* function declarations for obtaining and using a connection */
extern PGconn * GetConnection(char *nodeName, int32 nodePort);
extern void PurgeConnection(PGconn *connection);
extern void ReportRemoteError(PGconn *connection, PGresult *result);
#endif /* PG_SHARD_CONNECTION_H */