veil_config.c

Go to the documentation of this file.
00001 /**
00002  * @file   veil_config.c
00003  * \code
00004  *     Author:       Marc Munro
00005  *     Copyright (c) 2006-2010 Marc Munro
00006  *     License:      BSD
00007  * $Id: veil_config.c,v 1.5 2009/07/04 02:21:52 bloodnok Exp $
00008  * \endcode
00009  * @brief  
00010  * Code for setting and reading configuration data.
00011  * 
00012  */
00013 
00014 #include "postgres.h"
00015 #include "storage/fd.h"
00016 #include "utils/guc.h"
00017 #include "veil_version.h"
00018 #include "veil_funcs.h"
00019 
00020 
00021 /** 
00022  * The number of buckets to create in the hash for shared variables.
00023  * This defaults to 32 and may be defined in postgresql.conf using eg:
00024  * "veil.shared_hash_elems = 64"
00025  */
00026 static int shared_hash_elems = 32;
00027 
00028 /** 
00029  * The number of databases within the db cluster that will use veil.
00030  * Every veil-using database within the cluster will get the same
00031  * allocation of shared memory.
00032  */
00033 static int dbs_in_cluster = 2;
00034 
00035 /** 
00036  * The size in KBytes, of each of Veil's shared memory contexts.  Veil
00037  * will pre-allocate (from Postgres 8.2 onwards) twice this amount of
00038  * shared memory, one for each context area.
00039  * The default is 16384 Bytes and may be defined in postgresql.conf
00040  * using eg: "veil.shmem_context_size = 8192"
00041  */
00042 static int shmem_context_size = 16384;
00043 
00044 /** 
00045  * Return the number of databases, within the database cluster, that
00046  * will use Veil.  Each such database will be allocated 2 chunks of
00047  * shared memory (of shmem_context_size), and a single LWLock.
00048  * It defaults to 1 and may be defined in postgresql.conf using eg:
00049  * "veil.dbs_in_cluster = 2"
00050  */
00051 int
00052 veil_dbs_in_cluster()
00053 {
00054     veil_load_config();
00055     return dbs_in_cluster;
00056 }
00057 
00058 /** 
00059  * Return the number of entries that should be allocated for shared
00060  * variables in our shared hashes.  This defaults to 32 and may be
00061  * defined in postgresql.conf using eg:
00062  * "veil.shared_hash_elems = 64"
00063  */
00064 int
00065 veil_shared_hash_elems()
00066 {
00067     veil_load_config();
00068     return shared_hash_elems;
00069 }
00070 
00071 /** 
00072  * Return the amount of shared memory to be requested for each of the
00073  * two shared memory contexts.  This variable has no effect unless
00074  * shared_preload_libraries has been defined in postgresql.conf to load
00075  * the Veil shared library
00076  * Note that this must be large enough to allocate at least one chunk of
00077  * memory for each veil-using database in the Postgres cluster.  It
00078  * defaults to 16K and may be defined in postgresql.conf using eg: 
00079  * "veil.shmem_context_size = 16384"
00080  */
00081 int
00082 veil_shmem_context_size()
00083 {
00084     veil_load_config();
00085     return shmem_context_size;
00086 }
00087 
00088 /** 
00089  * Initialise Veil's use of GUC variables.
00090  */
00091 void
00092 veil_config_init()
00093 {
00094     static bool first_time = true;
00095     if (!first_time) {
00096         return;
00097     }
00098 
00099 #if PG_VERSION_GE(8, 4)
00100     DefineCustomIntVariable("veil.dbs_in_cluster",
00101                             "The number of databases within the cluster "
00102                             "that will be using veil (1)",
00103                             NULL,
00104                             &dbs_in_cluster,
00105                             1, 1, 16,
00106                             PGC_USERSET,
00107                             0, NULL, NULL);
00108     DefineCustomIntVariable("veil.shared_hash_elems",
00109                             "The number of entries for shared variables in "
00110                             "each shared memory context (32)",
00111                             NULL,
00112                             &shared_hash_elems,
00113                             32, 32, 8192,
00114                             PGC_USERSET,
00115                             0, NULL, NULL);
00116     DefineCustomIntVariable("veil.shmem_context_size",
00117                             "Size of each shared memory context",
00118                             "Size of each shared memory context in bytes.  "
00119                             "This cannot be increased without stopping "
00120                             "and restarting the database cluster.",
00121                             &shmem_context_size,
00122                             4096, 4096, 104857600,
00123                             PGC_USERSET,
00124                             0, NULL, NULL);
00125 #elif PG_VERSION_GE(8, 2)
00126     DefineCustomIntVariable("veil.dbs_in_cluster",
00127                             "The number of databases within the cluster "
00128                             "that will be using veil (1)",
00129                             NULL,
00130                             &dbs_in_cluster,
00131                             1, 16,
00132                             PGC_USERSET,
00133                             NULL, NULL);
00134     DefineCustomIntVariable("veil.shared_hash_elems",
00135                             "The number of entries for shared variables in "
00136                             "each shared memory context (32)",
00137                             NULL,
00138                             &shared_hash_elems,
00139                             32, 8192,
00140                             PGC_USERSET,
00141                             NULL, NULL);
00142     DefineCustomIntVariable("veil.shmem_context_size",
00143                             "Size of each shared memory context",
00144                             "Size of each shared memory context in bytes.  "
00145                             "This cannot be increased without stopping "
00146                             "and restarting the database cluster.",
00147                             &shmem_context_size,
00148                             4096, 104857600,
00149                             PGC_USERSET,
00150                             NULL, NULL);
00151 #endif
00152 
00153     first_time = false;
00154 }
00155 
00156 /** 
00157  * Retrieve Veil's GUC variables for this session.
00158  */
00159 void
00160 veil_load_config()
00161 {
00162     static bool first_time = true;
00163     if (!first_time) {
00164         return;
00165     }
00166 
00167 #if PG_VERSION_GE(8, 2)
00168 #ifdef VEIL_TRIAL
00169     veil_config_init();
00170 #else
00171     dbs_in_cluster = atoi(GetConfigOption("veil.dbs_in_cluster"));
00172     shared_hash_elems = atoi(GetConfigOption("veil.shared_hash_elems"));
00173     shmem_context_size = atoi(GetConfigOption("veil.shmem_context_size"));
00174 #endif  
00175 #endif
00176 
00177     first_time = false;
00178 }
00179 
00180 

Generated on Fri Mar 12 08:38:37 2010 for Veil by  doxygen 1.5.6