8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-27 17:23:03 +01:00
firebird-mirror/src/jrd/all.cpp

302 lines
7.7 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD Access Method
2003-12-22 11:00:59 +01:00
* MODULE: all.cpp
2001-05-23 15:26:42 +02:00
* DESCRIPTION: Internal block allocator
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
2001-05-23 15:26:42 +02:00
#include <string.h>
2004-03-22 12:38:23 +01:00
#include "../jrd/common.h"
2004-04-29 00:43:34 +02:00
#include <stdio.h>
2001-05-23 15:26:42 +02:00
#include "gen/iberror.h"
2003-09-15 18:32:22 +02:00
#include "../jrd/jrd.h"
#include "../jrd/all.h"
#include "../jrd/tra.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/all_proto.h"
#include "../jrd/err_proto.h"
2003-01-20 12:10:30 +01:00
#include <algorithm>
using namespace Jrd;
2004-04-29 16:51:02 +02:00
const int PERM_EXTEND_SIZE = 16 * 1024;
const int CACH_EXTEND_SIZE = 16 * 1024;
2001-05-23 15:26:42 +02:00
#ifdef DEV_BUILD
2001-12-24 03:51:06 +01:00
void ALL_check_memory()
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* A L L _ c h e c k _ m e m o r y
*
**************************************
*
* Functional description
* This routine goes through all allocated
* memory pools and checks the hunks of
* memory allocated to make sure they are
* valid. It is designed to be used for
* debugging purposes to find bad memory
* areas as soon as they are corrupted.
* A call to this routine can be made from
* looper() to ensure that it will be regularly
* executed.
*
**************************************/
Database* dbb = GET_DBB();
2001-05-23 15:26:42 +02:00
#ifdef V4_THREADING
2001-12-24 03:51:06 +01:00
V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_read);
#endif
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
// walk through all the pools in the database
2003-12-22 11:00:59 +01:00
Firebird::vector<JrdMemoryPool*>::iterator itr;
2004-03-07 08:58:55 +01:00
for (itr = dbb->dbb_pools.begin(); itr < dbb->dbb_pools.end(); ++itr)
2001-12-24 03:51:06 +01:00
{
JrdMemoryPool* pool = *itr;
if (pool) {
// walk through all the hunks in the pool
pool->verify_pool();
}
2001-05-23 15:26:42 +02:00
}
#ifdef V4_THREADING
2001-05-23 15:26:42 +02:00
V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools);
#endif
2001-05-23 15:26:42 +02:00
}
#endif /* DEV_BUILD */
JrdMemoryPool *JrdMemoryPool::createDbPool(Firebird::MemoryStats &stats) {
JrdMemoryPool* result = (JrdMemoryPool *)internal_create(
sizeof(JrdMemoryPool), NULL, stats);
result->plb_buckets = NULL;
result->plb_segments = NULL;
result->plb_dccs = NULL;
return result;
}
JrdMemoryPool *JrdMemoryPool::createPool() {
Database* dbb = GET_DBB();
fb_assert(dbb);
2003-01-20 12:10:30 +01:00
#ifdef SUPERSERVER
2003-12-22 11:00:59 +01:00
JrdMemoryPool* result = (JrdMemoryPool *)internal_create(sizeof(JrdMemoryPool),
dbb->dbb_permanent, dbb->dbb_memory_stats);
#else
JrdMemoryPool *result = (JrdMemoryPool *)internal_create(sizeof(JrdMemoryPool), dbb->dbb_permanent);
#endif
result->plb_buckets = NULL;
result->plb_segments = NULL;
result->plb_dccs = NULL;
dbb->dbb_pools.push_back(result);
return result;
}
2003-01-20 12:10:30 +01:00
void JrdMemoryPool::deletePool(JrdMemoryPool* pool) {
Database* dbb = GET_DBB();
2004-03-07 08:58:55 +01:00
Database::pool_vec_type::iterator itr =
2003-01-20 12:10:30 +01:00
std::find(dbb->dbb_pools.begin(), dbb->dbb_pools.end(), pool);
if (itr != dbb->dbb_pools.end()) dbb->dbb_pools.erase(itr);
2003-01-20 12:10:30 +01:00
MemoryPool::deletePool(pool);
}
void JrdMemoryPool::noDbbDeletePool(JrdMemoryPool* pool) {
MemoryPool::deletePool(pool);
}
TEXT* ALL_cstring(JrdMemoryPool* pool, const Firebird::string& in_string)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* A L L _ c s t r i n g
*
**************************************
*
* Functional description
* Copy a stack local string to an allocated
* string so it doesn't disappear before we
* return to the user or where ever.
*
**************************************/
TEXT* p = FB_NEW(*pool) TEXT[in_string.length() + 1];
2004-03-31 19:37:26 +02:00
strcpy(p, in_string.c_str());
return p;
2001-05-23 15:26:42 +02:00
}
void ALL_fini(void)
{
/**************************************
*
* A L L _ f i n i
*
**************************************
*
* Functional description
* Get rid of everything.
* NOTE: This routine does not lock any mutexes on
* its own behalf. It is assumed that mutexes will
* have been locked before entry.
* Call gds__free explicitly instead of ALL_free
2004-03-07 08:58:55 +01:00
* because it references the Database block which gets
2001-05-23 15:26:42 +02:00
* released at the top of this routine.
*
**************************************/
Database* dbb = GET_DBB();
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
/* Don't know if we even need to do this, so it is commented out */
//delete dbb;
2001-05-23 15:26:42 +02:00
}
void ALL_init(void)
{
/**************************************
*
* A L L _ i n i t
*
**************************************
*
* Functional description
* Initialize the pool system.
* NOTE: This routine does not lock any mutexes on
* its own behalf. It is assumed that mutexes will
* have been locked before entry.
*
**************************************/
thread_db* tdbb = JRD_get_thread_data();
2004-03-07 08:58:55 +01:00
Database* dbb = tdbb->tdbb_database;
2001-05-23 15:26:42 +02:00
2003-12-22 11:00:59 +01:00
JrdMemoryPool* pool = tdbb->tdbb_default = dbb->dbb_permanent;
2003-01-20 12:10:30 +01:00
// dbb->dbb_permanent->setExtendSize(PERM_EXTEND_SIZE);
2001-12-24 03:51:06 +01:00
dbb->dbb_pools[0] = pool;
dbb->dbb_bufferpool = JrdMemoryPool::createPool();
2003-01-20 12:10:30 +01:00
// FB_NEW(*pool) JrdMemoryPool(CACH_EXTEND_SIZE);
2001-05-23 15:26:42 +02:00
}
#ifdef SUPERSERVER
2004-04-29 00:43:34 +02:00
void ALL_print_memory_pool_info(FILE* fptr, Database* databases)
2001-05-23 15:26:42 +02:00
{
#ifdef NOT_USED_OR_REPLACED
2001-05-23 15:26:42 +02:00
/***********************************************************
*
* A L L _ p r i n t _ m e m o r y _ p o o l _ i n f o
*
***********************************************************
*
* Functional description
* Print the different block types allocated in the pool.
2004-03-07 08:58:55 +01:00
* Walk the Database's to print out pool info of every database
2001-05-23 15:26:42 +02:00
*
**************************************/
2004-03-07 08:58:55 +01:00
Database* dbb;
2001-05-23 15:26:42 +02:00
STR string;
VEC vector;
HNK hnk;
Attachment* att;
2001-05-23 15:26:42 +02:00
int i, j, k, col;
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\n\tALL_xx block types\n");
fprintf(fptr, "\t------------------");
2001-12-24 03:51:06 +01:00
for (i = 0, col = 0; i < types->type_MAX; i++) {
if (types->all_block_type_count[i]) {
2001-05-23 15:26:42 +02:00
if (col % 5 == 0)
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\n\t");
fprintf(fptr, "%s = %d ", types->ALL_types[i],
2001-12-24 03:51:06 +01:00
types->all_block_type_count[i]);
2001-05-23 15:26:42 +02:00
++col;
}
2001-12-24 03:51:06 +01:00
}
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\n");
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
// TMN: Note. Evil code.
2001-05-23 15:26:42 +02:00
for (i = 0, dbb = databases; dbb; dbb = dbb->dbb_next, ++i);
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\tNo of dbbs = %d\n", i);
2001-12-24 03:51:06 +01:00
for (k = 1, dbb = databases; dbb; dbb = dbb->dbb_next, ++k)
{
2001-05-23 15:26:42 +02:00
string = dbb->dbb_filename;
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\n\t dbb%d -> %s\n", k, string->str_data);
2001-05-23 15:26:42 +02:00
vector = (VEC) dbb->dbb_pools;
2001-12-24 03:51:06 +01:00
j = 0;
for (pool_vec_type::iterator itr = dbb->dbb_pools.begin();
itr != dbb->dbb_pools.end(); ++itr)
{
PLB myPool = *itr;
if (myPool) {
2001-05-23 15:26:42 +02:00
++j;
2001-12-24 03:51:06 +01:00
}
2001-05-23 15:26:42 +02:00
}
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\t %s has %d pools", string->str_data, j);
2001-05-23 15:26:42 +02:00
for (j = 0, att = dbb->dbb_attachments; att; att = att->att_next)
2001-12-24 03:51:06 +01:00
{
2001-05-23 15:26:42 +02:00
j++;
2001-12-24 03:51:06 +01:00
}
2004-04-29 00:43:34 +02:00
fprintf(fptr, " and %d attachment(s)", j);
2001-12-24 03:51:06 +01:00
for (i = 0; i < (int) vector->vec_count; i++)
{
PLB myPool = (PLB) vector->vec_object[i];
if (!myPool) {
2001-05-23 15:26:42 +02:00
continue;
2001-12-24 03:51:06 +01:00
}
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\n\t Pool %d", myPool->plb_pool_id);
2001-12-24 03:51:06 +01:00
// Count # of hunks
for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next) {
++j;
}
if (j) {
2004-04-29 00:43:34 +02:00
fprintf(fptr, " has %d hunks", j);
2001-12-24 03:51:06 +01:00
}
j = 0;
// Count # of "huge" hunks
for (hnk = myPool->plb_huge_hunks; hnk; hnk = hnk->hnk_next)
{
++j;
}
if (j) {
2004-04-29 00:43:34 +02:00
fprintf(fptr, " and %d huge_hunks", j);
2001-12-24 03:51:06 +01:00
}
2004-04-29 00:43:34 +02:00
fprintf(fptr, " Extend size is %d", myPool->plb_extend_size);
2001-12-24 03:51:06 +01:00
for (j = 0, col = 0; j < types->type_MAX; j++)
{
if (myPool->plb_blk_type_count[j])
{
2001-05-23 15:26:42 +02:00
if (col % 5 == 0)
2001-12-24 03:51:06 +01:00
{
2004-04-29 00:43:34 +02:00
fprintf(fptr, "\n\t ");
2001-12-24 03:51:06 +01:00
}
2004-04-29 00:43:34 +02:00
fprintf(fptr, "%s = %d ", types->ALL_types[j],
2001-05-23 15:26:42 +02:00
myPool->plb_blk_type_count[j]);
++col;
}
}
}
}
2001-12-24 03:51:06 +01:00
#endif // 0
2001-05-23 15:26:42 +02:00
}
2001-12-24 03:51:06 +01:00
#endif // SUPERSERVER
2001-05-23 15:26:42 +02:00