Veil
veil_config.c
Go to the documentation of this file.
1 /**
2  * @file veil_config.c
3  * \code
4  * Author: Marc Munro
5  * Copyright (c) 2006-2011 Marc Munro
6  * License: BSD
7  *
8  * \endcode
9  * @brief
10  * Code for setting and reading configuration data.
11  *
12  */
13 
14 #include "postgres.h"
15 #include "storage/fd.h"
16 #include "utils/guc.h"
17 #include "veil_version.h"
18 #include "veil_funcs.h"
19 
20 
21 /**
22  * The number of buckets to create in the hash for shared variables.
23  * This defaults to 32 and may be defined in postgresql.conf using eg:
24  * "veil.shared_hash_elems = 64"
25  */
26 static int shared_hash_elems = 32;
27 
28 /**
29  * The number of databases within the db cluster that will use veil.
30  * Every veil-using database within the cluster will get the same
31  * allocation of shared memory.
32  */
33 static int dbs_in_cluster = 2;
34 
35 /**
36  * The size in KBytes, of each of Veil's shared memory contexts. Veil
37  * will pre-allocate (from Postgres 8.2 onwards) twice this amount of
38  * shared memory, one for each context area.
39  * The default is 16384 Bytes and may be defined in postgresql.conf
40  * using eg: "veil.shmem_context_size = 8192"
41  */
42 static int shmem_context_size = 16384;
43 
44 /**
45  * Return the number of databases, within the database cluster, that
46  * will use Veil. Each such database will be allocated 2 chunks of
47  * shared memory (of shmem_context_size), and a single LWLock.
48  * It defaults to 1 and may be defined in postgresql.conf using eg:
49  * "veil.dbs_in_cluster = 2"
50  */
51 int
53 {
55  return dbs_in_cluster;
56 }
57 
58 /**
59  * Return the number of entries that should be allocated for shared
60  * variables in our shared hashes. This defaults to 32 and may be
61  * defined in postgresql.conf using eg:
62  * "veil.shared_hash_elems = 64"
63  */
64 int
66 {
68  return shared_hash_elems;
69 }
70 
71 /**
72  * Return the amount of shared memory to be requested for each of the
73  * two shared memory contexts. This variable has no effect unless
74  * shared_preload_libraries has been defined in postgresql.conf to load
75  * the Veil shared library
76  * Note that this must be large enough to allocate at least one chunk of
77  * memory for each veil-using database in the Postgres cluster. It
78  * defaults to 16K and may be defined in postgresql.conf using eg:
79  * "veil.shmem_context_size = 16384"
80  */
81 int
83 {
85  return shmem_context_size;
86 }
87 
88 /**
89  * Initialise Veil's use of GUC variables.
90  */
91 void
93 {
94  static bool first_time = true;
95  if (!first_time) {
96  return;
97  }
98 
99  DefineCustomIntVariable("veil.dbs_in_cluster",
100  "The number of databases within the cluster "
101  "that will be using veil (1)",
102  NULL,
104  1, 1, 16,
105  PGC_USERSET,
106  0, NULL, NULL, NULL);
107  DefineCustomIntVariable("veil.shared_hash_elems",
108  "The number of entries for shared variables in "
109  "each shared memory context (32)",
110  NULL,
112  32, 32, 8192,
113  PGC_USERSET,
114  0, NULL, NULL, NULL);
115  DefineCustomIntVariable("veil.shmem_context_size",
116  "Size of each shared memory context",
117  "Size of each shared memory context in bytes. "
118  "This cannot be increased without stopping "
119  "and restarting the database cluster.",
121  4096, 4096, 104857600,
122  PGC_USERSET,
123  0, NULL, NULL, NULL);
124 
125  first_time = false;
126 }
127 
128 
129 /**
130  * Retrieve Veil's GUC variables for this session.
131  */
132 void
134 {
135  static bool first_time = true;
136  if (!first_time) {
137  return;
138  }
139 
140  dbs_in_cluster = atoi(GetConfigOption("veil.dbs_in_cluster", FALSE, FALSE));
141  shared_hash_elems = atoi(GetConfigOption("veil.shared_hash_elems",
142  FALSE, FALSE));
143  shmem_context_size = atoi(GetConfigOption("veil.shmem_context_size",
144  FALSE, FALSE));
145  first_time = false;
146 }
147 
148 
static int dbs_in_cluster
The number of databases within the db cluster that will use veil.
Definition: veil_config.c:33
int veil_dbs_in_cluster()
Return the number of databases, within the database cluster, that will use Veil.
Definition: veil_config.c:52
static int shmem_context_size
The size in KBytes, of each of Veil's shared memory contexts.
Definition: veil_config.c:42
Provide definitions for all non-local C-callable Veil functions.
Provides version information for veil.
void veil_config_init()
Initialise Veil's use of GUC variables.
Definition: veil_config.c:92
static int shared_hash_elems
The number of buckets to create in the hash for shared variables.
Definition: veil_config.c:26
int veil_shmem_context_size()
Return the amount of shared memory to be requested for each of the two shared memory contexts...
Definition: veil_config.c:82
void veil_load_config()
Retrieve Veil's GUC variables for this session.
Definition: veil_config.c:133
int veil_shared_hash_elems()
Return the number of entries that should be allocated for shared variables in our shared hashes...
Definition: veil_config.c:65