Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/burp/BurpTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ void RestoreRelationTask::initItem(BurpGlobals* tdgbl, Item& item)
m_masterGbl->gbl_dpb_data.begin(),
m_masterGbl->gbl_dpb_data.getCount());

dpb.deleteWithTag(isc_dpb_gbak_attach);
//dpb.deleteWithTag(isc_dpb_gbak_attach);

const UCHAR* dpbBuffer = dpb.getBuffer();
const USHORT dpbLength = dpb.getBufferLength();
Expand Down
1 change: 1 addition & 0 deletions src/include/firebird/impl/msg/jrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,3 +995,4 @@ FB_IMPL_MSG(JRD, 992, invalid_timezone_region_or_displacement, -901, "HY", "000"
FB_IMPL_MSG(JRD, 993, argmustbe_exact_range_for, -833, "42", "000", "Arguments for range-based FOR must be exact numeric types")
FB_IMPL_MSG(JRD, 994, range_for_by_should_be_positive, -833, "42", "000", "Range-based FOR BY argument must be positive")
FB_IMPL_MSG(JRD, 995, missing_value_for_format_pattern, -901, "HY", "000", "Cannot find value in input string for \"@1\" pattern")
FB_IMPL_MSG(JRD, 996, no_user_att_while_restore, -901, "HY", "000", "User attachments are not allowed for the database being restoring")
19 changes: 17 additions & 2 deletions src/jrd/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ 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_sweep_starting = 0x40000L; // Auto-sweep is starting
const ULONG DBB_creating = 0x80000L; // Database creation is in progress
const ULONG DBB_creating = 0x80000L; // Database creation is in progress
const ULONG DBB_shared = 0x100000L; // Database object is shared among connections

//
Expand Down Expand Up @@ -311,6 +311,9 @@ class Database : public pool_alloc<type_dbb>
bool incTempCacheUsage(FB_SIZE_T size);
void decTempCacheUsage(FB_SIZE_T size);

bool getRestoring() const { return m_restoring; }
void setRestoring(bool value) { m_restoring = value; }

private:
const Firebird::string m_id;
const Firebird::RefPtr<const Firebird::Config> m_config;
Expand All @@ -321,14 +324,16 @@ class Database : public pool_alloc<type_dbb>
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;
bool m_restoring;

explicit GlobalObjectHolder(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())
m_tempCacheLimit(m_config->getTempCacheLimit()),
m_restoring(false)
{}
};

Expand Down Expand Up @@ -718,6 +723,16 @@ class Database : public pool_alloc<type_dbb>
dbb_gblobj_holder->decTempCacheUsage(size);
}

bool isRestoring() const
{
return dbb_gblobj_holder->getRestoring();
}

void setRestoring(bool value)
{
dbb_gblobj_holder->setRestoring(value);
}

private:
//static int blockingAstSharedCounter(void*);
static int blocking_ast_sweep(void* ast_object);
Expand Down
47 changes: 44 additions & 3 deletions src/jrd/dpm.epp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ namespace

return lock.release();
}

inline bool swept_at_restore(thread_db* tdbb, const jrd_rel* relation)
{
return tdbb->getDatabase()->isRestoring() && !relation->isSystem();
}
}


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

Ods::pag* page = rpb->getWindow(tdbb).win_buffer;
if (page->pag_flags & dpg_swept)

// When restoring, mark primary data page as swept, pointer page already marked by locate_space()
if (swept_at_restore(tdbb, rpb->rpb_relation) && (type == DPM_primary))
{
page->pag_flags |= dpg_swept;
CCH_RELEASE(tdbb, &rpb->getWindow(tdbb));
}
else if (page->pag_flags & dpg_swept)
{
page->pag_flags &= ~dpg_swept;
mark_full(tdbb, rpb);
Expand Down Expand Up @@ -3083,7 +3095,13 @@ static void extend_relation(thread_db* tdbb, jrd_rel* relation, WIN* window, con
UCHAR* bits = (UCHAR*) (ppage->ppg_page + dbb->dbb_dp_per_pp);
PPG_DP_BIT_CLEAR(bits, slot, PPG_DP_ALL_BITS);

if (type != DPM_primary)
if (type == DPM_primary)
{
// When restoring, mark slot as swept, data page will be marked by our caller
if (swept_at_restore(tdbb, relation))
PPG_DP_BIT_SET(bits, slot, ppg_dp_swept);
}
else
PPG_DP_BIT_SET(bits, slot, ppg_dp_secondary);

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

PPG_DP_BIT_CLEAR(bits, slot, ppg_dp_empty);
if (type == DPM_primary)
{
PPG_DP_BIT_CLEAR(bits, slot, ppg_dp_secondary);

// When restoring, mark slot as swept, data page will be marked by our caller
if (swept_at_restore(tdbb, relation))
PPG_DP_BIT_SET(bits, slot, ppg_dp_swept);
}
else
PPG_DP_BIT_SET(bits, slot, ppg_dp_secondary);

Expand Down Expand Up @@ -3918,11 +3942,28 @@ static void store_big_record(thread_db* tdbb,
header->rhdf_b_page, header->rhdf_b_line);
#endif


bool markPP = false;

// When restoring, mark primary data page as swept, pointer page already marked by locate_space()
if (swept_at_restore(tdbb, rpb->rpb_relation) && (type == DPM_primary))
{
page->dpg_header.pag_flags |= dpg_swept;
}
else if (page->dpg_header.pag_flags & dpg_swept)
{
page->dpg_header.pag_flags &= ~dpg_swept;
markPP = true;
}

if (!(page->dpg_header.pag_flags & dpg_large))
{
page->dpg_header.pag_flags |= dpg_large;
mark_full(tdbb, rpb);
markPP = true;
}

if (markPP)
mark_full(tdbb, rpb);
else
CCH_RELEASE(tdbb, &rpb->getWindow(tdbb));
}
11 changes: 11 additions & 0 deletions src/jrd/jrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,12 @@ JAttachment* JProvider::internalAttach(CheckStatusWrapper* user_status, const ch
dbb->dbb_crypto_manager->attach(tdbb, attachment);
}

if (dbb->isRestoring())
{
if (!options.dpb_gbak_attach && !options.dpb_map_attach && !options.dpb_worker_attach)
ERR_post(Arg::Gds(isc_no_user_att_while_restore));
}

// Basic DBB initialization complete
initGuard.leave();

Expand Down Expand Up @@ -3105,6 +3111,8 @@ JAttachment* JProvider::createDatabase(CheckStatusWrapper* user_status, const ch

// Initialize the global objects
dbb->initGlobalObjects();
if (attachment->isGbak())
dbb->setRestoring(true);

// Initialize locks
LCK_init(tdbb, LCK_OWNER_database);
Expand Down Expand Up @@ -7894,6 +7902,9 @@ void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment, XThreadEns
if (!other)
sync.lock(SYNC_EXCLUSIVE);

if (attachment->att_flags & ATT_creator)
dbb->setRestoring(false);

// remove the attachment block from the dbb linked list
for (Jrd::Attachment** ptr = &dbb->dbb_attachments; *ptr; ptr = &(*ptr)->att_next)
{
Expand Down
Loading