Commit b72d1507 authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#39084: Getting intermittent errors with statement-based binary logging

Problem was that partitioning cached the table flags.
These flags could change due to TRANSACTION LEVEL changes.
Solution was to remove the cache and always return the table flags
from the first partition (if the handler was initialized).

mysql-test/r/partition_innodb_stmt.result:
  Bug#39084: Getting intermittent errors with statement-based binary logging
  
  New test result file.
mysql-test/t/partition_innodb_stmt.test:
  Bug#39084: Getting intermittent errors with statement-based binary logging
  
  New test file.
sql/ha_partition.cc:
  Bug#39084: Getting intermittent errors with statement-based binary logging
  
  Removed m_table_flags, and added m_handler_status.
  Added checks that all partitions have the same
  table flags.
  Moved some variable initializations.
  Updated some comments.
  Fixed typo initialise -> initialize
  Changed HA_EXTTA_NO_READCHECK to do nothing, since it
  is only used in ha_open, which is called for every
  partition in ::open anyway.
sql/ha_partition.h:
  Bug#39084: Getting intermittent errors with statement-based binary logging
  
  Removed m_table_flags, and added m_handler_status.
  Always return the first partitions table flags, instead of using
  cached table flags.
  Added define of enabled/disabled partitioning table flags
  Fixed type initialise -> initialize
  Updated some comments.
sql/handler.cc:
  Bug#39084: Getting intermittent errors with statement-based binary logging
  
  Fixed type initialise -> initialize.
sql/handler.h:
  Bug#39084: Getting intermittent errors with statement-based binary logging
  
  Added comment to understand where the cached value is set.
