ic_proxy.h 1.9 KB
Newer Older
N
Ning Yu 已提交
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
/*-------------------------------------------------------------------------
 *
 * ic_proxy.h
 *
 *
 * Copyright (c) 2020-Present Pivotal Software, Inc.
 *
 *
 *-------------------------------------------------------------------------
 */

#ifndef IC_PROXY_H
#define IC_PROXY_H

#include "postgres.h"

#include "cdb/cdbinterconnect.h"
#include "cdb/cdbvars.h"
#include "nodes/pg_list.h"
#include "postmaster/postmaster.h"

#define IC_PROXY_BACKLOG 1024
#define IC_PROXY_INVALID_CONTENT ((uint16) -2)
#define IC_PROXY_INVALID_DBID ((int16) 0)
#define IC_PROXY_TRESHOLD_PAUSE 4
#define IC_PROXY_TRESHOLD_RESUME 2

#ifndef IC_PROXY_LOG_LEVEL
29
#define IC_PROXY_LOG_LEVEL WARNING
N
Ning Yu 已提交
30 31 32 33
#endif

#define ic_proxy_alloc(size) palloc(size)
#define ic_proxy_free(ptr) pfree(ptr)
34
#define ic_proxy_new(type) ((type *) ic_proxy_alloc(sizeof(type)))
N
Ning Yu 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48

#define ic_proxy_log(elevel, msg...) do { \
	if (elevel >= IC_PROXY_LOG_LEVEL) \
	{ \
		elog(elevel, msg); \
	} \
} while (0)

/*
 * Build the domain socket path.
 *
 * Every proxy on the same host must use a different path, this is important to
 * let proxies from different segments or even different clusters to coexist.
 *
49
 * This is ensured by including the postmaster port & pid in the path.
N
Ning Yu 已提交
50 51 52 53
 */
static inline void
ic_proxy_build_server_sock_path(char *buf, size_t bufsize)
{
54 55
	snprintf(buf, bufsize, "/tmp/.s.PGSQL.ic_proxy.%d.%d",
			 PostPortNumber, PostmasterPid);
N
Ning Yu 已提交
56 57
}

N
Ning Yu 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
/*
 * Free a list.
 *
 * The difference with list_free() is we always return NIL.
 */
static inline List *
ic_proxy_list_free(List *list)
{
	list_free(list);
	return NIL;
}

/*
 * Free a list and the cells.
 *
 * The cells must be allocated with the ic_proxy_alloc() / ic_proxy_new()
 * allocators.
 *
 * Always return NIL.
 */
static inline List *
ic_proxy_list_free_deep(List *list)
{
	ListCell   *cell;

	foreach(cell, list)
	{
		ic_proxy_free(lfirst(cell));
	}

	return ic_proxy_list_free(list);
}

N
Ning Yu 已提交
91
#endif   /* IC_PROXY_H */