Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
43
cde/programs/dtinfo/DtMmdb/storage/Imakefile
Normal file
43
cde/programs/dtinfo/DtMmdb/storage/Imakefile
Normal file
@@ -0,0 +1,43 @@
|
||||
XCOMM $XConsortium: Imakefile /main/10 1996/08/21 15:53:41 drk $
|
||||
|
||||
XCOMM ** WARNING **
|
||||
XCOMM
|
||||
XCOMM The files named here may appear in many different Imakefiles.
|
||||
XCOMM If you add or remove a file, be sure to update all locations.
|
||||
XCOMM It's unfortunate, but all this redundancy serves a purpose.
|
||||
XCOMM
|
||||
XCOMM Other possible locations are:
|
||||
XCOMM .../lib/DtMmdb/Imakefile
|
||||
XCOMM .../lib/DtMmdb/<subdir>/Imakefile
|
||||
XCOMM .../programs/dtinfo/mmdb/Imakefile
|
||||
XCOMM .../programs/dtinfo/mmdb/<subdir>/Imakefile
|
||||
|
||||
#define DoNormalLib NormalLibDtMmdb
|
||||
#define DoSharedLib SharedLibDtMmdb
|
||||
#define DoDebugLib DebugLibDtMmdb
|
||||
#define DoProfileLib ProfileLibDtMmdb
|
||||
#define LibName DtMmdb
|
||||
#define SoRev SODTMMDBREV
|
||||
#define LibHeaders NO
|
||||
#define LibCreate NO
|
||||
#define LargePICTable YES
|
||||
|
||||
#define CplusplusSource YES
|
||||
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
|
||||
|
||||
XCOMM In DtMmdb we compile as C_API sources.
|
||||
DEFINES = -DC_API -DPORTABLE_DB
|
||||
INCLUDES = -I.. $(EXCEPTIONS_INCLUDES)
|
||||
|
||||
SRCS = abs_storage.C chunks_index.C heap_comp_funcs.C \
|
||||
lru.C page.C page_cache.C \
|
||||
page_rep.C page_storage.C rep_cell.C \
|
||||
rep_policy.C store_test.C unixf_storage.C \
|
||||
version.C vm_storage.C
|
||||
OBJS = $(SRCS:.C=.o)
|
||||
|
||||
#include <Library.tmpl>
|
||||
|
||||
SubdirLibraryRule($(OBJS))
|
||||
|
||||
DependTarget()
|
||||
61
cde/programs/dtinfo/DtMmdb/storage/abs_storage.C
Normal file
61
cde/programs/dtinfo/DtMmdb/storage/abs_storage.C
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* $XConsortium: abs_storage.cc /main/6 1996/07/18 14:52:12 drk $
|
||||
*
|
||||
* Copyright (c) 1992 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/abs_storage.h"
|
||||
|
||||
abs_storage::abs_storage( char* file_path, char* file_name,
|
||||
c_code_t c_id, rep_policy* p ) :
|
||||
policy(p), root(c_id), index_num(-1), v_swap_order(false)
|
||||
{
|
||||
strcpy(path, file_path);
|
||||
strcpy(name, file_name);
|
||||
}
|
||||
|
||||
abs_storage::~abs_storage()
|
||||
{
|
||||
}
|
||||
|
||||
int abs_storage::byte_order()
|
||||
{
|
||||
unsigned int x;
|
||||
unsigned char *p;
|
||||
|
||||
x = 0x01020304;
|
||||
p = (unsigned char *)&x;
|
||||
|
||||
switch (*p) {
|
||||
case 1:
|
||||
return (mmdb_big_endian);
|
||||
case 4:
|
||||
return (mmdb_little_endian);
|
||||
default:
|
||||
throw(stringException("neither BIG_ENDIAN or LITTLE_ENDIAN machine"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
106
cde/programs/dtinfo/DtMmdb/storage/abs_storage.h
Normal file
106
cde/programs/dtinfo/DtMmdb/storage/abs_storage.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* $XConsortium: abs_storage.h /main/6 1996/07/18 14:52:29 drk $
|
||||
*
|
||||
* Copyright (c) 1992 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _abs_storage_h
|
||||
#define _abs_storage_h 1
|
||||
|
||||
#include "storage/rep_policy.h"
|
||||
#include "utility/buffer.h"
|
||||
#include "utility/types.h"
|
||||
#include "object/root.h"
|
||||
#include "storage/version.h"
|
||||
|
||||
/*****************************************
|
||||
// abstract storage class
|
||||
// this class provides a set of common
|
||||
// member function signatures and a policy
|
||||
// pointer for all derived storage classes.
|
||||
*****************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
mmdb_big_endian = 1,
|
||||
mmdb_little_endian = 2
|
||||
} mmdb_byte_order_t;
|
||||
|
||||
|
||||
class abs_storage : public root
|
||||
{
|
||||
public:
|
||||
int index_num;
|
||||
|
||||
abs_storage( char* path, char* name,
|
||||
c_code_t c_id,
|
||||
rep_policy* rep_p = 0
|
||||
);
|
||||
virtual ~abs_storage() ;
|
||||
|
||||
void sync() {};
|
||||
virtual void remove() = 0; // wipe all contents
|
||||
|
||||
// i/o functions
|
||||
virtual int readString (mmdb_pos_t loc, char* base, int len,
|
||||
int str_offset = 0) = 0;
|
||||
virtual int insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush = false) = 0;
|
||||
virtual int appendString(mmdb_pos_t loc, const char*, int len,
|
||||
Boolean flush_opt = false) = 0;
|
||||
|
||||
|
||||
virtual int get_str_ptr(mmdb_pos_t loc, char*&, int& len
|
||||
) = 0;
|
||||
|
||||
virtual int updateString(mmdb_pos_t loc, const char* base, int len,
|
||||
int string_ofst = 0, Boolean flush = false) = 0;
|
||||
virtual int deleteString (mmdb_pos_t loc, Boolean flush = false) = 0;
|
||||
virtual int allocString (mmdb_pos_t& loc, int len,
|
||||
char*&, int mode = 0) = 0;
|
||||
// status functions
|
||||
virtual const char* my_path() { return path; };
|
||||
virtual const char* my_name() { return name; };
|
||||
virtual Boolean io_mode(int mode) = 0;
|
||||
|
||||
// return byte order of the machine with one of enums in MMDB_BYTE_ORDER
|
||||
int byte_order();
|
||||
virtual Boolean swap_order() { return v_swap_order; };
|
||||
|
||||
mm_version& get_db_version() { return f_version; };
|
||||
|
||||
friend class storage_mgr_t;
|
||||
|
||||
protected:
|
||||
char path[PATHSIZ];
|
||||
char name[PATHSIZ];
|
||||
rep_policy *policy;
|
||||
Boolean v_swap_order;
|
||||
|
||||
mm_version f_version;
|
||||
};
|
||||
|
||||
typedef abs_storage* storagePtr;
|
||||
|
||||
#endif
|
||||
149
cde/programs/dtinfo/DtMmdb/storage/chunks_index.C
Normal file
149
cde/programs/dtinfo/DtMmdb/storage/chunks_index.C
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* $XConsortium: chunks_index.cc /main/4 1996/07/18 14:52:47 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "storage/chunks_index.h"
|
||||
|
||||
/****************************************************/
|
||||
// record and comparison functions for string index
|
||||
/****************************************************/
|
||||
|
||||
Boolean str_index_record_ls(const void* o1, const void* o2)
|
||||
{
|
||||
const str_index_record_t* x = (str_index_record_t*)o1;
|
||||
const str_index_record_t* y = (str_index_record_t*)o2;
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "LS");
|
||||
debug(cerr, x -> str_offset);
|
||||
debug(cerr, x -> loc);
|
||||
debug(cerr, y -> str_offset);
|
||||
debug(cerr, y -> loc);
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
return ( x -> str_offset < y -> str_offset ) ? true : false;
|
||||
}
|
||||
|
||||
Boolean str_index_record_eq(const void* o1, const void* o2)
|
||||
{
|
||||
const str_index_record_t* x = (str_index_record_t*)o1;
|
||||
const str_index_record_t* y = (str_index_record_t*)o2;
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "EQ");
|
||||
debug(cerr, x -> str_offset);
|
||||
debug(cerr, x -> loc);
|
||||
debug(cerr, y -> str_offset);
|
||||
debug(cerr, y -> loc);
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
return ( x -> str_offset == y -> str_offset ) ? true : false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
chunks_index::chunks_index(abs_storage* store,
|
||||
mmdb_pos_t loc) :
|
||||
v_index_imp(str_index_record_eq, str_index_record_ls),
|
||||
v_storage_ptr(store), v_initial_loc(loc)
|
||||
{
|
||||
str_index_record_tPtr* vector = 0;
|
||||
int vector_sz = 0;
|
||||
|
||||
if ( v_storage_ptr == 0 || v_initial_loc == 0 )
|
||||
return ;
|
||||
|
||||
((page_storage*)v_storage_ptr) -> get_str_locs(loc, vector, vector_sz);
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "vector:");
|
||||
debug(cerr, vector_sz);
|
||||
for ( int i=0; i<vector_sz; i++ ) {
|
||||
debug(cerr, i);
|
||||
debug(cerr, vector[i] -> loc);
|
||||
debug(cerr, vector[i] -> str_offset);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
binary_insert(vector, 0, vector_sz-1);
|
||||
delete vector;
|
||||
}
|
||||
|
||||
chunks_index::~chunks_index()
|
||||
{
|
||||
v_index_imp.del_elements(delete_str_index_record);
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
// Note: given that the keys in vector are non-
|
||||
// decreasing, it is optimal to binarilly
|
||||
// insert keys to obtained a
|
||||
// balanced binary search tree.
|
||||
//
|
||||
// get_str_locs() returns a non-decreasing
|
||||
// key vector
|
||||
/***************************************************/
|
||||
|
||||
Boolean
|
||||
chunks_index::binary_insert(str_index_record_tPtr* vector,
|
||||
int left, int right)
|
||||
{
|
||||
if ( left > right )
|
||||
return true;
|
||||
|
||||
int middle = (right + 1 - left) / 2 + left;
|
||||
//debug(cerr, middle);
|
||||
v_index_imp.insert(vector[middle]);
|
||||
|
||||
Boolean ok1 = binary_insert(vector, left, middle-1);
|
||||
Boolean ok2 = binary_insert(vector, middle+1, right);
|
||||
|
||||
return ( ok1 == true && ok2 == true ) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
str_index_record_t*
|
||||
chunks_index::chunk_location( int offset )
|
||||
{
|
||||
str_index_record_t key(offset);
|
||||
|
||||
str_index_record_t* anchor = (str_index_record_t*)
|
||||
v_index_imp.smaller_member((root*)&key);
|
||||
|
||||
if ( anchor == 0 ) {
|
||||
throw(stringException("chunk_location(): no smaller member"));
|
||||
}
|
||||
|
||||
return anchor;
|
||||
}
|
||||
|
||||
57
cde/programs/dtinfo/DtMmdb/storage/chunks_index.h
Normal file
57
cde/programs/dtinfo/DtMmdb/storage/chunks_index.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* $XConsortium: chunks_index.h /main/5 1996/07/18 14:53:08 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _chunks_index_h
|
||||
#define _chunks_index_h 1
|
||||
|
||||
#include "storage/page.h"
|
||||
#include "storage/page_storage.h"
|
||||
#include "dstr/bset.h"
|
||||
|
||||
class chunks_index
|
||||
{
|
||||
|
||||
public:
|
||||
chunks_index(abs_storage* store, mmdb_pos_t loc);
|
||||
virtual ~chunks_index() ;
|
||||
|
||||
str_index_record_t* chunk_location( int offset );
|
||||
|
||||
protected:
|
||||
Boolean binary_insert(str_index_record_tPtr* vector,
|
||||
int left, int right);
|
||||
|
||||
protected:
|
||||
abs_storage* v_storage_ptr;
|
||||
mmdb_pos_t v_initial_loc;
|
||||
bset v_index_imp;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
64
cde/programs/dtinfo/DtMmdb/storage/heap_comp_funcs.C
Normal file
64
cde/programs/dtinfo/DtMmdb/storage/heap_comp_funcs.C
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* $XConsortium: heap_comp_funcs.cc /main/3 1996/06/11 17:33:36 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/heap_comp_funcs.h"
|
||||
|
||||
//memory_pool fbytes_t::heap_cell_space_pool;
|
||||
|
||||
#ifndef C_API
|
||||
memory_pool g_memory_pool;
|
||||
#endif
|
||||
|
||||
Boolean fbytes_t_ls(const void* x, const void* y)
|
||||
{
|
||||
if ( ((fbytes_t*)x) -> free_bytes < ((fbytes_t*)y) -> free_bytes )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean fbytes_t_eq(const void* x, const void* y)
|
||||
{
|
||||
if ( ((fbytes_t*)x) -> free_bytes == ((fbytes_t*)y) -> free_bytes )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void* fbytes_t::operator new( size_t x )
|
||||
{
|
||||
//return (void*)heap_cell_space_pool.alloc(x);
|
||||
return (void*)g_memory_pool.alloc(x);
|
||||
}
|
||||
|
||||
void fbytes_t::operator delete( void* ptr )
|
||||
{
|
||||
//heap_cell_space_pool.free((char*)ptr);
|
||||
g_memory_pool.free((char*)ptr);
|
||||
}
|
||||
|
||||
63
cde/programs/dtinfo/DtMmdb/storage/heap_comp_funcs.h
Normal file
63
cde/programs/dtinfo/DtMmdb/storage/heap_comp_funcs.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* $XConsortium: heap_comp_funcs.h /main/3 1996/06/11 17:33:41 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _heap_comp_funcs
|
||||
#define _heap_comp_funcs 1
|
||||
|
||||
#include "utility/types.h"
|
||||
#include "utility/debug.h"
|
||||
#include "dstr/memory_pool.h"
|
||||
|
||||
/**************************************/
|
||||
// struct for managing free page bytes
|
||||
/**************************************/
|
||||
class fbytes_t
|
||||
{
|
||||
|
||||
public:
|
||||
fbytes_t(int fbytes, int pnum) {
|
||||
free_bytes = fbytes;
|
||||
page_num = pnum;
|
||||
};
|
||||
virtual ~fbytes_t() {};
|
||||
|
||||
void* operator new( size_t );
|
||||
void operator delete( void* );
|
||||
|
||||
public:
|
||||
int free_bytes;
|
||||
int page_num;
|
||||
|
||||
protected:
|
||||
//static memory_pool heap_cell_space_pool;
|
||||
};
|
||||
|
||||
Boolean fbytes_t_ls(const void*x, const void* y);
|
||||
Boolean fbytes_t_eq(const void*x, const void* y);
|
||||
|
||||
#endif
|
||||
221
cde/programs/dtinfo/DtMmdb/storage/lru.C
Normal file
221
cde/programs/dtinfo/DtMmdb/storage/lru.C
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* $XConsortium: lru.cc /main/4 1996/07/18 14:53:29 drk $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/lru.h"
|
||||
|
||||
lru::lru(int a_sz, int i_sz, Boolean remove_cells) :
|
||||
rep_policy(a_sz, i_sz), active_list(remove_cells),
|
||||
inactive_list(remove_cells)
|
||||
{
|
||||
}
|
||||
|
||||
lru::~lru()
|
||||
{
|
||||
}
|
||||
|
||||
// Move the last cell in the active list to the end of the
|
||||
// inactive list.
|
||||
// Out: replaced points at the last cell from the active list;
|
||||
// it is zero if the active list is empty.
|
||||
void lru::lower_last(rep_cell*& replaced)
|
||||
{
|
||||
// if the active list is empty, just return
|
||||
if ( active_list.count() == 0 )
|
||||
return ;
|
||||
|
||||
// delete the last cell from the active list
|
||||
dlist_cell *atl = active_list.get_tail();
|
||||
active_list.delete_cell(atl);
|
||||
|
||||
|
||||
// insert the removed last cell into the inactive list (last position)
|
||||
dlist_cell *itl = inactive_list.get_tail();
|
||||
inactive_list.insert_after(itl, atl);
|
||||
|
||||
replaced = (rep_cell*)atl;
|
||||
replaced -> set_position(INACTIVE);
|
||||
}
|
||||
|
||||
|
||||
Boolean
|
||||
lru::promote(rep_cell& x, rep_cell*& replaced)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "enter promote");
|
||||
debug(cerr, int(this));
|
||||
debug(cerr, active_list.count());
|
||||
debug(cerr, inactive_list.count());
|
||||
*/
|
||||
|
||||
|
||||
replaced = 0;
|
||||
Boolean ok = true;
|
||||
|
||||
switch (x.get_position()) {
|
||||
case ACTIVE:
|
||||
//MESSAGE(cerr, "active");
|
||||
active_list.delete_cell(&x);
|
||||
break;
|
||||
|
||||
case INACTIVE:
|
||||
//MESSAGE(cerr, "inactive");
|
||||
inactive_list.delete_cell(&x);
|
||||
lower_last(replaced);
|
||||
break;
|
||||
|
||||
case NOWHERE:
|
||||
//MESSAGE(cerr, "nowhere");
|
||||
if ( active_sz > active_list.count() )
|
||||
break;
|
||||
else
|
||||
if ( active_sz == active_list.count() &&
|
||||
inactive_sz == inactive_list.count() ) {
|
||||
throw(stringException("lru::promote(): pool too small"));
|
||||
} else
|
||||
lower_last(replaced);
|
||||
break;
|
||||
}
|
||||
//debug(cerr, "to merge");
|
||||
|
||||
active_list.insert_before(active_list.get_head(), &x);
|
||||
x.set_position(ACTIVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean lru::promote(rep_cell& x)
|
||||
{
|
||||
rep_cell* dummy = 0;
|
||||
return this -> promote(x, dummy);
|
||||
}
|
||||
|
||||
Boolean lru::derank(rep_cell& x, position_t opt)
|
||||
{
|
||||
Boolean ok = true;
|
||||
|
||||
switch (x.get_position()) {
|
||||
case ACTIVE:
|
||||
//MESSAGE(cerr, "active status to derank");
|
||||
active_list.delete_cell(&x);
|
||||
break;
|
||||
|
||||
case INACTIVE:
|
||||
//MESSAGE(cerr, "derand: an inactive cell");
|
||||
inactive_list.delete_cell(&x);
|
||||
opt = INACTIVE;
|
||||
break;
|
||||
|
||||
case NOWHERE:
|
||||
throw(stringException("lru::derand(): nowhere status"));
|
||||
}
|
||||
|
||||
switch ( opt ) {
|
||||
case ACTIVE:
|
||||
active_list.insert_as_tail(&x);
|
||||
x.set_position(ACTIVE);
|
||||
break;
|
||||
case INACTIVE:
|
||||
inactive_list.insert_as_tail(&x);
|
||||
x.set_position(INACTIVE);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
long lru::first(position_t option)
|
||||
{
|
||||
switch (option) {
|
||||
case ACTIVE:
|
||||
return active_list.first();
|
||||
case INACTIVE:
|
||||
return inactive_list.first();
|
||||
default:
|
||||
throw(stringException("lru::first(): bad option"));
|
||||
}
|
||||
}
|
||||
|
||||
rep_cell* lru::operator()(long index, position_t option)
|
||||
{
|
||||
switch (option) {
|
||||
case ACTIVE:
|
||||
return (rep_cell*)(index);
|
||||
case INACTIVE:
|
||||
return (rep_cell*)(index);
|
||||
default:
|
||||
throw(stringException("lru::operator(): bad option"));
|
||||
}
|
||||
}
|
||||
|
||||
void lru::next(long& index, position_t option)
|
||||
{
|
||||
switch (option) {
|
||||
case ACTIVE:
|
||||
active_list.next(index);
|
||||
return;
|
||||
case INACTIVE:
|
||||
inactive_list.next(index);
|
||||
return;
|
||||
default:
|
||||
throw(stringException("lru::next(): bad option"));
|
||||
}
|
||||
}
|
||||
|
||||
long lru::last(position_t option)
|
||||
{
|
||||
switch (option) {
|
||||
case ACTIVE:
|
||||
return active_list.last();
|
||||
case INACTIVE:
|
||||
return inactive_list.last();
|
||||
default:
|
||||
throw(stringException("lru::last(): bad option"));
|
||||
}
|
||||
}
|
||||
|
||||
Boolean lru::remove(rep_cell& x)
|
||||
{
|
||||
switch (x.get_position()) {
|
||||
case ACTIVE:
|
||||
active_list.delete_cell(&x);
|
||||
return true;
|
||||
|
||||
case INACTIVE:
|
||||
inactive_list.delete_cell(&x);
|
||||
return true;
|
||||
|
||||
case NOWHERE:
|
||||
throw(stringException("lru::last(): bad option"));
|
||||
}
|
||||
}
|
||||
|
||||
void lru::remove()
|
||||
{
|
||||
active_list.remove();
|
||||
inactive_list.remove();
|
||||
}
|
||||
|
||||
void lru::forget()
|
||||
{
|
||||
active_list.empty_list();
|
||||
inactive_list.empty_list();
|
||||
}
|
||||
|
||||
91
cde/programs/dtinfo/DtMmdb/storage/lru.h
Normal file
91
cde/programs/dtinfo/DtMmdb/storage/lru.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* $XConsortium: lru.h /main/5 1996/08/21 15:53:46 drk $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _lru_h
|
||||
#define _lru_h 1
|
||||
|
||||
#ifdef C_API
|
||||
#include "utility/c_stream.h"
|
||||
#else
|
||||
#include <stream.h>
|
||||
#endif
|
||||
|
||||
#include "utility/debug.h"
|
||||
#include "dstr/dlist.h"
|
||||
#include "storage/rep_policy.h"
|
||||
|
||||
class lru: public rep_policy {
|
||||
|
||||
protected:
|
||||
dlist active_list;
|
||||
dlist inactive_list;
|
||||
|
||||
protected:
|
||||
void lower_last(rep_cell*& replaced);
|
||||
|
||||
public:
|
||||
lru(int a_size, int i_size, Boolean remove_cells) ;
|
||||
virtual ~lru() ;
|
||||
|
||||
// promotes the cell x to the active list.
|
||||
// In the first version, the replaced is the cell dumped from the
|
||||
// active list. It is set to zero if no dumping takes place.
|
||||
// Boolean = true: replaced is saved in the inactive list
|
||||
|
||||
virtual Boolean promote(rep_cell& x, rep_cell*& replaced);
|
||||
virtual Boolean promote(rep_cell& x);
|
||||
|
||||
// put x to the last of position_t list. Only from
|
||||
// somewhere in active list -> active list's last
|
||||
// or
|
||||
// somewhere in active list -> inactive list's last
|
||||
//
|
||||
// not possible:
|
||||
// somewhere in inactive list -> active list's last
|
||||
//
|
||||
|
||||
virtual Boolean derank(rep_cell& x, position_t);
|
||||
|
||||
// walk through all cells in either the active or inactive list,
|
||||
long first(position_t = ACTIVE);
|
||||
rep_cell* operator()(long index, position_t);
|
||||
rep_cell* operator()(long index) { return operator()(index, ACTIVE); };
|
||||
void next(long & index, position_t = ACTIVE);
|
||||
|
||||
// the last cell in either of the list
|
||||
long last(position_t = ACTIVE);
|
||||
|
||||
Boolean remove(rep_cell& x); // remove a cell x
|
||||
void remove(); // remove all cells
|
||||
void forget(); // let go all cells, do nothing on them
|
||||
|
||||
// counts
|
||||
int active_elmts() { return active_list.count(); };
|
||||
int inactive_elmts() { return inactive_list.count(); };
|
||||
|
||||
dlist& get_active_list() { return active_list; };
|
||||
dlist& get_inactive_list() { return inactive_list; };
|
||||
};
|
||||
|
||||
typedef lru *lruPtr;
|
||||
|
||||
#endif
|
||||
630
cde/programs/dtinfo/DtMmdb/storage/page.C
Normal file
630
cde/programs/dtinfo/DtMmdb/storage/page.C
Normal file
@@ -0,0 +1,630 @@
|
||||
/*
|
||||
* $XConsortium: page.cc /main/6 1996/08/15 14:14:45 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/page.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// SLOT_HEADER_SIZE is defined for these fields:
|
||||
//(sizeof(fwd_ptr) + sizeof(header.int_view) + sizeof(int))
|
||||
//
|
||||
// Note: the last int field is not used. It is here for
|
||||
// backward compatibility. qfc 12-13-95
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
#define SLOT_HEADER_SIZE (sizeof(mmdb_pos_t) + sizeof(unsigned int) + sizeof(int))
|
||||
|
||||
spointer_t::spointer_t(char* page_base, int slot): swapped(false)
|
||||
{
|
||||
page_image = page_base + sizeof(count_t) + (slot-1)*SLOT_HEADER_SIZE;
|
||||
|
||||
memcpy((char*)&fwd_ptr, page_image, sizeof(fwd_ptr));
|
||||
memcpy(
|
||||
(char*)&header.int_view,
|
||||
page_image+sizeof(fwd_ptr),
|
||||
sizeof(header.int_view)
|
||||
);
|
||||
#ifdef PAGE_DEBUG
|
||||
MESSAGE(cerr, "spointer_t::spointer_t() [1]");
|
||||
debug(cerr, slot);
|
||||
debug(cerr, (int)(void*)page_base);
|
||||
debug(cerr, (int)(void*)page_image);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
spointer_t::spointer_t(char* page_base, int slot_num, int ofst, int len) :
|
||||
fwd_ptr(0), swapped(false)
|
||||
{
|
||||
header.bit_view.spointer = ofst;
|
||||
header.bit_view.length = len;
|
||||
|
||||
set_mode(DELETED, false);
|
||||
set_mode(IS_OBJECT, false);
|
||||
|
||||
set_mode(UPDATED, true);
|
||||
|
||||
page_image = page_base + sizeof(count_t) + (slot_num-1) * SLOT_HEADER_SIZE;
|
||||
}
|
||||
|
||||
spointer_t::~spointer_t()
|
||||
{
|
||||
|
||||
//MESSAGE(cerr, "spointer_t::~spointer_t()");
|
||||
//debug(cerr, header.bit_view.spointer);
|
||||
|
||||
if ( swapped == true || get_mode(UPDATED) == true ) {
|
||||
memcpy(page_image, (char*)&fwd_ptr, sizeof(fwd_ptr));
|
||||
memcpy(page_image+sizeof(fwd_ptr),
|
||||
(char*)&(header.int_view),
|
||||
sizeof(header.int_view)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void spointer_t::set_mode(spointer_mode m, Boolean b)
|
||||
{
|
||||
switch ( m ) {
|
||||
case IS_OBJECT:
|
||||
header.bit_view.is_object = ( b == true ) ? 1 : 0;
|
||||
header.bit_view.updated = 1;
|
||||
break;
|
||||
case FIRST_RECD:
|
||||
header.bit_view.first_recd = ( b == true ) ? 1 : 0;
|
||||
header.bit_view.updated = 1;
|
||||
break;
|
||||
case DELETED:
|
||||
header.bit_view.deleted = ( b == true ) ? 1 : 0;
|
||||
header.bit_view.updated = 1;
|
||||
break;
|
||||
case UPDATED:
|
||||
header.bit_view.updated = ( b == true ) ? 1 : 0;
|
||||
break;
|
||||
default:
|
||||
MESSAGE(cerr, "page::set_mode(): invalid mode");
|
||||
throw( intException((int)m) );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Boolean spointer_t::get_mode(spointer_mode m)
|
||||
{
|
||||
switch ( m ) {
|
||||
case IS_OBJECT:
|
||||
return ( header.bit_view.is_object == 1 ) ? true : false;
|
||||
case FIRST_RECD:
|
||||
return ( header.bit_view.first_recd == 1 ) ? true : false;
|
||||
case DELETED:
|
||||
return ( header.bit_view.deleted == 1 ) ? true : false;
|
||||
case UPDATED:
|
||||
return ( header.bit_view.updated == 1 ) ? true : false;
|
||||
default:
|
||||
MESSAGE(cerr, "page::get_mode(): invalid mode");
|
||||
throw( intException((int)m) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int align_offset;
|
||||
|
||||
page::page(int buf_sz, int pid, Boolean swap_order) :
|
||||
buffer( buf_sz ), pageid(pid), dirty(false), num_locks(0),
|
||||
v_swap_order(swap_order)
|
||||
{
|
||||
v_memalign_offset = align_offset;
|
||||
clean_all();
|
||||
}
|
||||
|
||||
page::~page()
|
||||
{
|
||||
align_offset = v_memalign_offset;
|
||||
}
|
||||
|
||||
|
||||
/***************************/
|
||||
//
|
||||
/***************************/
|
||||
void page::clean_all()
|
||||
{
|
||||
v_eptr = v_base + buf_sz();
|
||||
set_count(1);
|
||||
|
||||
//////////////////////////////////////////
|
||||
// use spointer_t's dstr to write slot info to page.
|
||||
//////////////////////////////////////////
|
||||
spointer_t x(v_base, 1,
|
||||
buf_sz(), buf_sz()-sizeof(count_t)-2*SLOT_HEADER_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*************************************
|
||||
* Get the ith string pointer from the
|
||||
* page.
|
||||
**************************************/
|
||||
spointer_t* page::get_spointer(int slot_num) const
|
||||
{
|
||||
if ( !INRANGE(slot_num, 1, count()) ) {
|
||||
throw( boundaryException(1, count(), slot_num));
|
||||
}
|
||||
|
||||
return new spointer_t(v_base, slot_num);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// Get a string from the page.
|
||||
//////////////////////////////
|
||||
Boolean
|
||||
page::get( int slot_num, buffer& target,
|
||||
int offset, int bytes_to_read
|
||||
) const
|
||||
{
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "in page::get()");
|
||||
debug(cerr, slot_num);
|
||||
debug(cerr, offset);
|
||||
debug(cerr, bytes_to_read);
|
||||
*/
|
||||
|
||||
if ( ! INRANGE(slot_num, 1, count()-1) )
|
||||
throw( boundaryException(1, count()-1, slot_num) );
|
||||
|
||||
|
||||
spointer_t slot_info(v_base, slot_num);
|
||||
|
||||
if ( slot_info.get_mode(spointer_t::DELETED) == true ) {
|
||||
MESSAGE(cerr, "page::get(): get a deleted slot");
|
||||
return false;
|
||||
}
|
||||
|
||||
int string_len = slot_info.string_leng();
|
||||
//debug(cerr, string_len);
|
||||
|
||||
if ( bytes_to_read == 0 )
|
||||
bytes_to_read = string_len;
|
||||
|
||||
//debug(cerr, bytes_to_read);
|
||||
|
||||
if ( bytes_to_read + offset > slot_info.string_leng() ) {
|
||||
MESSAGE(cerr, "page::get(): too many bytes to read");
|
||||
throw( boundaryException(0, slot_info.string_leng(),
|
||||
bytes_to_read + offset)
|
||||
);
|
||||
}
|
||||
|
||||
offset += slot_info.string_ofst();
|
||||
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "page::get()");
|
||||
debug(cerr, offset);
|
||||
debug(cerr, long(v_base + offset));
|
||||
debug(cerr, bytes_to_read);
|
||||
|
||||
for (int ki=0; ki<bytes_to_read; ki++)
|
||||
cerr << int(v_base[offset+ki]) << " ";
|
||||
cerr << "\n";
|
||||
*/
|
||||
|
||||
|
||||
target.put(v_base + offset, bytes_to_read);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*************************************/
|
||||
// Put a string on the page.
|
||||
// slot_num: slot number to be returned
|
||||
// buf: string
|
||||
/**************************************/
|
||||
Boolean
|
||||
page::put(int& slot_num, buffer& source)
|
||||
{
|
||||
#ifdef PAGE_DEBUG
|
||||
MESSAGE(cerr, "page::put()");
|
||||
debug(cerr, free_bytes());
|
||||
#endif
|
||||
|
||||
int source_len = source.content_sz();
|
||||
|
||||
char* target = 0;
|
||||
|
||||
alloc_slot( slot_num, source_len, target );
|
||||
|
||||
#ifdef PAGE_DEBUG
|
||||
MESSAGE(cerr, "AAA");
|
||||
debug(cerr, slot_num);
|
||||
debug(cerr, free_bytes());
|
||||
#endif
|
||||
|
||||
memcpy(target, source.get_base(), source_len);
|
||||
|
||||
#ifdef PAGE_DEBUG
|
||||
debug(cerr, (int)(void*)target);
|
||||
debug(cerr, source_len);
|
||||
MESSAGE(cerr, "BBB");
|
||||
debug(cerr, free_bytes());
|
||||
#endif
|
||||
|
||||
spointer_t slot_info(v_base, slot_num) ;
|
||||
slot_info.set_mode(spointer_t::DELETED, false);
|
||||
slot_info.set_string_leng(source_len);
|
||||
|
||||
#ifdef PAGE_DEBUG
|
||||
MESSAGE(cerr, "CCC");
|
||||
debug(cerr, free_bytes());
|
||||
MESSAGE(cerr, "page::put() done");
|
||||
#endif
|
||||
|
||||
dirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean page::del_slot(int slot_num)
|
||||
{
|
||||
if ( ! INRANGE(slot_num, 1, count()-1) )
|
||||
throw(boundaryException( 1, count()-1, slot_num));
|
||||
|
||||
spointer_t deleted_slot_info(v_base, slot_num);
|
||||
|
||||
deleted_slot_info.set_mode(spointer_t::DELETED, true);
|
||||
|
||||
spointer_t manage_slot_info(v_base, count());
|
||||
|
||||
deleted_slot_info.set_forward_ptr(
|
||||
(int)(manage_slot_info.forward_ptr())
|
||||
);
|
||||
|
||||
manage_slot_info.set_forward_ptr( slot_num );
|
||||
|
||||
dirty = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean page::update_slot( int slot_num, buffer& source, int offset )
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "page::update_slot()");
|
||||
debug(cerr, slot_num);
|
||||
*/
|
||||
|
||||
if ( ! INRANGE(slot_num, 1, count()-1) )
|
||||
throw(boundaryException( 1, count()-1, slot_num));
|
||||
|
||||
|
||||
spointer_t slot_info(v_base, slot_num) ;
|
||||
|
||||
int ofst = slot_info.string_ofst() + offset;
|
||||
int leng = MIN(slot_info.string_leng(), source.content_sz());
|
||||
/*
|
||||
debug(cerr, ofst);
|
||||
debug(cerr, leng);
|
||||
*/
|
||||
|
||||
memcpy(v_base + ofst, source.get_base(), leng);
|
||||
dirty = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// Allocate a slot on the page
|
||||
///////////////////////////////
|
||||
Boolean page::alloc_slot( int& slot_num, int size, char*& str_ptr )
|
||||
{
|
||||
#ifdef PAGE_DEBUG
|
||||
debug(cerr, size);
|
||||
#endif
|
||||
|
||||
Boolean ok = false;
|
||||
slot_num = count();
|
||||
int prev_slot_num = 0;
|
||||
|
||||
while ( slot_num != 0 &&
|
||||
( ok = _alloc_slot( slot_num, size, str_ptr )) == false ) {
|
||||
prev_slot_num = slot_num;
|
||||
|
||||
spointer_t slot_info(v_base, slot_num);
|
||||
slot_num = (int)slot_info.forward_ptr();
|
||||
}
|
||||
|
||||
if ( prev_slot_num && slot_num ) {
|
||||
|
||||
spointer_t slot_info(v_base, slot_num);
|
||||
|
||||
int next_slot_num = (int)slot_info.forward_ptr();
|
||||
|
||||
spointer_t prev_slot_info(v_base, prev_slot_num);
|
||||
|
||||
prev_slot_info.set_forward_ptr(next_slot_num);
|
||||
}
|
||||
#ifdef PAGE_DEBUG
|
||||
debug(cerr, free_bytes());
|
||||
MESSAGE(cerr, " page::alloc_slot done");
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
Boolean page::_alloc_slot( int slot_num, int size, char*& str_ptr )
|
||||
{
|
||||
//MESSAGE(cerr, "_alloc_slot");
|
||||
|
||||
spointer_t* slot_info = new spointer_t(v_base, slot_num);
|
||||
|
||||
/*************************************************************/
|
||||
// make sure that the new string starts at an aligned position
|
||||
/*************************************************************/
|
||||
|
||||
int end_ptr = slot_info -> string_ofst() - size;
|
||||
|
||||
|
||||
#ifdef NO_COPY
|
||||
int left_shift_delta = end_ptr % 4;
|
||||
end_ptr -= left_shift_delta;
|
||||
size += left_shift_delta;
|
||||
#endif
|
||||
|
||||
|
||||
int new_blank_len = slot_info -> string_leng() ;
|
||||
|
||||
if ( new_blank_len < size )
|
||||
return false;
|
||||
|
||||
slot_info -> set_string_ofst( end_ptr );
|
||||
slot_info -> set_string_leng( size );
|
||||
slot_info -> set_mode(spointer_t::DELETED, false);
|
||||
slot_info -> set_forward_ptr(0);
|
||||
|
||||
delete slot_info;
|
||||
|
||||
if ( slot_num == count() ) {
|
||||
|
||||
//MESSAGE(cerr, "slot_num == count() case:");
|
||||
|
||||
new_blank_len -= size;
|
||||
//debug(cerr, new_blank_len);
|
||||
|
||||
if ( new_blank_len < 2*SLOT_HEADER_SIZE + 10 )
|
||||
new_blank_len = 0;
|
||||
else
|
||||
new_blank_len -= SLOT_HEADER_SIZE; // space allocated for new
|
||||
// free space slot
|
||||
|
||||
//debug(cerr, new_blank_len);
|
||||
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "in page::alloc");
|
||||
debug(cerr, size);
|
||||
debug(cerr, i_th -> string_leng());
|
||||
debug(cerr, i_th -> string_ofst());
|
||||
debug(cerr, new_blank_len);
|
||||
*/
|
||||
|
||||
///////////////////////////////
|
||||
// append a new slot to the end
|
||||
///////////////////////////////
|
||||
set_count(count()+1);
|
||||
spointer_t* z = new spointer_t(v_base, count(), end_ptr, new_blank_len);
|
||||
delete z;
|
||||
|
||||
//debug(cerr, free_bytes());
|
||||
//MESSAGE(cerr, "page::alloc done");
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "in page::alloc");
|
||||
debug(cerr, end_ptr);
|
||||
debug(cerr, size);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
str_ptr = v_base + end_ptr;
|
||||
|
||||
//debug(cerr, int(base));
|
||||
//debug(cerr, i_th -> string_ofst());
|
||||
|
||||
//debug(cerr, slot_num);
|
||||
//debug(cerr, long(str_ptr));
|
||||
//debug(cerr, long(v_base));
|
||||
//debug(cerr, end_ptr);
|
||||
|
||||
//if ( count() >= 1 ) {
|
||||
//spointer_t first_slot(v_base, 1);
|
||||
//debug(cerr, first_slot.string_ofst());
|
||||
//debug(cerr, first_slot.string_leng());
|
||||
//}
|
||||
|
||||
dirty = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Boolean page::get_str_ptr( int slot_num, char*& str, int& len )
|
||||
{
|
||||
if ( ! INRANGE(slot_num, 1, count()-1) )
|
||||
throw(boundaryException( 1, count()-1, slot_num));
|
||||
|
||||
spointer_t slot_info(v_base, slot_num);
|
||||
|
||||
str = slot_info.string_ofst() + v_base;
|
||||
len = slot_info.string_leng();
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "page::get_str_ptr(), result:");
|
||||
debug(cerr, slot_info.string_ofst());
|
||||
debug(cerr, slot_info.string_leng());
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// return number of free bytes on the page
|
||||
int page::free_bytes() const
|
||||
{
|
||||
spointer_t slot_info(v_base, count());
|
||||
return slot_info.string_leng() - SLOT_HEADER_SIZE - 10;
|
||||
}
|
||||
|
||||
int page::free_slots() const // return number of free slots on the page
|
||||
{
|
||||
spointer_t *x;
|
||||
int sum = 0;
|
||||
int ind = first();
|
||||
while ( ind ) {
|
||||
|
||||
x = new spointer_t(v_base, ind);
|
||||
|
||||
if ( x -> get_mode(spointer_t::DELETED) == true )
|
||||
sum++;
|
||||
|
||||
delete x;
|
||||
|
||||
next(ind);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void page::next(int& ind) const // return next index relative to 'ind'
|
||||
{
|
||||
if ( ind >= count()-1 )
|
||||
ind = 0;
|
||||
else
|
||||
ind ++;
|
||||
}
|
||||
|
||||
void page::prev(int& ind) const // return prev index relative to 'ind'
|
||||
{
|
||||
if ( ind == 1 )
|
||||
ind = 0;
|
||||
else
|
||||
ind --;
|
||||
}
|
||||
|
||||
void page::_swap_order(Boolean swap_count_field_first)
|
||||
{
|
||||
if ( v_swap_order == true ) {
|
||||
/*
|
||||
MESSAGE(cerr, "page::_swap_order()");
|
||||
debug(cerr, pageid);
|
||||
*/
|
||||
|
||||
int& x = *((count_t*)v_base); // use this version to point at
|
||||
// the count field
|
||||
|
||||
//debug(cerr, x);
|
||||
if ( swap_count_field_first == true ) {
|
||||
ORDER_SWAP_UINT(x); // swap the count field first
|
||||
//MESSAGE(cerr, "swap earlier");
|
||||
//debug(cerr, x);
|
||||
}
|
||||
|
||||
for ( int i=1; i<=x; i++ ) {
|
||||
//debug(cerr, i);
|
||||
spointer_t slot_info(v_base, i);
|
||||
//debug(cerr, hex(slot_info.header.int_view));
|
||||
//debug(cerr, slot_info.string_ofst());
|
||||
slot_info.swap_order();
|
||||
//debug(cerr, hex(slot_info.header.int_view));
|
||||
//debug(cerr, slot_info.string_ofst());
|
||||
}
|
||||
|
||||
if ( swap_count_field_first == false ) {
|
||||
ORDER_SWAP_UINT(x); // swap the count field second
|
||||
//MESSAGE(cerr, "swap later");
|
||||
//debug(cerr, x);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream&s, page& p)
|
||||
{
|
||||
buffer lbuf;
|
||||
debug(s, int(p.dirty));
|
||||
debug(s, p.count());
|
||||
debug(s, p.pageid);
|
||||
debug(s, p.free_bytes());
|
||||
|
||||
debug(s, long(p.v_base));
|
||||
debug(s, long(p.v_eptr));
|
||||
|
||||
int ind = p.first();
|
||||
while ( ind ) {
|
||||
debug(s, int(ind));
|
||||
lbuf.reset();
|
||||
if ( p.get(ind, lbuf, 0) == true ) {
|
||||
s << lbuf;
|
||||
s << "\n";
|
||||
}
|
||||
p.next(ind);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void* page::operator new( size_t sz )
|
||||
{
|
||||
int alignment_overhead = sizeof(char*);
|
||||
|
||||
char* p = ::new char[alignment_overhead+sz];
|
||||
|
||||
if ( p ) {
|
||||
align_offset = int(alignment_overhead - long(p) % alignment_overhead);
|
||||
return (void*)(p + align_offset);
|
||||
} else {
|
||||
MESSAGE(cerr, "page::new() memalign call failed");
|
||||
throw(systemException(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void page::operator delete( void* p, size_t )
|
||||
{
|
||||
if ( p )
|
||||
free((char*)((char*)p - align_offset));
|
||||
}
|
||||
|
||||
/*
|
||||
int page::cdr_sizeof()
|
||||
{
|
||||
return sizeof(pageid) + v_bufsz;
|
||||
}
|
||||
|
||||
io_status page::cdrIn(buffer& buf)
|
||||
{
|
||||
buf.put(pageid);
|
||||
buffer::cdrIn(buf);
|
||||
return done;
|
||||
}
|
||||
|
||||
io_status page::cdrOut(buffer& buf)
|
||||
{
|
||||
buf.get(pageid);
|
||||
buffer::cdrOut(buf);
|
||||
return done;
|
||||
}
|
||||
*/
|
||||
141
cde/programs/dtinfo/DtMmdb/storage/page.h
Normal file
141
cde/programs/dtinfo/DtMmdb/storage/page.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* $XConsortium: page.h /main/10 1996/07/18 14:54:33 drk $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _page_h
|
||||
#define _page_h 1
|
||||
|
||||
#include "utility/config.h"
|
||||
#include "utility/funcs.h"
|
||||
#include "utility/buffer.h"
|
||||
#include "storage/rep_cell.h"
|
||||
#include "storage/spointer.h"
|
||||
|
||||
|
||||
// do not change to short! (for alignment reason)
|
||||
typedef int count_t;
|
||||
|
||||
|
||||
class page : private buffer
|
||||
{
|
||||
|
||||
public:
|
||||
page(int buf_sz = PAGSIZ, int pid = 0, Boolean swap_order = false);
|
||||
virtual ~page() ;
|
||||
|
||||
// wipe the page clean
|
||||
void clean_all();
|
||||
|
||||
// get and put functions
|
||||
Boolean get( int slot_num, buffer& target,
|
||||
int offset = 0, int bytes_to_read = 0
|
||||
) const;
|
||||
// get the byte string at slot 'slot_num' from buf.
|
||||
|
||||
Boolean put( int& slot_num, buffer& source );
|
||||
// put buf into the page into next
|
||||
// available slot. the index of the slot
|
||||
// is returned in slot_num.
|
||||
|
||||
Boolean alloc_slot( int& slot_num, int size, char*& string_ptr );
|
||||
|
||||
Boolean del_slot( int slot_num );
|
||||
// delete the slot at postiion 'slot_num'
|
||||
|
||||
Boolean update_slot( int slot_num, buffer& source, int offset = 0 );
|
||||
Boolean get_str_ptr( int slot_num, char*& str, int& len );
|
||||
|
||||
virtual void reset() { buffer::reset(); };
|
||||
|
||||
spointer_t* get_spointer(int slot_num) const;
|
||||
|
||||
// return the number of objects on the page
|
||||
int count() const { return *((count_t*)v_base); } ;
|
||||
|
||||
int page_id() { return pageid; };// page id
|
||||
int free_bytes() const; // free bytes on the page
|
||||
int free_slots() const; // free slots on the page
|
||||
char* page_base() { return v_base; };
|
||||
|
||||
// iteration functions
|
||||
|
||||
// go over all strings on the page
|
||||
int first() const { return ( count() <= 1 ) ? 0 : 1; };
|
||||
|
||||
void next(int &) const;
|
||||
void prev(int &) const;
|
||||
|
||||
// new operator
|
||||
void* operator new( size_t );
|
||||
void operator delete( void*, size_t );
|
||||
|
||||
// IO function and friend class
|
||||
friend ostream& operator<<(ostream&, page&);
|
||||
|
||||
friend class page_storage;
|
||||
friend class page_cache_global_part;
|
||||
friend class dyn_hash;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// slot management funcs
|
||||
void set_count(int i) {
|
||||
count_t& count = *(count_t*)(v_base);
|
||||
count = i; // reset count
|
||||
};
|
||||
|
||||
Boolean _alloc_slot( int slot_num, int size, char*& string_ptr );
|
||||
|
||||
void _swap_order(Boolean swap_count_field_first);
|
||||
|
||||
protected:
|
||||
int num_locks; // no. of locks
|
||||
unsigned int pageid ; // page id
|
||||
Boolean dirty ; // = false: page has not been written;
|
||||
int v_memalign_offset; // align offset of the memory
|
||||
// chunk for this page
|
||||
|
||||
Boolean v_swap_order;
|
||||
|
||||
};
|
||||
|
||||
typedef page* pagePtr;
|
||||
|
||||
class page_storage;
|
||||
|
||||
class lru_page : public page, public rep_cell
|
||||
{
|
||||
|
||||
public:
|
||||
lru_page(page_storage* st, int buf_sz = PAGSIZ,
|
||||
int pid = 0, Boolean swap_order = false
|
||||
) :
|
||||
page(buf_sz, pid, swap_order), f_store(st) {};
|
||||
virtual ~lru_page() {};
|
||||
|
||||
page_storage* f_store;
|
||||
};
|
||||
|
||||
typedef lru_page* lru_pagePtr;
|
||||
|
||||
#endif
|
||||
368
cde/programs/dtinfo/DtMmdb/storage/page_cache.C
Normal file
368
cde/programs/dtinfo/DtMmdb/storage/page_cache.C
Normal file
@@ -0,0 +1,368 @@
|
||||
/* $XConsortium: page_cache.cc /main/4 1996/06/11 17:44:22 cde-hal $
|
||||
*
|
||||
* (c) Copyright 1996 Digital Equipment Corporation.
|
||||
* (c) Copyright 1996 Hewlett-Packard Company.
|
||||
* (c) Copyright 1996 International Business Machines Corp.
|
||||
* (c) Copyright 1996 Sun Microsystems, Inc.
|
||||
* (c) Copyright 1996 Novell, Inc.
|
||||
* (c) Copyright 1996 FUJITSU LIMITED.
|
||||
* (c) Copyright 1996 Hitachi.
|
||||
*/
|
||||
|
||||
#include "utility/debug.h"
|
||||
#include "storage/page.h"
|
||||
#include "storage/heap_comp_funcs.h"
|
||||
#include "storage/page_rep.h"
|
||||
#include "storage/page_storage.h"
|
||||
|
||||
page_cache_local_part::page_cache_local_part(unsigned int exp_cached_page) :
|
||||
f_num_cached_pages(0),
|
||||
f_free_space(fbytes_t_eq, fbytes_t_ls, exp_cached_page),
|
||||
f_page_pool_index(page_rep_eq, page_rep_ls),
|
||||
f_current_page_num(0),
|
||||
f_current_page_ptr(0)
|
||||
{
|
||||
}
|
||||
|
||||
page_cache_local_part::~page_cache_local_part()
|
||||
{
|
||||
f_page_pool_index.del_elements(page_rep_del);
|
||||
}
|
||||
|
||||
Boolean page_cache_local_part::init_heap(page_storage* st)
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// We use a different strategy. Since pages are most of time read-only and
|
||||
// grows linearly when loaded, we assume the 1st to pages()-1 th page are
|
||||
// full.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if ( st -> pages() > 0 ) {
|
||||
|
||||
page* z = (*st)(st -> pages(), page_storage::READ);
|
||||
|
||||
f_free_space.insert(
|
||||
new fbytes_t(z -> free_bytes(), z -> page_id())
|
||||
);
|
||||
|
||||
f_free_space.heapify();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean page_cache_local_part::quit_heap(page_storage* st)
|
||||
{
|
||||
int ind = f_free_space.first();
|
||||
|
||||
while ( ind ) {
|
||||
fbytes_t *x = (fbytes_t*)f_free_space(ind);
|
||||
|
||||
/*
|
||||
debug(cerr, x -> page_num);
|
||||
debug(cerr, x -> free_bytes);
|
||||
*/
|
||||
|
||||
delete x;
|
||||
f_free_space.next(ind);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
page* page_cache_local_part::in_cache(page_storage* st, int page_num)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
st -> total_page_access++;
|
||||
#endif
|
||||
|
||||
if ( f_current_page_num == page_num ) {
|
||||
return f_current_page_ptr;
|
||||
}
|
||||
|
||||
page_rep data(page_num, 0);
|
||||
page_rep *result = 0;
|
||||
|
||||
/*
|
||||
cerr << "member(): " << st -> my_name() << " ";
|
||||
cerr << page_num ;
|
||||
cerr << " " << (void*)&f_page_pool_index;
|
||||
cerr << "\n";
|
||||
*/
|
||||
|
||||
if ( (result = (page_rep*)f_page_pool_index.member(&data)) ) {
|
||||
//cerr << "In Cache: page " << page_num << " of " << st -> my_name() << "\n";
|
||||
|
||||
lru_page* p = result -> f_page_ptr;
|
||||
|
||||
if ( p -> page_id() != page_num ) {
|
||||
throw(stringException("corrupted store"));
|
||||
}
|
||||
|
||||
if ( p -> get_position() == ACTIVE ) {
|
||||
#ifndef C_API
|
||||
(p -> f_store -> f_global_pcache).f_replace_policy.promote(*p);
|
||||
#else
|
||||
(p -> f_store -> f_global_pcache_ptr -> f_replace_policy).promote(*p);
|
||||
#endif
|
||||
//cerr << "Promoting:" << (long)p << endl;
|
||||
}
|
||||
|
||||
return p;
|
||||
|
||||
} else {
|
||||
|
||||
#ifdef DEBUG
|
||||
st -> pagings++;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void page_cache_local_part::adjust_heap(fbytes_t* v, Boolean new_page)
|
||||
{
|
||||
if ( new_page == false ) {
|
||||
if ( v -> free_bytes < 10 ) {
|
||||
f_free_space.delete_max();
|
||||
delete v;
|
||||
} else
|
||||
f_free_space.adjust_max_to(v);
|
||||
} else {
|
||||
f_free_space.insert_heapify(v);
|
||||
}
|
||||
}
|
||||
|
||||
fbytes_t*
|
||||
page_cache_local_part::find_host_page(
|
||||
page_storage* st, Boolean& new_page, int len
|
||||
)
|
||||
{
|
||||
|
||||
fbytes_t* x = (fbytes_t*)f_free_space.max_elm();
|
||||
|
||||
//if ( x )
|
||||
// debug(cerr, x -> free_bytes);
|
||||
//else
|
||||
// MESSAGE(cerr, "no cached page");
|
||||
|
||||
if ( x != 0 && x -> free_bytes > len ) {
|
||||
|
||||
new_page = false;
|
||||
|
||||
} else {
|
||||
st -> add_page_frames(1);
|
||||
new_page = true;
|
||||
x = new fbytes_t((*st)(st->pages(), page_storage::READ) -> free_bytes(), st->pages());
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
page_cache_global_part::page_cache_global_part(unsigned int allowed_pages) :
|
||||
f_total_allowed_pages(allowed_pages),
|
||||
f_replace_policy(allowed_pages, 0, true)
|
||||
{
|
||||
if ( allowed_pages == 0 ) {
|
||||
char* s = getenv("MMDB_CACHED_PAGES");
|
||||
if ( s ) {
|
||||
f_total_allowed_pages = atoi(s);
|
||||
if ( f_total_allowed_pages < MIN_MMDB_CACHED_PAGES ) // minimal value
|
||||
f_total_allowed_pages = MIN_MMDB_CACHED_PAGES;
|
||||
} else
|
||||
f_total_allowed_pages = MMDB_CACHED_PAGES;
|
||||
|
||||
f_replace_policy.set_params(f_total_allowed_pages, 0);
|
||||
} else
|
||||
if ( allowed_pages < MIN_MMDB_CACHED_PAGES ) {
|
||||
f_total_allowed_pages = MIN_MMDB_CACHED_PAGES;
|
||||
f_replace_policy.set_params(f_total_allowed_pages, 0);
|
||||
}
|
||||
}
|
||||
|
||||
page_cache_global_part::~page_cache_global_part()
|
||||
{
|
||||
}
|
||||
|
||||
page*
|
||||
page_cache_global_part::load_new_page(
|
||||
page_storage* st, int new_page_num, Boolean byte_order)
|
||||
{
|
||||
lru_pagePtr p = 0;
|
||||
|
||||
if ( f_replace_policy.active_elmts() < f_total_allowed_pages ) {
|
||||
|
||||
/*
|
||||
debug(cerr, page_cache -> active_elmts());
|
||||
debug(cerr, num_cached_pages);
|
||||
MESSAGE(cerr, "new a page");
|
||||
*/
|
||||
p = new lru_page(st, st -> page_sz, new_page_num, byte_order);
|
||||
|
||||
//cerr << "New page " << new_page_num << " of " << st -> my_name() << "\n";
|
||||
|
||||
} else {
|
||||
|
||||
long ind = f_replace_policy.last(ACTIVE);
|
||||
//cerr << "Getting last:" << (long)ind << endl;
|
||||
|
||||
if ( ind == 0 )
|
||||
throw(stringException("corrupted store"));
|
||||
|
||||
p = (lru_page*)f_replace_policy(ind, ACTIVE);
|
||||
|
||||
int pid = p -> page_id();
|
||||
page_rep key(pid, 0);
|
||||
|
||||
page_storage* pst = p -> f_store;
|
||||
|
||||
//cerr << "Removing " << pid ;
|
||||
//cerr << " for " << pst -> my_name() << " ";
|
||||
|
||||
delete (page_rep*)((pst->f_local_pcache).f_page_pool_index.remove(&key));
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// Clean the current_page entry in the local cache.
|
||||
////////////////////////////////////////////////////
|
||||
int & local_pid = (pst->f_local_pcache).f_current_page_num;
|
||||
if ( local_pid == pid ) local_pid = 0;
|
||||
|
||||
if ( p -> dirty == true ) {
|
||||
|
||||
#ifdef PORTABLE_DB
|
||||
////////////////////////////////////////////////////////////
|
||||
// swap the count field last.
|
||||
// no need to flip back to the original as the page frame
|
||||
// is reused.
|
||||
////////////////////////////////////////////////////////////
|
||||
p -> _swap_order(false);
|
||||
#endif
|
||||
|
||||
//cerr << " swapout";
|
||||
|
||||
int page_aoff = ( pid - 1 ) * (pst -> page_sz);
|
||||
pst -> storage_ptr -> updateString(
|
||||
page_storage::abs_off + mmdb_pos_t(page_aoff),
|
||||
p -> page_base(),
|
||||
pst->page_sz
|
||||
);
|
||||
}
|
||||
//cerr << "\n";
|
||||
|
||||
p -> expand_chunk(st -> page_size());
|
||||
p -> reset();
|
||||
p -> clean_all();
|
||||
p -> pageid = new_page_num;
|
||||
p -> f_store = st;
|
||||
}
|
||||
|
||||
p -> dirty = false;
|
||||
f_replace_policy.promote(*p);
|
||||
|
||||
/////////////////////////
|
||||
// read in the content
|
||||
/////////////////////////
|
||||
|
||||
page_rep* data = new page_rep(new_page_num, p);
|
||||
|
||||
//cerr << "Inserting " << new_page_num << " for " << st -> my_name() << " to page index.";
|
||||
//cerr << (void*)&(st->f_local_pcache.f_page_pool_index);
|
||||
|
||||
st->f_local_pcache.f_page_pool_index.insert(data);
|
||||
|
||||
int offset = (new_page_num-1) * (st->page_sz);
|
||||
|
||||
if ( offset <
|
||||
(((unixf_storage*)(st->storage_ptr))->bytes()-page_storage::abs_off))
|
||||
{
|
||||
|
||||
|
||||
//cerr << " swap in the page";
|
||||
//debug(cerr, offset);
|
||||
//debug(cerr, int(p -> page_base()));
|
||||
|
||||
((unixf_storage*)(st->storage_ptr)) ->
|
||||
readString( page_storage::abs_off + mmdb_pos_t(offset),
|
||||
p -> page_base(),
|
||||
st->page_sz
|
||||
);
|
||||
|
||||
#ifdef PORTABLE_DB
|
||||
p -> _swap_order(true); // swap count field first
|
||||
#endif
|
||||
}
|
||||
//cerr << "\n";
|
||||
|
||||
(st->f_local_pcache).f_current_page_num = new_page_num;
|
||||
(st->f_local_pcache).f_current_page_ptr = p;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void remove_from_global_cache(const void* x)
|
||||
{
|
||||
page_rep* y = (page_rep*)x;
|
||||
lru_page* p = y -> f_page_ptr;
|
||||
page_storage* st = p -> f_store;
|
||||
//cerr << "removing " << y -> f_page_num << "\n";
|
||||
#ifndef C_API
|
||||
((st -> f_global_pcache).f_replace_policy).remove(*p);
|
||||
#else
|
||||
(st -> f_global_pcache_ptr -> f_replace_policy).remove(*p);
|
||||
#endif
|
||||
delete p;
|
||||
}
|
||||
|
||||
void page_cache_global_part::remove_pages(page_storage* st)
|
||||
{
|
||||
//cerr << "remove_pages(): for " << st -> my_name() << "\n";
|
||||
(st -> f_local_pcache).f_page_pool_index.apply(remove_from_global_cache);
|
||||
|
||||
/*
|
||||
lru_pagePtr* temps = new lru_pagePtr[f_replace_policy.active_elmts()];
|
||||
int ind = f_replace_policy.first();
|
||||
|
||||
int i=0;
|
||||
while ( ind != 0 ) {
|
||||
lru_page* p = (lru_page*)f_replace_policy(ind, ACTIVE);
|
||||
if ( p -> f_store == st )
|
||||
temps[i++] = p;
|
||||
f_replace_policy.next(ind, ACTIVE);
|
||||
}
|
||||
|
||||
for ( int j=0; j<i; j++ )
|
||||
f_replace_policy.remove(*temps[j]);
|
||||
delete temps;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
ostream& page_cache_global_part::print_cached_pages(ostream& s)
|
||||
{
|
||||
MESSAGE(s, "cached pages:");
|
||||
long ind = f_replace_policy.first();
|
||||
while ( ind != 0 ) {
|
||||
lru_page* p = (lru_page*)f_replace_policy(ind, ACTIVE);
|
||||
debug(s, long(p));
|
||||
|
||||
if ( p == 0 )
|
||||
throw(stringException("corrupted store"));
|
||||
|
||||
debug(s, *p);
|
||||
f_replace_policy.next(ind, ACTIVE);
|
||||
debug(s, ind);
|
||||
}
|
||||
MESSAGE(s, "print cached pages done");
|
||||
return s;
|
||||
}
|
||||
|
||||
77
cde/programs/dtinfo/DtMmdb/storage/page_cache.h
Normal file
77
cde/programs/dtinfo/DtMmdb/storage/page_cache.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* $XConsortium: page_cache.h /main/3 1996/06/11 17:44:27 cde-hal $ */
|
||||
|
||||
#ifndef _page_cache_h
|
||||
#define _page_cache_h 1
|
||||
|
||||
class page;
|
||||
class page_storage;
|
||||
|
||||
#define MMDB_CACHED_PAGES 100
|
||||
#define MIN_MMDB_CACHED_PAGES 10
|
||||
|
||||
#include "dstr/bset.h"
|
||||
|
||||
class page_cache_local_part
|
||||
{
|
||||
|
||||
protected:
|
||||
int f_num_cached_pages ; // number of cached pages
|
||||
|
||||
heap f_free_space; // a heap recording free
|
||||
// space on each page
|
||||
|
||||
bset f_page_pool_index; // index to pages in the pool
|
||||
|
||||
int f_current_page_num;
|
||||
page* f_current_page_ptr;
|
||||
|
||||
public:
|
||||
page_cache_local_part(unsigned int exp_cached_page);
|
||||
virtual ~page_cache_local_part();
|
||||
|
||||
// init the heap
|
||||
Boolean init_heap(page_storage*);
|
||||
Boolean quit_heap(page_storage*);
|
||||
|
||||
// does the cache hold page 'page_num'?
|
||||
page* in_cache(page_storage* st, int page_num);
|
||||
|
||||
// get a non-empty page
|
||||
fbytes_t* find_host_page(page_storage*, Boolean& new_page, int len = 0);
|
||||
void adjust_heap(fbytes_t* v, Boolean new_page);
|
||||
|
||||
friend class page_cache_global_part ;
|
||||
};
|
||||
|
||||
class lru;
|
||||
|
||||
class page_cache_global_part
|
||||
{
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// The default value (0) triggers the constructor to
|
||||
// search for the value in the shell variable MMDB_CACHED_PAGES.
|
||||
// If the varialble is undefind, the value set by const MMDB_CACHED_PAGES
|
||||
// will be used.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
page_cache_global_part(unsigned int total_allowed_pages = 0);
|
||||
virtual ~page_cache_global_part() ;
|
||||
|
||||
void remove_pages(page_storage* st);
|
||||
|
||||
// return a free page frame from cache
|
||||
page* load_new_page(page_storage*, int page_num, Boolean byteOrder);
|
||||
|
||||
ostream& print_cached_pages(ostream&); // show cached pages.
|
||||
|
||||
friend class page_cache_local_part;
|
||||
friend class page_storage;
|
||||
friend void remove_from_global_cache(const void*);
|
||||
|
||||
protected:
|
||||
unsigned int f_total_allowed_pages;
|
||||
lru f_replace_policy;
|
||||
};
|
||||
|
||||
#endif
|
||||
26
cde/programs/dtinfo/DtMmdb/storage/page_rep.C
Normal file
26
cde/programs/dtinfo/DtMmdb/storage/page_rep.C
Normal file
@@ -0,0 +1,26 @@
|
||||
// $XConsortium: page_rep.cc /main/3 1996/06/11 17:44:32 cde-hal $
|
||||
|
||||
#include "storage/page_rep.h"
|
||||
|
||||
void page_rep_del(const void* x)
|
||||
{
|
||||
delete (page_rep*)x;
|
||||
}
|
||||
|
||||
Boolean page_rep_ls(const void* x, const void* y)
|
||||
{
|
||||
if ( ((page_rep*)x) -> f_page_num < ((page_rep*)y) -> f_page_num )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean page_rep_eq(const void* x, const void* y)
|
||||
{
|
||||
if ( ((page_rep*)x) -> f_page_num == ((page_rep*)y) -> f_page_num )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
34
cde/programs/dtinfo/DtMmdb/storage/page_rep.h
Normal file
34
cde/programs/dtinfo/DtMmdb/storage/page_rep.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* $XConsortium: page_rep.h /main/3 1996/06/11 17:44:37 cde-hal $ */
|
||||
|
||||
#ifndef _page_rep
|
||||
#define _page_rep 1
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class lru_page;
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// struct for managing page number/page ptr pair
|
||||
//////////////////////////////////////////////////
|
||||
class page_rep
|
||||
{
|
||||
|
||||
public:
|
||||
page_rep(int pnum, lru_page* ptr = 0) {
|
||||
f_page_ptr = ptr;
|
||||
f_page_num = pnum;
|
||||
};
|
||||
virtual ~page_rep() {};
|
||||
|
||||
public:
|
||||
lru_page* f_page_ptr;
|
||||
int f_page_num;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
Boolean page_rep_ls(const void*x, const void* y);
|
||||
Boolean page_rep_eq(const void*x, const void* y);
|
||||
void page_rep_del(const void* x);
|
||||
|
||||
#endif
|
||||
1331
cde/programs/dtinfo/DtMmdb/storage/page_storage.C
Normal file
1331
cde/programs/dtinfo/DtMmdb/storage/page_storage.C
Normal file
File diff suppressed because it is too large
Load Diff
231
cde/programs/dtinfo/DtMmdb/storage/page_storage.h
Normal file
231
cde/programs/dtinfo/DtMmdb/storage/page_storage.h
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* $XConsortium: page_storage.h /main/7 1996/07/18 14:55:30 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _page_storage_h
|
||||
#define _page_storage_h 1
|
||||
|
||||
#define NUM_PAGES 10
|
||||
|
||||
#include "utility/pm_random.h"
|
||||
#include "dstr/heap.h"
|
||||
#include "dstr/void_ptr_array.h"
|
||||
#include "dynhash/imp_die.h"
|
||||
#include "storage/unixf_storage.h"
|
||||
#include "storage/heap_comp_funcs.h"
|
||||
#include "storage/page_cache.h"
|
||||
#include "storage/spointer.h"
|
||||
|
||||
enum direction { positive, negative };
|
||||
|
||||
class page;
|
||||
|
||||
class str_index_record_t : public root
|
||||
{
|
||||
|
||||
public:
|
||||
int str_offset;
|
||||
mmdb_pos_t loc;
|
||||
|
||||
str_index_record_t(int offset, mmdb_pos_t lc = 0);
|
||||
virtual ~str_index_record_t() {};
|
||||
};
|
||||
|
||||
void delete_str_index_record(const void* str_index_record_ptr);
|
||||
|
||||
typedef str_index_record_t* str_index_record_tPtr;
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
class store_trans
|
||||
{
|
||||
|
||||
protected:
|
||||
enum trans_t { ENABLED, DISABLED };
|
||||
|
||||
int page_sz;
|
||||
int max_pages;
|
||||
trans_t status;
|
||||
unixf_storage* log_store;
|
||||
imp_die* log_index;
|
||||
|
||||
char* path;
|
||||
char* name;
|
||||
|
||||
public:
|
||||
store_trans(char* path, char*name, int page_sz);
|
||||
~store_trans();
|
||||
|
||||
void init(rep_policy*);
|
||||
void quit();
|
||||
|
||||
void set_max_pages(int max_pgs) {
|
||||
max_pages = max_pgs;
|
||||
};
|
||||
|
||||
friend class page_storage;
|
||||
};
|
||||
|
||||
/******************************************************/
|
||||
// cached page storage. Implemented on Unix file class.
|
||||
/******************************************************/
|
||||
|
||||
#ifdef C_API
|
||||
#define f_global_pcache (*f_global_pcache_ptr)
|
||||
#endif
|
||||
|
||||
|
||||
class page_storage : public abs_storage
|
||||
{
|
||||
|
||||
protected:
|
||||
buffer* v_buf; // aux. buf.
|
||||
|
||||
int page_sz ; // page size
|
||||
|
||||
static int dv_sz ;
|
||||
static int abs_off ;
|
||||
|
||||
#ifndef C_API
|
||||
static page_cache_global_part f_global_pcache;
|
||||
#else
|
||||
static page_cache_global_part* f_global_pcache_ptr;
|
||||
#endif
|
||||
|
||||
page_cache_local_part f_local_pcache;
|
||||
|
||||
int total_pages;
|
||||
|
||||
int pagings ;
|
||||
int total_page_access;
|
||||
|
||||
store_trans trans_info;
|
||||
|
||||
// byte order
|
||||
int v_server_order;
|
||||
int v_db_order;
|
||||
|
||||
protected:
|
||||
|
||||
Boolean seek_loc_negative(mmdb_pos_t& loc, int smd);
|
||||
Boolean seek_loc_positive(mmdb_pos_t& loc, int smd);
|
||||
|
||||
public:
|
||||
page_storage(char* path, char* name,
|
||||
unixf_storage* store,
|
||||
int page_sz = PAGSIZ,
|
||||
int num_cached_pages = NUM_PAGES,
|
||||
mmdb_byte_order_t db_order_when_create_store = mmdb_big_endian
|
||||
);
|
||||
virtual ~page_storage();
|
||||
|
||||
void remove(); // remove all pages in the store
|
||||
|
||||
void sync();
|
||||
void sync(int pagenum);
|
||||
void sync(page*);
|
||||
|
||||
void begin_trans();
|
||||
void commit_trans();
|
||||
void roll_back();
|
||||
void save_to_log(page* page_ptr);
|
||||
|
||||
// get server and db order
|
||||
int server_order() { return v_server_order; } ;
|
||||
int db_order() { return v_db_order; };
|
||||
|
||||
|
||||
// i/o functions
|
||||
int readString (mmdb_pos_t loc, char* base, int len, int str_offset = 0);
|
||||
int get_str_ptr(mmdb_pos_t loc, char*&, int& len) ;
|
||||
|
||||
int updateString(mmdb_pos_t loc, const char* base, int len, int string_ofst = 0, Boolean flush = false);
|
||||
int deleteString (mmdb_pos_t loc, Boolean flush = false);
|
||||
int insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush = false);
|
||||
int allocString (mmdb_pos_t& loc, int len, char*&, int mode = 0);
|
||||
int appendString(mmdb_pos_t loc, const char*, int len, Boolean flush_opt = false);
|
||||
|
||||
int set_page_dirty(mmdb_pos_t loc);
|
||||
|
||||
// iteration functions
|
||||
typedef enum access { READ, WRITE } access_t;
|
||||
int first() const; // first page's index in the store
|
||||
page* operator()(int page_num, enum access intent) ; //get the page
|
||||
void next(int&) const; // next page's index.
|
||||
|
||||
|
||||
// format the store to contain extra empty 'pages' pages
|
||||
int add_page_frames(int pages);
|
||||
|
||||
|
||||
// get locs of the pieces that a long string is broken into
|
||||
// The array should be deleted after use.
|
||||
int get_str_locs(mmdb_pos_t str_loc, str_index_record_tPtr*& locs, int& vector_leng);
|
||||
|
||||
// seek loc to (loc +/- 1) position
|
||||
Boolean seek_loc(mmdb_pos_t& loc, const direction = positive, int = spointer_t::FIRST_RECD );
|
||||
mmdb_pos_t first_loc(); // return first loc in the store
|
||||
mmdb_pos_t last_loc(); // return last loc in the store
|
||||
|
||||
// store status query functions
|
||||
int page_size() { return page_sz; };
|
||||
|
||||
//
|
||||
void set_page_size(int pgsz) { page_sz = pgsz; };
|
||||
|
||||
// how many pages in total in the store
|
||||
int pages() const { return total_pages; };
|
||||
|
||||
// paging counting function
|
||||
void reset_paging_count();
|
||||
int paging_count() const;
|
||||
|
||||
Boolean io_mode(int mode) ;
|
||||
|
||||
// return an aux. buf.
|
||||
buffer& aux_buf();
|
||||
|
||||
// printing functions
|
||||
virtual io_status asciiOut(ostream&) ;
|
||||
|
||||
friend void close_file(const void*);
|
||||
friend void remove_from_global_cache(const void*);
|
||||
|
||||
friend class storage_mgr_t;
|
||||
friend class handler;
|
||||
friend class page_cache_local_part;
|
||||
friend class page_cache_global_part;
|
||||
|
||||
#ifdef C_API
|
||||
friend void initialize_MMDB();
|
||||
friend void quit_MMDB();
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef page_storage* page_storagePtr;
|
||||
|
||||
#endif
|
||||
149
cde/programs/dtinfo/DtMmdb/storage/pool.C
Normal file
149
cde/programs/dtinfo/DtMmdb/storage/pool.C
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* $XConsortium: pool.cc /main/3 1996/06/11 17:34:18 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/memory_pool.h"
|
||||
#include "utility/xtime.h"
|
||||
|
||||
#define NUMS 100000
|
||||
#define SIZE 20
|
||||
|
||||
pool_test1()
|
||||
{
|
||||
MESSAGE(cerr, "pool alloc/free test1");
|
||||
memory_pool x;
|
||||
|
||||
char* ptrs[NUMS];
|
||||
|
||||
for ( int i=0; i<NUMS; i++ ) {
|
||||
ptrs[i] = x.alloc(SIZE);
|
||||
}
|
||||
|
||||
MESSAGE(cerr, "alloc done!");
|
||||
|
||||
for ( i=0; i<NUMS; i++ ) {
|
||||
x.free(ptrs[i]);
|
||||
}
|
||||
MESSAGE(cerr, "free done!");
|
||||
}
|
||||
|
||||
pool_test2()
|
||||
{
|
||||
MESSAGE(cerr, "pool alloc/free test2");
|
||||
memory_pool x;
|
||||
|
||||
char* ptrs[100];
|
||||
|
||||
for ( int i=0; i<NUMS/100; i++ ) {
|
||||
|
||||
for ( int j=0; j<100; j++ ) {
|
||||
ptrs[j] = x.alloc(SIZE);
|
||||
}
|
||||
|
||||
|
||||
for ( j=0; j<100; j++ ) {
|
||||
x.free(ptrs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
new_delete_test1()
|
||||
{
|
||||
MESSAGE(cerr, "new/delete test1");
|
||||
char* ptrs[NUMS];
|
||||
|
||||
for ( int i=0; i<NUMS; i++ ) {
|
||||
ptrs[i] = new char[SIZE];
|
||||
}
|
||||
|
||||
MESSAGE(cerr, "alloc done!");
|
||||
|
||||
for ( i=NUMS-1; i>=0; i-- ) {
|
||||
delete ptrs[i];
|
||||
}
|
||||
MESSAGE(cerr, "free done!");
|
||||
}
|
||||
|
||||
new_delete_test2()
|
||||
{
|
||||
MESSAGE(cerr, "new/delete test2");
|
||||
char* ptrs[100];
|
||||
|
||||
for ( int i=0; i<NUMS/100; i++ ) {
|
||||
|
||||
for ( int j=0; j<100; j++ ) {
|
||||
ptrs[j] = new char[SIZE];
|
||||
}
|
||||
|
||||
|
||||
for ( j=0; j<100; j++ ) {
|
||||
delete ptrs[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main( int argc, char** argv )
|
||||
{
|
||||
assert ( argc == 2 );
|
||||
|
||||
int ok;
|
||||
float cpul
|
||||
long elap;
|
||||
xtime tm;
|
||||
|
||||
tm.snap_shot();
|
||||
|
||||
if ( strcmp(argv[1], "-pool1") == 0 ) {
|
||||
pool_test1();
|
||||
ok = 0;
|
||||
} else
|
||||
if ( strcmp(argv[1], "-pool2") == 0 ) {
|
||||
pool_test2();
|
||||
ok = 0;
|
||||
} else
|
||||
if ( strcmp(argv[1], "-new1") == 0 ) {
|
||||
new_delete_test1();
|
||||
ok = 0;
|
||||
} else
|
||||
if ( strcmp(argv[1], "-new2") == 0 ) {
|
||||
new_delete_test2();
|
||||
ok = 0;
|
||||
}
|
||||
else {
|
||||
MESSAGE(cerr, "apply a param: -pool[1|2] or -new[1|2]");
|
||||
ok = -1;
|
||||
}
|
||||
|
||||
tm.duration(cpu, elap);
|
||||
debug(cerr, cpu);
|
||||
debug(cerr, elap);
|
||||
|
||||
return ok;
|
||||
}
|
||||
32
cde/programs/dtinfo/DtMmdb/storage/rep_cell.C
Normal file
32
cde/programs/dtinfo/DtMmdb/storage/rep_cell.C
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* $XConsortium: rep_cell.cc /main/3 1996/06/11 17:34:23 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/rep_cell.h"
|
||||
|
||||
rep_cell::~rep_cell()
|
||||
{
|
||||
}
|
||||
|
||||
lru_cell_void_dt::~lru_cell_void_dt()
|
||||
{
|
||||
}
|
||||
|
||||
65
cde/programs/dtinfo/DtMmdb/storage/rep_cell.h
Normal file
65
cde/programs/dtinfo/DtMmdb/storage/rep_cell.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* $XConsortium: rep_cell.h /main/4 1996/08/21 15:53:50 drk $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _rep_cell_h
|
||||
#define _rep_cell_h 1
|
||||
|
||||
#ifdef C_API
|
||||
#include "utility/c_stream.h"
|
||||
#else
|
||||
#include <stream.h>
|
||||
#endif
|
||||
|
||||
#include "dstr/dlist.h"
|
||||
#include "utility/debug.h"
|
||||
|
||||
|
||||
enum position_t { ACTIVE, INACTIVE, NOWHERE };
|
||||
|
||||
class rep_cell : public dlist_cell
|
||||
{
|
||||
public:
|
||||
rep_cell() : pos(NOWHERE) {};
|
||||
virtual ~rep_cell() ;
|
||||
|
||||
position_t get_position() { return pos; };
|
||||
void set_position(position_t x) { pos = x; };
|
||||
|
||||
protected:
|
||||
position_t pos;
|
||||
|
||||
};
|
||||
|
||||
class lru_cell_void_dt : public rep_cell
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
void* dt;
|
||||
|
||||
lru_cell_void_dt(void* x = 0) : dt(x) {};
|
||||
virtual ~lru_cell_void_dt();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
33
cde/programs/dtinfo/DtMmdb/storage/rep_policy.C
Normal file
33
cde/programs/dtinfo/DtMmdb/storage/rep_policy.C
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* $XConsortium: rep_policy.cc /main/3 1996/06/11 17:34:32 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/rep_policy.h"
|
||||
|
||||
rep_policy::rep_policy(int a_sz, int i_sz)
|
||||
{
|
||||
active_sz = a_sz;
|
||||
inactive_sz = i_sz;
|
||||
}
|
||||
|
||||
rep_policy::~rep_policy()
|
||||
{
|
||||
}
|
||||
52
cde/programs/dtinfo/DtMmdb/storage/rep_policy.h
Normal file
52
cde/programs/dtinfo/DtMmdb/storage/rep_policy.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* $XConsortium: rep_policy.h /main/4 1996/06/11 17:34:37 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _rep_policy_h
|
||||
#define _rep_policy_h 1
|
||||
|
||||
#include "utility/funcs.h"
|
||||
#include "dstr/dlist.h"
|
||||
#include "storage/rep_cell.h"
|
||||
|
||||
class rep_policy {
|
||||
|
||||
protected:
|
||||
int active_sz;
|
||||
int inactive_sz;
|
||||
|
||||
public:
|
||||
rep_policy(int a_sz, int i_sz) ;
|
||||
virtual ~rep_policy() ;
|
||||
|
||||
void set_params(int a_sz, int i_sz)
|
||||
{ active_sz = a_sz; inactive_sz = i_sz; };
|
||||
|
||||
// promotes the cell x to the window.
|
||||
virtual Boolean promote(rep_cell&, rep_cell*& replaced) = 0;
|
||||
virtual Boolean promote(rep_cell& x) = 0;
|
||||
|
||||
virtual Boolean remove(rep_cell& x) = 0;
|
||||
};
|
||||
|
||||
typedef rep_policy *rep_policyPtr;
|
||||
|
||||
#endif
|
||||
122
cde/programs/dtinfo/DtMmdb/storage/spointer.h
Normal file
122
cde/programs/dtinfo/DtMmdb/storage/spointer.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/* $XConsortium: spointer.h /main/6 1996/07/18 16:35:10 drk $ */
|
||||
|
||||
#ifndef _spointer_h
|
||||
#define _spointer_h 1
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Macros to manipulate page number and item number components.
|
||||
//
|
||||
// Variable definitions:
|
||||
// x: compacted representation of page id and item
|
||||
// index in the page;
|
||||
// y: page size;
|
||||
// u: page id;
|
||||
// v: item index in the page;
|
||||
////////////////////////////////////////////////////////////
|
||||
#define PAGE_ID(x, y) ( unsigned(x) >> pos_of_LSB(y) )
|
||||
#define PAGE_IDX(x, y) ( unsigned(x) & ~(~0 << pos_of_LSB(y)) )
|
||||
#define FORM_PAGE_REF(u, v, y) ( ((u) << pos_of_LSB(y)) | PAGE_IDX((v), (y)) )
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// . page class. group of pages are under LRU management;
|
||||
// . use buffer to hold page content (implementation);
|
||||
// . LRU implementation is made possible by defining 'lru'
|
||||
// as one of the base class.
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#define HEADER_MASK 0xf
|
||||
|
||||
struct header_t
|
||||
{
|
||||
#ifdef MMDB_BIG_ENDIAN
|
||||
unsigned spointer : 14;
|
||||
unsigned length : 14;
|
||||
unsigned is_object : 1;
|
||||
unsigned updated : 1;
|
||||
unsigned first_recd : 1;
|
||||
unsigned deleted : 1;
|
||||
#else
|
||||
unsigned deleted : 1;
|
||||
unsigned first_recd : 1;
|
||||
unsigned updated : 1;
|
||||
unsigned is_object : 1;
|
||||
unsigned length : 14;
|
||||
unsigned spointer : 14;
|
||||
#endif
|
||||
};
|
||||
|
||||
class spointer_t
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum spointer_mode { IS_OBJECT=8,
|
||||
UPDATED=4,
|
||||
FIRST_RECD=2,
|
||||
DELETED=1
|
||||
};
|
||||
|
||||
spointer_t(char* page_base, int slot_num);
|
||||
spointer_t(char* page_base, int slot_num, int ofst, int len);
|
||||
~spointer_t();
|
||||
|
||||
void set_mode(spointer_mode, Boolean);
|
||||
Boolean get_mode(spointer_mode);
|
||||
void add_mode(int m) {
|
||||
header.int_view |= (HEADER_MASK & m);
|
||||
set_mode(UPDATED, true);
|
||||
};
|
||||
Boolean test_mode(int m) {
|
||||
return ( (header.int_view & HEADER_MASK & m) == m ) ? true : false;
|
||||
};
|
||||
|
||||
mmdb_pos_t forward_ptr() { return fwd_ptr; };
|
||||
int string_leng() {
|
||||
return int(header.bit_view.length);
|
||||
};
|
||||
|
||||
int string_ofst() {
|
||||
return int(header.bit_view.spointer);
|
||||
};
|
||||
|
||||
void set_string_leng(int l) {
|
||||
header.bit_view.length = l;
|
||||
set_mode(UPDATED, true);
|
||||
};
|
||||
void set_string_ofst(int ofst) {
|
||||
header.bit_view.spointer = ofst;
|
||||
set_mode(UPDATED, true);
|
||||
};
|
||||
|
||||
void set_forward_ptr(mmdb_pos_t ptr) {
|
||||
fwd_ptr = ptr;
|
||||
set_mode(UPDATED, true);
|
||||
};
|
||||
|
||||
void swap_order() {
|
||||
#ifdef __osf__
|
||||
ORDER_SWAP_INT(fwd_ptr);
|
||||
#else
|
||||
ORDER_SWAP_LONG(fwd_ptr);
|
||||
#endif
|
||||
ORDER_SWAP_UINT(header.int_view);
|
||||
swapped = true;
|
||||
};
|
||||
|
||||
friend class page;
|
||||
friend class page_storage;
|
||||
|
||||
protected:
|
||||
mmdb_pos_t fwd_ptr;
|
||||
union {
|
||||
header_t bit_view;
|
||||
unsigned int int_view;
|
||||
} header;
|
||||
|
||||
char* page_image;
|
||||
Boolean swapped;
|
||||
};
|
||||
|
||||
#endif
|
||||
77
cde/programs/dtinfo/DtMmdb/storage/storage.h
Normal file
77
cde/programs/dtinfo/DtMmdb/storage/storage.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* $XConsortium: storage.h /main/5 1996/08/21 15:53:54 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _unixf_storage_h
|
||||
#define _unixf_storage_h 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef C_API
|
||||
#include "utility/c_fstream.h"
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
|
||||
#include "utility/macro.h"
|
||||
#include "storage/lru.h"
|
||||
#include "storage/storage.h"
|
||||
|
||||
extern lru unixf_mgr;
|
||||
|
||||
class storage : public rep_cell, public root, private fstream
|
||||
{
|
||||
|
||||
protected:
|
||||
int mode;
|
||||
char name[PATHSIZ];
|
||||
rep_policy *policy;
|
||||
|
||||
int _open();
|
||||
|
||||
public:
|
||||
// mode: see ios::in etc. stuff in file iostream.h
|
||||
unixf_storage(char* filenm, int init_buf_sz = LBUFSIZ,
|
||||
int md = ios::in | ios::out, rep_policy* = 0
|
||||
);
|
||||
virtual ~unixf_storage() ;
|
||||
|
||||
// IO functions
|
||||
virtual int readString (mmdb_pos_t loc, char*&, int len, int str_offset = 0);
|
||||
virtual int appendString(mmdb_pos_t& loc, char*, int len);
|
||||
virtual int updateString(mmdb_pos_t loc, char* base, int len, int string_ofst = 0);
|
||||
virtual int allocString (mmdb_pos_t&, int, char*&, int = 0) = 0;
|
||||
|
||||
// status function
|
||||
const char* my_nick_name() ; // name of the unix file
|
||||
int bytes() ;
|
||||
};
|
||||
|
||||
typedef storage* storagePtr;
|
||||
|
||||
#endif
|
||||
134
cde/programs/dtinfo/DtMmdb/storage/store_test.C
Normal file
134
cde/programs/dtinfo/DtMmdb/storage/store_test.C
Normal file
@@ -0,0 +1,134 @@
|
||||
/* $XConsortium: store_test.C /main/7 1996/08/21 15:56:52 drk $ */
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include "utility/pm_random.h"
|
||||
#include "storage/page_storage.h"
|
||||
|
||||
////////////////////////////
|
||||
// case: store pages exist
|
||||
////////////////////////////
|
||||
void real_page_cache_test_1(pm_random& rand_gen, page_storage** st, unsigned int ct, unsigned int no_access)
|
||||
{
|
||||
unsigned int j, k;
|
||||
page_storage::access_t l;
|
||||
|
||||
for ( int i=0; i< no_access; i++)
|
||||
{
|
||||
|
||||
j = rand_gen.rand() % ct; // pick the store
|
||||
k = rand_gen.rand() % (st[j] -> pages()) + 1; // pick the page
|
||||
|
||||
// pick the READ/WRITE option
|
||||
|
||||
l = (rand_gen.rand_01()>0.5) ? page_storage::READ : page_storage::WRITE;
|
||||
|
||||
cerr << "store=" << st[j] -> my_name() << " ";
|
||||
cerr << "page=" << k << " ";
|
||||
if (l==page_storage::READ)
|
||||
cerr << "read" ;
|
||||
else
|
||||
cerr << "write";
|
||||
cerr << "\n";
|
||||
|
||||
(*st[j])(k, l);
|
||||
}
|
||||
}
|
||||
|
||||
page_storage**
|
||||
prepare_store(char* path, lru& open_file_policy,
|
||||
pm_random& rand_gen, unsigned int ct, unsigned int low, unsigned int high)
|
||||
{
|
||||
char name[256];
|
||||
|
||||
page_storage** x = new page_storagePtr[ct];
|
||||
unixf_storage* unix_file = 0;
|
||||
|
||||
for ( int i=0; i<ct; i++) {
|
||||
int pages = rand_gen.rand() % (high-low) + low;
|
||||
|
||||
/*
|
||||
if ( i == 0 )
|
||||
pages = 2;
|
||||
if ( i == 1 )
|
||||
pages = 17;
|
||||
*/
|
||||
|
||||
sprintf(name, "test.%d", i);
|
||||
|
||||
if ( exist_file(name) == true )
|
||||
del_file(name);
|
||||
|
||||
unix_file = new unixf_storage(path, name, &open_file_policy);
|
||||
x[i] = new page_storage(path, name, unix_file, 1024);
|
||||
x[i] -> add_page_frames(pages);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
void quit_store(page_storage** st, unsigned int ct)
|
||||
{
|
||||
for ( int i=0; i<ct; i++) {
|
||||
delete st[i];
|
||||
}
|
||||
delete st;
|
||||
}
|
||||
|
||||
int page_cache_test_1(int argc, char** argv)
|
||||
{
|
||||
if ( argc != 7 ) {
|
||||
cerr << "usage: page_cache_test1 db_path stores min_pages max_pages no_probes\n";
|
||||
cerr << "where \n";
|
||||
cerr << " db_path: a path where the test dbs will be created;\n";
|
||||
cerr << " stores: number of stores;\n";
|
||||
cerr << " min_pages: min number of pages in these stores;\n";
|
||||
cerr << " max_pages: max number of pages in these stores;\n";
|
||||
cerr << " no_probes: number of probes to check the page cache.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __uxp__
|
||||
int seed;
|
||||
struct tms tp;
|
||||
if ((seed = (int)times(&tp)) < 0)
|
||||
seed = 19;
|
||||
#else
|
||||
struct timeval tp;
|
||||
struct timezone tzp;
|
||||
|
||||
int seed = ( gettimeofday(&tp, &tzp) == 0 ) ? int(tp.tv_sec) : 19;
|
||||
#endif
|
||||
pm_random rand_gen;
|
||||
rand_gen.seed(seed);
|
||||
|
||||
char* path = argv[2];
|
||||
|
||||
if ( check_and_create_dir(path) != true )
|
||||
return -1;
|
||||
|
||||
lru open_file_policy(20, 1000, false);
|
||||
|
||||
unsigned int ct = atoi(argv[3]);
|
||||
unsigned int low = atoi(argv[4]); if ( low == 0 ) low = 1;
|
||||
|
||||
unsigned int high = atoi(argv[5]);
|
||||
unsigned int no_access= atoi(argv[6]);
|
||||
|
||||
page_storage** st =
|
||||
prepare_store(path, open_file_policy, rand_gen, ct, low, high);
|
||||
|
||||
real_page_cache_test_1(rand_gen, st, ct, no_access);
|
||||
|
||||
quit_store(st, ct);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int store_test(int argc, char** argv)
|
||||
{
|
||||
if ( strcmp(argv[1], "page_cache_test_1") == 0 )
|
||||
return page_cache_test_1(argc, argv);
|
||||
else
|
||||
return 2;
|
||||
}
|
||||
|
||||
8
cde/programs/dtinfo/DtMmdb/storage/store_test.h
Normal file
8
cde/programs/dtinfo/DtMmdb/storage/store_test.h
Normal file
@@ -0,0 +1,8 @@
|
||||
/* $XConsortium: store_test.h /main/3 1996/06/11 17:44:52 cde-hal $ */
|
||||
|
||||
#ifndef _store_test_h
|
||||
#define _store_test_h 1
|
||||
|
||||
extern int store_test(int argc, char** argv);
|
||||
|
||||
#endif
|
||||
330
cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C
Normal file
330
cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C
Normal file
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* $TOG: unixf_storage.C /main/8 1998/04/17 11:50:39 mgreess $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "storage/unixf_storage.h"
|
||||
|
||||
#ifdef _IBMR2 /* connolly 2/21/95 from the AIX fsync() manpage */
|
||||
extern "C" int fsync(int fd);
|
||||
#endif
|
||||
|
||||
/***********************************************************/
|
||||
// Constructor
|
||||
/***********************************************************/
|
||||
unixf_storage::
|
||||
unixf_storage( char* file_path, char* file_name,
|
||||
rep_policy* rep_p, int m
|
||||
) :
|
||||
abs_storage( file_path, file_name, UNIX_STORAGE_CODE, rep_p ),
|
||||
mode(m), fstream(),
|
||||
total_bytes(-1), v_file_exist(exist_file(file_name, file_path))
|
||||
{
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
// Destructor
|
||||
/***********************************************************/
|
||||
unixf_storage::~unixf_storage()
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "~unixf storeage ()");
|
||||
debug(cerr, my_path());
|
||||
debug(cerr, my_name());
|
||||
*/
|
||||
if ( policy )
|
||||
policy -> remove(*this);
|
||||
|
||||
#ifdef REPORT_IO_COUNT
|
||||
#endif
|
||||
}
|
||||
|
||||
void unixf_storage::remove()
|
||||
{
|
||||
int fd = rdbuf() -> fd();
|
||||
fsync(fd);
|
||||
::close(fd);
|
||||
del_file(my_name(), my_path());
|
||||
/*
|
||||
int md = mode;
|
||||
_open(ios::trunc);
|
||||
mode = md;
|
||||
_open(mode);
|
||||
*/
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
// Open the physical file associated with this store
|
||||
/***********************************************************/
|
||||
int unixf_storage::_open(int new_mode)
|
||||
{
|
||||
char *fmt = NULL;
|
||||
|
||||
if ( ! ( *this ) ) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "fstream is in bad status @ %s:%d\n",
|
||||
__FILE__, __LINE__);
|
||||
#endif
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
|
||||
rep_cell* replaced = 0;
|
||||
|
||||
if ( policy != 0 ) {
|
||||
|
||||
policy -> promote(*this, replaced);
|
||||
|
||||
if ( replaced ) {
|
||||
unixf_storage* us = ((unixf_storage*)replaced);
|
||||
us -> fstream::close();
|
||||
if ( us -> fstream::fail() ) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Can't close db file %s/%s @ %s:%d\n",
|
||||
us->my_path(), us->my_name(), __FILE__, __LINE__);
|
||||
#endif
|
||||
throw(streamException(us -> fstream::rdstate()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( v_file_exist == false ) {
|
||||
SET_BIT(new_mode, ios::out);
|
||||
v_file_exist = true;
|
||||
}
|
||||
|
||||
//MESSAGE(cerr, "_open");
|
||||
//debug(cerr, total_bytes);
|
||||
|
||||
if ( !BIT_TEST(mode, new_mode) ) {
|
||||
|
||||
if ( fstream::rdbuf() -> is_open() ) {
|
||||
fstream::close();
|
||||
|
||||
if ( fstream::fail() ) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Can't close db file %s/%s @ %s:%d\n",
|
||||
path, name, __FILE__, __LINE__);
|
||||
#endif
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
}
|
||||
|
||||
SET_BIT(mode, new_mode);
|
||||
|
||||
fmt = ::form("%s/%s", path, name);
|
||||
fstream::open((const char *) fmt, mode, open_file_prot());
|
||||
|
||||
} else {
|
||||
|
||||
if ( ! fstream::rdbuf() -> is_open() ) {
|
||||
fmt = ::form("%s/%s", path, name);
|
||||
fstream::open((const char *) fmt, mode, open_file_prot());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( (!(*this)) || !fstream::rdbuf() -> is_open() ) {
|
||||
MESSAGE(cerr, "_open failed");
|
||||
debug(cerr, new_mode);
|
||||
debug(cerr, mode);
|
||||
debug(cerr, my_path());
|
||||
debug(cerr, my_name());
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Can't close db file %s/%s @ %s:%d\n",
|
||||
path, name, __FILE__, __LINE__);
|
||||
#endif
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
// Read a string from the store. Use internal buffer.
|
||||
/***********************************************************/
|
||||
int
|
||||
unixf_storage::readString(mmdb_pos_t loc, char* base, int len, int str_off)
|
||||
{
|
||||
_open(ios::in);
|
||||
|
||||
int offset = int(loc) + str_off;
|
||||
|
||||
if ( seekg( offset, ios::beg ) == 0 ) {
|
||||
MESSAGE(cerr, "seekg failed");
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
|
||||
if ( read( base, len ) == 0 || len != fstream::gcount() ) {
|
||||
MESSAGE(cerr, "read() failed");
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
// Write a string to the store. Use external buffer.
|
||||
/***********************************************************/
|
||||
int unixf_storage::updateString(mmdb_pos_t loc, const char* base, int len, int string_ofst, Boolean flush_opt)
|
||||
{
|
||||
/*
|
||||
debug(cerr, len);
|
||||
debug(cerr, loc);
|
||||
debug(cerr, int(base));
|
||||
debug(cerr, string_ofst);
|
||||
debug(cerr, int(flush_opt));
|
||||
*/
|
||||
|
||||
/*
|
||||
fprintf(stderr, "updateString():");
|
||||
fprintf(stderr, "len=%d, ", len);
|
||||
fprintf(stderr, "loc=%d, ", loc);
|
||||
fprintf(stderr, "string_ofst=%d, ", string_ofst);
|
||||
fprintf(stderr, "flush option=%d\n", flush_opt);
|
||||
*/
|
||||
|
||||
_open(ios::out);
|
||||
|
||||
#ifdef C_API
|
||||
if ( ! seekg(loc+string_ofst, ios::beg) ) {
|
||||
MESSAGE(cerr, form("seek() failed on %s", my_name()));
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
#else
|
||||
if ( ! seekp(loc+string_ofst, ios::beg) ) {
|
||||
MESSAGE(cerr, form("seek() failed on %s", my_name()));
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( ! write( base, len ) ) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "write() failed on %s @ %s:%d\n",
|
||||
my_name(), __FILE__, __LINE__);
|
||||
#endif
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
|
||||
if ( flush_opt == true )
|
||||
flush();
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "%d bytes have been written at offset %d in %s/%s @ %s:%d\n", len, loc+string_ofst, path, name, __FILE__, __LINE__);
|
||||
#ifndef C_API
|
||||
{
|
||||
char fname[64];
|
||||
sprintf(fname, "%s.%d-%d", name, loc+string_ofst, len);
|
||||
ofstream output(fname);
|
||||
output.write(base, len);
|
||||
output.flush();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if ( !(*this) ) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "write() failed on %s @ %s:%d\n",
|
||||
my_name(), __FILE__, __LINE__);
|
||||
#endif
|
||||
throw(streamException(fstream::rdstate()));
|
||||
}
|
||||
|
||||
total_bytes = MAX(total_bytes, int(loc)+len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
// insert a string.
|
||||
/***********************************************************/
|
||||
int unixf_storage::appendString(mmdb_pos_t, const char* base, int len, Boolean flush_opt)
|
||||
{
|
||||
mmdb_pos_t loc = bytes();
|
||||
updateString(loc, base, len, 0, flush_opt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
// Return the number of bytes in the store.
|
||||
/***********************************************************/
|
||||
int unixf_storage::bytes()
|
||||
{
|
||||
if ( total_bytes == -1 ) {
|
||||
|
||||
_open(ios::in);
|
||||
|
||||
|
||||
if ( !good() )
|
||||
clear();
|
||||
|
||||
|
||||
total_bytes = ::bytes(rdbuf() -> fd());
|
||||
}
|
||||
|
||||
return total_bytes;
|
||||
}
|
||||
|
||||
Boolean unixf_storage::io_mode(int test_mode)
|
||||
{
|
||||
Boolean opened = false;
|
||||
|
||||
if ( fstream::rdbuf() -> is_open() ) {
|
||||
opened = true ;
|
||||
fstream::close();
|
||||
}
|
||||
|
||||
fstream::open(name, test_mode, open_file_prot());
|
||||
|
||||
if ( ! fstream::rdbuf() -> is_open() )
|
||||
return false;
|
||||
else {
|
||||
fstream::close();
|
||||
|
||||
if ( opened == true )
|
||||
fstream::open(name, mode, open_file_prot());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int unixf_storage::truncate(int target_length_in_bytes)
|
||||
{
|
||||
char *fmt = NULL;
|
||||
|
||||
_open(ios::out);
|
||||
|
||||
if ( total_bytes > target_length_in_bytes ) {
|
||||
fmt = ::form("%s/%s", path, name);
|
||||
if ( ::truncate((const char *) fmt, target_length_in_bytes) != 0 ) {
|
||||
throw(systemException(errno));
|
||||
}
|
||||
|
||||
total_bytes = target_length_in_bytes;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
90
cde/programs/dtinfo/DtMmdb/storage/unixf_storage.h
Normal file
90
cde/programs/dtinfo/DtMmdb/storage/unixf_storage.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* $XConsortium: unixf_storage.h /main/5 1996/07/18 14:56:35 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _unixf_storage_h
|
||||
#define _unixf_storage_h 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "utility/funcs.h"
|
||||
#include "storage/lru.h"
|
||||
#include "storage/abs_storage.h"
|
||||
|
||||
extern lru unixf_mgr;
|
||||
|
||||
//class unixf_storage : public rep_cell, public abs_storage, public fstream
|
||||
class unixf_storage : public abs_storage, public fstream
|
||||
{
|
||||
|
||||
protected:
|
||||
int mode;
|
||||
int total_bytes;
|
||||
int _open(int mode);
|
||||
Boolean v_file_exist;
|
||||
|
||||
public:
|
||||
// mode: see ios::in etc. stuff in file iostream.h
|
||||
unixf_storage( char* file_path,
|
||||
char* file_nm,
|
||||
rep_policy*,
|
||||
int md = ios::in | ios::out
|
||||
);
|
||||
virtual ~unixf_storage() ;
|
||||
|
||||
virtual void remove() ;
|
||||
|
||||
// IO functions
|
||||
int readString (mmdb_pos_t loc, char*, int len, int str_offset = 0);
|
||||
int appendString(mmdb_pos_t loc, const char*, int len, Boolean flush_opt = false);
|
||||
int updateString(mmdb_pos_t loc, const char* base, int len, int string_ofst = 0, Boolean flush = false);
|
||||
|
||||
|
||||
// non-applicable funcs
|
||||
int insertString(mmdb_pos_t& , const char* , int, Boolean = false)
|
||||
{ return -1; };
|
||||
int get_str_ptr(mmdb_pos_t, char*&, int& )
|
||||
{ return -1; };
|
||||
|
||||
int deleteString (mmdb_pos_t, Boolean = false )
|
||||
{ return -1; };
|
||||
int allocString (mmdb_pos_t& , int, char*&, int = 0)
|
||||
{ return -1; };
|
||||
virtual int truncate(int target_length_in_bytes);
|
||||
|
||||
Boolean io_mode(int mode) ;
|
||||
int bytes() ;
|
||||
|
||||
friend class storage_mgr_t;
|
||||
friend class ld_dyn_hash;
|
||||
friend class handler;
|
||||
};
|
||||
|
||||
typedef unixf_storage* unixf_storagePtr;
|
||||
|
||||
#endif
|
||||
80
cde/programs/dtinfo/DtMmdb/storage/version.C
Normal file
80
cde/programs/dtinfo/DtMmdb/storage/version.C
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* $XConsortium: version.C /main/4 1996/08/21 15:53:59 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "version.h"
|
||||
|
||||
mm_version::mm_version(char* str, Boolean swap_order)
|
||||
{
|
||||
short x ;
|
||||
short y ;
|
||||
|
||||
memcpy((char*)&x, str, sizeof(x));
|
||||
memcpy((char*)&y, str+major_bytes(), sizeof(y));
|
||||
|
||||
if ( swap_order == true ) {
|
||||
ORDER_SWAP_USHORT(x);
|
||||
ORDER_SWAP_USHORT(y);
|
||||
}
|
||||
|
||||
v_major = x;
|
||||
v_minor = y;
|
||||
}
|
||||
|
||||
Boolean mm_version::operator<(const mm_version& v2) const
|
||||
{
|
||||
if ( v_major < v2.v_major )
|
||||
return true;
|
||||
|
||||
if ( v_major == v2.v_major && v_minor < v2.v_minor )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean mm_version::operator==(const mm_version& v2) const
|
||||
{
|
||||
if ( v_major == v2.v_major && v_minor == v2.v_minor )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void mm_version::to_byte_string(char* str, Boolean swap_order)
|
||||
{
|
||||
short x = v_major;
|
||||
short y = v_minor;
|
||||
|
||||
if ( swap_order == true ) {
|
||||
ORDER_SWAP_USHORT(x);
|
||||
ORDER_SWAP_USHORT(y);
|
||||
}
|
||||
|
||||
memcpy(str, &x, sizeof(v_major));
|
||||
memcpy(str+major_bytes(), &y, sizeof(v_minor));
|
||||
|
||||
}
|
||||
66
cde/programs/dtinfo/DtMmdb/storage/version.h
Normal file
66
cde/programs/dtinfo/DtMmdb/storage/version.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* $XConsortium: version.h /main/5 1996/08/21 15:54:03 drk $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _mm_version_h
|
||||
#define _mm_version_h 1
|
||||
|
||||
#include "utility/funcs.h"
|
||||
|
||||
/*************************************/
|
||||
// The mm_version class
|
||||
/*************************************/
|
||||
|
||||
class mm_version
|
||||
{
|
||||
protected:
|
||||
short v_major;
|
||||
short v_minor;
|
||||
|
||||
public:
|
||||
mm_version(short ma =-1, short mi =-1) : v_major(ma), v_minor(mi) {};
|
||||
mm_version(char*, Boolean swap_order = false);
|
||||
virtual ~mm_version() {};
|
||||
|
||||
Boolean operator< (const mm_version&) const;
|
||||
Boolean operator== (const mm_version&) const;
|
||||
|
||||
static int version_bytes() { return major_bytes() + minor_bytes(); };
|
||||
static int major_bytes() { return sizeof(short); };
|
||||
static int minor_bytes() { return sizeof(short); };
|
||||
|
||||
void to_byte_string(char*, Boolean swap_order = false);
|
||||
|
||||
short major_version() { return v_major; };
|
||||
short minor_version() { return v_minor; };
|
||||
|
||||
};
|
||||
|
||||
typedef mm_version* mm_versionPtr;
|
||||
|
||||
#endif
|
||||
167
cde/programs/dtinfo/DtMmdb/storage/vm_storage.C
Normal file
167
cde/programs/dtinfo/DtMmdb/storage/vm_storage.C
Normal file
@@ -0,0 +1,167 @@
|
||||
/* $XConsortium: vm_storage.cc /main/4 1996/07/18 16:05:10 drk $ */
|
||||
|
||||
#include "storage/vm_storage.h"
|
||||
#include "utility/mmdb_exception.h"
|
||||
|
||||
vm_storage::vm_storage( char* _path, char* _name, rep_policy* rep_p):
|
||||
abs_storage( _path, _name, MEM_STORAGE_CODE, rep_p ), f_array(20)
|
||||
{
|
||||
}
|
||||
|
||||
vm_storage::~vm_storage()
|
||||
{
|
||||
remove();
|
||||
}
|
||||
|
||||
void vm_storage::remove()
|
||||
{
|
||||
for ( int i=0; i<f_array.no_elmts(); i++ ) {
|
||||
delete (buffer*)f_array[i];
|
||||
f_array.insert(0, i) ;
|
||||
}
|
||||
f_array.reset_elmts(0);
|
||||
}
|
||||
|
||||
int vm_storage::appendString(mmdb_pos_t loc, const char*, int len,
|
||||
Boolean flush_opt)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int vm_storage::readString(mmdb_pos_t loc, char* base, int len, int str_offset)
|
||||
{
|
||||
//MESSAGE(cerr, "vm: read");
|
||||
//debug(cerr, loc);
|
||||
//debug(cerr, len);
|
||||
//debug(cerr, str_offset);
|
||||
|
||||
char* x;
|
||||
int y;
|
||||
int ok = get_str_ptr(loc, x, y);
|
||||
|
||||
if ( ok == 0 && str_offset+len <= y ) {
|
||||
memcpy(base, x+str_offset, len);
|
||||
//MESSAGE(cerr, "========");
|
||||
return 0;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int vm_storage::insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush)
|
||||
{
|
||||
//MESSAGE(cerr, "vm: insert");
|
||||
//debug(cerr, len);
|
||||
|
||||
|
||||
char* x;
|
||||
int ok = allocString (loc, len, x, 0);
|
||||
//debug(cerr, loc);
|
||||
//MESSAGE(cerr, "========");
|
||||
|
||||
if ( ok == 0 ) {
|
||||
return updateString(loc, base, len, 0);
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int vm_storage::get_str_ptr(mmdb_pos_t loc, char*& x, int& len)
|
||||
{
|
||||
//MESSAGE(cerr, "vm: get_str_ptr");
|
||||
//debug(cerr, loc);
|
||||
|
||||
if ( loc >= f_array.no_elmts() ) {
|
||||
debug(cerr, loc);
|
||||
debug(cerr, f_array.no_elmts());
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer* b = (buffer*)f_array[(int)loc];
|
||||
|
||||
if ( b == 0 ) {
|
||||
MESSAGE(cerr, "null pointer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
x = b -> get_base();
|
||||
len = b -> buf_sz();
|
||||
//debug(cerr, (void*)x);
|
||||
//debug(cerr, len);
|
||||
//MESSAGE(cerr, "========");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vm_storage::updateString(mmdb_pos_t loc, const char* base, int len,
|
||||
int string_ofst, Boolean flush)
|
||||
{
|
||||
//MESSAGE(cerr, "updateString");
|
||||
//debug(cerr, loc);
|
||||
//debug(cerr, len);
|
||||
|
||||
if ( loc >= f_array.no_elmts() ) {
|
||||
debug(cerr, loc);
|
||||
debug(cerr, f_array.no_elmts());
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer* b = (buffer*)f_array[(int)loc];
|
||||
|
||||
if ( b == 0 ) {
|
||||
MESSAGE(cerr, "null pointer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if ( b -> buf_sz() < len + string_ofst )
|
||||
b -> expand_chunk(len + string_ofst);
|
||||
|
||||
/*
|
||||
for (int i=0; i<len; i++)
|
||||
if ( isascii(base[i]) )
|
||||
cerr << base[i];
|
||||
else
|
||||
cerr << int(base[i]);
|
||||
cerr << "\n";
|
||||
MESSAGE(cerr, "========");
|
||||
*/
|
||||
|
||||
char* x = b -> get_base();
|
||||
memcpy(x+string_ofst, base, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vm_storage::deleteString (mmdb_pos_t loc, Boolean flush)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vm_storage::allocString (mmdb_pos_t& loc, int len, char*& x, int mode)
|
||||
{
|
||||
//MESSAGE(cerr, "vm: allocate");
|
||||
//debug(cerr, len);
|
||||
|
||||
int c = f_array.no_elmts();
|
||||
|
||||
if ( c >= f_array.count() ) {
|
||||
f_array.expandWith(10);
|
||||
}
|
||||
|
||||
buffer* b = new buffer(len==0 ? 1 : len);
|
||||
f_array.insert(b, c) ;
|
||||
|
||||
f_array.reset_elmts(c+1);
|
||||
|
||||
x = b -> get_base();
|
||||
loc = c;
|
||||
//debug(cerr, (void*)x);
|
||||
//debug(cerr, loc);
|
||||
//MESSAGE(cerr, "========");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Boolean vm_storage::io_mode(int mode)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
42
cde/programs/dtinfo/DtMmdb/storage/vm_storage.h
Normal file
42
cde/programs/dtinfo/DtMmdb/storage/vm_storage.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* $XConsortium: vm_storage.h /main/4 1996/07/18 16:35:41 drk $ */
|
||||
|
||||
#ifndef _vm_storage_h
|
||||
#define _vm_storage_h 1
|
||||
|
||||
#include "dstr/void_ptr_array.h"
|
||||
#include "storage/abs_storage.h"
|
||||
|
||||
class vm_storage : public abs_storage
|
||||
{
|
||||
protected:
|
||||
void_ptr_array f_array;
|
||||
|
||||
public:
|
||||
vm_storage(char* path, char* name, rep_policy* rep_p = 0);
|
||||
~vm_storage() ;
|
||||
|
||||
void remove();
|
||||
|
||||
// i/o functions
|
||||
int readString (mmdb_pos_t loc, char* base, int len,
|
||||
int str_offset = 0) ;
|
||||
int insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush = false) ;
|
||||
int get_str_ptr(mmdb_pos_t loc, char*&, int& len);
|
||||
|
||||
int updateString(mmdb_pos_t loc, const char* base, int len,
|
||||
int string_ofst = 0, Boolean flush = false) ;
|
||||
int deleteString (mmdb_pos_t loc, Boolean flush = false) ;
|
||||
int allocString (mmdb_pos_t& loc, int len, char*&, int mode = 0);
|
||||
|
||||
int appendString(mmdb_pos_t loc, const char*, int len,
|
||||
Boolean flush_opt = false) ;
|
||||
|
||||
// status functions
|
||||
Boolean io_mode(int mode) ;
|
||||
|
||||
friend class storage_mgr_t;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user