Skip to content

Commit f54cd06

Browse files
NoremosArtyom Abakumovdyemanovhvlad
authored
Allow specifying exactly what type of database string is expected in the database section for trace configuration (#8427)
* Add ability to specify database string type in trace.conf * Restore spaces in fbtrace.conf * Use new section keys instead of specifiers * Parenthesis around boolean condition Co-authored-by: Vlad Khorsun <[email protected]> --------- Co-authored-by: Artyom Abakumov <[email protected]> Co-authored-by: Dmitry Yemanov <[email protected]> Co-authored-by: Vlad Khorsun <[email protected]>
1 parent e066244 commit f54cd06

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

src/common/config/config_file.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,3 +959,37 @@ bool ConfigFile::Parameter::asBoolean() const
959959
value.equalsNoCase("yes") ||
960960
value.equalsNoCase("y");
961961
}
962+
963+
/******************************************************************************
964+
*
965+
* Parse name as a section key
966+
*/
967+
968+
ConfigFile::SectionType ConfigFile::Parameter::parseSectionKey() const
969+
{
970+
if (name == "database")
971+
{
972+
return SectionType::DATABASE;
973+
}
974+
else if (name == "databaseName")
975+
{
976+
return SectionType::DATABASE_NAME;
977+
}
978+
else if (name == "databaseRegex")
979+
{
980+
return SectionType::DATABASE_REGEX;
981+
}
982+
else if (name == "service")
983+
{
984+
return SectionType::SERVICE;
985+
}
986+
else
987+
{
988+
fatal_exception::raiseFmt("error while parsing trace configuration\n\t"
989+
"line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"service\" is expected",
990+
line);
991+
992+
// Return something to calm down the compiler
993+
return SectionType::DATABASE;
994+
}
995+
}

src/common/config/config_file.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted
7575
virtual const char* getFileName() const = 0;
7676
};
7777

78+
// Possible section types
79+
enum class SectionType
80+
{
81+
DATABASE,
82+
DATABASE_NAME,
83+
DATABASE_REGEX,
84+
SERVICE
85+
};
86+
7887
struct Parameter : public AutoStorage
7988
{
8089
Parameter(MemoryPool& p, const Parameter& par)
@@ -87,6 +96,7 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted
8796

8897
SINT64 asInteger() const;
8998
bool asBoolean() const;
99+
SectionType parseSectionKey() const;
90100

91101
KeyType name;
92102
String value;

src/utilities/ntrace/TraceConfiguration.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,8 @@ void TraceCfgReader::readConfig()
8989
{
9090
const ConfigFile::Parameter* section = &params[n];
9191

92-
const bool isDatabase = (section->name == "database");
93-
if (!isDatabase && section->name != "services")
94-
//continue;
95-
fatal_exception::raiseFmt(ERROR_PREFIX
96-
"line %d: wrong section header, \"database\" or \"service\" is expected",
97-
section->line);
92+
const ConfigFile::SectionType sectionType = section->parseSectionKey();
93+
const bool isDatabase = (sectionType != ConfigFile::SectionType::SERVICE);
9894

9995
const ConfigFile::String pattern = section->value;
10096
bool match = false;
@@ -131,14 +127,16 @@ void TraceCfgReader::readConfig()
131127
noQuotePattern.alltrim(" '\'");
132128
PathName expandedName;
133129

134-
if (m_databaseName == noQuotePattern ||
130+
if (sectionType != ConfigFile::SectionType::DATABASE_REGEX && (m_databaseName == noQuotePattern ||
135131
(expandDatabaseName(noQuotePattern, expandedName, nullptr),
136-
m_databaseName == expandedName) )
132+
m_databaseName == expandedName) ))
137133
{
134+
// Compare by name
138135
match = exactMatch = true;
139136
}
140-
else
137+
else if (sectionType != ConfigFile::SectionType::DATABASE_NAME)
141138
{
139+
// Compare by regex
142140
bool regExpOk = false;
143141
try
144142
{

src/utilities/ntrace/fbtrace.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
# database = (%[\\/](e[[:DIGIT:]]{2}).fdb)
2525
# type
2626
# database = (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
27+
#
28+
# It is also possible to specify exactly what type of database string is expected
29+
# For example:
30+
# databaseName = /var/dbs/primary-db.fdb
31+
# type
32+
# databaseRegex = (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
2733

2834

2935
database

0 commit comments

Comments
 (0)