Skip to content

Commit 30448b5

Browse files
committed
Move database GUID to the core header part
1 parent 963d71a commit 30448b5

File tree

6 files changed

+36
-39
lines changed

6 files changed

+36
-39
lines changed

src/jrd/ods.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,16 @@ struct header_page
486486
UCHAR hdr_cc; // Compiler of engine on which database was created
487487
UCHAR hdr_compat; // Cross-platform database transfer compatibility flags
488488
} hdr_db_impl;
489+
UCHAR hdr_guid[16]; // Database GUID
489490
SLONG hdr_creation_date[2]; // Date/time of creation
490491
SLONG hdr_shadow_count; // Event count for shadow synchronization
491-
USHORT hdr_sequence; // sequence number of file
492492
USHORT hdr_end; // offset of HDR_end in page
493493
ULONG hdr_crypt_page; // Page at which processing is in progress
494494
TEXT hdr_crypt_plugin[32]; // Name of plugin used to crypt this DB
495495
UCHAR hdr_data[1]; // Misc data
496496
};
497497

498-
static_assert(sizeof(struct header_page) == 144, "struct header_page size mismatch");
498+
static_assert(sizeof(struct header_page) == 160, "struct header_page size mismatch");
499499
static_assert(offsetof(struct header_page, hdr_header) == 0, "hdr_header offset mismatch");
500500
static_assert(offsetof(struct header_page, hdr_page_size) == 16, "hdr_page_size offset mismatch");
501501
static_assert(offsetof(struct header_page, hdr_ods_version) == 18, "hdr_ods_version offset mismatch");
@@ -512,13 +512,15 @@ static_assert(offsetof(struct header_page, hdr_oldest_active) == 56, "hdr_oldest
512512
static_assert(offsetof(struct header_page, hdr_oldest_snapshot) == 64, "hdr_oldest_snapshot offset mismatch");
513513
static_assert(offsetof(struct header_page, hdr_attachment_id) == 72, "hdr_attachment_id offset mismatch");
514514
static_assert(offsetof(struct header_page, hdr_db_impl) == 80, "hdr_shadow_count offset mismatch");
515-
static_assert(offsetof(struct header_page, hdr_creation_date) == 84, "hdr_creation_date offset mismatch");
516-
static_assert(offsetof(struct header_page, hdr_shadow_count) == 92, "hdr_shadow_count offset mismatch");
517-
static_assert(offsetof(struct header_page, hdr_sequence) == 96, "hdr_sequence offset mismatch");
518-
static_assert(offsetof(struct header_page, hdr_end) == 98, "hdr_end offset mismatch");
519-
static_assert(offsetof(struct header_page, hdr_crypt_page) == 100, "hdr_crypt_page offset mismatch");
520-
static_assert(offsetof(struct header_page, hdr_crypt_plugin) == 104, "hdr_crypt_plugin offset mismatch");
521-
static_assert(offsetof(struct header_page, hdr_data) == 136, "hdr_data offset mismatch");
515+
static_assert(offsetof(struct header_page, hdr_guid) == 84, "hdr_guid offset mismatch");
516+
static_assert(offsetof(struct header_page, hdr_creation_date) == 100, "hdr_creation_date offset mismatch");
517+
static_assert(offsetof(struct header_page, hdr_shadow_count) == 108, "hdr_shadow_count offset mismatch");
518+
static_assert(offsetof(struct header_page, hdr_end) == 112, "hdr_end offset mismatch");
519+
static_assert(offsetof(struct header_page, hdr_crypt_page) == 116, "hdr_crypt_page offset mismatch");
520+
static_assert(offsetof(struct header_page, hdr_crypt_plugin) == 120, "hdr_crypt_plugin offset mismatch");
521+
static_assert(offsetof(struct header_page, hdr_data) == 152, "hdr_data offset mismatch");
522+
523+
static_assert(sizeof(header_page::hdr_guid) == Firebird::Guid::SIZE, "hdr_guid size mismatch");
522524

523525
#define HDR_SIZE static_cast<FB_SIZE_T>(offsetof(Ods::header_page, hdr_data[0]))
524526

@@ -538,7 +540,7 @@ inline constexpr UCHAR HDR_difference_file = 6; // Delta file that is used duri
538540
inline constexpr UCHAR HDR_backup_guid = 7; // GUID generated on each switch into backup mode
539541
inline constexpr UCHAR HDR_crypt_key = 8; // Name of a key used to crypt database
540542
inline constexpr UCHAR HDR_crypt_hash = 9; // Validator of key correctness
541-
inline constexpr UCHAR HDR_db_guid = 10; // Database GUID
543+
//inline constexpr UCHAR HDR_db_guid = 10; // Database GUID
542544
inline constexpr UCHAR HDR_repl_seq = 11; // Replication changelog sequence
543545
inline constexpr UCHAR HDR_max = 11; // Maximum HDR_clump value
544546

src/jrd/os/posix/unix.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ static bool raw_devices_validate_database(int desc, const PathName& file_name)
12251225
}
12261226

