8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-25 00:43:03 +01:00
firebird-mirror/src/jrd/pag.h

260 lines
6.1 KiB
C
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD Access Method
* MODULE: pag.h
* DESCRIPTION: Page interface definitions
*
* 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): ______________________________________.
*/
/*
* Modified by: Patrick J. P. Griffin
* Date: 11/29/2000
* Problem: Bug 116733 Too many generators corrupt database.
* DPM_gen_id was not calculating page and offset correctly.
* Change: Add pgc_gpg, number of generators per page,
* for use in DPM_gen_id.
*/
#ifndef JRD_PAG_H
#define JRD_PAG_H
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
#include "../jrd/jrd_blks.h"
#include "../include/fb_blk.h"
2006-05-22 00:07:35 +02:00
#include "../common/classes/array.h"
2001-12-24 03:51:06 +01:00
namespace Jrd {
2001-05-23 15:26:42 +02:00
/* Page control block -- used by PAG to keep track of critical
constants */
2006-05-22 00:07:35 +02:00
/**
class PageControl : public pool_alloc<type_pgc>
2001-12-24 03:51:06 +01:00
{
public:
2006-05-22 00:07:35 +02:00
SLONG pgc_high_water; // Lowest PIP with space
SLONG pgc_ppp; // Pages per pip
SLONG pgc_pip; // First pointer page
ULONG pgc_bytes; // Number of bytes of bit in PIP
ULONG pgc_tpt; // Transactions per TIP
ULONG pgc_gpg; // Generators per generator page
};
**/
// page spaces below TEMP_PAGE_SPACE is regular database pages
// TEMP_PAGE_SPACE and page spaces above TEMP_PAGE_SPACE is temporary pages
const USHORT DB_PAGE_SPACE = 1;
const USHORT TEMP_PAGE_SPACE = 256;
class jrd_file;
class PageSpace : public pool_alloc<type_PageSpace>
{
public:
PageSpace(USHORT aPageSpaceID)
{
2006-05-24 05:03:52 +02:00
pageSpaceID = aPageSpaceID;
pipHighWater = 0;
ppFirst = 0;
file = 0;
maxPageNumber = 0;
2006-05-22 00:07:35 +02:00
}
~PageSpace();
USHORT pageSpaceID;
SLONG pipHighWater; // Lowest PIP with space
SLONG ppFirst; // First pointer page
jrd_file* file;
inline bool isTemporary() const {
return (pageSpaceID >= TEMP_PAGE_SPACE);
}
2006-05-24 13:38:16 +02:00
static inline SLONG generate(const void* , const PageSpace* Item) {
2006-05-24 05:03:52 +02:00
return Item->pageSpaceID;
}
// how many pages allocated
ULONG actAlloc(const USHORT pageSize);
2007-07-02 12:28:50 +02:00
static ULONG actAlloc(const Database* dbb);
// number of last allocated page
ULONG maxAlloc(const USHORT pageSize);
2007-07-02 12:28:50 +02:00
static ULONG maxAlloc(const Database* dbb);
// extend page space
bool extend(thread_db*, const ULONG);
private:
ULONG maxPageNumber;
2006-05-22 00:07:35 +02:00
};
class PageManager : public pool_alloc<type_PageManager>
{
public:
PageManager(Firebird::MemoryPool& aPool) :
2006-05-24 05:03:52 +02:00
pageSpaces(aPool),
pool(aPool)
2006-05-22 00:07:35 +02:00
{
2006-05-24 05:03:52 +02:00
pagesPerPIP = 0;
bytesBitPIP = 0;
transPerTIP = 0;
gensPerPage = 0;
dbPageSpace = addPageSpace(DB_PAGE_SPACE);
// addPageSpace(TEMP_PAGE_SPACE);
2006-05-22 00:07:35 +02:00
}
~PageManager()
{
2006-05-24 13:38:16 +02:00
for (int i = pageSpaces.getCount() - 1; i >= 0; --i)
2006-05-22 00:07:35 +02:00
{
2006-05-24 13:38:16 +02:00
PageSpace* pageSpace = pageSpaces[i];
pageSpaces.remove(i);
2006-05-22 00:07:35 +02:00
delete pageSpace;
}
}
PageSpace* addPageSpace(const USHORT pageSpaceID);
2007-07-02 12:28:50 +02:00
PageSpace* findPageSpace(const USHORT pageSpaceID) const;
2006-05-22 00:07:35 +02:00
void delPageSpace(const USHORT pageSpaceID);
USHORT getTempPageSpaceID(thread_db* tdbb);
void closeAll();
void releaseLocks();
2006-05-22 00:07:35 +02:00
SLONG pagesPerPIP; // Pages per pip
ULONG bytesBitPIP; // Number of bytes of bit in PIP
SLONG transPerTIP; // Transactions per TIP
2006-05-22 00:07:35 +02:00
ULONG gensPerPage; // Generators per generator page
PageSpace* dbPageSpace; // database page space
private:
typedef Firebird::SortedArray<
PageSpace*, Firebird::EmptyStorage<PageSpace*>,
USHORT, PageSpace> PageSpaceArray;
PageSpaceArray pageSpaces;
Firebird::MemoryPool& pool;
2001-12-24 03:51:06 +01:00
};
2001-05-23 15:26:42 +02:00
2006-05-22 00:07:35 +02:00
class PageNumber
{
public:
inline PageNumber(const USHORT aPageSpace, const SLONG aPageNum) {
pageSpaceID = aPageSpace;
pageNum = aPageNum;
}
2006-05-24 05:03:52 +02:00
/*
2006-05-22 00:07:35 +02:00
inline PageNumber(const SLONG aPageNum) {
pageSpaceID = DB_PAGE_SPACE;
pageNum = aPageNum;
}
2006-05-24 05:03:52 +02:00
*/
2006-05-22 00:07:35 +02:00
inline PageNumber(const PageNumber& from) {
pageSpaceID = from.pageSpaceID;
pageNum = from.pageNum;
}
inline SLONG getPageNum() const {
return pageNum;
};
inline SLONG getPageSpaceID() const {
return pageSpaceID;
}
inline SLONG setPageSpaceID(const USHORT aPageSpaceID) {
pageSpaceID = aPageSpaceID;
return pageSpaceID;
}
2007-02-22 15:12:04 +01:00
inline bool isTemporary() const {
return (pageSpaceID >= TEMP_PAGE_SPACE);
}
2006-05-22 00:07:35 +02:00
inline static SSHORT getLockLen() {
2007-09-07 09:41:07 +02:00
return sizeof(SLONG) + sizeof(ULONG);
2006-05-22 00:07:35 +02:00
}
inline void getLockStr(UCHAR* str) const {
2007-09-07 09:41:07 +02:00
memcpy(str, &pageNum, sizeof(SLONG));
str += sizeof(SLONG);
const ULONG val = pageSpaceID;
memcpy(str, &val, sizeof(ULONG));
2006-05-22 00:07:35 +02:00
}
inline PageNumber& operator=(const PageNumber& from) {
pageSpaceID = from.pageSpaceID;
pageNum = from.pageNum;
return *this;
}
inline SLONG operator=(const SLONG from) {
pageNum = from;
return pageNum;
}
inline bool operator==(const PageNumber& other) const {
return (pageNum == other.pageNum) &&
(pageSpaceID == other.pageSpaceID);
}
inline bool operator!=(const PageNumber& other) const {
return !(*this == other);
}
inline bool operator>(const PageNumber& other) const {
return (pageSpaceID > other.pageSpaceID) ||
(pageSpaceID == other.pageSpaceID) && (pageNum > other.pageNum);
}
inline bool operator>=(const PageNumber& other) const {
return (pageSpaceID > other.pageSpaceID) ||
(pageSpaceID == other.pageSpaceID) && (pageNum >= other.pageNum);
}
inline bool operator<(const PageNumber& other) const {
return !(*this >= other);
}
inline bool operator<=(const PageNumber& other) const {
return !(*this > other);
}
2006-05-24 05:03:52 +02:00
/*
2006-05-22 00:07:35 +02:00
inline operator SLONG() const {
return pageNum;
}
2006-05-24 05:03:52 +02:00
*/
2006-05-22 00:07:35 +02:00
private:
SLONG pageNum;
USHORT pageSpaceID;
};
const PageNumber ZERO_PAGE_NUMBER(0, 0);
const PageNumber HEADER_PAGE_NUMBER(DB_PAGE_SPACE, HEADER_PAGE);
const PageNumber LOG_PAGE_NUMBER(DB_PAGE_SPACE, LOG_PAGE);
} //namespace Jrd
#endif /* JRD_PAG_H */