veil_funcs.h File Reference


Detailed Description

Provide definitions for all non-local C-callable Veil functions.

     Author:       Marc Munro
     Copyright (c) 2005, 2006 Marc Munro
     License:      BSD
 $Id: veil_funcs.h,v 1.5 2007/07/31 22:18:27 bloodnok Exp $

Definition in file veil_funcs.h.

#include "veil_datatypes.h"

Include dependency graph for veil_funcs.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * vl_malloc (size_t size)
char * vl_ObjTypeName (ObjType obj)
VarEntryvl_lookup_shared_variable (char *name)
VarEntryvl_lookup_variable (char *name)
veil_variable_tvl_next_variable (veil_variable_t *prev)
void vl_ClearInt4Array (Int4Array *array)
Int4Arrayvl_NewInt4Array (Int4Array *current, bool shared, int32 min, int32 max)
void vl_Int4ArraySet (Int4Array *array, int32 idx, int32 value)
int32 vl_Int4ArrayGet (Int4Array *array, int32 idx)
Rangevl_NewRange (bool shared)
Int4Varvl_NewInt4 (bool shared)
void vl_ClearBitmap (Bitmap *bitmap)
void vl_NewBitmap (Bitmap **p_bitmap, bool shared, int32 min, int32 max)
void vl_BitmapSetbit (Bitmap *bitmap, int32 bit)
void vl_BitmapClearbit (Bitmap *bitmap, int32 bit)
bool vl_BitmapTestbit (Bitmap *bitmap, int32 bit)
void vl_BitmapUnion (Bitmap *target, Bitmap *source)
void vl_BitmapIntersect (Bitmap *target, Bitmap *source)
int32 vl_BitmapNextBit (Bitmap *bitmap, int32 bit, bool *found)
Bitmapvl_BitmapFromArray (BitmapArray *bmarray, int32 elem)
void vl_ClearBitmapArray (BitmapArray *bmarray)
void vl_NewBitmapArray (BitmapArray **p_bmarray, bool shared, int32 arrayzero, int32 arraymax, int32 bitzero, int32 bitmax)
VarEntryvl_NextHashEntry (HTAB *hash, VarEntry *prev)
void vl_NewBitmapHash (BitmapHash **p_bmhash, char *name, int32 bitzero, int32 bitmax)
Bitmapvl_BitmapFromHash (BitmapHash *bmhash, char *hashelem)
Bitmapvl_AddBitmapToHash (BitmapHash *bmhash, char *hashelem)
void vl_list_hash (HTAB *hash, char *info)
HTAB * vl_get_shared_hash (void)
bool vl_prepare_context_switch (void)
bool vl_complete_context_switch (void)
void vl_force_context_switch (void)
void * vl_shmalloc (size_t size)
void vl_free (void *mem)
void _PG_init (void)
int vl_spi_connect ()
int vl_spi_finish ()
bool vl_bool_from_query (const char *qry, bool *result)
bool vl_db_exists (Oid db_id)
void veil_config_init (void)
int veil_shared_hash_elems (void)
int veil_dbs_in_cluster (void)
int veil_shmem_context_size (void)


Function Documentation

void _PG_init ( void   ) 

Veil's startup function. This should be run when the Veil shared library is loaded by postgres.

If shared_preload_libraries is not defined, Veil may still be run but it will steal shared memory from postgres, potentially exhausting it.

This function is not defined if VEIL_TRIAL is set. This allows a veil_trail shared object to be created separately from the normal veil shared object, which may be used without defining shared_preload_libraries.

Definition at line 125 of file veil_shmem.c.

References veil_config_init(), veil_dbs_in_cluster(), and veil_shmem_context_size().

Here is the call graph for this function:

void veil_config_init ( void   ) 

Initialise Veil's use of GUC variables.

Definition at line 92 of file veil_config.c.

References dbs_in_cluster, shared_hash_elems, and shmem_context_size.

Referenced by _PG_init(), veil_dbs_in_cluster(), veil_shared_hash_elems(), and veil_shmem_context_size().

int veil_dbs_in_cluster ( void   ) 

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"

Definition at line 52 of file veil_config.c.

References dbs_in_cluster, and veil_config_init().

Referenced by _PG_init(), and get_shmem_context().

Here is the call graph for this function:

int veil_shared_hash_elems ( void   ) 

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"

Definition at line 65 of file veil_config.c.

References shared_hash_elems, and veil_config_init().

Referenced by create_shared_hash().

Here is the call graph for this function:

int veil_shmem_context_size ( void   ) 

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"

Definition at line 82 of file veil_config.c.

References shmem_context_size, and veil_config_init().

Referenced by _PG_init().

Here is the call graph for this function:

Bitmap* vl_AddBitmapToHash ( BitmapHash bmhash,
char *  hashelem 
)

