Skip to content

Commit f9bed00

Browse files
TreeHunter9Artyom Ivanov
andauthored
Do not allow run concurrent sweep instances (#8320)
* Do not allow run concurrent sweep instances * Silently ignore error about concurrent sweep instance when we try to run auto sweep * Add more error messages that describe a reason of failed sweep startup * Pass ISC_STATUS instead of Arg::Gds to function --------- Co-authored-by: Artyom Ivanov <[email protected]>
1 parent f640f76 commit f9bed00

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

src/include/firebird/impl/msg/jrd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,3 +987,7 @@ FB_IMPL_MSG(JRD, 984, incompatible_format_patterns, -901, "HY", "000", "@1 incom
987987
FB_IMPL_MSG(JRD, 985, only_one_pattern_can_be_used, -901, "HY", "000", "Can use only one of these patterns @1")
988988
FB_IMPL_MSG(JRD, 986, can_not_use_same_pattern_twice, -901, "HY", "000", "Cannot use the same pattern twice: @1")
989989
FB_IMPL_MSG(JRD, 987, sysf_invalid_gen_uuid_version, -833, "42", "000", "Invalid GEN_UUID version (@1). Must be 4 or 7")
990+
FB_IMPL_MSG(JRD, 988, sweep_unable_to_run, -901, "42", "000", "Unable to run sweep")
991+
FB_IMPL_MSG(JRD, 989, sweep_concurrent_instance, -901, "42", "000", "Another instance of sweep is already running")
992+
FB_IMPL_MSG(JRD, 990, sweep_read_only, -901, "42", "000", "Database in read only state")
993+
FB_IMPL_MSG(JRD, 991, sweep_attach_no_cleanup, -901, "42", "000", "Attachment has no cleanup flag set")

src/include/gen/Firebird.pas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,6 +5777,10 @@ IProfilerStatsImpl = class(IProfilerStats)
57775777
isc_only_one_pattern_can_be_used = 335545305;
57785778
isc_can_not_use_same_pattern_twice = 335545306;
57795779
isc_sysf_invalid_gen_uuid_version = 335545307;
5780+
isc_sweep_unable_to_run = 335545308;
5781+
isc_sweep_concurrent_instance = 335545309;
5782+
isc_sweep_read_only = 335545310;
5783+
isc_sweep_attach_no_cleanup = 335545311;
57805784
isc_gfix_db_name = 335740929;
57815785
isc_gfix_invalid_sw = 335740930;
57825786
isc_gfix_incmp_sw = 335740932;

src/jrd/Database.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747

4848
using namespace Firebird;
4949

50+
namespace
51+
{
52+
void unableToRunSweepException(ISC_STATUS reason)
53+
{
54+
ERR_post(Arg::Gds(isc_sweep_unable_to_run) << Arg::Gds(reason));
55+
}
56+
}
57+
5058
namespace Jrd
5159
{
5260
bool Database::onRawDevice() const
@@ -299,35 +307,35 @@ namespace Jrd
299307
}
300308
}
301309

302-
bool Database::allowSweepRun(thread_db* tdbb)
310+
void Database::initiateSweepRun(thread_db* tdbb)
303311
{
304-
SPTHR_DEBUG(fprintf(stderr, "allowSweepRun %p\n", this));
312+
SPTHR_DEBUG(fprintf(stderr, FB_FUNCTION " %p\n", this));
305313

306314
if (readOnly())
307-
return false;
315+
unableToRunSweepException(isc_sweep_read_only);
308316

309317
Jrd::Attachment* const attachment = tdbb->getAttachment();
310318
if (attachment->att_flags & ATT_no_cleanup)
311-
return false;
319+
unableToRunSweepException(isc_sweep_attach_no_cleanup);
312320

313321
while (true)
314322
{
315323
AtomicCounter::counter_type old = dbb_flags;
316324
if (old & DBB_sweep_in_progress)
317325
{
318326
clearSweepStarting();
319-
return false;
327+
unableToRunSweepException(isc_sweep_concurrent_instance);
320328
}
321329

322330
if (dbb_flags.compareExchange(old, old | DBB_sweep_in_progress))
323331
break;
324332
}
325333

326-
SPTHR_DEBUG(fprintf(stderr, "allowSweepRun - set DBB_sweep_in_progress\n"));
334+
SPTHR_DEBUG(fprintf(stderr, FB_FUNCTION " - set DBB_sweep_in_progress\n"));
327335

328336
if (!(dbb_flags & DBB_sweep_starting))
329337
{
330-
SPTHR_DEBUG(fprintf(stderr, "allowSweepRun - createSweepLock\n"));
338+
SPTHR_DEBUG(fprintf(stderr, FB_FUNCTION " - createSweepLock\n"));
331339

332340
createSweepLock(tdbb);
333341
if (!LCK_lock(tdbb, dbb_sweep_lock, LCK_EX, -1))
@@ -336,17 +344,15 @@ namespace Jrd
336344
fb_utils::init_status(tdbb->tdbb_status_vector);
337345

338346
dbb_flags &= ~DBB_sweep_in_progress;
339-
return false;
347+
unableToRunSweepException(isc_sweep_concurrent_instance);
340348
}
341349
}
342350
else
343351
{
344-
SPTHR_DEBUG(fprintf(stderr, "allowSweepRun - clearSweepStarting\n"));
352+
SPTHR_DEBUG(fprintf(stderr, FB_FUNCTION " - clearSweepStarting\n"));
345353
attachment->att_flags |= ATT_from_thread;
346354
clearSweepStarting();
347355
}
348-
349-
return true;
350356
}
351357

352358
void Database::clearSweepFlags(thread_db* tdbb)

src/jrd/Database.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ class Database : public pool_alloc<type_dbb>
657657

658658
// returns true if sweeper thread could start
659659
bool allowSweepThread(thread_db* tdbb);
660-
// returns true if sweep could run
661-
bool allowSweepRun(thread_db* tdbb);
660+
// Throw an exception if sweep cannot be run
661+
void initiateSweepRun(thread_db* tdbb);
662662
// reset sweep flag and release sweep lock
663663
void clearSweepFlags(thread_db* tdbb);
664664
// reset sweep starting flag, release thread starting mutex

src/jrd/tra.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,11 +1846,7 @@ void TRA_sweep(thread_db* tdbb)
18461846
Database* const dbb = tdbb->getDatabase();
18471847
CHECK_DBB(dbb);
18481848

1849-
if (!dbb->allowSweepRun(tdbb))
1850-
{
1851-
dbb->clearSweepFlags(tdbb);
1852-
return;
1853-
}
1849+
dbb->initiateSweepRun(tdbb);
18541850

18551851
fb_assert(dbb->dbb_flags & DBB_sweep_in_progress);
18561852

@@ -2756,6 +2752,9 @@ namespace {
27562752
status.check();
27572753

27582754
AutoRelease<IAttachment> att(prov->attachDatabase(&status, dbName.c_str(), dpbLen, dpbBytes));
2755+
if (fb_utils::containsErrorCode(status->getErrors(), isc_sweep_unable_to_run))
2756+
return;
2757+
27592758
status.check();
27602759
}
27612760

0 commit comments

Comments
 (0)