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.
All ObjectStore programs must include the header file <ostore/ostore.hh>.
void allow_external_pointers();Once invoked, cross-database pointers are allowed from the specified segment.
At any given time, a pointer from one database, db1, to another, db2, points to 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.
os_database_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. 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 will store 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.
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 error messages such as database not found.
os_segment::create_object_cluster()
os_object_cluster *create_object_cluster(os_unsigned_int32 size);Creates an object cluster in the specified segment. The size of the new cluster in bytes is round_up(size, page_size) - 4. size must be no greater than 65536, or else err_cluster_too_big is signaled. The function returns a pointer to an instance of the class os_object_cluster. This instance is a transient object representing the new cluster. Note that, since it is transient, pointers to it cannot be stored in persistent memory. In particular, the return value of this function cannot be stored persistently.
os_database *database_of();Returns a pointer to the database in which the specified segment resides. The transient database is returned if the transient segment is specified.
void destroy();Deletes the segment for which the function is called. When a segment is destroyed, all data it contains is permanently destroyed, and pointers into the segment become invalid. Any subsequent use of the destroyed segment (such as an attempt to allocate memory within it) is an error.
void external_pointer_status(os_int32 *allowed, os_int32 *exist);Sets the argument to reflect the specified segment's state with respect to cross-database pointers. allowed is 1 (true) if cross-database pointers are allowed in the segment, and exist is set to 1 (true) if the segment contains any cross-database pointers.
os_segment_access *get_access_control() const;Returns a pointer to the segment's associated os_segment_access, which indicates the segment's primary group and permissions.
void get_all_object_clusters( os_int32 max_to_return, os_object_cluster_p *cluster_array, os_int32 &n_returned) ) const;Provides access to all the object clusters in the specified segment. The os_object_cluster_p* is an array of pointers to object clusters. This array must be allocated by the user. The function os_segment::get_n_object_clusters() 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_returned refers to the actual number of segment pointers returned.
void *get_application_info() const;Returns a pointer to the object pointed to by the pointer last passed, during the current process, to os_segment::set_application_info() for the specified segment. If set_application_info() has not been called for the specified segment during the current process, 0 is returned.
os_boolean get_check_illegal_pointers() const;If the segment is in check_illegal_pointers mode, the function returns 1; otherwise, it returns 0.
char *get_comment() const;Returns a transient copy of the string associated by means of os_segment::set_comment() with the specified segment. If set_comment() has not been called for the specified segment, a zero-length string is returned. The user is responsible for deleting the returned string.
void get_database_references( os_int32 &n_refs, os_database_reference_p *&array ) const;Allocates an array of database references, one for each database referenced by the specified segment. 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.
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 segment's current fetch policy. See os_segment::set_fetch_policy().
os_segment::get_lock_whole_segment()
objectstore_lock_option get_lock_whole_segment();Indicates the current locking behavior for the specified segment. 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_segment::get_n_object_clusters()
os_int32 get_n_object_clusters();Returns the number of object clusters in the specified segment.
os_boolean get_null_illegal_pointers();If the specified segment is in null_illegal_pointers mode, the function returns nonzero (that is, true); otherwise, it returns 0 (that is, false). See os_segment::set_null_illegal_pointers().
os_unsigned_int32 get_number() const;Returns the segment number of the specified segment. This number is suitable for passing to the os_pathname_and_segment_number constructor.
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 segment. The actual timeout is rounded up to the nearest greater number of seconds. A value of -1 indicates that the process will wait forever if necessary.
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 segment. The actual timeout is rounded up to the nearest greater number of seconds. A value of -1 indicates that the process will wait forever if necessary.
static os_segment *const get_transient_segment();Returns a pointer to the transient segment. The transient segment can be used as argument to new(), to cause allocation of transient memory.
os_boolean is_deleted();Returns a nonzero os_boolean (true) if the specified os_segment has been deleted; returns 0 (false) otherwise.
os_boolean is_empty() const;Returns a nonzero os_boolean (true) if the specified os_segment contains no nondeleted objects; returns 0 (false) otherwise.
void lock_into_cache();Reduces the likelihood that the pages of a specified segment will be removed from the cache (by cache replacement). The function os_segment::unlock_from_cache() allows cache replacement to be performed on the segment's pages again. Note that a page's being locked or wired into the cache is independent of its locking state, in the sense of locking relevant to concurrency control; a page can be locked in the cache without being read- or write-locked.
static os_segment *of(void *location);Returns a pointer to the segment in which the specified object resides. If the specified void* is 0 or points to transient memory, a pointer to the transient segment is returned (see os_segment::get_transient_segment()).
os_unsigned_int32 return_memory(os_boolean evict_now);Just like objectstore::return_memory(), except that it acts on a specified segment rather than a specified range of addresses.
void set_access_control(const os_segment_access *new_access);Associates the specified os_segment_access with the specified segment. The os_segment_access determines the primary group and permissions for the os_segment. The caller must be the owner of the database containing the specified segment.
void set_application_info(void *info);Associates the specified object with the specified segment for the current process. The argument info must point to a transient object. See os_segment::get_application_info().
os_segment::set_check_illegal_pointers()
void set_check_illegal_pointers(os_boolean);At the end of each transaction, all persistently allocated data is written to database memory. Pointers written to the database that point to transient memory are illegal pointers. In addition, cross-database pointers from a segment that is not in allow_external_pointers mode are also illegal. If you subsequently retrieve and dereference an illegal pointer, you might access arbitrary memory.
By default, ObjectStore sometimes checks for illegal pointers, but other times the checking is optimized out. However, you can instruct ObjectStore always to check for illegal pointers in a given segment or database on transaction commit.
If you pass 1 (true) to set_check_illegal_pointers(), check_illegal_pointers mode is enabled for the specified segment. Upon commit of each transaction, for each segment in check_illegal_pointers mode, ObjectStore always checks each page used in the transaction. You can specify the default behavior by passing 0 (false).
The results of using this function do not remain in effect after the current process ends, and are invisible to other processes.
void set_comment(char *info);Associates a persistent copy of the specified string with the specified segment. The string must be 31 characters or fewer. The utility ossize prints the comment, if set, when displaying information about the segment. See ObjectStore Management. See also os_segment::get_comment().
os_segment::set_fetch_policy()
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 the specified segment. The policy argument should be one of the following enumerators: os_fetch_segment, os_fetch_page, os_fetch_stream.
The default fetch policy is os_fetch_page, with a fetch quantum of 1 page (see below).
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 zero bytes, this will be rounded up, and the unit of transfer will be a single page.)
The default value for the fetch quantum depends on the default page size of the machine. 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_lock_whole_segment(objectstore_lock_option);Determines locking behavior for the specified segment. objectstore_lock_option is an enumeration type whose enumerators are objectstore::lock_as_used, objectstore::lock_segment_read, and objectstore::lock_segment_write.
The member function os_segment::set_fetch_policy() controls whether or not a given segment is transferred to the client cache all at once. By default, even when a segment's pages are transferred all at once, only the page containing the referenced data is locked. You can override this default for a given segment, however, by passing objectstore::lock_segment_read or objectstore::lock_segment_write to set_lock_whole_segment().
A value of lock_segment_read causes pages in the segment to be read-locked when cached in response to attempted access by the client. Subsequently, upgrading to read/write locks occurs on a page-by-page basis, as needed.
A value of lock_segment_write causes the segment's pages to be write-locked when cached in response to attempted read or write access by the client. In this case, the Server assumes from the start that write access to the entire segment is desired.
Note also that this function pertains only to the current process. The initial value of this data member for existing segments is lock_as_used. The initial value for segments created by the current process is the value of os_database::set_default_lock_whole_segment() for the database in which the segment resides.
void set_null_illegal_pointers(os_boolean);By default, ObjectStore signals a run-time error when it detects an illegal pointer. If you pass 1 (true) to this function, then, for segments in check_illegal_pointers mode, ObjectStore changes the illegal pointer to 0 (null). You can specify the default behavior by passing 0 (false) to this function. The results of using this function do not remain in effect after the current process ends, and they are invisible to other processes. See also os_database::set_default_null_illegal_pointers().
os_segment::set_readlock_timeout()
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 segment. The actual timeout is rounded up to the nearest greater number of seconds. A value of -1 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 is signaled. If the attempt causes a deadlock, the transaction is aborted regardless of the value of the specified timeout.
os_unsigned_int32 set_size(os_unsigned_int32);Increases the size of the specified segment to the specified number of bytes. If a size that is not larger than the current segment size is specified, the function has no effect.
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 segment. The actual timeout is rounded up to the nearest greater number of seconds. A value of -1 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 is signaled. If the attempt causes a deadlock, the transaction is aborted regardless of the value of the specified timeout.
os_unsigned_int32 size();Returns the size in bytes of the specified segment.
void unlock_from_cache();Allows cache replacement to be performed on a segment's pages after replacement has been disabled by the function os_segment::lock_into_cache(). Note that a page's being locked or wired into the cache is independent of its locking state, in the sense of locking relevant to concurrency control; a page can be locked in the cache without being read- or write-locked.
os_unsigned_int32 unused_space() const;Returns the amount of space (in bytes) in the segment not currently occupied by any object. It accounts for space resulting from objects that have been deleted as well as space that cannot be used as a result of internal ObjectStore alignment considerations. You can use it as a rough guide to determine whether a segment needs to be compacted.
Updated: 03/31/98 17:25:09