Persistent data can be accessed only if the database in which it resides is open. Databases are created, destroyed, opened, and closed with database member functions. The functions for creating, opening, and closing databases can be called either inside or outside a transaction. The function for destroying databases should be called outside a transaction.
Each database retrieved by a given process has an associated open count for that process. The member function os_database::open() increments the open count by 1, and the member function os_database::close() decrements the open count by 1. When the open count for a process increases from 0 to 1, the database becomes open for that process. A database becomes closed for a process when its open count becomes 0.
When a process terminates, any databases left open are automatically closed.
Instances of the class os_database are sometimes used to hold process local or per-process state, representing a property of the database for the current process. For example, the function os_database::is_writable() returns a value indicating whether the specified database is writable for the current process. This is per-process information since the database might be unwritable by one process (because it opened the database for read only - see os_database::open()) while it is writable by another process. As a consequence, it is sometimes preferable to think of an instance of this class as representing an association between a database and a process (the process that retrieves the pointer to it). In fact, instances of os_database are actually transient objects.
Invoking ::operator delete() on an os_database is illegal.
The types os_int32 and os_boolean, used throughout this manual, are each defined as a signed 32-bit integer type. The type os_unsigned_int32 is defined as an unsigned 32-bit integer type. The type os_unixtime_t is defined as unsigned long.
os_database::allow_external_pointers()
void allow_external_pointers(os_boolean set_default_only = 0);Must be called from within a transaction. Once invoked, cross-database pointers are allowed from all current and future segments of the specified database, unless set_default_only is specified as a nonzero value (true), in which case cross-database pointers will be allowed only from subsequently created segments.
A pointer from one database, db1, to another, db2, points to, at any given time, whichever database has a certain pathname - namely, db2's pathname at the time the pointer was stored. If db2's pathname changes (for example, as a result of performing osmv on db2), the pointer will no longer refer to data in db2. If some other database, db3, is given db2's original pathname (for example, as a result of performing osmv on db3), the pointer will refer to data in db3.
The pathname is not stored as part of the cross-database pointer (which takes the form of a regular virtual memory address), but rather as part of an os_database_reference stored in a table associated with the pointer.
It is illegal to rename a database so that a pointer that used to refer to another database now refers to the database in which the pointer itself resides.
References normally store a relative pathname; that is, if the source and destination databases have a common ancestor directory, the common directory is not stored as part of the pathname - only the part of the target database's pathname that is not shared with the source database's pathname is stored. On UNIX systems, for example, the common part of the pathname is preceded by the appropriate number of "../"s to traverse the hierarchy up from the source directory to the common ancestor directory. For example, if the source and target databases are named "/sys/appl/mydb" and "/sys/lib/lib1" respectively, the reference stores the relative pathname, "../lib/lib1".
You can override use of relative pathnames with the functions os_database::set_relative_directory() and os_database::get_relative_directory() - see the entries for these functions below.
Dereferencing a cross-database pointer causes the destination database, if not already open, to be opened for read/write. Thus, dereferencing such a pointer can result in err_database_not_found.
void change_database_reference( os_database_reference *old_ref, os_database_reference *new_ref );Substitutes new_ref for old_ref in all tables that resolve pointers out of the specified database. Can be used to change the type of a cross-database pointer's associated os_database_reference. Does not affect pointers already resolved. This function signals err_trans if it is called within a transaction.
os_database::change_database_reference starts its own transaction (outside any user transaction), and iterates over every segment in the database to find and change the reference. Be aware that there is a small risk of an address space problem if there are pvars that trigger data page use during the internal transaction that os_database::change_database_reference uses.
See also the functions os_database::allow_external_pointers() and os_database::get_database_references(), and the class os_database_reference.
os_database::change_schema_key()
void change_schema_key( os_unsigned_int32 old_key_low, os_unsigned_int32 old_key_high, os_unsigned_int32 new_key_low, os_unsigned_int32 new_key_high );Sets the schema key of the specified database. Call this function from within an update transaction. The specified database must be opened for update, otherwise ObjectStore signals err_opened_read_only, and issues an error message like the following:
<err-0025-0155> Attempt to change the schema key of database db1, but it is opened for read only.If the database has had its key frozen, err_schema_key is signaled, and ObjectStore issues an error message like the following:
err_schema_key <err-0025-0152> The schema key of database db1 is frozen and may not be changed.If the database already has a schema key at the time of the call, old_key_low must match the first component of the key and old_key_high must match the second component, or err_schema_key is signaled, and ObjectStore issues an error message like the following:
Error using schema keys <err-0025-0158>Unable to change schema key of database db1. The schema is already protected and the key provided did not match the old key in the schema. (err_schema_key)If the database has no schema key, old_key_low and old_key_high are ignored.
new_key_low specifies the first component of the database's new schema key, and new_key_high specifies the second component. If both these arguments are 0, calling this function causes the database to have no schema key.
void close();If the open count of the database for which the function is called is greater than 0, decrements the open count by 1. If the function is called from within a transaction, the open count is not decremented until the end of the current outermost transaction. If the open count becomes 0, the database is closed. If the new open count, c, remains greater than 0, the database is given the access type (opened for read or opened for read/write) it had as of the last time the open count was c.
static os_database *create( const char *pathname, os_int32 mode = 0664, os_boolean if_exists_overwrite = 0, os_database *schema_database = 0 );Returns a pointer to a newly created database, an instance of the class os_database, with the specified pathname and mode (the values of mode are as described in ObjectStore Management, oschmod: Changing Database Permissions). The new database is also opened for read/write, and its open count is incremented.
If a database with the specified pathname already exists, an err_database_exists exception is signaled, unless if_exists_overwrite is nonzero (true). If if_exists_overwrite is nonzero, any existing database with the same pathname is deleted, a new database is created with the specified mode, and the new database is opened for read/write.
os_database::create(pathname, mode, if_exists_overwrite);If schema_database is nonzero, the database it specifies is used as the schema database for the newly created database. This means that ObjectStore installs in the schema database all schema information for the data stored in the new database; the new database itself will have no schema information in it.
The specified schema database must be open at the time of the call to create(); if it is not, err_schema_database is signaled. If the schema database was opened for read only, ObjectStore attempts to reopen it for read/write. If this fails because of protections on the database, it remains open for read only. This prevents any update to the new database that requires schema installation.
Note that the new database's schema database can also contain regular user data (that is, data other than schema information). The schema database must store its own schema locally. If the schema for the user data in schema_database is stored remotely, err_schema_database is signaled.
For file databases, pathname is an operating system pathname. ObjectStore takes into account local NFS mount points when interpreting the pathname, so pathnames can refer to databases on foreign hosts. To refer to a database on a foreign host for which there is no local mount point, use a Server host prefix, the name of the foreign host followed by a colon (:), as in oak:/foo/bar.
For databases in ObjectStore directories, pathname consists of a rooted pathname preceded by a rawfs host prefix of the form host-name:: (for example oak::/foo/bar). The rawfs host prefix can be followed by a Server host prefix of the form host-name: (as in oak::beech:/foo/bar).
The Server host name specifies the file system on which you want the new database stored. If no Server host name is supplied, the value of the ObjectStore environment variable OS_SERVER_HOST is used.
os_database_root *create_root(char *name);Creates a root in the specified database to associate a copy of the specified name with an as-yet-unspecified entry-point object. (Since the name is copied to persistent memory by this function, the supplied char* can point to transient memory.) If the specified name is already associated with an entry-point object in the same database, an err_root_exists exception is signaled. If the specified database is the transient database, an err_database_not_open exception is signaled.
os_segment *create_segment();Creates a segment in the specified database, and returns a pointer to an instance of the class os_segment. Call this function from within a transaction. The return value points to a transient object representing the new segment. Note that, since it points to transient memory, the return value of this function cannot be stored persistently. Performing this function on the transient database returns a pointer to the transient segment.
void decache();This function deletes all internal storage associated with the given database. Its purpose is to allow applications to open large numbers of databases without continuing to use more virtual memory and commseg space for each database opened.
Calling decache() on an os_database makes the os_database object, and any os_segment objects for that database, unusable. You should not refer to the os_database or os_segment objects again; doing so could lead to unpredictable results. If you want to open or look up the database again, use os_database::lookup() or the overloading of os_database::open() that takes a pathname argument.
There are some restrictions on when this function can be used. The call to os_database::decache() must be made outside a transaction. The application cannot be in retain_persistent_addresses mode. The database being decached cannot be the transient database, be currently opened by the application, or have open the database that it wants to decache. ObjectStore will raise an err_misc exception if any of these restrictions is violated.
Calling decache() on an os_database invalidates any os_reference_transient objects that refer to objects within the database. Attempting to resolve these invalidated references will have unpredictable results.
Applications should only call this routine if they probably will not refer to the database soon. There is some overhead associated with using a database for the first time that will be incurred again if the database is opened after it is decached.
void destroy();Deletes the database for which the function is called. To make your program portable, only call this function from outside any transaction. If the database is open at the time of the call, destroy() closes the database before deleting it.
When a process destroys a database, this can affect other processes that have the database opened. Such a process might subsequently be unable to access some of the database's data - even if earlier in the same transaction it successfully accessed the database.
Data already cached in the process's client cache will continue to be accessible, but attempts to access other data will cause ObjectStore to signal err_database_not_found. Attempts to open the database will also provoke err_database_not_found. Note that performing os_database::lookup() on the destroyed database's pathname might succeed, since the instance of os_database representing the destroyed database might be in the process's client cache.
If you call this function from within a transaction, beware of the following:
os_database_root *find_root(char *name);Returns a pointer to the root in the specified database with the specified name. Returns 0 if not found.
void freeze_schema_key( os_unsigned_int32 key_low, os_unsigned_int32 key_high );Freezes the specified database's schema key, preventing any change to the key, even by applications with a matching key.
Call this function from within an update transaction. The specified database must be opened for update, otherwise ObjectStore signals err_opened_read_only, and issues an error message like the following:
<err-0025-0156> Attempt to freeze the schema key of database db1, but it is opened for read only.If the database is schema protected and has not been accessed since the last time its open count was incremented from 0 to 1, the application's schema key must match the database's schema key. If it does not, err_schema_key is signaled, and ObjectStore issues an error message like the following:
<err-0025-0151>The schema is protected and the key, if provided, did not match the one in the schema of database dba.key_low and key_high must match the database's schema key, or else err_schema_key is signaled, and ObjectStore issues an error message like the following:
<err-0025-0159>Unable to freeze the schema key of database db1. The schema is protected and the key provided did not match the key in the schema.If the database's schema key is already frozen, and you specify the correct key, the call has no effect.
static void get_all_databases( os_int32 max_to_return, os_database_p *dbs, os_int32& n_ret );Provides access to all the databases retrieved by the current process. The os_database_p*dbs is an array of pointers to databases. This array must be allocated by the user. The function os_database::get_n_databases() can be used to determine how large an array to allocate. max_to_return is specified by the user, and is the maximum number of elements the array is to have.
void get_all_roots( os_int32 max_to_return, os_database_root_p *roots, os_int32& n_ret );Provides access to all the roots in the specified database (see os_database_root). The os_database_root_p* is an array of pointers to roots. This array must be allocated by the user. The function os_database::get_n_roots() can be used to determine how large an array to allocate. max_to_return is specified by the user, and is the maximum number of elements the array is to have. n_ret refers to the actual number of elements in the array.
os_database::get_all_segments()
void get_all_segments( os_int32 max_to_return, os_segment_p *segs, os_int32& n_ret );iProvides access to all the segments in the specified database. The os_segment_p* is an array of pointers to segments. This array must be allocated by the user. The function os_database::get_n_segments() can be used to determine how large an array to allocate. max_to_return is specified by the user, and is the maximum number of elements the array is to have. n_ret refers to the actual number of segment pointers returned.
void get_all_segments_and_permissions( os_int32 max_to_return, os_segment_p* segs, os_segment_access_p* controls, os_int32 &n_returned );Provides access to all the segments in the specified database, together with each segment's associated os_segment_access. The nth element of controls points to the os_segment_access associated with the segment pointed to by the nth element of segs. The arrays controls and segs must be allocated by the user. max_to_return is specified by the user.
void *get_application_info() const;Returns a pointer to the object pointed to by the pointer last passed, during the current process, to os_database::set_application_info() for the specified database. If set_application_info() has not been called for the specified database during the current process, 0 is returned.
os_boolean get_check_illegal_pointers() const;Returns nonzero if the database is in check_illegal_pointers mode; returns 0 otherwise.
void get_database_references( os_int32 &n_refs, os_database_reference_p *&array ) const;Allocates an array of database references on the heap, one for each database referenced by the specified database. When the function returns, n_refs refers to the number of elements in the array. Note that it is the user's responsibility to deallocate the array when it is no longer needed.
os_boolean get_default_check_illegal_pointers() const;Returns nonzero if the specified database is in default_check_illegal_pointers mode; returns 0 otherwise. See os_database::set_default_check_illegal_pointers().
os_database::get_default_lock_whole_segment()
objectstore_lock_option get_default_lock_whole_segment() const;Indicates the locking behavior for segments newly created in the specified database. objectstore_lock_option is an enumeration type whose enumerators are objectstore::lock_as_used, objectstore::lock_segment_read, and objectstore::lock_segment_write. See os_database::set_default_lock_whole_segment().
os_database::get_default_null_illegal_pointers()
os_boolean get_default_null_illegal_pointers() const;Returns nonzero if the specified database is in default_null_illegal_pointers mode; returns 0 otherwise. See os_database::set_default_null_illegal_pointers().
os_database::get_default_segment()
os_segment *get_default_segment() const;Returns a pointer to the default segment of the specified database. The default segment is the segment in which persistent memory is allocated by default, when the function new is called with only an os_database* argument. Initially the default segment is the initial segment, the one segment (besides the schema segment) with which the database was created. A process can change this at any time (see os_database::set_default_segment()), but the change remains in effect only for the duration of the process, and is invisible to other processes. Simple ObjectStore applications need not create any segments; all the database's persistent data can be stored in the initial segment, if desired. But if more sophisticated clustering is required, the application can create new segments in the database, and it might be convenient to make one of these the default.
os_database::get_default_segment_size()
os_int32 get_default_segment_size() const;The initial size in bytes of segments in the specified database. See os_database::set_default_segment_size().
os_database::get_dirman_host_name()
char *get_dirman_host_name() const;If the specified database is a rawfs database, the function allocates on the heap and returns the name of the host machine for the rawfs. If the database is a file database or the transient database, 0 is returned. Note that it is the user's responsibility to deallocate the character array when it is no longer needed.
void get_fetch_policy(os_fetch_policy &policy, os_int32 &bytes);Sets policy and bytes to references to an os_fetch_policy and integer that indicate the database's current fetch policy. See os_database::set_fetch_policy().
os_database::get_file_host_name()
char *get_file_host_name() const;If the specified database is a file database, the function allocates on the heap and returns the name of the host machine for the database. If the database is a rawfs database or the transient database, 0 is returned. Note that it is the user's responsibility to deallocate the character array when it is no longer needed.
char *get_host_name() const;Returns the name of the host machine on which the specified database resides. The returned char* points to an array allocated on the heap by this function. Note that it is the user's responsibility to deallocate the character array when it is no longer needed.
os_database_id *get_id() const;Returns the os_database_id of the specified database.
os_boolean get_incremental_schema_installation();Returns nonzero (true) if the schema installation mode of the specified database is set to incremental mode. Returns 0 (false) if the mode is set to batch mode (the default). See os_database::set_incremental_schema_installation().
os_database::get_lock_whole_segment()
objectstore_lock_option get_lock_whole_segment() const;Indicates the locking behavior currently in effect for the specified database. objectstore_lock_option is an enumeration type whose enumerators are objectstore::lock_as_used, objectstore::lock_segment_read, and objectstore::lock_segment_write. See os_segment::set_lock_whole_segment().
os_database::get_n_databases()
static os_int32 get_n_databases();Returns the number of databases retrieved by the current process.
os_int32 get_n_roots() const;Returns the number of roots in the specified database (see os_database_root).
os_int32 get_n_segments() const;Returns the number of segments in the specified database, including the schema segment.
os_boolean get_opt_cache_lock_mode() const;Returns nonzero if opt_cache_lock_mode is on for the current process and the specified database; returns 0 otherwise. See os_database::set_opt_cache_lock_mode().
char *get_pathname() const;Returns the pathname of the specified database. For databases in ObjectStore directories, the pathname consists of a rawfs host prefix ("rawfs-host-name::") followed by a rooted pathname (for example, "oak::/parts/db1"). For file databases, the pathname is identical to the one passed to os_database::open(), os_database::create(), or os_database::lookup() when this was first retrieved by the current process. The returned char* points to an array allocated on the heap by this function. Note that it is the user's responsibility to deallocate the array when it is no longer needed.
os_boolean get_prms_are_in_standard_format() const;
os_int32 get_readlock_timeout() const;Returns the time in milliseconds for which the current process will wait to acquire a read lock on pages in the specified database. A value of -1, the default, indicates that the process will wait forever if necessary.
char *get_relative_directory() const;Returns a string indicating the current method used for storing database references. If 0 (null) is returned, the default method is used. If an empty string is returned, rooted pathnames are used. Otherwise, the string returned indicates the name of a directory to be treated as a common ancestor to the source and destination databases. On UNIX systems, for example, the common part of the pathnames is preceded by the appropriate number of "../"s to traverse the hierarchy up from the source directory to this common ancestor directory. If the indicated directory is not actually a common ancestor, a rooted pathname is used. The returned char* points to an array allocated on the heap by this function. Note that it is the user's responsibility to deallocate the array when it is no longer needed. See os_database::allow_external_pointers() and os_database::set_relative_directory().
os_database::get_required_DLL_identifiers()
Component Schema
const char* const* get_required_DLL_identifiers( os_unsigned_int32& count );Returns an array of pointers to DLL identifiers and the number of elements in the array. The order of elements in the array is not significant. The array and the elements must not be modified or deallocated.
This function can only be called within a transaction with the database open. The returned array and strings might reside in the database so they are only valid for one transaction.
os_database *get_schema_database() const;Returns a pointer to the schema database for this. If this is not a database whose schema is stored remotely, 0 is returned. This function must be invoked within a transaction.
os_unsigned_int32 get_sector_size();Returns the size of a sector, in bytes.
os_segment *get_segment(os_unsigned_int32 segment_number);Returns a pointer to the segment in the specified database with the specified segment number. See os_segment::get_number().
os_database::get_transient_database()
static os_database *const get_transient_database();Returns a pointer to the transient database, which can be used to request transient memory allocation, for example as an argument to new().
os_int32 get_writelock_timeout() const;Returns the time in milliseconds for which the current process will wait to acquire a write lock on pages in the specified database. A value of -1, the default, indicates that the process will wait forever if necessary.
void insert_required_DLL_identifier( const char* DLL_identifier );Copies the DLL_identifier string and adds it to the database's set of required DLLs. If the DLL_identifier is already in the database's set of required DLLs, this function does nothing. Call this function only in an update transaction with the database open for write.
See also os_database::insert_required_DLL_identifiers()
os_database::insert_required_DLL_identifiers()
void insert_required_DLL_identifiers (const char* const* DLL_identifiers, os_unsigned_int32 count );Copies DLL_identifiers to a database's set of required DLLs.
For each identifier, checks that the identifier is not already in the set. If already present, the identifier is not copied. If the identifier isn't present in the set of required DLLs, it is copied and added to the set. This function can only be called in an update transaction with the database open for write.
os_database::insert_required_DLL_identifiers is equivalent to repeated calls to os_database::insert_required_DLL_identifier but is more efficient.
os_boolean is_open() const;Returns a nonzero os_boolean (true) if the database for which the function is called is open, and 0 (false) otherwise.
os_boolean is_open_mvcc() const;Returns nonzero if this is opened for MVCC, and 0 otherwise. See os_database::open_mvcc().
os_database::is_open_read_only()
os_boolean is_open_read_only() const;Returns a nonzero os_boolean (true) if the database for which the function is called is open for read only, and 0 (false) otherwise.
os_boolean is_writable() const;Returns a nonzero os_boolean (true) if the database for which the function is called is writable by the current process. The function returns 0 (false) if the database is not writable, for example because the current process opened it read_only, or because, due to access control, the process does not have write permission. The return value is not affected by whether the current transaction, if any, is a read_only transaction. If performed on a database that is not open, a run-time error is signaled.
static os_database *lookup( const char *pathname os_int32 create_mode = 0 );Returns a pointer to the database with the specified pathname (but does not open it). If not found, an err_database_not_found exception is signaled. create_mode is a boolean; if its value is nonzero and no database named pathname exists, it creates the database.
For information on database pathnames, see os_database::create().
static os_database *of(void *location);Returns a pointer to the database in which the specified object resides. If the object is transiently allocated, a pointer to the transient database is returned. In almost all cases you should use os_segment::of() instead of os_database::of(). In particular, you should never use the result of os_database::of() to allocate a new persistent object. Doing so will defeat segment clustering. When in doubt, use os_segment::of().
void open(os_boolean read_only = 0);Increases the open count of the specified database by 1, and establishes the access type specified by read_only - nonzero (true) for read only and 0 for read/write.
static os_database *open( const char *pathname, os_boolean read_only = 0, os_int32 create_mode = 0 );Increments the open count of the database with the specified pathname, establishes the access type specified by read_only - nonzero (true) for read only and 0 (false) for read/write - and returns a pointer to that database. If not found, an err_database_not_found exception is signaled, unless create_mode is nonzero.
If create_mode is nonzero and no database named pathname exists, the effect is the same as calling os_database::create() with the same pathname, create_mode, and schema_database arguments. The values of create_mode - which must be octal numbers, beginning with 0 - are described in ObjectStore Management.
For information on database pathnames, see os_database::create().
static os_database *open( const char *pathname, os_boolean read_only, os_int32 create_mode, os_database *schema_database );The first three arguments are as described for the previous overloading of open(). If no database named pathname is found, and schema_database is nonzero, schema_database is used as the schema database for the newly created database. This means that ObjectStore installs in the schema database all schema information for the data stored in the new database; the new database itself will have no schema information in it.
The specified schema database must be open at the time of the call to open(); if it is not, err_schema_database is signaled. If the schema database was opened read only, ObjectStore attempts to reopen it for read/write. If this fails because of protections on the database, it remains open for read only. This prevents any update to the new database that requires schema installation.
Note that the new database's schema database can also contain regular user data (that is, data other than schema information). The schema database must store its own schema locally. If the schema for the user data in schema_database is stored remotely, err_schema_database is signaled.
void open_mvcc();Opens a database for multiversion concurrency control (MVCC). Once you open a database for MVCC, multiversion concurrency control is used for access to it until you close it. If the database is already opened, but not for MVCC, err_mvcc_nested is signaled. If you try to perform write access on a database opened for MVCC, err_opened_read_only is signaled.
If an application has a database opened for MVCC, it never has to wait for locks to be released in order to read the database. Reading a database opened for MVCC also never causes other applications to have to wait to update the database. In addition, an application never causes a deadlock by accessing a database it has opened for MVCC.
In each transaction in which an application accesses a database opened for MVCC, the application sees what it would see if viewing a snapshot of the database taken sometime during the transaction. This snapshot has the following characteristics:
Even though the snapshot might be out of date by the time some of the access is performed, multiversion concurrency control retains serializability, if each transaction that accesses an MVCC database accesses only that one database. Such a transaction sees a database state that would have resulted from some serial execution of all transactions, and all the transactions produce the same effects as would have been produced by the serial execution.
static os_database *open_mvcc(const char *pathname);Opens the database with the specified pathname for multiversion concurrency control. See the first overloading of open_mvcc(), above.
void remove_required_DLL_identifier( const char* DLL_identifier );Removes the DLL_identifier from the database's set of required DLLs. If DLL_identifier is not in the set, this function does nothing. This function can only be called in an update transaction with the database open for write.
typedef void (*os_access_hook) ( void *object, enum os_access_reason reason, void *user_data, void *start_range, void *end_range ); void set_access_hooks os_char_p class_name, os_access_hook inbound_hook, os_access_hook outbound_hook, os_void_p user_data, os_access_hook *old_inbound_hook = 0, os_access_hook *old_outbound_hook = 0, os_void_p *old_user_data = 0 );Registers an inbound and outbound hook function for the specified database and class.
The class_name argument is the name of the class with which these hook functions should be associated.
inbound_hook is the user-supplied hook function that is called each time an instance of the specified class in the specified database becomes accessible (that is, the first time in each transaction the object is accessed, as well as each time the object is transferred into the client cache).
outbound_hook is the user-supplied hook function that is called each time an instance of the specified class in the specified database undergoes outbound relocation. This typically occurs each time the transaction ends and the object is in the client cache, and each time the object is transferred out of the client cache.
In some cases, however, an object might be transferred out of the client cache without undergoing outbound relocation (see for example OS_EVICT_IN_ABORT in ObjectStore Management), and so the outbound_hook is not called. This means that there is not necessarily a call to the outbound_hook for each call to the inbound_hook. So you must structure your application to allow for consecutive calls to the inbound hook without intervening calls to the outbound hook.
The inbound_hook and outbound_hook arguments can be null pointers in order to specify that there should be no hook. To disable both hooks, pass a null pointer for both these arguments.
user_data is a pointer to user data to be passed to the hook functions.
The previous value for the inbound_hook is returned in the location pointed to by old_inbound_hook, if old_inbound_hook is a nonnull pointer. The previous value will be 0 if no inbound_hook was enabled. Similarly, the previous values of outbound_hook and user_data are returned in the locations pointed to by old_outbound_hook and old_user_data if these are nonnull pointers.
The hook functions are called with the following arguments:
object points to the beginning of the object for which the access hook is registered.
For an inbound hook, reason is always set to os_reason_accessed. For an outbound hook, reason is os_reason_committed if the object is on a page that is being relocated out at the end of a transaction, os_reason_aborted if the page is being relocated out during a transaction abort, and os_reason_returned if the page is being relocated out at some other time, presumably to make space in the cache for other data.
user_data is set to the value of user_data that was passed to os_database::set_access_hooks().
start_range is the first address that is being made accessible during an inbound hook, or made inaccessible during an outbound hook. end_range is the first address beyond the range being made accessible or inaccessible. That is, all addresses greater than or equal to start_range and less than end_range are being made accessible or inaccessible.
Only a portion of the object might lie within start_range and end_range. The hook should only write within this address range. You should make all modifications by calling objectstore::hidden_write(). Note that the active region of the object might be writable in the context of the hook, but under no circumstances should the application modify any persistent addresses from within the hook by any other means other than by using the objectstore::hidden_write() function.
Read access is allowed to any part of the object, not just the part within the address range. You cannot safely dereference pointers outside the object, but you can pass them to objectstore::get_pointer_numbers().
Classes within unions will not have access hooks called.
void set_application_info(void *info);Associates the specified object with the specified database for the current process. The argument info must point to a transient object. See os_database::get_application_info().
os_database::set_check_illegal_pointers()
void set_check_illegal_pointers(os_boolean);Provides a convenient way to set check_illegal_pointers mode for every segment in the specified database. If the argument is 1 (that is, true), it loops over every segment, including internal segments, enabling check_illegal_pointers. It also enables default_check_illegal_pointers mode for the specified database. If the argument is 0 (that is, false), it disables check_illegal_pointers mode for every segment, and disables default_check_illegal_pointers mode for the specified database. See os_segment::set_check_illegal_pointers() and os_database::set_default_check_illegal_pointers().
os_database::set_default_check_illegal_pointers()
void set_default_check_illegal_pointers(os_boolean);If the argument is 1 (that is, true), this enables default_check_illegal_pointers mode for the specified database. In this mode, new segments are created in check_illegal_pointers mode. If the argument is 0 (that is, false), this disables default_check_illegal_pointers mode, and new segments are created with check_illegal_pointers disabled. By default, default_check_illegal_pointers mode is disabled. See also objectstore::set_check_illegal_pointers().
os_database::set_default_lock_whole_segment()
void set_default_lock_whole_segment(objectstore_lock_option);Specifies the locking behavior for segments newly created in the specified database. See os_segment::set_lock_whole_segment().
os_database::set_default_null_illegal_pointers()
void set_default_null_illegal_pointers(os_boolean);If the argument is 1 (that is, true), this enables default_null_illegal_pointers mode for the specified database. In this mode, new segments are created in null_illegal_pointers mode. If the argument is 0 (that is, false), this disables default_null_illegal_pointers mode, and new segments are created with null_illegal_pointers disabled. By default, default_null_illegal_pointers mode is disabled. See also objectstore::set_null_illegal_pointers().
os_database::set_default_segment()
void set_default_segment(os_segment*);Sets the default segment for the specified database. The default segment is the segment in which persistent memory is allocated by default, when the function new is called with only an os_database* argument. Initially the default segment is the initial segment, the one segment (besides the schema segment) with which the database was created. Changing the default segment remains in effect only for the duration of the process, and is invisible to other processes. Simple ObjectStore applications need not create any segments; all the database's persistent data can be stored in the initial segment, if desired. But if more sophisticated clustering is required, the application can create new segments in the database, and it might be convenient to make one of these the default.
void set_default_segment_size(os_int32);The specified os_int32 is used to determine the initial size of segments in the specified database. This size is either the specified value (in bytes) or an implementation-dependent minimum size, whichever is larger.
enum os_fetch_policy { os_fetch_segment, os_fetch_page, os_ fetch_stream }; void set_fetch_policy(os_fetch_policy policy, os_int32 bytes);Specifies the fetch policy for all the segments in the specified database. The policy argument should be one of the following enumerators: os_fetch_segment, os_fetch_page, or os_fetch_stream.
The default fetch policy is os_fetch_page.
If an operation manipulates a substantial portion of a small segment, use the os_fetch_segment policy when performing the operation on the segment. Under this policy, ObjectStore attempts to fetch the entire segment containing the desired page in a single client/server interaction, if the segment will fit in the client cache without evicting any other data. If there is not enough space in the cache to hold the entire segment, the behavior is the same as for os_fetch_page with a fetch quantum specified by bytes.
If an operation uses a segment larger than the client cache, or does not refer to a significant portion of the segment, use the os_fetch_page policy when performing the operation on the segment. This policy causes ObjectStore to fetch a specified number of bytes at a time, rounded up to the nearest positive number of pages, beginning with the page required to resolve a given object reference. bytes specifies the fetch quantum. (Note that if you specify 0 bytes, this will be rounded up, and the unit of transfer will be a single page.)
The default value for the fetch quantum is 4096 bytes (1 page). Appropriate values might range from 4 kilobytes to 256 kilobytes or higher, depending on the size and locality of the application data structures.
For special operations that scan sequentially through very large data structures, os_fetch_stream might considerably improve performance. As with os_fetch_page, this fetch policy lets you specify the amount of data to fetch in each client/server interaction for a particular segment. But, in addition, it specifies that a double buffering policy should be used to stream data from the segment.
This means that after the first two transfers from the segment, each transfer from the segment replaces the data cached by the second-to-last transfer from that segment. This way, the last two chunks of data retrieved from the segment will generally be in the client cache at the same time. And, after the first two transfers, transfers from the segment generally will not result in eviction of data from other segments. This policy also greatly reduces the internal overhead of finding pages to evict.
When you perform allocation that extends a segment whose fetch policy is os_fetch_stream, the double buffering described above begins when allocation reaches an offset in the segment that is aligned with the fetch quantum (that is, when the offset mod the fetch quantum is 0).
For all policies, if the fetch quantum exceeds the amount of available cache space (cache size minus wired pages), transfers are performed a page at a time. In general, the fetch quantum should be less than half the size of the client cache.
Note that a fetch policy established with set_fetch_policy() (for either a segment or a database) remains in effect only until the end of the process making the function call. Moreover, set_fetch_policy() only affects transfers made by this process. Other concurrent processes can use a different fetch policy for the same segment or database.
void set_incremental_schema_installation(os_boolean);If a nonzero os_boolean (true) is supplied as argument, the schema installation mode of the specified database is set to incremental mode. With incremental schema installation, a class is added to a database's schema only when an instance of that class is first allocated in the database. If 0 (false) is supplied as argument, the mode is set to batch mode (the default). With batch mode, whenever an application creates or opens the database, every class in the application's schema is added to the database's schema (if not already present in the database schema).
void set_lock_whole_segment(objectstore_lock_option);Provides a convenient way to set lock_whole_segment mode for every segment in the specified database. It loops over every segment, including internal segments, setting lock_whole_segment, and setting default_lock_whole_segment in the database. See os_segment::set_lock_whole_segment() and os_database::set_default_lock_whole_segment().
os_int32 set_new_id();Changes the ID of the specified database to be a new unique ID.
void set_null_illegal_pointers(os_boolean);Provides a convenient way to set null_illegal_pointers mode for every segment in the specified database.
If the argument is 1 (that is, true), it loops over every segment, including internal segments, enabling null_illegal_pointers. It also enables default_null_illegal_pointers mode for the specified database.
If the argument is 0 (that is, false), it disables null_illegal_pointers mode for every segment, and disables default_null_illegal_pointers mode for the specified database.
See os_segment::set_null_illegal_pointers() and os_database::set_default_null_illegal_pointers().
os_database::set_opt_cache_lock_mode()
void set_opt_cache_lock_mode(os_boolean);A nonzero argument turns on opt_cache_lock_mode for the current process and the specified database; a 0 argument turns the mode off.
Turning on this mode will improve performance for applications that perform writes to the specified database and expect little or no contention from other processes for access to the database. When this mode is on, the amount of client/server communication required to upgrade locks is reduced. Once a page from the database is cached on the client, the client can subsequently upgrade the page's lock from read to read/write when needed without communicating with the Server. However, the amount of client/server communication required for concurrent processes to obtain locks on pages in the database might increase.
Note that this function sets the mode for the current process only, and does not affect the mode for other processes.
void set_readlock_timeout(os_int32);Sets the time in milliseconds for which the current process will wait to acquire a read lock on pages in the specified database. A value of -1, the default, indicates that the process should wait forever if necessary. After an attempt to acquire a read lock, if the specified time elapses without the lock's becoming available, an os_lock_timeout_exception exception is signaled. If the attempt causes a deadlock, the transaction is aborted regardless of the value of the specified timeout.
void set_relative_directory(char *dir_name);Sets the method to be used for storing database references. Remains in effect only for the duration of the current process. If 0 (null) is supplied, the default method is used. If an empty string is supplied, rooted pathnames are used. Otherwise, the string supplied indicates the name of a directory to be treated as a common ancestor to the source and destination databases. The common part of the pathnames is preceded by the appropriate number of "../"s to traverse the hierarchy up from the source directory to this common ancestor directory. If the indicated directory is not actually a common ancestor, a rooted pathname is used. The contents of the specified character array are copied by this function. After this function returns, the array's contents have no bearing on the relative directory. See os_database::allow_external_pointers() and os_database::get_relative_directory().
os_database::set_schema_database()
void set_schema_database(os_database& schema_database);If you move a schema database, you must use os_database::set_schema_database() or the ObjectStore utility ossetrsp to inform ObjectStore of the schema database's new pathname. Calling this function establishes schema_database as the schema database for this. You must invoke this function outside any transaction.
If you copy the schema database with an operating system command or an ObjectStore utility, you can also use os_database::set_schema_database() to establish the copy as the schema database for this. If schema_database is not the result of copying or moving a database that has served as schema database for this, err_schema_database is signaled.
void set_writelock_timeout(os_int32);Sets the time in milliseconds for which the current process will wait to acquire a write lock on pages in the specified database. A value of -1, the default, indicates that the process should wait forever if necessary. After an attempt to acquire a write lock, if the specified time elapses without the lock's becoming available, an os_lock_timeout_exception exception is signaled. If the attempt causes a deadlock, the transaction is aborted regardless of the value of the specified timeout.
os_unsigned_int32 size() const;Returns the size in bytes of the specified database. If this number cannot be represented in 32 bits, err_misc is signaled.
os_unsigned_int32 size_in_sectors() const;Returns the size in sectors of the specified database. If this number cannot be represented in 32 bits, err_misc is signaled.
os_unixtime_t time_created() const;Returns the time at which the database was created.
Updated: 03/31/98 17:25:09