Skip to content

Commit 1ab5457

Browse files
committed
Successfully created security.fdb
1 parent a25c5c5 commit 1ab5457

File tree

11 files changed

+189
-101
lines changed

11 files changed

+189
-101
lines changed

src/common/classes/alloc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,8 @@ MemPool::~MemPool(void)
21832183
}
21842184

21852185
#ifdef MEM_DEBUG
2186+
fb_assert(!child);
2187+
21862188
if (parent)
21872189
{
21882190
MutexLockGuard unlinkGuard(parent->mutex, FB_FUNCTION);

src/jrd/HazardPtr.h

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,14 @@ namespace Jrd {
471471
template <class Object, unsigned SUBARRAY_SHIFT = 8>
472472
class HazardArray : public Firebird::PermanentStorage
473473
{
474-
private:
474+
public:
475475
static const unsigned SUBARRAY_SIZE = 1 << SUBARRAY_SHIFT;
476476
static const unsigned SUBARRAY_MASK = SUBARRAY_SIZE - 1;
477477

478478
typedef std::atomic<Object*> SubArrayElement;
479479
typedef std::atomic<SubArrayElement*> ArrayElement;
480+
typedef SharedReadVector<ArrayElement, 4> Storage;
480481

481-
public:
482482
explicit HazardArray(MemoryPool& pool)
483483
: Firebird::PermanentStorage(pool),
484484
m_objects(getPool())
@@ -533,6 +533,11 @@ namespace Jrd {
533533
return m_objects.readAccessor(par)->getCount() << SUBARRAY_SHIFT;
534534
}
535535

536+
static FB_SIZE_T getCount(const HazardPtr<typename Storage::Generation>& v)
537+
{
538+
return v->getCount() << SUBARRAY_SHIFT;
539+
}
540+
536541
void grow(thread_db* tdbb, FB_SIZE_T reqSize)
537542
{
538543
fb_assert(reqSize > 0);
@@ -594,9 +599,9 @@ namespace Jrd {
594599
template <class DDS>
595600
bool load(DDS* par, FB_SIZE_T id, HazardPtr<Object>& val) const
596601
{
597-
if (id < getCount(par))
602+
auto a = m_objects.readAccessor(par);
603+
if (id < getCount(a))
598604
{
599-
auto a = m_objects.readAccessor(par);
600605
SubArrayElement* sub = a->value(id >> SUBARRAY_SHIFT).load(std::memory_order_acquire);
601606
if (sub)
602607
{
@@ -613,11 +618,20 @@ namespace Jrd {
613618
HazardPtr<Object> load(DDS* par, FB_SIZE_T id) const
614619
{
615620
HazardPtr<Object> val;
616-
load(par, id, val);
621+
if (!load(par, id, val))
622+
val.clear();
617623
return val;
618624
}
619625

620-
class iterator
626+
template <class DDS>
627+
HazardPtr<typename Storage::Generation> readAccessor(DDS* par) const
628+
{
629+
return m_objects.readAccessor(par);
630+
}
631+
632+
class Snapshot;
633+
634+
class Iterator
621635
{
622636
public:
623637
HazardPtr<Object> operator*()
@@ -630,27 +644,21 @@ namespace Jrd {
630644
return get();
631645
}
632646

633-
iterator& operator++()
634-
{
635-
++index;
636-
return *this;
637-
}
638-
639-
iterator& operator--()
647+
Iterator& operator++()
640648
{
641-
--index;
649+
index = snap->locateData(index + 1);
642650
return *this;
643651
}
644652

645-
bool operator==(const iterator& itr) const
653+
bool operator==(const Iterator& itr) const
646654
{
647-
fb_assert(array == itr.array);
655+
fb_assert(snap == itr.snap);
648656
return index == itr.index;
649657
}
650658

651-
bool operator!=(const iterator& itr) const
659+
bool operator!=(const Iterator& itr) const
652660
{
653-
fb_assert(array == itr.array);
661+
fb_assert(snap == itr.snap);
654662
return index != itr.index;
655663
}
656664

@@ -660,33 +668,90 @@ namespace Jrd {
660668

661669
public:
662670
enum class Location {Begin, End};
663-
iterator(const HazardArray* a, Location loc = Location::Begin)
664-
: array(a),
671+
Iterator(const Snapshot* s, Location loc)
672+
: snap(s),
665673
hd(HazardPtr<Object>::getHazardDelayed()),
666-
index(loc == Location::Begin ? 0 : array->getCount(hd))
674+
index(loc == Location::Begin ? snap->locateData(0) :
675+
snap->data->getCount() << SUBARRAY_SHIFT)
667676
{ }
668677

669678
HazardPtr<Object> get()
670679
{
671680
HazardPtr<Object> rc(hd);
672-
array->load(hd, index, rc);
681+
if (!snap->load(index, rc))
682+
rc.clear();
673683
return rc;
674684
}
675685

676686
private:
677-
const HazardArray* array;
687+
const Snapshot* snap;
678688
HazardDelayedDelete* hd;
679689
FB_SIZE_T index;
680690
};
681691

682-
iterator begin() const
692+
class Snapshot
683693
{
684-
return iterator(this);
685-
}
694+
private:
695+
void* operator new(size_t);
696+
void* operator new[](size_t);
697+
698+
public:
699+
Snapshot(const HazardArray* array)
700+
: hd(HazardPtr<Object>::getHazardDelayed()),
701+
data(array->readAccessor(hd))
702+
{ }
703+
704+
Iterator begin() const
705+
{
706+
return Iterator(this, Iterator::Location::Begin);
707+
}
708+
709+
Iterator end() const
710+
{
711+
return Iterator(this, Iterator::Location::End);
712+
}
713+
714+
FB_SIZE_T locateData(FB_SIZE_T index) const
715+
{
716+
for (FB_SIZE_T i = index >> SUBARRAY_SHIFT; i < data->getCount(); ++i, index = 0)
717+
{
718+
SubArrayElement* const sub = data->value(i).load(std::memory_order_acquire);
719+
if (!sub)
720+
continue;
721+
722+
for (FB_SIZE_T j = index & SUBARRAY_MASK; j < SUBARRAY_SIZE; ++j)
723+
{
724+
auto p = sub[j].load(std::memory_order_acquire);
725+
if (p && p->hasData())
726+
return (i << SUBARRAY_SHIFT) + j;
727+
}
728+
}
729+
return data->getCount() << SUBARRAY_SHIFT;
730+
}
731+
732+
bool load(FB_SIZE_T id, HazardPtr<Object>& val) const
733+
{
734+
if (id < (data->getCount() << SUBARRAY_SHIFT))
735+
{
736+
SubArrayElement* sub = data->value(id >> SUBARRAY_SHIFT).load(std::memory_order_acquire);
737+
if (sub)
738+
{
739+
val.set(sub[id & SUBARRAY_MASK]);
740+
if (val && val->hasData())
741+
return true;
742+
}
743+
}
744+
745+
return false;
746+
}
747+
748+
HazardDelayedDelete* hd;
749+
HazardPtr<typename Storage::Generation> data;
750+
};
686751

687-
iterator end() const
752+
Snapshot snapshot() const
688753
{
689-
return iterator(this, iterator::Location::End);
754+
return Snapshot(this);
690755
}
691756

692757
private:

src/jrd/Relation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Trigger : public HazardObject
6868

6969
bool hasData() const
7070
{
71-
return name.hasData();
71+
return name.hasData() || sysTrigger;
7272
}
7373

7474
Key getKey() const
@@ -480,8 +480,8 @@ class jrd_rel : public CacheObject
480480

481481
void fillPagesSnapshot(RelPagesSnapshot&, const bool AttachmentOnly = false);
482482

483-
bool checkObject(thread_db* tdbb, Firebird::Arg::StatusVector&);
484-
void afterUnlock(thread_db* tdbb);
483+
bool checkObject(thread_db* tdbb, Firebird::Arg::StatusVector&) override;
484+
void afterUnlock(thread_db* tdbb) override;
485485

486486
private:
487487
typedef Firebird::SortedArray<

src/jrd/Statement.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ Statement* Statement::makeStatement(thread_db* tdbb, CompilerScratch* csb, bool
154154
Database* const dbb = tdbb->getDatabase();
155155
fb_assert(dbb);
156156

157+
MemoryPool* defPool = tdbb->getDefaultPool();
158+
for (FB_SIZE_T i = 1; i < dbb->dbb_pools.getCount(); ++i)
159+
{
160+
if (dbb->dbb_pools[i] == defPool)
161+
goto found;
162+
}
163+
fb_assert(!"wrong pool in makeStatement");
164+
found:
165+
157166
Request* const old_request = tdbb->getRequest();
158167
tdbb->setRequest(NULL);
159168

@@ -349,11 +358,11 @@ Request* Statement::getRequest(thread_db* tdbb, USHORT level)
349358

350359
requests.grow(level + 1);
351360

352-
MemoryStats* const parentStats = (flags & FLAG_INTERNAL) ?
353-
&dbb->dbb_memory_stats : &attachment->att_memory_stats;
361+
// MemoryStats* const parentStats = (flags & FLAG_INTERNAL) ?
362+
// &dbb->dbb_memory_stats : &attachment->att_memory_stats;
354363

355364
// Create the request.
356-
Request* const request = FB_NEW_POOL(*pool) Request(attachment, this, parentStats);
365+
Request* const request = FB_NEW_POOL(*pool) Request(attachment, this, &dbb->dbb_memory_stats);
357366

358367
if (level == 0)
359368
pool->setStatsGroup(request->req_memory_stats);
@@ -559,17 +568,25 @@ void Statement::release(thread_db* tdbb)
559568

560569
const auto attachment = tdbb->getAttachment();
561570

562-
FB_SIZE_T pos;
563-
if (attachment->att_statements.find(this, pos))
564-
attachment->att_statements.remove(pos);
565-
else
566-
fb_assert(false);
571+
if (attachment)
572+
{
573+
// !!!!!!!!!!!!!!!! need to walk all attachments in database
574+
// or change att_statements to dbb_statements
575+
FB_SIZE_T pos;
576+
if (attachment->att_statements.find(this, pos))
577+
attachment->att_statements.remove(pos);
578+
else
579+
fb_assert(false);
580+
}
567581

568582
sqlText = NULL;
569583

570584
// Sub statement pool is the same of the main statement, so don't delete it.
571585
if (!parentStatement)
572-
attachment->deletePool(pool);
586+
{
587+
Database* dbb = tdbb->getDatabase();
588+
dbb->deletePool(pool);
589+
}
573590
}
574591

575592
// Returns a formatted textual plan for all RseNode's in the specified request

src/jrd/cmp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ Statement* CMP_compile(thread_db* tdbb, const UCHAR* blr, ULONG blrLength, bool
149149
Statement* statement = nullptr;
150150

151151
SET_TDBB(tdbb);
152-
const auto att = tdbb->getAttachment();
152+
const auto dbb = tdbb->getDatabase();
153153

154154
// 26.09.2002 Nickolay Samofatov: default memory pool will become statement pool
155155
// and will be freed by CMP_release
156-
const auto newPool = att->createPool();
156+
const auto newPool = dbb->createPool();
157157

158158
try
159159
{
@@ -193,7 +193,7 @@ Statement* CMP_compile(thread_db* tdbb, const UCHAR* blr, ULONG blrLength, bool
193193
if (statement)
194194
statement->release(tdbb);
195195
else
196-
att->deletePool(newPool);
196+
dbb->deletePool(newPool);
197197
ERR_punt();
198198
}
199199

src/jrd/exe.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
566566
TrigVectorPtr triggersPtr = &triggers;
567567
unsigned n = 0;
568568

569-
for (auto t : **cachedTriggers)
569+
for (auto t : cachedTriggers->load()->snapshot())
570570
{
571571
if ((t->type & (1LL << action)) &&
572572
((preTriggers && (t->type & 0x1) == 0) || (!preTriggers && (t->type & 0x1) == 0x1)))
@@ -1155,7 +1155,7 @@ void EXE_execute_triggers(thread_db* tdbb,
11551155

11561156
try
11571157
{
1158-
for (TrigVector::iterator ptr = vector.load()->begin(); ptr != vector.load()->end(); ++ptr)
1158+
for (auto ptr : vector.load()->snapshot())
11591159
{
11601160
ptr->compile(tdbb);
11611161

@@ -1929,8 +1929,8 @@ void ResourceList::releaseResources(thread_db* tdbb, jrd_tra* transaction)
19291929
if (transaction)
19301930
EXT_tra_detach(r.rsc_rel->rel_file, transaction);
19311931
}
1932+
r.rsc_state = Resource::State::Locked;
19321933
}
1933-
r.rsc_state = Resource::State::Locked;
19341934

19351935
if (r.rsc_state == Resource::State::Posted ||
19361936
r.rsc_state == Resource::State::Registered ||

src/jrd/intl.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,23 +359,21 @@ HazardPtr<Collation> CharSetContainer::lookupCollation(thread_db* tdbb, USHORT t
359359
}
360360
}
361361

362-
Collation* coll = Collation::createInstance(*dbb->dbb_permanent, tt_id, tt, info.attributes, charset);
363-
coll->name = info.collationName;
362+
Collation* collation = Collation::createInstance(*dbb->dbb_permanent, tt_id, tt, info.attributes, charset);
363+
collation->name = info.collationName;
364364

365365
// we don't need a lock in the charset
366366
if (id != 0)
367367
{
368-
coll->existenceLock = CharSetContainer::createCollationLock(tdbb, tt_id, coll);
368+
collation->existenceLock = CharSetContainer::createCollationLock(tdbb, tt_id, collation);
369369

370-
fb_assert(coll->useCount == 0);
371-
fb_assert(!coll->obsolete);
370+
fb_assert(collation->useCount == 0);
371+
fb_assert(!collation->obsolete);
372372
}
373373

374-
charset_collations.store(tdbb, id, coll);
375-
376374
if (id != 0)
377375
{
378-
LCK_lock(tdbb, coll->existenceLock, LCK_SR, LCK_WAIT);
376+
LCK_lock(tdbb, collation->existenceLock, LCK_SR, LCK_WAIT);
379377

380378
// as we just obtained SR lock for new collation instance
381379
// we could safely delete obsolete instance
@@ -385,6 +383,8 @@ HazardPtr<Collation> CharSetContainer::lookupCollation(thread_db* tdbb, USHORT t
385383
//
386384
// We did not delete "to_delete" when id == 0. Why??????????????????
387385
//
386+
387+
coll = charset_collations.store(tdbb, id, collation);
388388
}
389389
else
390390
{
@@ -447,7 +447,7 @@ static INTL_BOOL lookup_texttype(texttype* tt, const SubtypeInfo* info)
447447

448448
void Jrd::MetadataCache::releaseIntlObjects(thread_db* tdbb)
449449
{
450-
for (auto cs : mdc_charsets)
450+
for (auto cs : mdc_charsets.snapshot())
451451
{
452452
if (cs)
453453
cs->release(tdbb);

0 commit comments

Comments
 (0)