Skip to content

Commit

Permalink
Bug CORE-5707 : Begin and end of physical backup in the same transact…
Browse files Browse the repository at this point in the history
…ion could crash engine

Incompatible clauses in the same ALTER DATABASE statement is prohibited now.
  • Loading branch information
hvlad committed Jan 15, 2018
1 parent b217175 commit 45a4ecb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/dsql/DdlNodes.epp
Expand Up @@ -11638,9 +11638,33 @@ bool AlterDatabaseNode::checkPermission(thread_db* tdbb, jrd_tra* transaction)
return true;
}

void AlterDatabaseNode::checkClauses(thread_db* tdbb)
{
if (clauses & CLAUSE_END_BACKUP)
{
// msg 298: Incompatible ALTER DATABASE clauses: '@1' and '@2'
if (clauses & CLAUSE_BEGIN_BACKUP)
(Arg::PrivateDyn(298) << Arg::Str("BEGIN BACKUP") << Arg::Str("END BACKUP")).raise();

if (differenceFile.hasData())
(Arg::PrivateDyn(298) << Arg::Str("END BACKUP") << Arg::Str("ADD DIFFERENCE FILE")).raise();

if (clauses & CLAUSE_DROP_DIFFERENCE)
(Arg::PrivateDyn(298) << Arg::Str("END BACKUP") << Arg::Str("DROP DIFFERENCE FILE")).raise();
}

if ((clauses & CLAUSE_DROP_DIFFERENCE) && differenceFile.hasData())
{
// msg 298: Incompatible ALTER DATABASE clauses: '@1' and '@2'
(Arg::PrivateDyn(298) << Arg::Str("ADD DIFFERENCE FILE") << Arg::Str("DROP DIFFERENCE FILE")).raise();
}
}

void AlterDatabaseNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
jrd_tra* transaction)
{
checkClauses(tdbb);

// Take a LCK_alter_database lock to prevent altering of the database from
// parallel transactions

Expand Down
1 change: 1 addition & 0 deletions src/dsql/DdlNodes.h
Expand Up @@ -2254,6 +2254,7 @@ class AlterDatabaseNode : public DdlNode
private:
static void changeBackupMode(thread_db* tdbb, jrd_tra* transaction, unsigned clause);
static void defineDifference(thread_db* tdbb, jrd_tra* transaction, const Firebird::PathName& file);
void checkClauses(thread_db* tdbb);

public:
bool create; // Is the node created with a CREATE DATABASE command?
Expand Down
2 changes: 1 addition & 1 deletion src/msgs/facilities2.sql
Expand Up @@ -6,7 +6,7 @@ set bulk_insert INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUM
('2015-01-07 18:01:51', 'GFIX', 3, 134)
('1996-11-07 13:39:40', 'GPRE', 4, 1)
('2016-02-23 00:00:00', 'DSQL', 7, 40)
('2018-01-08 20:22:00', 'DYN', 8, 298)
('2018-01-15 00:15:00', 'DYN', 8, 299)
('1996-11-07 13:39:40', 'INSTALL', 10, 1)
('1996-11-07 13:38:41', 'TEST', 11, 4)
('2015-07-23 14:20:00', 'GBAK', 12, 370)
Expand Down
1 change: 1 addition & 0 deletions src/msgs/messages2.sql
Expand Up @@ -1971,6 +1971,7 @@ COMMIT WORK;
('dyn_defvaldecl_package_func', 'CreatePackageBodyNode::execute', 'PackageNodes.epp', NULL, 8, 290, NULL, 'Default values for parameters are allowed only in declaration of packaged function @1.@2', NULL, NULL);
('dyn_create_user_no_password', 'CreateAlterUserNode', 'DdlNodes.epp', NULL, 8, 291, NULL, 'Password must be specified when creating user', NULL, NULL);
('dyn_concur_alter_database', 'AlterDatabaseNode::execute', 'DdlNodes.epp', NULL, 8, 297, NULL, 'Concurrent ALTER DATABASE is not supported', NULL, NULL);
('dyn_incompat_alter_database', 'AlterDatabaseNode::execute', 'DdlNodes.epp', NULL, 8, 298, NULL, 'Incompatible ALTER DATABASE clauses: ''@1'' and ''@2''', NULL, NULL);
COMMIT WORK;
-- TEST
(NULL, 'main', 'test.c', NULL, 11, 0, NULL, 'This is a modified text message', NULL, NULL);
Expand Down

0 comments on commit 45a4ecb

Please sign in to comment.