Skip to content

Commit a0e23c3

Browse files
committed
Back-ported pull request #8549
Implement #6413 : Data pages of newly gbak restored databases should marked as "swept" [CORE6164]
1 parent 449449c commit a0e23c3

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

src/burp/BurpTasks.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,6 @@ void RestoreRelationTask::initItem(BurpGlobals* tdgbl, Item& item)
902902
m_masterGbl->gbl_dpb_data.begin(),
903903
m_masterGbl->gbl_dpb_data.getCount());
904904

905-
dpb.deleteWithTag(isc_dpb_gbak_attach);
906-
907905
const UCHAR* dpbBuffer = dpb.getBuffer();
908906
const USHORT dpbLength = dpb.getBufferLength();
909907

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,3 +973,5 @@ FB_IMPL_MSG(JRD, 988, sweep_unable_to_run, -901, "42", "000", "Unable to run swe
973973
FB_IMPL_MSG(JRD, 989, sweep_concurrent_instance, -901, "42", "000", "Another instance of sweep is already running")
974974
FB_IMPL_MSG(JRD, 990, sweep_read_only, -901, "42", "000", "Database in read only state")
975975
FB_IMPL_MSG(JRD, 991, sweep_attach_no_cleanup, -901, "42", "000", "Attachment has no cleanup flag set")
976+
// Codes 992..997 are used in v6
977+
FB_IMPL_MSG(JRD, 998, no_user_att_while_restore, -901, "HY", "000", "User attachments are not allowed for the database being restored")

src/include/gen/Firebird.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5759,6 +5759,7 @@ IProfilerStatsImpl = class(IProfilerStats)
57595759
isc_sweep_concurrent_instance = 335545309;
57605760
isc_sweep_read_only = 335545310;
57615761
isc_sweep_attach_no_cleanup = 335545311;
5762+
isc_no_user_att_while_restore = 335545318;
57625763
isc_gfix_db_name = 335740929;
57635764
isc_gfix_invalid_sw = 335740930;
57645765
isc_gfix_incmp_sw = 335740932;

src/jrd/Database.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ const ULONG DBB_sweep_starting = 0x80000L; // Auto-sweep is starting
231231
const ULONG DBB_creating = 0x100000L; // Database creation is in progress
232232
const ULONG DBB_shared = 0x200000L; // Database object is shared among connections
233233
//const ULONG DBB_closing = 0x400000L; // Database closing, special backgroud threads should exit
234+
const ULONG DBB_restoring = 0x800000L; // Database restore is in progress
234235

235236
//
236237
// dbb_ast_flags
@@ -711,6 +712,19 @@ class Database : public pool_alloc<type_dbb>
711712
dbb_gblobj_holder->decTempCacheUsage(size);
712713
}
713714

715+
bool isRestoring() const
716+
{
717+
return dbb_flags & DBB_restoring;
718+
}
719+
720+
void setRestoring(bool value)
721+
{
722+
if (value)
723+
dbb_flags |= DBB_restoring;
724+
else
725+
dbb_flags &= ~DBB_restoring;
726+
}
727+
714728
private:
715729
//static int blockingAstSharedCounter(void*);
716730
static int blocking_ast_sweep(void* ast_object);

src/jrd/dpm.epp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ namespace
100100

101101
return lock.release();
102102
}
103+
104+
inline bool swept_at_restore(thread_db* tdbb, const jrd_rel* relation)
105+
{
106+
return tdbb->getDatabase()->isRestoring() && !relation->isSystem();
107+
}
103108
}
104109

105110

@@ -2232,7 +2237,14 @@ void DPM_store( thread_db* tdbb, record_param* rpb, PageStack& stack, const Jrd:
22322237
memset(data + size, 0, fill);
22332238

22342239
Ods::pag* page = rpb->getWindow(tdbb).win_buffer;
2235-
if (page->pag_flags & dpg_swept)
2240+
2241+
// When restoring, mark primary data page as swept, pointer page already marked by locate_space()
2242+
if (swept_at_restore(tdbb, rpb->rpb_relation) && (type == DPM_primary))
2243+
{
2244+
page->pag_flags |= dpg_swept;
2245+
CCH_RELEASE(tdbb, &rpb->getWindow(tdbb));
2246+
}
2247+
else if (page->pag_flags & dpg_swept)
22362248
{
22372249
page->pag_flags &= ~dpg_swept;
22382250
mark_full(tdbb, rpb);
@@ -3083,7 +3095,13 @@ static void extend_relation(thread_db* tdbb, jrd_rel* relation, WIN* window, con
30833095
UCHAR* bits = (UCHAR*) (ppage->ppg_page + dbb->dbb_dp_per_pp);
30843096
PPG_DP_BIT_CLEAR(bits, slot, PPG_DP_ALL_BITS);
30853097

3086-
if (type != DPM_primary)
3098+
if (type == DPM_primary)
3099+
{
3100+
// When restoring, mark slot as swept, data page will be marked by our caller
3101+
if (swept_at_restore(tdbb, relation))
3102+
PPG_DP_BIT_SET(bits, slot, ppg_dp_swept);
3103+
}
3104+
else
30873105
PPG_DP_BIT_SET(bits, slot, ppg_dp_secondary);
30883106

30893107
for (unsigned i = 1; i < cntAlloc; i++)
@@ -3536,7 +3554,13 @@ static rhd* locate_space(thread_db* tdbb,
35363554

35373555
PPG_DP_BIT_CLEAR(bits, slot, ppg_dp_empty);
35383556
if (type == DPM_primary)
3557+
{
35393558
PPG_DP_BIT_CLEAR(bits, slot, ppg_dp_secondary);
3559+
3560+
// When restoring, mark slot as swept, data page will be marked by our caller
3561+
if (swept_at_restore(tdbb, relation))
3562+
PPG_DP_BIT_SET(bits, slot, ppg_dp_swept);
3563+
}
35403564
else
35413565
PPG_DP_BIT_SET(bits, slot, ppg_dp_secondary);
35423566

@@ -3918,11 +3942,28 @@ static void store_big_record(thread_db* tdbb,
39183942
header->rhdf_b_page, header->rhdf_b_line);
39193943
#endif
39203944

3945+
3946+
bool markPP = false;
3947+
3948+
// When restoring, mark primary data page as swept, pointer page already marked by locate_space()
3949+
if (swept_at_restore(tdbb, rpb->rpb_relation) && (type == DPM_primary))
3950+
{
3951+
page->dpg_header.pag_flags |= dpg_swept;
3952+
}
3953+
else if (page->dpg_header.pag_flags & dpg_swept)
3954+
{
3955+
page->dpg_header.pag_flags &= ~dpg_swept;
3956+
markPP = true;
3957+
}
3958+
39213959
if (!(page->dpg_header.pag_flags & dpg_large))
39223960
{
39233961
page->dpg_header.pag_flags |= dpg_large;
3924-
mark_full(tdbb, rpb);
3962+
markPP = true;
39253963
}
3964+
3965+
if (markPP)
3966+
mark_full(tdbb, rpb);
39263967
else
39273968
CCH_RELEASE(tdbb, &rpb->getWindow(tdbb));
39283969
}

src/jrd/jrd.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,12 @@ JAttachment* JProvider::internalAttach(CheckStatusWrapper* user_status, const ch
18851885
dbb->dbb_crypto_manager->attach(tdbb, attachment);
18861886
}
18871887

1888+
if (dbb->isRestoring())
1889+
{
1890+
if (!options.dpb_gbak_attach && !options.dpb_map_attach && !options.dpb_worker_attach)
1891+
ERR_post(Arg::Gds(isc_no_user_att_while_restore));
1892+
}
1893+
18881894
// Basic DBB initialization complete
18891895
initGuard.leave();
18901896

@@ -3052,6 +3058,8 @@ JAttachment* JProvider::createDatabase(CheckStatusWrapper* user_status, const ch
30523058

30533059
// Initialize the global objects
30543060
dbb->initGlobalObjects();
3061+
if (attachment->isGbak())
3062+
dbb->setRestoring(true);
30553063

30563064
// Initialize locks
30573065
LCK_init(tdbb, LCK_OWNER_database);
@@ -7840,6 +7848,9 @@ void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment, XThreadEns
78407848
if (!other)
78417849
sync.lock(SYNC_EXCLUSIVE);
78427850

7851+
if (attachment->att_flags & ATT_creator)
7852+
dbb->setRestoring(false);
7853+
78437854
// remove the attachment block from the dbb linked list
78447855
for (Jrd::Attachment** ptr = &dbb->dbb_attachments; *ptr; ptr = &(*ptr)->att_next)
78457856
{

src/jrd/shut.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ union shutdown_data
5252
SLONG data_long;
5353
};
5454

55+
// Low byte of shutdown_data::flag used by shutdown modes, see isc_dpb_shut_XXX
56+
// High byte used for additional flags
57+
58+
const SSHORT SHUT_flag_restoring = 0x0100; // database restore is in progress
5559

5660
// Define this to true if you need to allow no-op behavior when requested shutdown mode
5761
// matches current. Logic of jrd8_create_database may need attention in this case too
@@ -127,6 +131,9 @@ bool SHUT_blocking_ast(thread_db* tdbb, bool ast)
127131
return false;
128132
}
129133

134+
if (flag & SHUT_flag_restoring)
135+
dbb->setRestoring(true);
136+
130137
if ((flag & isc_dpb_shut_force) && !delay)
131138
return shutdown(tdbb, flag, ast);
132139

@@ -478,6 +485,9 @@ static bool notify_shutdown(thread_db* tdbb, SSHORT flag, SSHORT delay, Sync* gu
478485
data.data_items.flag = flag;
479486
data.data_items.delay = delay;
480487

488+
if (dbb->isRestoring())
489+
data.data_items.flag |= SHUT_flag_restoring;
490+
481491
LCK_write_data(tdbb, dbb->dbb_lock, data.data_long);
482492

483493
{ // scope

0 commit comments

Comments
 (0)