12271227
// Validate database header. Code lifted from PAG_header.
1228-
if (hp->hdr_header.pag_type != pag_header /*|| hp->hdr_sequence*/)
1228+
if (hp->hdr_header.pag_type != pag_header)
12291229
goto quit;
12301230

12311231
if (!Ods::isSupported(hp))
@@ -1240,10 +1240,8 @@ static bool raw_devices_validate_database(int desc, const PathName& file_name)
12401240

12411241
quit:
12421242
#ifdef DEV_BUILD
1243-
gds__log ("raw_devices_validate_database: %s -> %s%s\n",
1244-
file_name.c_str(),
1245-
retval ? "true" : "false",
1246-
retval && hp->hdr_sequence != 0 ? " (continuation file)" : "");
1243+
gds__log ("raw_devices_validate_database: %s -> %s\n",
1244+
file_name.c_str(), retval ? "true" : "false");
12471245
#endif
12481246
return retval;
12491247
}

src/jrd/pag.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ void PAG_header_init(thread_db* tdbb)
11131113
PIO_header(tdbb, temp_page, headerSize);
11141114
const header_page* header = (header_page*) temp_page;
11151115

1116-
if (header->hdr_header.pag_type != pag_header || header->hdr_sequence)
1116+
if (header->hdr_header.pag_type != pag_header)
11171117
ERR_post(Arg::Gds(isc_bad_db_format) << Arg::Str(attachment->att_filename));
11181118

11191119
const USHORT ods_version = header->hdr_ods_version & ~ODS_FIREBIRD_FLAG;
@@ -1227,11 +1227,6 @@ void PAG_init2(thread_db* tdbb)
12271227
memcpy(&dbb->dbb_sweep_interval, p + 2, sizeof(SLONG));
12281228
break;
12291229

1230-
case HDR_db_guid:
1231-
fb_assert(p[1] == Guid::SIZE);
1232-
dbb->dbb_guid = Guid(p + 2);
1233-
break;
1234-
12351230
case HDR_repl_seq:
12361231
fb_assert(p[1] == sizeof(FB_UINT64));
12371232
memcpy(&dbb->dbb_repl_sequence, p + 2, sizeof(FB_UINT64));
@@ -1390,7 +1385,18 @@ void PAG_set_db_guid(thread_db* tdbb, const Guid& guid)
13901385
*
13911386
**************************************/
13921387
SET_TDBB(tdbb);
1393-
storeClump(tdbb, HDR_db_guid, Guid::SIZE, guid.getData());
1388+
ensureDbWritable(tdbb);
1389+
1390+
WIN window(HEADER_PAGE_NUMBER);
1391+
header_page* header = (header_page*) CCH_FETCH(tdbb, &window, LCK_write, pag_header);
1392+
CCH_MARK_MUST_WRITE(tdbb, &window);
1393+
1394+
const auto dbb = tdbb->getDatabase();
1395+
1396+
guid.copyTo(header->hdr_guid);
1397+
dbb->dbb_guid = guid;
1398+
1399+
CCH_RELEASE(tdbb, &window);
13941400
}
13951401

