8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 20:03:03 +01:00
firebird-mirror/src/jrd/GarbageCollector.h

111 lines
2.8 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 Vlad Khorsun
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2011 Vlad Khorsun <hvlad@users.sourceforge.net>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#ifndef JRD_GARBAGE_COLLECTOR_H
#define JRD_GARBAGE_COLLECTOR_H
#include "firebird.h"
#include "../common/classes/array.h"
#include "../common/classes/GenericMap.h"
#include "../common/classes/SyncObject.h"
#include "../jrd/sbm.h"
namespace Jrd {
class Database;
class Savepoint;
class GarbageCollector
{
public:
GarbageCollector(MemoryPool& p, Database* dbb)
: m_pool(p), m_database(dbb), m_relations(m_pool), m_nextRelID(0)
{}
~GarbageCollector();
void addPage(const USHORT relID, const ULONG pageno, const SLONG tranid);
2011-05-27 18:18:39 +02:00
bool getPageBitmap(const SLONG oldest_snapshot, USHORT &relID, PageBitmap** sbm);
void removeRelation(const USHORT relID);
void sweptRelation(const SLONG oldest_snapshot, const USHORT relID);
SLONG minTranID(const USHORT relID);
private:
typedef Firebird::Pair<Firebird::NonPooled<SLONG, PageBitmap*> > TranBitMap;
typedef Firebird::GenericMap<TranBitMap> TranData;
class RelationData
{
public:
explicit RelationData(MemoryPool& p, USHORT relID)
: m_pool(p), m_tranData(p), m_relID(relID)
{}
2011-05-27 18:18:39 +02:00
~RelationData()
{
clear();
}
void addPage(const ULONG pageno, const SLONG tranid);
2011-05-27 18:18:39 +02:00
void getPageBitmap(const SLONG oldest_snapshot, PageBitmap** sbm);
void swept(const SLONG oldest_snapshot);
SLONG minTranID() const;
USHORT getRelID() const
{
return m_relID;
}
2011-05-27 18:18:39 +02:00
static inline const USHORT generate(void const*, const RelationData* item)
{
2011-05-27 18:18:39 +02:00
return item->m_relID;
}
void clear();
Firebird::MemoryPool& m_pool;
Firebird::SyncObject m_sync;
TranData m_tranData;
USHORT m_relID;
};
typedef Firebird::SortedArray<
RelationData*,
Firebird::EmptyStorage<RelationData*>,
2011-05-27 11:48:24 +02:00
USHORT,
RelationData> RelGarbageArray;
2011-05-27 18:18:39 +02:00
RelationData* getRelData(Firebird::Sync& sync, const USHORT relID, bool allowCreate);
Firebird::MemoryPool& m_pool;
Firebird::SyncObject m_sync;
Database* m_database;
RelGarbageArray m_relations;
USHORT m_nextRelID;
};
} // namespace Jrd
2011-05-27 18:04:56 +02:00
#endif // JRD_GARBAGE_COLLECTOR_H