Create a newly allocated empty Bitmap to a BitmapHash

Parameters:
bmhash The BitmapHash to which to add the new Bitmap.
hashelem The key for the new entry
Returns:
Pointer to the newly allocated empty Bitmap.

Definition at line 642 of file veil_bitmap.c.

void vl_BitmapClearbit ( Bitmap bitmap,
int32  bit 
)

Clear a bit within a Bitmap. If the bit is outside of the acceptable range, raise an error.

Parameters:
bitmap The Bitmap within which the bit is to be cleared.
bit The bit to be cleared.

Definition at line 221 of file veil_bitmap.c.

References Bitmap::bitmax, and Bitmap::bitzero.

Bitmap* vl_BitmapFromArray ( BitmapArray bmarray,
int32  elem 
)

Return a specified Bitmap from a BitmapArray.

Parameters:
bmarray The BitmapArray from which the result is to be returned.
elem The index of the Bitmap within the array.
Returns:
The bitmap corresponding to the parameters, or NULL if no such entry exists within the array.

Definition at line 364 of file veil_bitmap.c.

Referenced by veil_bitmap_array_bits().

Bitmap* vl_BitmapFromHash ( BitmapHash bmhash,
char *  hashelem 
)

Return a specified Bitmap from a BitmapHash. Raise an error if the returned object from the hash search is not a bitmap.

Parameters:
bmhash The BitmapHash from which the result is to be returned.
hashelem The key of the Bitmap within the hash.
Returns:
The bitmap corresponding to the parameters, or NULL if no such entry exists within the hash.

Definition at line 600 of file veil_bitmap.c.

References VarEntry::obj, and Object::type.

Referenced by veil_bitmap_hash_bits().

void vl_BitmapIntersect ( Bitmap target,
Bitmap source 
)

Create the intersection of two bitmaps, updating the first with the result.

Parameters:
target The Bitmap into which the result will be placed.
source The Bitmap to be intersected into target.

Definition at line 304 of file veil_bitmap.c.

References Bitmap::bitmax, and Bitmap::bitzero.

int32 vl_BitmapNextBit ( Bitmap bitmap,
int32  bit,
bool *  found 
)

Return the next set bit in the Bitmap.

Parameters:
bitmap The Bitmap being scanned.
bit The starting bit from which to scan the bitmap
found Boolean that will be set to true when a set bit has been found.
Returns:
The bit id of the found bit, or zero if no set bits were found.

Definition at line 338 of file veil_bitmap.c.

void vl_BitmapSetbit ( Bitmap bitmap,
int32  bit 
)

Set a bit within a Bitmap. If the bit is outside of the acceptable range, raise an error.

Parameters:
bitmap The Bitmap within which the bit is to be set.
bit The bit to be set.

Definition at line 187 of file veil_bitmap.c.

References bitmasks, Bitmap::bitmax, Bitmap::bitset, BITSET_BIT, BITSET_ELEM, Bitmap::bitzero, BITZERO, DBG_CHECK_INDEX, DBG_TEST_CANARY, and DBG_TEST_TRAILER.

bool vl_BitmapTestbit ( Bitmap bitmap,
int32  bit 
)

Test a bit within a Bitmap. If the bit is outside of the acceptable range return false.

Parameters:
bitmap The Bitmap within which the bit is to be set.
bit The bit to be tested.
Returns:
True if the bit is set, false otherwise.

Definition at line 251 of file veil_bitmap.c.

void vl_BitmapUnion ( Bitmap target,
Bitmap source 
)

Create the union of two bitmaps, updating the first with the result.

Parameters:
target The Bitmap into which the result will be placed.
source The Bitmap to be unioned into target.

Definition at line 273 of file veil_bitmap.c.

References Bitmap::bitmax, and Bitmap::bitzero.

bool vl_bool_from_query ( const char *  qry,
bool *  result 
)

Executes a query that returns a single bool value.

Parameters:
qry The text of the query to be performed.
result Variable into which the result of the query will be placed.
Returns:
true if the query returned a record, false otherwise.

Definition at line 296 of file veil_query.c.

References fetch_one_bool(), and query().

Referenced by ensure_init(), and veil_init().

Here is the call graph for this function:

void vl_ClearBitmap ( Bitmap bitmap  ) 

Clear all bits in a Bitmap.

Parameters:
bitmap The Bitmap in which all bits are to be cleared

Definition at line 107 of file veil_bitmap.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitset, and Bitmap::bitzero.

Referenced by vl_NewBitmap().

void vl_ClearBitmapArray ( BitmapArray bmarray  ) 

Clear all bitmaps in the given BitmapArray

Parameters:
bmarray The BitmapArray to be cleared

Definition at line 387 of file veil_bitmap.c.