parent 0d220ba7
# connection default
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
CREATE TABLE t1
(
id SMALLINT NOT NULL,
PRIMARY KEY (id)
) ENGINE=innodb
PARTITION BY RANGE (id)
(
PARTITION p1 VALUES LESS THAN (2),
PARTITION p2 VALUES LESS THAN (4),
PARTITION p3 VALUES LESS THAN (10)
);
INSERT INTO t1 VALUES (1),(2),(3);
# Test READ COMMITTED -> REPEATABLE READ
FLUSH TABLES;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
SELECT * FROM t1;
id
1
2
3
#connection con1
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
INSERT INTO t1 VALUES(7);
COMMIT;
# connection default
COMMIT;
FLUSH TABLES;
# Test REPEATABLE READ -> READ COMMITTED
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
SELECT * FROM t1;
id
1
2
3
7
# connection con1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
INSERT INTO t1 VALUES(9);
ERROR HY000: Binary logging not possible. Message: Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'
COMMIT;
COMMIT;
DROP TABLE t1;
--source include/have_binlog_format_statement.inc
--source include/have_innodb.inc
--echo # connection default
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
CREATE TABLE t1
(
id SMALLINT NOT NULL,
PRIMARY KEY (id)
) ENGINE=innodb
PARTITION BY RANGE (id)
(
PARTITION p1 VALUES LESS THAN (2),
PARTITION p2 VALUES LESS THAN (4),
PARTITION p3 VALUES LESS THAN (10)
);
INSERT INTO t1 VALUES (1),(2),(3);
--echo # Test READ COMMITTED -> REPEATABLE READ
FLUSH TABLES;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
SELECT * FROM t1;
connect (con1, localhost, root,,);
connection con1;
--echo #connection con1
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
INSERT INTO t1 VALUES(7);
COMMIT;
connection default;
--echo # connection default
COMMIT;
FLUSH TABLES;
--echo # Test REPEATABLE READ -> READ COMMITTED
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
SELECT * FROM t1;
connection con1;
--echo # connection con1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
--error ER_BINLOG_LOGGING_IMPOSSIBLE
INSERT INTO t1 VALUES(9);
COMMIT;
disconnect con1;
connection default;
COMMIT;
DROP TABLE t1;
This diff is collapsed.
......@@ -48,6 +48,13 @@ typedef struct st_ha_data_partition
} HA_DATA_PARTITION;
#define PARTITION_BYTES_IN_POS 2
#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ)
#define PARTITION_DISABLED_TABLE_FLAGS (HA_CAN_GEOMETRY | \
HA_CAN_FULLTEXT | \
HA_DUPLICATE_POS | \
HA_CAN_SQL_HANDLER | \
HA_CAN_INSERT_DELAYED | \
HA_PRIMARY_KEY_REQUIRED_FOR_POSITION)
class ha_partition :public handler
{
private:
......@@ -85,8 +92,15 @@ private:
for this since the MySQL Server sometimes allocating the handler object
without freeing them.
*/
longlong m_table_flags;
ulong m_low_byte_first;
enum enum_handler_status
{
handler_not_initialized= 0,
handler_initialized,
handler_opened,
handler_closed
};
enum_handler_status m_handler_status;
uint m_reorged_parts; // Number of reorganised parts
uint m_tot_parts; // Total number of partitions;
......@@ -182,7 +196,7 @@ public:
enable later calls of the methods to retrieve constants from the under-
lying handlers. Returns false if not successful.
*/
bool initialise_partition(MEM_ROOT *mem_root);
bool initialize_partition(MEM_ROOT *mem_root);
/*
-------------------------------------------------------------------------
......@@ -585,6 +599,8 @@ public:
The partition handler will support whatever the underlying handlers
support except when specifically mentioned below about exceptions
to this rule.
NOTE: This cannot be cached since it can depend on TRANSACTION ISOLATION
LEVEL which is dynamic, see bug#39084.
HA_READ_RND_SAME:
Not currently used. (Means that the handler supports the rnd_same() call)
......@@ -709,9 +725,33 @@ public:
transfer those calls into index_read and other calls in the
index scan module.
(NDB)
HA_PRIMARY_KEY_REQUIRED_FOR_POSITION:
Does the storage engine need a PK for position?
Used with hidden primary key in InnoDB.
Hidden primary keys cannot be supported by partitioning, since the
partitioning expressions columns must be a part of the primary key.
(InnoDB)
HA_FILE_BASED is always set for partition handler since we use a
special file for handling names of partitions, engine types.
HA_REC_NOT_IN_SEQ is always set for partition handler since we cannot
guarantee that the records will be returned in sequence.
HA_CAN_GEOMETRY, HA_CAN_FULLTEXT, HA_CAN_SQL_HANDLER, HA_DUPLICATE_POS,
HA_CAN_INSERT_DELAYED, HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is disabled
until further investigated.
*/
virtual ulonglong table_flags() const
{ return m_table_flags; }
virtual Table_flags table_flags() const
{
DBUG_ENTER("ha_partition::table_flags");
if (m_handler_status < handler_initialized ||
m_handler_status >= handler_closed)
DBUG_RETURN(PARTITION_ENABLED_TABLE_FLAGS);
else
DBUG_RETURN((m_file[0]->ha_table_flags() &
~(PARTITION_DISABLED_TABLE_FLAGS)) |
(PARTITION_ENABLED_TABLE_FLAGS));
}
/*
This is a bitmap of flags that says how the storage engine
......@@ -889,7 +929,7 @@ public:
/*
-------------------------------------------------------------------------
MODULE initialise handler for HANDLER call
MODULE initialize handler for HANDLER call
-------------------------------------------------------------------------
This method is a special InnoDB method called before a HANDLER query.
-------------------------------------------------------------------------
......
......@@ -263,7 +263,7 @@ handler *get_ha_partition(partition_info *part_info)
DBUG_ENTER("get_ha_partition");
if ((partition= new ha_partition(partition_hton, part_info)))
{
if (partition->initialise_partition(current_thd->mem_root))
if (partition->initialize_partition(current_thd->mem_root))
{
delete partition;
partition= 0;
......
......@@ -1198,6 +1198,9 @@ public:
{
return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
}
/**
The cached_table_flags is set at ha_open and ha_external_lock
*/
Table_flags ha_table_flags() const { return cached_table_flags; }
/**
These functions represent the public interface to *users* of the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment