summaryrefslogtreecommitdiff
path: root/sql/sql_truncate.h
diff options
context:
space:
mode:
authorSujatha Sivakumar <sujatha.sivakumar@oracle.com>2014-04-15 15:17:25 +0530
committerSujatha Sivakumar <sujatha.sivakumar@oracle.com>2014-04-15 15:17:25 +0530
commit1b74f2e3da53dd8b965920fad2ff599df2d1fc89 (patch)
tree23a4a9122231307ef4549e9187e0f1d979933d27 /sql/sql_truncate.h
parentea38c2658229c45e48bf417168efc85f4768cef4 (diff)
downloadmariadb-git-1b74f2e3da53dd8b965920fad2ff599df2d1fc89.tar.gz
Bug#17942050:KILL OF TRUNCATE TABLE WILL LEAD TO BINARY LOG
WRITTEN WHILE ROWS REMAINS Problem: ======== When truncate table fails while using transactional based engines even though the operation errors out we still continue and log it to binlog. Because of this master has data but the truncate will be written to binary log which will cause inconsistency. Analysis: ======== Truncate table can happen either through drop and create of table or by deleting rows. In the second case the existing code is written in such a way that even if an error occurs the truncate statement will always be binlogged. Which is not correct. Binlogging of TRUNCATE TABLE statement should check whether truncate is executed "transactionally or not". If the table is transaction based we log the TRUNCATE TABLE only on successful completion. If table is non transactional there are possibilities that on error we could have partial changes done hence in such cases we do log in spite of errors as some of the lines might have been removed, so the statement has to be sent to slave. Fix: === Using table handler whether truncate table is being executed in transaction based mode or not is identified and statement is binlogged accordingly. mysql-test/suite/binlog/r/binlog_truncate_kill.result: Added test case to test the fix for Bug#17942050. mysql-test/suite/binlog/t/binlog_truncate_kill.test: Added test case to test the fix for Bug#17942050. sql/sql_truncate.cc: Check if truncation is successful or not and retun appropriate return values so that binlogging can be done based on that. sql/sql_truncate.h: Added a new enum.
Diffstat (limited to 'sql/sql_truncate.h')
-rw-r--r--sql/sql_truncate.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/sql/sql_truncate.h b/sql/sql_truncate.h
index 95a2f35df4f..0280ecc4932 100644
--- a/sql/sql_truncate.h
+++ b/sql/sql_truncate.h
@@ -1,6 +1,6 @@
#ifndef SQL_TRUNCATE_INCLUDED
#define SQL_TRUNCATE_INCLUDED
-/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -47,11 +47,17 @@ public:
bool execute(THD *thd);
protected:
+ enum truncate_result{
+ TRUNCATE_OK=0,
+ TRUNCATE_FAILED_BUT_BINLOG,
+ TRUNCATE_FAILED_SKIP_BINLOG
+ };
+
/** Handle locking a base table for truncate. */
bool lock_table(THD *, TABLE_LIST *, bool *);
/** Truncate table via the handler method. */
- int handler_truncate(THD *, TABLE_LIST *, bool);
+ enum truncate_result handler_truncate(THD *, TABLE_LIST *, bool);
/**
Optimized delete of all rows by doing a full regenerate of the table.