2 * $XConsortium: page_storage.h /main/7 1996/07/18 14:55:30 drk $
4 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
5 * All rights reserved. Unpublished -- rights reserved under
6 * the Copyright Laws of the United States. USE OF A COPYRIGHT
7 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
10 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
11 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
12 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
13 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
16 * RESTRICTED RIGHTS LEGEND
17 * Use, duplication, or disclosure by the Government is subject
18 * to the restrictions as set forth in subparagraph (c)(l)(ii)
19 * of the Rights in Technical Data and Computer Software clause
20 * at DFARS 252.227-7013.
22 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
29 #ifndef _page_storage_h
30 #define _page_storage_h 1
34 #include "utility/pm_random.h"
35 #include "dstr/heap.h"
36 #include "dstr/void_ptr_array.h"
37 #include "dynhash/imp_die.h"
38 #include "storage/unixf_storage.h"
39 #include "storage/heap_comp_funcs.h"
40 #include "storage/page_cache.h"
41 #include "storage/spointer.h"
43 enum direction { positive, negative };
47 class str_index_record_t : public root
54 str_index_record_t(int offset, mmdb_pos_t lc = 0);
55 virtual ~str_index_record_t() {};
58 void delete_str_index_record(const void* str_index_record_ptr);
60 typedef str_index_record_t* str_index_record_tPtr;
62 ////////////////////////////////////////////
63 ////////////////////////////////////////////
68 enum trans_t { ENABLED, DISABLED };
73 unixf_storage* log_store;
80 store_trans(char* path, char*name, int page_sz);
83 void init(rep_policy*);
86 void set_max_pages(int max_pgs) {
90 friend class page_storage;
93 /******************************************************/
94 // cached page storage. Implemented on Unix file class.
95 /******************************************************/
98 #define f_global_pcache (*f_global_pcache_ptr)
102 class page_storage : public abs_storage
106 buffer* v_buf; // aux. buf.
108 int page_sz ; // page size
114 static page_cache_global_part f_global_pcache;
116 static page_cache_global_part* f_global_pcache_ptr;
119 page_cache_local_part f_local_pcache;
124 int total_page_access;
126 store_trans trans_info;
134 Boolean seek_loc_negative(mmdb_pos_t& loc, int smd);
135 Boolean seek_loc_positive(mmdb_pos_t& loc, int smd);
138 page_storage(char* path, char* name,
139 unixf_storage* store,
140 int page_sz = PAGSIZ,
141 int num_cached_pages = NUM_PAGES,
142 mmdb_byte_order_t db_order_when_create_store = mmdb_big_endian
144 virtual ~page_storage();
146 void remove(); // remove all pages in the store
149 void sync(int pagenum);
155 void save_to_log(page* page_ptr);
157 // get server and db order
158 int server_order() { return v_server_order; } ;
159 int db_order() { return v_db_order; };
163 int readString (mmdb_pos_t loc, char* base, int len, int str_offset = 0);
164 int get_str_ptr(mmdb_pos_t loc, char*&, int& len) ;
166 int updateString(mmdb_pos_t loc, const char* base, int len, int string_ofst = 0, Boolean flush = false);
167 int deleteString (mmdb_pos_t loc, Boolean flush = false);
168 int insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush = false);
169 int allocString (mmdb_pos_t& loc, int len, char*&, int mode = 0);
170 int appendString(mmdb_pos_t loc, const char*, int len, Boolean flush_opt = false);
172 int set_page_dirty(mmdb_pos_t loc);
174 // iteration functions
175 typedef enum access { READ, WRITE } access_t;
176 int first() const; // first page's index in the store
177 page* operator()(int page_num, enum access intent) ; //get the page
178 void next(int&) const; // next page's index.
181 // format the store to contain extra empty 'pages' pages
182 int add_page_frames(int pages);
185 // get locs of the pieces that a long string is broken into
186 // The array should be deleted after use.
187 int get_str_locs(mmdb_pos_t str_loc, str_index_record_tPtr*& locs, int& vector_leng);
189 // seek loc to (loc +/- 1) position
190 Boolean seek_loc(mmdb_pos_t& loc, const direction = positive, int = spointer_t::FIRST_RECD );
191 mmdb_pos_t first_loc(); // return first loc in the store
192 mmdb_pos_t last_loc(); // return last loc in the store
194 // store status query functions
195 int page_size() { return page_sz; };
198 void set_page_size(int pgsz) { page_sz = pgsz; };
200 // how many pages in total in the store
201 int pages() const { return total_pages; };
203 // paging counting function
204 void reset_paging_count();
205 int paging_count() const;
207 Boolean io_mode(int mode) ;
209 // return an aux. buf.
212 // printing functions
213 virtual io_status asciiOut(ostream&) ;
215 friend void close_file(const void*);
216 friend void remove_from_global_cache(const void*);
218 friend class storage_mgr_t;
219 friend class handler;
220 friend class page_cache_local_part;
221 friend class page_cache_global_part;
224 friend void initialize_MMDB();
225 friend void quit_MMDB();
229 typedef page_storage* page_storagePtr;