- Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathDatabase.h
732 lines (608 loc) · 21.8 KB
/
Database.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/*
* PROGRAM: JRD access method
* MODULE: Database.h
* DESCRIPTION: Common descriptions
*
* 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): ______________________________________.
*
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
*
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
* Claudio Valderrama C.
*
*/
#ifndef JRD_DATABASE_H
#defineJRD_DATABASE_H
#include"firebird.h"
#include"../jrd/cch.h"
#include"../common/gdsassert.h"
#include"../common/dsc.h"
#include"../jrd/btn.h"
#include"../jrd/jrd_proto.h"
#include"../jrd/val.h"
#include"../jrd/irq.h"
#include"../jrd/drq.h"
#include"../jrd/lck.h"
#include"../include/iberror.h"
#include"../common/classes/fb_atomic.h"
#include"../common/classes/fb_string.h"
#include"../common/classes/auto.h"
#include"../jrd/MetaName.h"
#include"../common/classes/array.h"
#include"../common/classes/Hash.h"
#include"../common/classes/objects_array.h"
#include"../common/classes/stack.h"
#include"../common/classes/timestamp.h"
#include"../common/classes/GenericMap.h"
#include"../common/classes/RefCounted.h"
#include"../common/classes/semaphore.h"
#include"../common/classes/XThreadMutex.h"
#include"../common/utils_proto.h"
#include"../jrd/RandomGenerator.h"
#include"../common/os/guid.h"
#include"../common/os/os_utils.h"
#include"../jrd/ods.h"
#include"../jrd/sbm.h"
#include"../jrd/flu.h"
#include"../jrd/RuntimeStatistics.h"
#include"../jrd/event_proto.h"
#include"../jrd/ExtEngineManager.h"
#include"../jrd/Coercion.h"
#include"../lock/lock_proto.h"
#include"../common/config/config.h"
#include"../common/classes/SyncObject.h"
#include"../common/classes/Synchronize.h"
#include"../jrd/replication/Manager.h"
#include"../dsql/Keywords.h"
#include"fb_types.h"
#defineSPTHR_DEBUG(A)
namespaceJrd
{
template <typename T> classvec;
classjrd_rel;
classShadow;
classBlobFilter;
classTipCache;
classBackupManager;
classExternalFileDirectoryList;
classMonitoringData;
classGarbageCollector;
classCryptoManager;
classKeywordsMap;
// general purpose vector
template <classT, BlockType TYPE = type_vec>
classvec_base : protectedpool_alloc<TYPE>
{
public:
typedeftypename Firebird::Array<T>::iterator iterator;
typedeftypename Firebird::Array<T>::const_iterator const_iterator;
/*
static vec_base* newVector(MemoryPool& p, int len)
{
return FB_NEW_POOL(p) vec_base<T, TYPE>(p, len);
}
static vec_base* newVector(MemoryPool& p, const vec_base& base)
{
return FB_NEW_POOL(p) vec_base<T, TYPE>(p, base);
}
*/
FB_SIZE_T count() const { return v.getCount(); }
T& operator[](FB_SIZE_T index) { return v[index]; }
const T& operator[](FB_SIZE_T index) const { return v[index]; }
iterator begin() { return v.begin(); }
iterator end() { return v.end(); }
const_iterator begin() const { return v.begin(); }
const_iterator end() const { return v.end(); }
voidclear() { v.clear(); }
T* memPtr() { return &v[0]; }
voidresize(FB_SIZE_T n, T val = T()) { v.resize(n, val); }
voidoperatordelete(void* mem) { MemoryPool::globalFree(mem); }
protected:
vec_base(MemoryPool& p, int len)
: v(p, len)
{
v.resize(len);
}
vec_base(MemoryPool& p, const vec_base& base)
: v(p)
{
v = base.v;
}
private:
Firebird::Array<T> v;
};
template <typename T>
classvec : publicvec_base<T, type_vec>
{
public:
static vec* newVector(MemoryPool& p, int len)
{
returnFB_NEW_POOL(p) vec<T>(p, len);
}
static vec* newVector(MemoryPool& p, const vec& base)
{
returnFB_NEW_POOL(p) vec<T>(p, base);
}
static vec* newVector(MemoryPool& p, vec* base, int len)
{
if (!base)
base = FB_NEW_POOL(p) vec<T>(p, len);
elseif (len > (int) base->count())
base->resize(len);
return base;
}
private:
vec(MemoryPool& p, int len) : vec_base<T, type_vec>(p, len) {}
vec(MemoryPool& p, const vec& base) : vec_base<T, type_vec>(p, base) {}
};
classvcl : publicvec_base<ULONG, type_vcl>
{
public:
static vcl* newVector(MemoryPool& p, int len)
{
returnFB_NEW_POOL(p) vcl(p, len);
}
static vcl* newVector(MemoryPool& p, const vcl& base)
{
returnFB_NEW_POOL(p) vcl(p, base);
}
static vcl* newVector(MemoryPool& p, vcl* base, int len)
{
if (!base)
base = FB_NEW_POOL(p) vcl(p, len);
elseif (len > (int) base->count())
base->resize(len);
return base;
}
private:
vcl(MemoryPool& p, int len) : vec_base<ULONG, type_vcl>(p, len) {}
vcl(MemoryPool& p, const vcl& base) : vec_base<ULONG, type_vcl>(p, base) {}
};
typedef vec<TraNumber> TransactionsVector;
//
// bit values for dbb_flags
//
const ULONG DBB_damaged = 0x1L;
const ULONG DBB_exclusive = 0x2L; // Database is accessed in exclusive mode
const ULONG DBB_bugcheck = 0x4L; // Bugcheck has occurred
const ULONG DBB_garbage_collector = 0x8L; // garbage collector thread exists
const ULONG DBB_gc_active = 0x10L; // ... and is actively working.
const ULONG DBB_gc_pending = 0x20L; // garbage collection requested
const ULONG DBB_force_write = 0x40L; // Database is forced write
const ULONG DBB_no_reserve = 0x80L; // No reserve space for versions
const ULONG DBB_DB_SQL_dialect_3 = 0x100L; // database SQL dialect 3
const ULONG DBB_read_only = 0x200L; // DB is ReadOnly (RO). If not set, DB is RW
const ULONG DBB_being_opened_read_only = 0x400L; // DB is being opened RO. If unset, opened as RW
const ULONG DBB_no_ast = 0x800L; // AST delivery is prohibited
const ULONG DBB_sweep_in_progress = 0x1000L; // A database sweep operation is in progress
const ULONG DBB_gc_starting = 0x2000L; // garbage collector thread is starting
const ULONG DBB_suspend_bgio = 0x4000L; // Suspend I/O by background threads
const ULONG DBB_new = 0x8000L; // Database object is just created
const ULONG DBB_gc_cooperative = 0x10000L; // cooperative garbage collection
const ULONG DBB_gc_background = 0x20000L; // background garbage collection by gc_thread
const ULONG DBB_no_fs_cache = 0x40000L; // Not using file system cache
const ULONG DBB_sweep_starting = 0x80000L; // Auto-sweep is starting
const ULONG DBB_creating = 0x100000L; // Database creation is in progress
const ULONG DBB_shared = 0x200000L; // Database object is shared among connections
//const ULONG DBB_closing = 0x400000L; // Database closing, special backgroud threads should exit
//
// dbb_ast_flags
//
const ULONG DBB_blocking = 0x1L; // Exclusive mode is blocking
const ULONG DBB_get_shadows = 0x2L; // Signal received to check for new shadows
const ULONG DBB_assert_locks = 0x4L; // Locks are to be asserted
const ULONG DBB_shutdown = 0x8L; // Database is shutdown
const ULONG DBB_shut_attach = 0x10L; // no new attachments accepted
const ULONG DBB_shut_tran = 0x20L; // no new transactions accepted
const ULONG DBB_shut_force = 0x40L; // forced shutdown in progress
const ULONG DBB_shutdown_full = 0x80L; // Database fully shut down
const ULONG DBB_shutdown_single = 0x100L; // Database is in single-user maintenance mode
classDatabase : publicpool_alloc<type_dbb>
{
// This class is a reference-counted container for all "global"
// (shared among different dbb's) objects -- e.g. the lock manager.
// The contained objects are created on demand (upon the first reference).
// The container is destroyed by the last dbb going away and
// it automatically destroys all the objects it holds.
classGlobalObjectHolder : publicFirebird::RefCounted, public Firebird::GlobalStorage
{
structDbId;
typedef Firebird::HashTable<DbId, Firebird::DEFAULT_HASH_SIZE,
Firebird::string, DbId, DbId > DbIdHash;
structDbId : publicDbIdHash::Entry, public Firebird::GlobalStorage
{
DbId(const Firebird::string& x, GlobalObjectHolder* h)
: id(getPool(), x), holder(h)
{}
DbId* get()
{
returnthis;
}
boolisEqual(const Firebird::string& val) const
{
return val == id;
}
staticconst Firebird::string& generate(const DbId& item)
{
return item.id;
}
static FB_SIZE_T hash(const Firebird::string& value, FB_SIZE_T hashSize)
{
returnFirebird::InternalHash::hash(value.length(),
(const UCHAR*) value.c_str(),
hashSize);
}
const Firebird::string id;
GlobalObjectHolder* const holder;
};
static Firebird::GlobalPtr<DbIdHash> g_hashTable;
static Firebird::GlobalPtr<Firebird::Mutex> g_mutex;
public:
static GlobalObjectHolder* init(const Firebird::string& id,
const Firebird::PathName& filename,
Firebird::RefPtr<const Firebird::Config> config);
intrelease() constoverride;
~GlobalObjectHolder();
LockManager* getLockManager();
EventManager* getEventManager();
Replication::Manager* getReplManager(bool create);
const Replication::Config* getReplConfig()
{
return m_replConfig.get();
}
boolincTempCacheUsage(FB_SIZE_T size);
voiddecTempCacheUsage(FB_SIZE_T size);
private:
const Firebird::string m_id;
const Firebird::RefPtr<const Firebird::Config> m_config;
const Firebird::AutoPtr<const Replication::Config> m_replConfig;
Firebird::AutoPtr<LockManager> m_lockMgr;
Firebird::AutoPtr<EventManager> m_eventMgr;
Firebird::AutoPtr<Replication::Manager> m_replMgr;
Firebird::Mutex m_mutex;
std::atomic<FB_UINT64> m_tempCacheUsage; // total size of in-memory temp space chunks (see TempSpace class)
const FB_UINT64 m_tempCacheLimit;
explicitGlobalObjectHolder(const Firebird::string& id,
const Firebird::PathName& filename,
Firebird::RefPtr<const Firebird::Config> config)
: m_id(getPool(), id), m_config(config),
m_replConfig(Replication::Config::get(filename)),
m_tempCacheUsage(0),
m_tempCacheLimit(m_config->getTempCacheLimit())
{}
};
public:
classExistenceRefMutex : publicFirebird::RefCounted
{
public:
ExistenceRefMutex()
: exist(true)
{ }
~ExistenceRefMutex()
{ }
public:
voiddestroy()
{
exist = false;
}
booldoesExist() const
{
return exist;
}
voidenter()
{
mutex.enter("ExistenceRefMutex::enter()");
}
voidleave()
{
mutex.leave();
}
private:
Firebird::Mutex mutex;
bool exist;
};
classLingerfinal :
public Firebird::RefCntIface<Firebird::ITimerImpl<Linger, Firebird::CheckStatusWrapper> >
{
public:
explicitLinger(Database* a_dbb)
: dbb(a_dbb), active(false)
{ }
voidset(unsigned seconds);
voidreset();
voiddestroy();
// ITimer implementation
voidhandler();
private:
Database* dbb;
bool active;
};
static Database* create(Firebird::IPluginConfig* pConf, bool shared)
{
Firebird::MemoryStats temp_stats;
MemoryPool* const pool = MemoryPool::createPool(NULL, temp_stats);
Database* const dbb = FB_NEW_POOL(*pool) Database(pool, pConf, shared);
pool->setStatsGroup(dbb->dbb_memory_stats);
return dbb;
}
// The destroy() function MUST be used to delete a Database object.
// The function hides some tricky order of operations. Since the
// memory for the vectors in the Database is allocated out of the Database's
// permanent memory pool, the entire delete() operation needs
// to complete _before_ the permanent pool is deleted, or else
// risk an aborted engine.
staticvoiddestroy(Database* const toDelete)
{
if (!toDelete)
return;
MemoryPool* const perm = toDelete->dbb_permanent;
// Memory pool destruction below decrements memory statistics
// situated in database block we are about to deallocate right now
Firebird::MemoryStats temp_stats;
perm->setStatsGroup(temp_stats);
delete toDelete;
MemoryPool::deletePool(perm);
}
static ULONG getLockOwnerId()
{
returnfb_utils::genUniqueId();
}
MemoryPool* dbb_permanent;
Firebird::Guid dbb_guid; // database GUID
Firebird::SyncObject dbb_sync;
Firebird::SyncObject dbb_sys_attach; // synchronize operations with dbb_sys_attachments
Firebird::ICryptKeyCallback* dbb_callback; // Parent's crypt callback
Database* dbb_next; // Next database block in system
Attachment* dbb_attachments; // Active attachments
Attachment* dbb_sys_attachments; // System attachments
BufferControl* dbb_bcb; // Buffer control block
Lock* dbb_lock; // database lock
Lock* dbb_sweep_lock; // sweep lock
Firebird::SyncObject dbb_sh_counter_sync;
Firebird::SyncObject dbb_shadow_sync;
Shadow* dbb_shadow; // shadow control block
Lock* dbb_shadow_lock; // lock for synchronizing addition of shadows
Lock* dbb_retaining_lock; // lock for preserving commit retaining snapshot
PageManager dbb_page_manager;
BlobFilter* dbb_blob_filters; // known blob filters
MonitoringData* dbb_monitoring_data; // monitoring data
private:
Firebird::string dbb_file_id; // system-wide unique file ID
Firebird::RefPtr<GlobalObjectHolder> dbb_gblobj_holder;
Firebird::SyncObject dbb_modules_sync;
DatabaseModules dbb_modules; // external function/filter modules
// Vectors of known pages and their synchronization
Firebird::SyncObject dbb_pages_sync; // guard access to dbb_XXX_pages vectors
vcl* dbb_tip_pages; // known TIP pages
vcl* dbb_gen_pages; // known generator pages
public:
Firebird::AutoPtr<ExtEngineManager> dbb_extManager; // external engine manager
Firebird::SyncObject dbb_flush_count_mutex;
Firebird::RWLock dbb_ast_lock; // avoids delivering AST to going away database
Firebird::AtomicCounter dbb_ast_flags; // flags modified at AST level
Firebird::AtomicCounter dbb_flags;
USHORT dbb_ods_version; // major ODS version number
USHORT dbb_minor_version; // minor ODS version number
USHORT dbb_page_size; // page size
USHORT dbb_dp_per_pp; // data pages per pointer page
USHORT dbb_max_records; // max record per data page
USHORT dbb_max_idx; // max number of indexes on a root page
#ifdef SUPERSERVER_V2
USHORT dbb_prefetch_sequence; // sequence to pace frequency of prefetch requests
USHORT dbb_prefetch_pages; // prefetch pages per request
#endif
Firebird::PathName dbb_filename; // filename string
Firebird::PathName dbb_database_name; // database visible name (file name or alias)
#ifdef HAVE_ID_BY_NAME
Firebird::UCharBuffer dbb_id;
#endif
MetaName dbb_owner; // database owner
Firebird::SyncObject dbb_pools_sync;
Firebird::Array<MemoryPool*> dbb_pools; // pools
Firebird::SyncObject dbb_sortbuf_sync;
Firebird::Array<UCHAR*> dbb_sort_buffers; // sort buffers ready for reuse
TraNumber dbb_oldest_active; // Cached "oldest active" transaction
TraNumber dbb_oldest_transaction; // Cached "oldest interesting" transaction
TraNumber dbb_oldest_snapshot; // Cached "oldest snapshot" of all active transactions
TraNumber dbb_next_transaction; // Next transaction id used by NETWARE
AttNumber dbb_attachment_id; // Next attachment id for ReadOnly DB's
ULONG dbb_page_buffers; // Page buffers from header page
GarbageCollector* dbb_garbage_collector; // GarbageCollector class
Firebird::Semaphore dbb_gc_sem; // Event to wake up garbage collector
Firebird::Semaphore dbb_gc_init; // Event for initialization garbage collector
ThreadFinishSync<Database*> dbb_gc_fini; // Sync for finalization garbage collector
Firebird::MemoryStats dbb_memory_stats;
RuntimeStatistics dbb_stats;
mutable Firebird::Mutex dbb_stats_mutex;
TraNumber dbb_last_header_write; // Transaction id of last header page physical write
SLONG dbb_flush_cycle; // Current flush cycle
ULONG dbb_sweep_interval; // Transactions between sweep
const ULONG dbb_lock_owner_id; // ID for the lock manager
SLONG dbb_lock_owner_handle; // Handle for the lock manager
USHORT unflushed_writes; // unflushed writes
time_t last_flushed_write; // last flushed write time
TipCache* dbb_tip_cache; // cache of latest known state of all transactions in system
BackupManager* dbb_backup_manager; // physical backup manager
ISC_TIMESTAMP_TZ dbb_creation_date; // creation timestamp in GMT
ExternalFileDirectoryList* dbb_external_file_directory_list;
Firebird::RefPtr<const Firebird::Config> dbb_config;
CryptoManager* dbb_crypto_manager;
Firebird::RefPtr<ExistenceRefMutex> dbb_init_fini;
Firebird::XThreadMutex dbb_thread_mutex; // special threads start/stop mutex
Firebird::RefPtr<Linger> dbb_linger_timer;
unsigned dbb_linger_seconds;
time_t dbb_linger_end;
Firebird::RefPtr<Firebird::IPluginConfig> dbb_plugin_config;
TriState dbb_repl_state; // replication state
Lock* dbb_repl_lock; // replication state lock
Firebird::SyncObject dbb_repl_sync;
FB_UINT64 dbb_repl_sequence; // replication sequence
ReplicaMode dbb_replica_mode; // replica access mode
unsigned dbb_compatibility_index; // datatype backward compatibility level
Dictionary dbb_dic; // metanames dictionary
Firebird::InitInstance<Keywords, Keywords::Allocator, Firebird::TraditionalDelete> dbb_keywords;
// returns true if primary file is located on raw device
boolonRawDevice() const;
// returns an unique ID string for a database file
const Firebird::string& getUniqueFileId();
// returns the minimum IO block size
ULONG getIOBlockSize() const;
#ifdef DEV_BUILD
// returns true if main lock is in exclusive state
boollocked() const
{
return dbb_sync.ourExclusiveLock();
}
#endif
MemoryPool* createPool()
{
MemoryPool* const pool = MemoryPool::createPool(dbb_permanent, dbb_memory_stats);
Firebird::SyncLockGuard guard(&dbb_pools_sync, Firebird::SYNC_EXCLUSIVE, "Database::createPool");
dbb_pools.add(pool);
return pool;
}
voiddeletePool(MemoryPool* pool);
voidregisterModule(Module&);
boolisReplica() const
{
return (dbb_replica_mode != REPLICA_NONE);
}
boolisReplica(ReplicaMode mode) const
{
return (dbb_replica_mode == mode);
}
USHORT getEncodedOdsVersion() const
{
returnENCODE_ODS(dbb_ods_version, dbb_minor_version);
}
// Methods encapsulating operations with vectors of known pages
ULONG getKnownPagesCount(SCHAR ptype);
ULONG getKnownPage(SCHAR ptype, ULONG sequence);
voidsetKnownPage(SCHAR ptype, ULONG sequence, ULONG value);
voidcopyKnownPages(SCHAR ptype, ULONG count, ULONG* data);
private:
Database(MemoryPool* p, Firebird::IPluginConfig* pConf, bool shared)
: dbb_permanent(p),
dbb_page_manager(this, *p),
dbb_file_id(*p),
dbb_modules(*p),
dbb_extManager(nullptr),
dbb_flags(shared ? DBB_shared : 0),
dbb_filename(*p),
dbb_database_name(*p),
#ifdef HAVE_ID_BY_NAME
dbb_id(*p),
#endif
dbb_owner(*p),
dbb_pools(*p, 4),
dbb_sort_buffers(*p),
dbb_gc_fini(*p, garbage_collector, THREAD_medium),
dbb_stats(*p),
dbb_lock_owner_id(getLockOwnerId()),
dbb_tip_cache(NULL),
dbb_creation_date(Firebird::TimeZoneUtil::getCurrentGmtTimeStamp()),
dbb_external_file_directory_list(NULL),
dbb_init_fini(FB_NEW_POOL(*getDefaultMemoryPool()) ExistenceRefMutex()),
dbb_linger_seconds(0),
dbb_linger_end(0),
dbb_plugin_config(pConf),
dbb_repl_sequence(0),
dbb_replica_mode(REPLICA_NONE),
dbb_compatibility_index(~0U),
dbb_dic(*p)
{
dbb_pools.add(p);
}
~Database();
public:
AttNumber generateAttachmentId();
TraNumber generateTransactionId();
StmtNumber generateStatementId();
// void assignLatestTransactionId(TraNumber number);
voidassignLatestAttachmentId(AttNumber number);
AttNumber getLatestAttachmentId() const;
StmtNumber getLatestStatementId() const;
ULONG getMonitorGeneration() const;
ULONG newMonitorGeneration() const;
USHORT getMaxIndexKeyLength() const
{
return dbb_page_size / 4;
}
boolreadOnly() const
{
return (dbb_flags & DBB_read_only) != 0;
}
// returns true if sweeper thread could start
boolallowSweepThread(thread_db* tdbb);
// returns true if sweep could run
boolallowSweepRun(thread_db* tdbb);
// reset sweep flag and release sweep lock
voidclearSweepFlags(thread_db* tdbb);
// reset sweep starting flag, release thread starting mutex
boolclearSweepStarting();
staticvoidgarbage_collector(Database* dbb);
voidexceptionHandler(const Firebird::Exception& ex, ThreadFinishSync<Database*>::ThreadRoutine* routine);
voidensureGuid(thread_db* tdbb);
FB_UINT64 getReplSequence(thread_db* tdbb);
voidsetReplSequence(thread_db* tdbb, FB_UINT64 sequence);
boolisReplicating(thread_db* tdbb);
voidinvalidateReplState(thread_db* tdbb, bool broadcast);
staticintreplStateAst(void*);
const CoercionArray *getBindings() const;
voidstartTipCache(thread_db* tdbb);
voidinitGlobalObjects();
voidshutdownGlobalObjects();
LockManager* lockManager()
{
return dbb_gblobj_holder->getLockManager();
}
EventManager* eventManager()
{
return dbb_gblobj_holder->getEventManager();
}
Replication::Manager* replManager(bool create = false)
{
return dbb_gblobj_holder->getReplManager(create);
}
const Replication::Config* replConfig()
{
return dbb_gblobj_holder->getReplConfig();
}
boolincTempCacheUsage(FB_SIZE_T size)
{
return dbb_gblobj_holder->incTempCacheUsage(size);
}
voiddecTempCacheUsage(FB_SIZE_T size)
{
dbb_gblobj_holder->decTempCacheUsage(size);
}
private:
//static int blockingAstSharedCounter(void*);
staticintblocking_ast_sweep(void* ast_object);
Lock* createSweepLock(thread_db* tdbb);
// The delete operators are no-oped because the Database memory is allocated from the
// Database's own permanent pool. That pool has already been released by the Database
// destructor, so the memory has already been released. Hence the operator
// delete no-op.
voidoperatordelete(void*) {}
voidoperatordelete[](void*) {}
Database(const Database&); // no impl.
const Database& operator =(const Database&) { return *this; }
};
} // namespace Jrd
#endif // JRD_DATABASE_H