summaryrefslogtreecommitdiff
path: root/src/veil_config.c
blob: 0a440fc280197ebf880212eb74ac2f6f9ec47b20 (plain)
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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 * @file   veil_config.c
 * \code
 *     Author:       Marc Munro
 *     Copyright (c) 2006-2011 Marc Munro
 *     License:      BSD
 *
 * \endcode
 * @brief  
 * Code for setting and reading configuration data.
 * 
 */

#include "postgres.h"
#include "storage/fd.h"
#include "utils/guc.h"
#include "veil_version.h"
#include "veil_funcs.h"


/** 
 * The number of buckets to create in the hash for shared variables.
 * This defaults to 32 and may be defined in postgresql.conf using eg:
 * "veil.shared_hash_elems = 64"
 */
static int shared_hash_elems = 32;

/** 
 * The number of databases within the db cluster that will use veil.
 * Every veil-using database within the cluster will get the same
 * allocation of shared memory.
 */
static int dbs_in_cluster = 2;

/** 
 * The size in KBytes, of each of Veil's shared memory contexts.  Veil
 * will pre-allocate (from Postgres 8.2 onwards) twice this amount of
 * shared memory, one for each context area.
 * The default is 16384 Bytes and may be defined in postgresql.conf
 * using eg: "veil.shmem_context_size = 8192"
 */
static int shmem_context_size = 16384;

/** 
 * Return the number of databases, within the database cluster, that
 * will use Veil.  Each such database will be allocated 2 chunks of
 * shared memory (of shmem_context_size), and a single LWLock.
 * It defaults to 1 and may be defined in postgresql.conf using eg:
 * "veil.dbs_in_cluster = 2"
 */
int
veil_dbs_in_cluster()
{
	veil_load_config();
	return dbs_in_cluster;
}

/** 
 * Return the number of entries that should be allocated for shared
 * variables in our shared hashes.  This defaults to 32 and may be
 * defined in postgresql.conf using eg:
 * "veil.shared_hash_elems = 64"
 */
int
veil_shared_hash_elems()
{
	veil_load_config();
	return shared_hash_elems;
}

/** 
 * Return the amount of shared memory to be requested for each of the
 * two shared memory contexts.  This variable has no effect unless
 * shared_preload_libraries has been defined in postgresql.conf to load
 * the Veil shared library
 * Note that this must be large enough to allocate at least one chunk of
 * memory for each veil-using database in the Postgres cluster.  It
 * defaults to 16K and may be defined in postgresql.conf using eg: 
 * "veil.shmem_context_size = 16384"
 */
int
veil_shmem_context_size()
{
	veil_load_config();
	return shmem_context_size;
}

/** 
 * Initialise Veil's use of GUC variables.
 */
void
veil_config_init()
{
	static bool first_time = true;
	if (!first_time) {
		return;
	}

	DefineCustomIntVariable("veil.dbs_in_cluster",
							"The number of databases within the cluster "
							"that will be using veil (1)",
							NULL,
							&dbs_in_cluster,
							1, 1, 16,
							PGC_USERSET,
							0, NULL, NULL, NULL);
	DefineCustomIntVariable("veil.shared_hash_elems",
							"The number of entries for shared variables in "
							"each shared memory context (32)",
							NULL,
							&shared_hash_elems,
							32, 32, 8192,
							PGC_USERSET,
							0, NULL, NULL, NULL);
	DefineCustomIntVariable("veil.shmem_context_size",
							"Size of each shared memory context",
							"Size of each shared memory context in bytes.  "
							"This cannot be increased without stopping "
							"and restarting the database cluster.",
							&shmem_context_size,
							4096, 4096, 104857600,
							PGC_USERSET,
							0, NULL, NULL, NULL);

	first_time = false;
}


/** 
 * Retrieve Veil's GUC variables for this session.
 */
void
veil_load_config()
{
	static bool first_time = true;
	if (!first_time) {
		return;
	}

	dbs_in_cluster = atoi(GetConfigOption("veil.dbs_in_cluster", FALSE, FALSE));
	shared_hash_elems = atoi(GetConfigOption("veil.shared_hash_elems", 
											 FALSE, FALSE));
	shmem_context_size = atoi(GetConfigOption("veil.shmem_context_size", 
											  FALSE, FALSE));
	first_time = false;
}