Skip to content

Commit 287d690

Browse files
committed
dbb_guid cannot be optional anymore, except dbb being half-initialized
1 parent 9264932 commit 287d690

File tree

9 files changed

+25
-16
lines changed

9 files changed

+25
-16
lines changed

src/common/os/guid.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,18 @@ class Guid
6969
"{%08X-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}";
7070
static constexpr int GUID_FORMAT_ARGS = 11;
7171

72+
Guid()
73+
{
74+
memset(&m_data, 0, SIZE);
75+
}
76+
7277
public:
7378
static constexpr ULONG SIZE = sizeof(UUID);
7479

75-
Guid() = delete;
80+
static Guid empty()
81+
{
82+
return Guid();
83+
}
7684

7785
Guid(const Guid& other)
7886
: m_data(other.m_data)
@@ -84,7 +92,7 @@ class Guid
8492

8593
explicit Guid(const UCHAR* data)
8694
{
87-
memcpy(&m_data, data, sizeof(UUID));
95+
memcpy(&m_data, data, SIZE);
8896
}
8997

9098
Guid& operator=(const Guid& other)
@@ -95,7 +103,7 @@ class Guid
95103

96104
bool operator==(const Guid& other) const
97105
{
98-
return memcmp(&m_data, &other.m_data, sizeof(UUID)) == 0;
106+
return memcmp(&m_data, &other.m_data, SIZE) == 0;
99107
}
100108

101109
bool operator!=(const Guid& other) const
@@ -110,7 +118,7 @@ class Guid
110118

111119
void assign(const UCHAR* buffer)
112120
{
113-
memcpy(&m_data, buffer, sizeof(UUID));
121+
memcpy(&m_data, buffer, SIZE);
114122
}
115123

116124
void toString(char* buffer) const
@@ -160,7 +168,7 @@ class Guid
160168

161169
void copyTo(UCHAR* ptr) const
162170
{
163-
memcpy(ptr, &m_data, sizeof(UUID));
171+
memcpy(ptr, &m_data, SIZE);
164172
}
165173

166174
// Convert platform-dependent GUID into platform-independent form according to RFC 4122

src/jrd/Database.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class Database : public pool_alloc<type_dbb>
427427

428428
MemoryPool* dbb_permanent;
429429

430-
std::optional<Firebird::Guid> dbb_guid; // database GUID
430+
Firebird::Guid dbb_guid; // database GUID
431431

432432
Firebird::SyncObject dbb_sync;
433433
Firebird::SyncObject dbb_sys_attach; // synchronize operations with dbb_sys_attachments
@@ -608,6 +608,7 @@ class Database : public pool_alloc<type_dbb>
608608
private:
609609
Database(MemoryPool* p, Firebird::IPluginConfig* pConf, bool shared)
610610
: dbb_permanent(p),
611+
dbb_guid(Firebird::Guid::empty()),
611612
dbb_page_manager(this, *p),
612613
dbb_file_id(*p),
613614
dbb_modules(*p),

src/jrd/Monitoring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ void Monitoring::putDatabase(thread_db* tdbb, SnapshotData::DumpRecord& record)
936936
record.storeInteger(f_mon_db_na, dbb->getLatestAttachmentId());
937937
record.storeInteger(f_mon_db_ns, dbb->getLatestStatementId());
938938

939-
record.storeString(f_mon_db_guid, dbb->dbb_guid.value().toString());
939+
record.storeString(f_mon_db_guid, dbb->dbb_guid.toString());
940940
record.storeString(f_mon_db_file_id, dbb->getUniqueFileId());
941941

942942
record.storeInteger(f_mon_db_repl_mode, dbb->dbb_replica_mode);

