4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 %#pragma ident "%Z%%M% %I% %E% SMI"
36 %#include "db_mindex_c.h"
37 %#include "db_vers_c.h"
38 %#include "db_entry_c.h"
40 %#include "nisdb_rw.h"
42 %#include "db_mindex.h"
44 %#include "db_entry.h"
45 %#include "db_scheme.h"
49 #if RPC_HDR || RPC_XDR
56 db_mindex internal_db;
59 __nisdb_rwlock_t db_rwlock;
71 % db_mindex internal_db;
72 % bool_t logfile_opened;
76 %/* Delete old log file and descriptor */
79 %/* Open log file (and creates descriptor) if it has not been opened */
80 % int open_log(bool_t copylog);
82 %/* Incorporate updates in log to database already loaded.
83 % Does not affect "logfile" */
84 % int incorporate_log( char * );
86 %/* Execute the specified action using the rest of the arguments as input.
87 % Return a structure db_result containing the result. */
88 % db_result * exec_action( db_action, db_query *, entry_object *,
89 % db_next_desc *previous );
91 %/* Log the given action and execute it.
92 % The minor version of the database is updated after the action has
93 % been executed and the database is flagged as being changed.
94 % Return the structure db_result, or NULL if the loggin failed or the
95 % action is unknown. */
96 % db_result * log_action( db_action, db_query *, entry_object * );
98 % /* closes log file if opened */
99 % /* removes self from list of dbs have opened files */
100 % int close_log(int bypass_standby = 0);
102 %/* Constructor: Create a database using the given name, 'dbname.'
103 % The database is stored in a file named 'dbname'.
104 % The log file is stored in a file named 'dbname'.log.
105 % A temporary file 'dbname'.tmp is also used. */
108 %/* Destructor: deletes filenames and logfile descriptor.
109 % Note that associated files should be removed separately. */
112 %/* Write out in-memory copy of database to file.
113 % 1. Update major version.
114 % 2. Dump contents to temporary file.
115 % 3. Rename temporary file to real database file.
116 % 4. Remove log file.
117 % A checkpoint is done only if it has changed since the previous checkpoint.
118 % Returns TRUE if checkpoint was successful; FALSE otherwise. */
119 % bool_t checkpoint();
121 %/* Load database and incorporate any logged updates into the loaded copy.
122 % Return TRUE if load succeeds; FALSE otherwise. */
125 %/* Dump this database to a file.
126 % Return TRUE if dump succeeds; FALSE otherwise. */
127 % bool_t dump(char *outfile) {return (internal_db.dump(outfile));};
129 %/* Initialize the database using table scheme 's'.
130 % Because the 'scheme' must be 'remembered' between restarts,
131 % after the initialization, the empty database is checkpointed to record
132 % the scheme. Returns TRUE if initialization succeeds; FALSE otherwise. */
133 % bool_t init( db_scheme *s );
135 %/* Print out the database's statistics. */
136 % void print() { internal_db.print_stats();}
138 %/* Return whether the database has changed since its previous checkpoint. */
139 % bool_t changedp() { return changed;}
141 %/* Return the version of the database. */
142 % vers* get_version() { return internal_db.get_version(); }
145 %/* Execute 'action' using the rest of the arguments as input.
146 % Return the result of the operation in a db_result structure;
147 % Return NULL if the request is unknown.
148 % If the action involves updates (ADD and REMOVE), it is logged first. */
149 % db_result* execute( db_action, db_query *, entry_object *,
150 % db_next_desc* previous );
152 %/* Execute log entry 'j' on this db. 'j' is executed if its version is
153 % later than that of the database; if executed, the database's version
154 % will be changed to that of 'j', regardless of the status of the operation.
155 % Returns TRUE if 'j' was executed; FALSE if it was not.
156 % Log entry is added to this database's log if log_entry is applied. */
157 % bool_t execute_log_entry( db_log_entry * );
159 %/* Return structure db_log_list containing entries that are later
160 % than the version 'v' given. */
161 % db_log_list * get_log_entries_since( vers * );
163 %/* Sync the table log file */
164 % db_status sync_log();
166 %/* Delete all files associated with database. */
167 % int remove_files();
169 % /* for debugging */
170 %/* Print information on all indices of the database to stdout. */
171 % void print_all_indices() {internal_db.print_all_indices();}
173 %/* Print information on specified index of the the database to stdout. */
174 % void print_index( int n ) {internal_db.print_index( n ); }
176 %/* Mark this instance deferred */
177 % void markDeferred(void) {
178 % internal_db.markDeferred();
181 %/* Remove defer marking */
182 % void unmarkDeferred(void) {
183 % internal_db.unmarkDeferred();
186 %/* Exclusive access to this instance */
187 % int acqexcl(void) {
188 % return (WLOCK(db));
191 %/* Non-blocking exclusive access */
192 % int tryacqexcl(void) {
193 % return (TRYWLOCK(db));
196 %/* Release exclusive access */
197 % int relexcl(void) {
198 % return (WULOCK(db));
201 %/* Non-exclusive (readonly) access to this instance */
202 % int acqnonexcl(void) {
203 % return (RLOCK(db));
206 %/* Release non-exlusive access */
207 % int relnonexcl(void) {
208 % return (RULOCK(db));
211 %/* Destroy instance lock */
212 % int destroylock(void) {
213 % return (DESTROYRW(db));
216 %/* Pass configuration information to the db_mindex */
217 % bool_t configure(char *objName);
219 %/* Export a pointer to the db_mindex structure */
220 % db_mindex *mindex(void);
223 %typedef class db * dbp;
228 %#endif /* _DB_DB_H */