References ARRAYELEMS, BitmapArray::arraymax, BitmapArray::arrayzero, BitmapArray::bitmax, BitmapArray::bitzero, and DBG_TEST_CANARY.

void vl_ClearInt4Array ( Int4Array array  ) 

Reset all Int4 entries in an Int4Array (to zero).

Parameters:
array The array to be reset.

Definition at line 228 of file veil_variables.c.

References Int4Array::array.

Referenced by vl_NewInt4Array().

bool vl_complete_context_switch ( void   ) 

Complete the context switch started by vl_prepare_context_switch(). Raise an ERROR if the context switch cannot be completed.

Returns:
true if the context switch is successfully completed.

Definition at line 646 of file veil_shmem.c.

bool vl_db_exists ( Oid  db_id  ) 

Determine whether the given oid represents an existing database or not.

Parameters:
dbid Oid of the database in which we are interested.
Returns:
True if the database exists.

Definition at line 379 of file veil_query.c.

Referenced by get_shmem_context().

void vl_force_context_switch ( void   ) 

In desparation, if we are unable to complete a context switch, we should use this function.

Definition at line 689 of file veil_shmem.c.

void vl_free ( void *  mem  ) 

Free a piece of shared memory within the current context. Currently this does nothing as implementation of freeing of shared memory has been deferred.

Parameters:
mem Pointer to the memory to be freed.

Definition at line 408 of file veil_shmem.c.

Referenced by vl_NewBitmap().

HTAB* vl_get_shared_hash ( void   ) 

Return the shared hash for the current context.

Returns:
Pointer to the HTAB for the current context's shared hash.

Definition at line 522 of file veil_shmem.c.

References get_cur_context().

Referenced by ensure_init(), and vl_lookup_shared_variable().

Here is the call graph for this function:

int32 vl_Int4ArrayGet ( Int4Array array,
int32  idx 
)

Get an entry from an Int4Array. If idx is outside of the acceptable range, raise an error.

Parameters:
array The Int4Array within from the entry is to be read.
idx The index of the entry to be retrieved.
Returns:
The value of the entry

Definition at line 318 of file veil_variables.c.

References Int4Array::arraymax, and Int4Array::arrayzero.

void vl_Int4ArraySet ( Int4Array array,
int32  idx,
int32  value 
)

Set an entry within an Int4Array. If idx is outside of the acceptable range, raise an error.

Parameters:
array The Int4Array within which the entry is to be set.
idx The index of the entry to be set.
value The value to which the entry will be set.

Definition at line 293 of file veil_variables.c.

References Int4Array::arraymax, and Int4Array::arrayzero.

Referenced by veil_clear_int4array().

VarEntry* vl_lookup_shared_variable ( char *  name  ) 

Define a new, or attach to an existing, shared variable. Raise an ERROR if the variable already exists as a session variable or if we cannot create the variable due to resource limitations (out of memory, or out of space in the shared hash).

Parameters:
name The name of the variable.
Returns:
Pointer to the shared variable. If the variable is newly created by this call then it will be unitialised (ie it will have a NULL obj reference).

Definition at line 71 of file veil_variables.c.

References create_session_hash(), VarEntry::obj, session_hash, VarEntry::shared, and vl_get_shared_hash().

Here is the call graph for this function:

VarEntry* vl_lookup_variable ( char *  name  ) 

Lookup a variable by name, creating it as as a session variable if it does not already exist.

Parameters:
name The name of the variable
Returns:
Pointer to the shared or session variable. If the variable is newly created by this call then it will be unitialised (ie it will have a NULL obj reference).

Definition at line 125 of file veil_variables.c.

void* vl_malloc ( size_t  size  ) 

Dynamically allocate memory using palloc in TopMemoryContext.

Parameters:
size The size of the chunk of memory being requested.
Returns:
Pointer to the newly allocated chunk of memory

Definition at line 28 of file veil_utils.c.

Referenced by create_shared_hash(), get_shmem_context(), vl_NewBitmap(), vl_NewInt4(), and vl_NewRange().

void vl_NewBitmap ( Bitmap **  p_bitmap,
bool  shared,
int32  min,
int32  max 
)

Return a newly initialised (empty) Bitmap. The bitmap may already exist in which case it will be re-used if possible. The bitmap may be created in either session or shared memory depending on the value of shared.

Parameters:
p_bitmap Pointer to an existing bitmap if one exists.
shared Whether to create the bitmap in shared memory
min The smallest bit to be stored in the bitmap
max The largest bit to be stored in the bitmap

Definition at line 129 of file veil_bitmap.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitzero, DBG_SET_CANARY, DBG_SET_ELEMS, DBG_SET_TRAILER, DBG_TEST_CANARY, DBG_TEST_TRAILER, Bitmap::type, vl_ClearBitmap(), vl_free(), vl_malloc(), and vl_shmalloc().