src/jrd/SysFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4592,7 +4592,7 @@ dsc* evlGetContext(thread_db* tdbb, const SysFunction*, const NestValueArray& ar
45924592
else if (nameStr == DATABASE_NAME)
45934593
resultStr = dbb->dbb_database_name.ToString();
45944594
else if (nameStr == DATABASE_GUID)
4595-
resultStr = dbb->dbb_guid.value().toString();
4595+
resultStr = dbb->dbb_guid.toString();
45964596
else if (nameStr == PAGES_ALLOCATED)
45974597
{
45984598
resultStr.printf("%" ULONGFORMAT, PageSpace::actAlloc(dbb));

src/jrd/inf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ void INF_database_info(thread_db* tdbb,
919919

920920
case fb_info_db_guid:
921921
{
922-
const auto guidStr = dbb->dbb_guid.value().toString();
922+
const auto guidStr = dbb->dbb_guid.toString();
923923
if (!(info = INF_put_item(item, guidStr.length(), guidStr.c_str(), info, end)))
924924
return;
925925
}

src/jrd/jrd.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,9 +3133,6 @@ JAttachment* JProvider::createDatabase(CheckStatusWrapper* user_status, const ch
31333133

31343134
dbb->dbb_page_manager.initTempPageSpace(tdbb);
31353135

3136-
dbb->dbb_guid = Guid::generate();
3137-
PAG_set_db_guid(tdbb, dbb->dbb_guid.value());
3138-
31393136
if (options.dpb_set_page_buffers)
31403137
PAG_set_page_buffers(tdbb, options.dpb_page_buffers);
31413138

src/jrd/pag.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,12 @@ void PAG_format_header(thread_db* tdbb)
794794

795795
WIN window(HEADER_PAGE_NUMBER);
796796
header_page* header = (header_page*) CCH_fake(tdbb, &window, 1);
797+
header->hdr_header.pag_type = pag_header;
797798
header->hdr_header.pag_scn = 0;
799+
Guid::generate().copyTo(header->hdr_guid);
798800
*(ISC_TIMESTAMP*) header->hdr_creation_date = TimeZoneUtil::getCurrentGmtTimeStamp().utc_timestamp;
799801
// should we include milliseconds or not?
800802
//TimeStamp::round_time(header->hdr_creation_date->timestamp_time, 0);
801-
header->hdr_header.pag_type = pag_header;
802803
header->hdr_page_size = dbb->dbb_page_size;
803804
header->hdr_ods_version = ODS_VERSION | ODS_FIREBIRD_FLAG;
804805
DbImplementation::current.store(header);
@@ -816,6 +817,8 @@ void PAG_format_header(thread_db* tdbb)
816817
dbb->dbb_ods_version = header->hdr_ods_version & ~ODS_FIREBIRD_FLAG;
817818
dbb->dbb_minor_version = header->hdr_ods_minor;
818819

820+
dbb->dbb_guid.assign(header->hdr_guid);
821+
819822
CCH_RELEASE(tdbb, &window);
820823
}
821824

@@ -1039,7 +1042,7 @@ void PAG_header(thread_db* tdbb, bool info, const TriState newForceWrite)
10391042
const auto replicaMode = (ReplicaMode) header->hdr_replica_mode;
10401043
dbb->dbb_replica_mode.store(replicaMode, std::memory_order_relaxed);
10411044

1042-
dbb->dbb_guid = Guid(header->hdr_guid);
1045+
dbb->dbb_guid.assign(header->hdr_guid);
10431046

10441047
// If database in backup lock state...
10451048
if (!info && dbb->dbb_backup_manager->getState() != Ods::hdr_nbak_normal)

src/jrd/replication/Manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Manager::Manager(const string& dbId,
110110
const auto tdbb = JRD_get_thread_data();
111111
const auto dbb = tdbb->getDatabase();
112112

113-
const auto& guid = dbb->dbb_guid.value();
113+
const auto& guid = dbb->dbb_guid;
114114
m_sequence = dbb->dbb_repl_sequence;
115115

116116
if (config->journalDirectory.hasData())

src/jrd/replication/Publisher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace
129129
{
130130
auto& pool = *attachment->att_pool;
131131
const auto manager = dbb->replManager(true);
132-
const auto& guid = dbb->dbb_guid.value();
132+
const auto& guid = dbb->dbb_guid;
133133
const auto& userName = attachment->getUserName();
134134

135135
attachment->att_replicator = FB_NEW Replicator(pool, manager, guid, userName);

0 commit comments

Comments
 (0)