8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-28 03:23:03 +01:00
firebird-mirror/src/jrd/DatabaseSnapshot.h

158 lines
3.7 KiB
C
Raw Normal View History

/*
* The contents of this file are subject to the Initial
* Developer's 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.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* 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 Dmitry Yemanov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2006 Dmitry Yemanov <dimitr@users.sf.net>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
2006-07-17 21:26:43 +02:00
#ifndef JRD_DATABASE_SNAPSHOT_H
#define JRD_DATABASE_SNAPSHOT_H
#include "../common/classes/array.h"
#include "../common/classes/init.h"
#include "../common/classes/ClumpletReader.h"
#include "../common/classes/ClumpletWriter.h"
namespace Jrd {
// forward declarations
class jrd_rel;
class RecordBuffer;
class RuntimeStatistics;
2008-04-19 11:42:01 +02:00
class DatabaseSnapshot
{
struct RelationData
{
int rel_id;
RecordBuffer* data;
};
struct Element
{
SLONG processId;
SLONG localId;
ULONG length;
};
public:
class SharedData
2008-04-19 11:42:01 +02:00
{
static const ULONG MONITOR_VERSION = 2;
static const ULONG DEFAULT_SIZE = 1048576;
2008-04-19 11:42:01 +02:00
struct Header
{
ULONG version;
ULONG used;
ULONG allocated;
2008-02-04 20:19:05 +01:00
#ifndef WIN_NT
struct mtx mutex;
2008-02-04 20:19:05 +01:00
#endif
};
class DumpGuard
{
public:
explicit DumpGuard(SharedData* ptr)
: data(ptr)
{
data->acquire();
}
~DumpGuard()
{
data->release();
}
private:
DumpGuard(const DumpGuard&);
DumpGuard& operator=(const DumpGuard&);
SharedData* const data;
};
public:
explicit SharedData(const Database*);
~SharedData();
void acquire();
void release();
UCHAR* read(MemoryPool&, ULONG&);
void write(ULONG, const UCHAR*);
private:
// copying is prohibited
SharedData(const SharedData&);
SharedData& operator =(const SharedData&);
void cleanup();
2008-02-06 14:47:08 +01:00
void extend();
static void checkMutex(const TEXT*, int);
static void init(void*, SH_MEM_T*, bool);
SH_MEM_T handle;
2008-02-04 20:19:05 +01:00
#ifdef WIN_NT
struct mtx mutex;
2008-02-04 20:19:05 +01:00
#endif
Header* base;
const SLONG process_id;
const SLONG local_id;
2007-07-16 17:26:04 +02:00
};
~DatabaseSnapshot();
RecordBuffer* getData(const jrd_rel*) const;
static DatabaseSnapshot* create(thread_db*);
static int blockingAst(void*);
protected:
DatabaseSnapshot(thread_db*, MemoryPool&);
private:
RecordBuffer* allocBuffer(thread_db*, MemoryPool&, int);
2006-07-17 21:26:43 +02:00
void clearRecord(Record*);
void putField(Record*, int, const Firebird::ClumpletReader&, bool);
2006-07-17 21:26:43 +02:00
static void dumpData(thread_db*);
static const char* checkNull(int, int, const char*, size_t);
static SINT64 getGlobalId(int);
static void putDatabase(const Database*, Firebird::ClumpletWriter&, int);
static void putAttachment(const Attachment*, Firebird::ClumpletWriter&, int);
static void putTransaction(const jrd_tra*, Firebird::ClumpletWriter&, int);
static void putRequest(const jrd_req*, Firebird::ClumpletWriter&, int);
static void putCall(const jrd_req*, Firebird::ClumpletWriter&, int);
2008-02-20 14:13:22 +01:00
static void putStatistics(const RuntimeStatistics&, Firebird::ClumpletWriter&, int, int);
static void putContextVars(Firebird::StringMap&, Firebird::ClumpletWriter&, int, bool);
static void putMemoryUsage(const Firebird::MemoryStats&, Firebird::ClumpletWriter&, int, int);
Firebird::Array<RelationData> snapshot;
Firebird::GenericMap<Firebird::Pair<Firebird::NonPooled<SINT64, SLONG> > > idMap;
int idCounter;
};
} // namespace
2006-07-17 21:26:43 +02:00
#endif // JRD_DATABASE_SNAPSHOT_H