13961402

src/utilities/gstat/ppg.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ void PPG_print_header(const header_page* header, bool nocreation, Firebird::Util
6666
uSvc->printf(false, "\tOldest active\t\t%" SQUADFORMAT"\n", header->hdr_oldest_active);
6767
uSvc->printf(false, "\tOldest snapshot\t\t%" SQUADFORMAT"\n", header->hdr_oldest_snapshot);
6868
uSvc->printf(false, "\tNext transaction\t%" SQUADFORMAT"\n", header->hdr_next_transaction);
69-
uSvc->printf(false, "\tSequence number\t\t%d\n", header->hdr_sequence);
7069
uSvc->printf(false, "\tNext attachment ID\t%" SQUADFORMAT"\n", header->hdr_attachment_id);
7170

7271
Firebird::DbImplementation imp(header);
@@ -89,6 +88,9 @@ void PPG_print_header(const header_page* header, bool nocreation, Firebird::Util
8988

9089
if (!nocreation)
9190
{
91+
const Guid guid(header->hdr_guid);
92+
uSvc->printf(false, "\tDatabase GUID:\t%s\n", guid.toString().c_str());
93+
9294
struct tm time;
9395
isc_decode_timestamp(reinterpret_cast<const ISC_TIMESTAMP*>(header->hdr_creation_date),
9496
&time);
@@ -264,14 +266,6 @@ void PPG_print_header(const header_page* header, bool nocreation, Firebird::Util
264266
uSvc->printf(false, "\tCrypt checksum:\t%*.*s\n", p[1], p[1], p + 2);
265267
break;
266268

267-
case HDR_db_guid:
268-
{
269-
fb_assert(p[1] == Guid::SIZE);
270-
const Guid guid(p + 2);
271-
uSvc->printf(false, "\tDatabase GUID:\t%s\n", guid.toString().c_str());
272-
break;
273-
}
274-
275269
case HDR_repl_seq:
276270
{
277271
FB_UINT64 sequence;

src/utilities/nbackup/nbackup.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ void NBackup::fixup_database(bool repl_seq, bool set_readonly)
859859

860860
if (!repl_seq)
861861
{
862+
// Replace existing database GUID with a regenerated one
863+
Guid::generate().copyTo(header->hdr_guid);
864+
862865
size = page_size;
863866
header = reinterpret_cast<Ods::header_page*>(header_buffer.getBuffer(size));
864867

@@ -871,18 +874,13 @@ void NBackup::fixup_database(bool repl_seq, bool set_readonly)
871874
const auto end = (UCHAR*) header + header->hdr_page_size;
872875
while (p < end && *p != Ods::HDR_end)
873876
{
874-
if (*p == Ods::HDR_db_guid)
875-
{
876-
// Replace existing database GUID with a regenerated one
877-
fb_assert(p[1] == Guid::SIZE);
878-
Guid::generate().copyTo(p + 2);
879-
}
880-
else if (*p == Ods::HDR_repl_seq)
877+
if (*p == Ods::HDR_repl_seq)
881878
{
882879
// Reset the sequence counter
883880
const FB_UINT64 sequence = 0;
884881
fb_assert(p[1] == sizeof(sequence));
885882
memcpy(p + 2, &sequence, sizeof(sequence));
883+
break;
886884
}
887885

888886
p += p[1] + 2;

src/utilities/rebuild/rebuild.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,6 @@ static void print_db_header( FILE* file, const header_page* header)
924924
fprintf(file, " Data pages per pointer page\t%ld\n", gdbb->tdbb_database->dbb_dp_per_pp);
925925
fprintf(file, " Max records per page\t%ld\n", gdbb->tdbb_database->dbb_max_records);
926926
927-
//fprintf (" Sequence number %d\n", header->hdr_sequence);
928927
//fprintf (" Creation date \n", header->hdr_creation_date);
929928
930929
fprintf(file, " Next attachment ID\t\t%ld\n", header->hdr_attachment_id);

0 commit comments

Comments
 (0)