Here is the call graph for this function:

void vl_NewBitmapArray ( BitmapArray **  p_bmarray,
bool  shared,
int32  arrayzero,
int32  arraymax,
int32  bitzero,
int32  bitmax 
)

Return a newly initialised (empty) BitmapArray. It may already exist in which case it will be re-used if possible. It may be created in either session or shared memory depending on the value of shared.

Parameters:
p_bmarray Pointer to an existing bitmap if one exists.
shared Whether to create the bitmap in shared memory
arrayzero The lowest array index
arraymax The highest array index
bitzero The smallest bit to be stored in the bitmap
bitmax The largest bit to be stored in the bitmap

Definition at line 417 of file veil_bitmap.c.

void vl_NewBitmapHash ( BitmapHash **  p_bmhash,
char *  name,
int32  bitzero,
int32  bitmax 
)

Return a newly initialised (empty) BitmapHash. It may already exist in which case it will be re-used if possible. BitmapHash variables may only be created as session (not shared) variables.

Parameters:
p_bmhash Pointer to an existing bitmap if one exists.
name The name to be used for the hash table
bitzero The smallest bit to be stored in the bitmap
bitmax The largest bit to be stored in the bitmap

Definition at line 550 of file veil_bitmap.c.

Int4Var* vl_NewInt4 ( bool  shared  ) 

Create a new session or shared Int4Var object.

Parameters:
shared Whether the object is to be created in shared (true) or session (false) memory.
Returns:
Pointer to newly created object.

Definition at line 52 of file veil_datatypes.c.

References Int4Var::isnull, Int4Var::type, vl_malloc(), and vl_shmalloc().

Here is the call graph for this function:

Int4Array* vl_NewInt4Array ( Int4Array current,
bool  shared,
int32  min,
int32  max 
)

Return a newly initialised (zeroed) Int4Array. It may already exist in which case it will be re-used if possible. It may be created in either session or shared memory depending on the value of shared.

Parameters:
current Pointer to an existing Int4Array if one exists.
shared Whether to create the variable in shared or session memory.
min Index of the first entry in the array.
max Index of the last entry in the array.

Definition at line 250 of file veil_variables.c.

References Int4Array::arraymax, Int4Array::arrayzero, and vl_ClearInt4Array().

Here is the call graph for this function:

Range* vl_NewRange ( bool  shared  ) 

Create a new session or shared Range object.

Parameters:
shared Whether the object is to be created in shared (true) or session (false) memory.
Returns:
Pointer to newly created object.

Definition at line 28 of file veil_datatypes.c.

References Range::type, vl_malloc(), and vl_shmalloc().

Here is the call graph for this function:

veil_variable_t* vl_next_variable ( veil_variable_t prev  ) 

Return the next variable from a scan of the hash of variables. Note that this function is not re-entrant.

Parameters:
prev The last variable retrieved by a scan, or NULL if starting a new scan.
Returns:
The next variable encountered in the scan. NULL if we have finished.

Definition at line 171 of file veil_variables.c.

References create_session_hash(), and session_hash.

Here is the call graph for this function:

VarEntry* vl_NextHashEntry ( HTAB *  hash,
VarEntry prev 
)

Utility function for scanning the hash table of a BitmapHash.

Parameters:
hash The hash table being scanned
prev The entry from which to scan, starting with NULL.
Returns:
The next element in the hash table (a VarEntry) or NULL when the last element has already been scanned.

Definition at line 525 of file veil_bitmap.c.

References BitmapHash::hash, VarEntry::obj, Object::type, and vl_NextHashEntry().

Referenced by vl_NextHashEntry().

Here is the call graph for this function:

char* vl_ObjTypeName ( ObjType  obj  ) 

Return a static string describing an ObjType object.

Parameters:
obj The ObjType for which we want a description.
Returns:
Pointer to a static string describing obj.

Definition at line 45 of file veil_utils.c.

Referenced by type_mismatch().

bool vl_prepare_context_switch ( void   ) 

Prepare for a switch to the alternate context. Switching will only be allowed if there are no transactions that may still be using the context to which we are switching, and there is no other process attempting the switch.

Returns:
true if the switch preparation was successful.

Definition at line 574 of file veil_shmem.c.

Referenced by veil_init().

void* vl_shmalloc ( size_t  size  ) 

Dynamically allocate a piece of shared memory from the current context.

Parameters:
size The size of the requested piece of memory.
Returns:
Pointer to dynamically allocated memory.

Definition at line 385 of file veil_shmem.c.

Referenced by vl_NewBitmap(), vl_NewInt4(), and vl_NewRange().


Generated on Tue Mar 11 10:08:37 2008 for Veil by  doxygen 1.5.4