@@ -949,7 +949,7 @@ void MET_error(const TEXT* string, ...)
949949 Arg::Gds(isc_random) << Arg::Str(s));
950950}
951951
952- Format* MET_format (thread_db* tdbb, RelationPermanent* relation , USHORT number)
952+ const Format* RelationPermanent::getFormat (thread_db* tdbb, USHORT number)
953953{
954954/**************************************
955955 *
@@ -965,23 +965,30 @@ Format* MET_format(thread_db* tdbb, RelationPermanent* relation, USHORT number)
965965 Attachment* attachment = tdbb->getAttachment();
966966 Database* dbb = tdbb->getDatabase();
967967
968- Format* format;
969- auto formats = relation->getFormats();
970- if ((number < formats->getCount()) && (format = formats->value(number)))
971- {
972- return format;
968+ { // scope
969+ auto formats = getFormats();
970+ if ((number < formats->getCount()) && formats->value(number))
971+ return formats->value(number);
972+ }
973+
974+ MutexLockGuard guard(rel_formats_grow, FB_FUNCTION);
975+
976+ { // scope
977+ auto formats = getFormats();
978+ if ((number < formats->getCount()) && formats->value(number))
979+ return formats->value(number);
973980 }
974981
975- // System relations don't have their formats stored inside RDB$FORMATS,
982+ // System relations and LTT don't have their formats stored inside RDB$FORMATS,
976983 // so it's absolutely pointless trying to find one there
977- fb_assert(!relation-> isSystem());
978- fb_assert(!(relation-> rel_flags & REL_temp_ltt));
984+ fb_assert(!isSystem());
985+ fb_assert(!(rel_flags & REL_temp_ltt));
979986
980- format = NULL;
987+ Format* format = NULL;
981988 AutoCacheRequest request(tdbb, irq_r_format, IRQ_REQUESTS);
982989
983990 FOR(REQUEST_HANDLE request)
984- X IN RDB$FORMATS WITH X.RDB$RELATION_ID EQ relation-> getId() AND
991+ X IN RDB$FORMATS WITH X.RDB$RELATION_ID EQ getId() AND
985992 X.RDB$FORMAT EQ number
986993 {
987994 blb* blob = blb::open(tdbb, attachment->getSysTransaction(), &X.RDB$DESCRIPTOR);
@@ -993,7 +1000,7 @@ Format* MET_format(thread_db* tdbb, RelationPermanent* relation, USHORT number)
9931000 unsigned bufferPos = 2;
9941001 USHORT count = buffer[0] | (buffer[1] << 8);
9951002
996- format = Format::newFormat(relation-> getPool(), count);
1003+ format = Format::newFormat(getPool(), count);
9971004
9981005 Array<Ods::Descriptor> odsDescs;
9991006 Ods::Descriptor* odsDesc = odsDescs.getBuffer(count);
@@ -1025,20 +1032,20 @@ Format* MET_format(thread_db* tdbb, RelationPermanent* relation, USHORT number)
10251032
10261033 desc.dsc_address = tmpArray.getBuffer(desc.dsc_length, false);
10271034 memcpy(desc.dsc_address, p, desc.dsc_length);
1028- EVL_make_value(tdbb, &desc, &format->fmt_defaults[offset], &relation-> getPool());
1035+ EVL_make_value(tdbb, &desc, &format->fmt_defaults[offset], &getPool());
10291036
10301037 p += desc.dsc_length;
10311038 }
10321039 }
10331040 END_FOR
10341041
1035- if (!format)
1036- format = Format::newFormat(relation->getPool());
1037-
1038- format->fmt_version = number;
1042+ if (format)
1043+ {
1044+ format->fmt_version = number;
10391045
1040- // Link the format block into the world
1041- relation->addFormat(format);
1046+ // Link the format block into the world
1047+ addFormat(format);
1048+ }
10421049
10431050 return format;
10441051}
@@ -3396,7 +3403,7 @@ ScanResult jrd_rel::scan(thread_db* tdbb, ObjectBase::Flag& flags)
33963403
33973404 delete csb;
33983405
3399- rel_current_format = MET_format (tdbb, rel_perm , rel_current_fmt);
3406+ rel_current_format = rel_perm->getFormat (tdbb, rel_current_fmt);
34003407 dependencies = false;
34013408
34023409 if (rel_fields)
0 commit comments