Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
12d03195
Commit
12d03195
authored
Feb 19, 2008
by
tsmith@ramayana.hindu.god
Browse files
Options
Browse Files
Download
Plain Diff
Merge ramayana.hindu.god:/home/tsmith/m/inno/feb18/51
into ramayana.hindu.god:/home/tsmith/m/bk/build/51
parents
3fe6684c
b8b6c7fc
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
629 additions
and
332 deletions
+629
-332
include/mysql/plugin.h
include/mysql/plugin.h
+10
-0
mysql-test/r/innodb.result
mysql-test/r/innodb.result
+15
-2
mysql-test/r/innodb_bug34053.result
mysql-test/r/innodb_bug34053.result
+1
-0
mysql-test/t/innodb.test
mysql-test/t/innodb.test
+32
-0
mysql-test/t/innodb_bug34053.test
mysql-test/t/innodb_bug34053.test
+49
-0
sql/mysql_priv.h
sql/mysql_priv.h
+9
-1
sql/sql_class.cc
sql/sql_class.cc
+12
-0
storage/innobase/btr/btr0cur.c
storage/innobase/btr/btr0cur.c
+1
-1
storage/innobase/handler/ha_innodb.cc
storage/innobase/handler/ha_innodb.cc
+53
-16
storage/innobase/include/os0sync.h
storage/innobase/include/os0sync.h
+32
-6
storage/innobase/include/read0read.h
storage/innobase/include/read0read.h
+0
-4
storage/innobase/include/row0mysql.h
storage/innobase/include/row0mysql.h
+11
-1
storage/innobase/include/sync0arr.h
storage/innobase/include/sync0arr.h
+8
-13
storage/innobase/include/sync0rw.h
storage/innobase/include/sync0rw.h
+12
-0
storage/innobase/include/sync0rw.ic
storage/innobase/include/sync0rw.ic
+10
-2
storage/innobase/include/sync0sync.h
storage/innobase/include/sync0sync.h
+1
-0
storage/innobase/include/sync0sync.ic
storage/innobase/include/sync0sync.ic
+1
-1
storage/innobase/os/os0sync.c
storage/innobase/os/os0sync.c
+100
-11
storage/innobase/read/read0read.c
storage/innobase/read/read0read.c
+0
-5
storage/innobase/row/row0mysql.c
storage/innobase/row/row0mysql.c
+46
-16
storage/innobase/srv/srv0srv.c
storage/innobase/srv/srv0srv.c
+8
-8
storage/innobase/sync/sync0arr.c
storage/innobase/sync/sync0arr.c
+157
-235
storage/innobase/sync/sync0rw.c
storage/innobase/sync/sync0rw.c
+19
-1
storage/innobase/sync/sync0sync.c
storage/innobase/sync/sync0sync.c
+42
-9
No files found.
include/mysql/plugin.h
View file @
12d03195
...
@@ -714,6 +714,16 @@ int mysql_tmpfile(const char *prefix);
...
@@ -714,6 +714,16 @@ int mysql_tmpfile(const char *prefix);
*/
*/
int
thd_killed
(
const
MYSQL_THD
thd
);
int
thd_killed
(
const
MYSQL_THD
thd
);
/**
Return the thread id of a user thread
@param thd user thread connection handle
@return thread id
*/
unsigned
long
thd_get_thread_id
(
const
MYSQL_THD
thd
);
/**
/**
Allocate memory in the connection's local memory pool
Allocate memory in the connection's local memory pool
...
...
mysql-test/r/innodb.result
View file @
12d03195
...
@@ -1062,6 +1062,19 @@ select count(*) from t2 /* must be 2 as restored after rollback caused by the er
...
@@ -1062,6 +1062,19 @@ select count(*) from t2 /* must be 2 as restored after rollback caused by the er
count(*)
count(*)
2
2
drop table t1, t2;
drop table t1, t2;
drop table if exists t1, t2;
CREATE TABLE t1 (a int, PRIMARY KEY (a));
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
create trigger trg_del_t2 after delete on t2 for each row
insert into t1 values (1);
insert into t1 values (1);
insert into t2 values (1),(2);
delete t2 from t2;
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
count(*)
2
drop table t1, t2;
create table t1 (a int, b int) engine=innodb;
create table t1 (a int, b int) engine=innodb;
insert into t1 values(20,null);
insert into t1 values(20,null);
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
...
@@ -1727,10 +1740,10 @@ Variable_name Value
...
@@ -1727,10 +1740,10 @@ Variable_name Value
Innodb_page_size 16384
Innodb_page_size 16384
show status like "Innodb_rows_deleted";
show status like "Innodb_rows_deleted";
Variable_name Value
Variable_name Value
Innodb_rows_deleted 7
0
Innodb_rows_deleted 7
1
show status like "Innodb_rows_inserted";
show status like "Innodb_rows_inserted";
Variable_name Value
Variable_name Value
Innodb_rows_inserted 108
2
Innodb_rows_inserted 108
4
show status like "Innodb_rows_updated";
show status like "Innodb_rows_updated";
Variable_name Value
Variable_name Value
Innodb_rows_updated 885
Innodb_rows_updated 885
...
...
mysql-test/r/innodb_bug34053.result
0 → 100644
View file @
12d03195
SET storage_engine=InnoDB;
mysql-test/t/innodb.test
View file @
12d03195
...
@@ -752,6 +752,38 @@ select count(*) from t2 /* must be 2 as restored after rollback caused by the er
...
@@ -752,6 +752,38 @@ select count(*) from t2 /* must be 2 as restored after rollback caused by the er
drop
table
t1
,
t2
;
drop
table
t1
,
t2
;
#
# Bug #29136 erred multi-delete on trans table does not rollback
#
# prepare
--
disable_warnings
drop
table
if
exists
t1
,
t2
;
--
enable_warnings
CREATE
TABLE
t1
(
a
int
,
PRIMARY
KEY
(
a
));
CREATE
TABLE
t2
(
a
int
,
PRIMARY
KEY
(
a
))
ENGINE
=
InnoDB
;
create
trigger
trg_del_t2
after
delete
on
t2
for
each
row
insert
into
t1
values
(
1
);
insert
into
t1
values
(
1
);
insert
into
t2
values
(
1
),(
2
);
# exec cases A, B - see multi_update.test
# A. send_error() w/o send_eof() branch
--
error
ER_DUP_ENTRY
delete
t2
from
t2
;
# check
select
count
(
*
)
from
t2
/* must be 2 as restored after rollback caused by the error */
;
# cleanup bug#29136
drop
table
t1
,
t2
;
#
#
# Testing of IFNULL
# Testing of IFNULL
#
#
...
...
mysql-test/t/innodb_bug34053.test
0 → 100644
View file @
12d03195
#
# Make sure http://bugs.mysql.com/34053 remains fixed.
#
--
source
include
/
have_innodb
.
inc
SET
storage_engine
=
InnoDB
;
# we do not really care about what gets printed, we are only
# interested in getting success or failure according to our
# expectations
--
disable_query_log
--
disable_result_log
GRANT
USAGE
ON
*.*
TO
'shane'
@
'localhost'
IDENTIFIED
BY
'12345'
;
FLUSH
PRIVILEGES
;
--
connect
(
con1
,
localhost
,
shane
,
12345
,)
--
connection
con1
--
error
ER_SPECIFIC_ACCESS_DENIED_ERROR
CREATE
TABLE
innodb_monitor
(
a
INT
)
ENGINE
=
INNODB
;
--
error
ER_SPECIFIC_ACCESS_DENIED_ERROR
CREATE
TABLE
innodb_mem_validate
(
a
INT
)
ENGINE
=
INNODB
;
CREATE
TABLE
innodb_monitorx
(
a
INT
)
ENGINE
=
INNODB
;
DROP
TABLE
innodb_monitorx
;
CREATE
TABLE
innodb_monito
(
a
INT
)
ENGINE
=
INNODB
;
DROP
TABLE
innodb_monito
;
CREATE
TABLE
xinnodb_monitor
(
a
INT
)
ENGINE
=
INNODB
;
DROP
TABLE
xinnodb_monitor
;
CREATE
TABLE
nnodb_monitor
(
a
INT
)
ENGINE
=
INNODB
;
DROP
TABLE
nnodb_monitor
;
--
connection
default
CREATE
TABLE
innodb_monitor
(
a
INT
)
ENGINE
=
INNODB
;
CREATE
TABLE
innodb_mem_validate
(
a
INT
)
ENGINE
=
INNODB
;
--
connection
con1
--
error
ER_SPECIFIC_ACCESS_DENIED_ERROR
DROP
TABLE
innodb_monitor
;
--
error
ER_SPECIFIC_ACCESS_DENIED_ERROR
DROP
TABLE
innodb_mem_validate
;
--
connection
default
DROP
TABLE
innodb_monitor
;
DROP
TABLE
innodb_mem_validate
;
DROP
USER
'shane'
@
'localhost'
;
--
disconnect
con1
sql/mysql_priv.h
View file @
12d03195
...
@@ -1035,7 +1035,6 @@ bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
...
@@ -1035,7 +1035,6 @@ bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
bool
no_grant
,
bool
no_errors
,
bool
schema_db
);
bool
no_grant
,
bool
no_errors
,
bool
schema_db
);
bool
check_table_access
(
THD
*
thd
,
ulong
want_access
,
TABLE_LIST
*
tables
,
bool
check_table_access
(
THD
*
thd
,
ulong
want_access
,
TABLE_LIST
*
tables
,
uint
number
,
bool
no_errors
);
uint
number
,
bool
no_errors
);
bool
check_global_access
(
THD
*
thd
,
ulong
want_access
);
#else
#else
inline
bool
check_access
(
THD
*
thd
,
ulong
access
,
const
char
*
db
,
inline
bool
check_access
(
THD
*
thd
,
ulong
access
,
const
char
*
db
,
ulong
*
save_priv
,
bool
no_grant
,
bool
no_errors
,
ulong
*
save_priv
,
bool
no_grant
,
bool
no_errors
,
...
@@ -1048,9 +1047,18 @@ inline bool check_access(THD *thd, ulong access, const char *db,
...
@@ -1048,9 +1047,18 @@ inline bool check_access(THD *thd, ulong access, const char *db,
inline
bool
check_table_access
(
THD
*
thd
,
ulong
want_access
,
TABLE_LIST
*
tables
,
inline
bool
check_table_access
(
THD
*
thd
,
ulong
want_access
,
TABLE_LIST
*
tables
,
uint
number
,
bool
no_errors
)
uint
number
,
bool
no_errors
)
{
return
false
;
}
{
return
false
;
}
#endif
/*NO_EMBEDDED_ACCESS_CHECKS*/
#endif
/* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
#ifndef NO_EMBEDDED_ACCESS_CHECKS
bool
check_global_access
(
THD
*
thd
,
ulong
want_access
);
#else
inline
bool
check_global_access
(
THD
*
thd
,
ulong
want_access
)
inline
bool
check_global_access
(
THD
*
thd
,
ulong
want_access
)
{
return
false
;
}
{
return
false
;
}
#endif
/*NO_EMBEDDED_ACCESS_CHECKS*/
#endif
/*NO_EMBEDDED_ACCESS_CHECKS*/
#endif
/* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
/*
/*
Support routine for SQL parser on partitioning syntax
Support routine for SQL parser on partitioning syntax
...
...
sql/sql_class.cc
View file @
12d03195
...
@@ -682,6 +682,7 @@ void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size)
...
@@ -682,6 +682,7 @@ void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size)
return
thd
->
memdup
(
str
,
size
);
return
thd
->
memdup
(
str
,
size
);
}
}
extern
"C"
void
thd_get_xid
(
const
MYSQL_THD
thd
,
MYSQL_XID
*
xid
)
void
thd_get_xid
(
const
MYSQL_THD
thd
,
MYSQL_XID
*
xid
)
{
{
*
xid
=
*
(
MYSQL_XID
*
)
&
thd
->
transaction
.
xid_state
.
xid
;
*
xid
=
*
(
MYSQL_XID
*
)
&
thd
->
transaction
.
xid_state
.
xid
;
...
@@ -2760,6 +2761,17 @@ extern "C" int thd_killed(const MYSQL_THD thd)
...
@@ -2760,6 +2761,17 @@ extern "C" int thd_killed(const MYSQL_THD thd)
return
(
thd
->
killed
);
return
(
thd
->
killed
);
}
}
/**
Return the thread id of a user thread
@param thd user thread
@return thread id
*/
extern
"C"
unsigned
long
thd_get_thread_id
(
const
MYSQL_THD
thd
)
{
return
((
unsigned
long
)
thd
->
thread_id
);
}
#ifdef INNODB_COMPATIBILITY_HOOKS
#ifdef INNODB_COMPATIBILITY_HOOKS
extern
"C"
struct
charset_info_st
*
thd_charset
(
MYSQL_THD
thd
)
extern
"C"
struct
charset_info_st
*
thd_charset
(
MYSQL_THD
thd
)
{
{
...
...
storage/innobase/btr/btr0cur.c
View file @
12d03195
...
@@ -52,7 +52,7 @@ can be released by page reorganize, then it is reorganized */
...
@@ -52,7 +52,7 @@ can be released by page reorganize, then it is reorganized */
#define BTR_CUR_PAGE_REORGANIZE_LIMIT (UNIV_PAGE_SIZE / 32)
#define BTR_CUR_PAGE_REORGANIZE_LIMIT (UNIV_PAGE_SIZE / 32)
/* When estimating number of different k
ay values in an index
sample
/* When estimating number of different k
ey values in an index,
sample
this many index pages */
this many index pages */
#define BTR_KEY_VAL_ESTIMATE_N_PAGES 8
#define BTR_KEY_VAL_ESTIMATE_N_PAGES 8
...
...
storage/innobase/handler/ha_innodb.cc
View file @
12d03195
...
@@ -129,7 +129,7 @@ static my_bool innobase_locks_unsafe_for_binlog = FALSE;
...
@@ -129,7 +129,7 @@ static my_bool innobase_locks_unsafe_for_binlog = FALSE;
static
my_bool
innobase_rollback_on_timeout
=
FALSE
;
static
my_bool
innobase_rollback_on_timeout
=
FALSE
;
static
my_bool
innobase_create_status_file
=
FALSE
;
static
my_bool
innobase_create_status_file
=
FALSE
;
static
my_bool
innobase_stats_on_metadata
=
TRUE
;
static
my_bool
innobase_stats_on_metadata
=
TRUE
;
static
my_bool
innobase_
use_adaptive_hash_indexes
=
TRUE
;
static
my_bool
innobase_
adaptive_hash_index
=
TRUE
;
static
char
*
internal_innobase_data_file_path
=
NULL
;
static
char
*
internal_innobase_data_file_path
=
NULL
;
...
@@ -1627,7 +1627,7 @@ innobase_init(
...
@@ -1627,7 +1627,7 @@ innobase_init(
srv_stats_on_metadata
=
(
ibool
)
innobase_stats_on_metadata
;
srv_stats_on_metadata
=
(
ibool
)
innobase_stats_on_metadata
;
srv_use_adaptive_hash_indexes
=
srv_use_adaptive_hash_indexes
=
(
ibool
)
innobase_
use_adaptive_hash_indexes
;
(
ibool
)
innobase_
adaptive_hash_index
;
srv_print_verbose_log
=
mysqld_embedded
?
0
:
1
;
srv_print_verbose_log
=
mysqld_embedded
?
0
:
1
;
...
@@ -2275,6 +2275,8 @@ ha_innobase::open(
...
@@ -2275,6 +2275,8 @@ ha_innobase::open(
dict_table_t
*
ib_table
;
dict_table_t
*
ib_table
;
char
norm_name
[
1000
];
char
norm_name
[
1000
];
THD
*
thd
;
THD
*
thd
;
ulint
retries
=
0
;
char
*
is_part
=
NULL
;
DBUG_ENTER
(
"ha_innobase::open"
);
DBUG_ENTER
(
"ha_innobase::open"
);
...
@@ -2308,11 +2310,29 @@ ha_innobase::open(
...
@@ -2308,11 +2310,29 @@ ha_innobase::open(
DBUG_RETURN
(
1
);
DBUG_RETURN
(
1
);
}
}
/* We look for pattern #P# to see if the table is partitioned
MySQL table. The retry logic for partitioned tables is a
workaround for http://bugs.mysql.com/bug.php?id=33349. Look
at support issue https://support.mysql.com/view.php?id=21080
for more details. */
is_part
=
strstr
(
norm_name
,
"#P#"
);
retry:
/* Get pointer to a table object in InnoDB dictionary cache */
/* Get pointer to a table object in InnoDB dictionary cache */
ib_table
=
dict_table_get
(
norm_name
,
TRUE
);
ib_table
=
dict_table_get
(
norm_name
,
TRUE
);
if
(
NULL
==
ib_table
)
{
if
(
NULL
==
ib_table
)
{
if
(
is_part
&&
retries
<
10
)
{
++
retries
;
os_thread_sleep
(
100000
);
goto
retry
;
}
if
(
is_part
)
{
sql_print_error
(
"Failed to open table %s after "
"%lu attemtps.
\n
"
,
norm_name
,
retries
);
}
sql_print_error
(
"Cannot find or open table %s from
\n
"
sql_print_error
(
"Cannot find or open table %s from
\n
"
"the internal data dictionary of InnoDB "
"the internal data dictionary of InnoDB "
"though the .frm file for the
\n
"
"though the .frm file for the
\n
"
...
@@ -4625,6 +4645,12 @@ innodb_check_for_record_too_big_error(
...
@@ -4625,6 +4645,12 @@ innodb_check_for_record_too_big_error(
}
}
}
}
/* limit innodb monitor access to users with PROCESS privilege.
See http://bugs.mysql.com/32710 for expl. why we choose PROCESS. */
#define IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(table_name, thd) \
(row_is_magic_monitor_table(table_name) \
&& check_global_access(thd, PROCESS_ACL))
/*********************************************************************
/*********************************************************************
Creates a table definition to an InnoDB database. */
Creates a table definition to an InnoDB database. */
static
static
...
@@ -4661,6 +4687,12 @@ create_table_def(
...
@@ -4661,6 +4687,12 @@ create_table_def(
DBUG_ENTER
(
"create_table_def"
);
DBUG_ENTER
(
"create_table_def"
);
DBUG_PRINT
(
"enter"
,
(
"table_name: %s"
,
table_name
));
DBUG_PRINT
(
"enter"
,
(
"table_name: %s"
,
table_name
));
ut_a
(
trx
->
mysql_thd
!=
NULL
);
if
(
IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS
(
table_name
,
(
THD
*
)
trx
->
mysql_thd
))
{
DBUG_RETURN
(
HA_ERR_GENERIC
);
}
n_cols
=
form
->
s
->
fields
;
n_cols
=
form
->
s
->
fields
;
/* We pass 0 as the space id, and determine at a lower level the space
/* We pass 0 as the space id, and determine at a lower level the space
...
@@ -5201,6 +5233,14 @@ ha_innobase::delete_table(
...
@@ -5201,6 +5233,14 @@ ha_innobase::delete_table(
DBUG_ENTER
(
"ha_innobase::delete_table"
);
DBUG_ENTER
(
"ha_innobase::delete_table"
);
/* Strangely, MySQL passes the table name without the '.frm'
extension, in contrast to ::create */
normalize_table_name
(
norm_name
,
name
);
if
(
IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS
(
norm_name
,
thd
))
{
DBUG_RETURN
(
HA_ERR_GENERIC
);
}
/* Get the transaction associated with the current thd, or create one
/* Get the transaction associated with the current thd, or create one
if not yet created */
if not yet created */
...
@@ -5234,11 +5274,6 @@ ha_innobase::delete_table(
...
@@ -5234,11 +5274,6 @@ ha_innobase::delete_table(
assert
(
name_len
<
1000
);
assert
(
name_len
<
1000
);
/* Strangely, MySQL passes the table name without the '.frm'
extension, in contrast to ::create */
normalize_table_name
(
norm_name
,
name
);
/* Drop the table in InnoDB */
/* Drop the table in InnoDB */
error
=
row_drop_table_for_mysql
(
norm_name
,
trx
,
error
=
row_drop_table_for_mysql
(
norm_name
,
trx
,
...
@@ -7988,9 +8023,10 @@ static MYSQL_SYSVAR_BOOL(stats_on_metadata, innobase_stats_on_metadata,
...
@@ -7988,9 +8023,10 @@ static MYSQL_SYSVAR_BOOL(stats_on_metadata, innobase_stats_on_metadata,
"Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)"
,
"Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)"
,
NULL
,
NULL
,
TRUE
);
NULL
,
NULL
,
TRUE
);
static
MYSQL_SYSVAR_BOOL
(
use_adaptive_hash_indexes
,
innobase_use_adaptive_hash_indexes
,
static
MYSQL_SYSVAR_BOOL
(
adaptive_hash_index
,
innobase_adaptive_hash_index
,
PLUGIN_VAR_OPCMDARG
|
PLUGIN_VAR_READONLY
,
PLUGIN_VAR_OPCMDARG
|
PLUGIN_VAR_READONLY
,
"Enable the InnoDB adaptive hash indexes (enabled by default)"
,
"Enable InnoDB adaptive hash index (enabled by default). "
"Disable with --skip-innodb-adaptive-hash-index."
,
NULL
,
NULL
,
TRUE
);
NULL
,
NULL
,
TRUE
);
static
MYSQL_SYSVAR_LONG
(
additional_mem_pool_size
,
innobase_additional_mem_pool_size
,
static
MYSQL_SYSVAR_LONG
(
additional_mem_pool_size
,
innobase_additional_mem_pool_size
,
...
@@ -8080,10 +8116,11 @@ static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path,
...
@@ -8080,10 +8116,11 @@ static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path,
static
MYSQL_SYSVAR_LONG
(
autoinc_lock_mode
,
innobase_autoinc_lock_mode
,
static
MYSQL_SYSVAR_LONG
(
autoinc_lock_mode
,
innobase_autoinc_lock_mode
,
PLUGIN_VAR_RQCMDARG
|
PLUGIN_VAR_READONLY
,
PLUGIN_VAR_RQCMDARG
|
PLUGIN_VAR_READONLY
,
"The AUTOINC lock modes supported by InnoDB:
\n
"
"The AUTOINC lock modes supported by InnoDB: "
" 0 => Old style AUTOINC locking (for backward compatibility)
\n
"
"0 => Old style AUTOINC locking (for backward"
" 1 => New style AUTOINC locking
\n
"
" compatibility) "
" 2 => No AUTOINC locking (unsafe for SBR)"
,
"1 => New style AUTOINC locking "
"2 => No AUTOINC locking (unsafe for SBR)"
,
NULL
,
NULL
,
NULL
,
NULL
,
AUTOINC_NEW_STYLE_LOCKING
,
/* Default setting */
AUTOINC_NEW_STYLE_LOCKING
,
/* Default setting */
AUTOINC_OLD_STYLE_LOCKING
,
/* Minimum value */
AUTOINC_OLD_STYLE_LOCKING
,
/* Minimum value */
...
@@ -8121,7 +8158,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
...
@@ -8121,7 +8158,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
MYSQL_SYSVAR
(
open_files
),
MYSQL_SYSVAR
(
open_files
),
MYSQL_SYSVAR
(
rollback_on_timeout
),
MYSQL_SYSVAR
(
rollback_on_timeout
),
MYSQL_SYSVAR
(
stats_on_metadata
),
MYSQL_SYSVAR
(
stats_on_metadata
),
MYSQL_SYSVAR
(
use_adaptive_hash_indexes
),
MYSQL_SYSVAR
(
adaptive_hash_index
),
MYSQL_SYSVAR
(
status_file
),
MYSQL_SYSVAR
(
status_file
),
MYSQL_SYSVAR
(
support_xa
),
MYSQL_SYSVAR
(
support_xa
),
MYSQL_SYSVAR
(
sync_spin_loops
),
MYSQL_SYSVAR
(
sync_spin_loops
),
...
...
storage/innobase/include/os0sync.h
View file @
12d03195
...
@@ -112,9 +112,13 @@ os_event_set(
...
@@ -112,9 +112,13 @@ os_event_set(
os_event_t
event
);
/* in: event to set */
os_event_t
event
);
/* in: event to set */
/**************************************************************
/**************************************************************
Resets an event semaphore to the nonsignaled state. Waiting threads will
Resets an event semaphore to the nonsignaled state. Waiting threads will
stop to wait for the event. */
stop to wait for the event.
The return value should be passed to os_even_wait_low() if it is desired
that this thread should not wait in case of an intervening call to
os_event_set() between this os_event_reset() and the
os_event_wait_low() call. See comments for os_event_wait_low(). */
void
ib_longlong
os_event_reset
(
os_event_reset
(
/*===========*/
/*===========*/
os_event_t
event
);
/* in: event to reset */
os_event_t
event
);
/* in: event to reset */
...
@@ -125,16 +129,38 @@ void
...
@@ -125,16 +129,38 @@ void
os_event_free
(
os_event_free
(
/*==========*/
/*==========*/
os_event_t
event
);
/* in: event to free */
os_event_t
event
);
/* in: event to free */
/**************************************************************
/**************************************************************
Waits for an event object until it is in the signaled state. If
Waits for an event object until it is in the signaled state. If
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
waiting thread when the event becomes signaled (or immediately if the
waiting thread when the event becomes signaled (or immediately if the
event is already in the signaled state). */
event is already in the signaled state).
Typically, if the event has been signalled after the os_event_reset()
we'll return immediately because event->is_set == TRUE.
There are, however, situations (e.g.: sync_array code) where we may
lose this information. For example:
thread A calls os_event_reset()
thread B calls os_event_set() [event->is_set == TRUE]
thread C calls os_event_reset() [event->is_set == FALSE]
thread A calls os_event_wait() [infinite wait!]
thread C calls os_event_wait() [infinite wait!]
Where such a scenario is possible, to avoid infinite wait, the
value returned by os_event_reset() should be passed in as
reset_sig_count. */
#define os_event_wait(event) os_event_wait_low((event), 0)
void
void
os_event_wait
(
os_event_wait_low
(
/*==========*/
/*==============*/
os_event_t
event
);
/* in: event to wait */
os_event_t
event
,
/* in: event to wait */
ib_longlong
reset_sig_count
);
/* in: zero or the value
returned by previous call of
os_event_reset(). */
/**************************************************************
/**************************************************************
Waits for an event object until it is in the signaled state or
Waits for an event object until it is in the signaled state or
a timeout is exceeded. In Unix the timeout is always infinite. */
a timeout is exceeded. In Unix the timeout is always infinite. */
...
...
storage/innobase/include/read0read.h
View file @
12d03195
...
@@ -111,10 +111,6 @@ struct read_view_struct{
...
@@ -111,10 +111,6 @@ struct read_view_struct{
dulint
undo_no
;
/* (0, 0) or if type is VIEW_HIGH_GRANULARITY
dulint
undo_no
;
/* (0, 0) or if type is VIEW_HIGH_GRANULARITY
transaction undo_no when this high-granularity
transaction undo_no when this high-granularity
consistent read view was created */
consistent read view was created */
ibool
can_be_too_old
;
/* TRUE if the system has had to purge old
versions which this read view should be able
to access: the read view can bump into the
DB_MISSING_HISTORY error */
dulint
low_limit_no
;
/* The view does not need to see the undo
dulint
low_limit_no
;
/* The view does not need to see the undo
logs for transactions whose transaction number
logs for transactions whose transaction number
is strictly smaller (<) than this value: they
is strictly smaller (<) than this value: they
...
...
storage/innobase/include/row0mysql.h
View file @
12d03195
...
@@ -319,7 +319,7 @@ row_mysql_unfreeze_data_dictionary(
...
@@ -319,7 +319,7 @@ row_mysql_unfreeze_data_dictionary(
/*===============================*/
/*===============================*/
trx_t
*
trx
);
/* in: transaction */
trx_t
*
trx
);
/* in: transaction */
/*************************************************************************
/*************************************************************************
Drop
s a table for MySQL. If the name of the table ends in
Create
s a table for MySQL. If the name of the table ends in
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
"innodb_table_monitor", then this will also start the printing of monitor
"innodb_table_monitor", then this will also start the printing of monitor
output by the master thread. If the table name ends in "innodb_mem_validate",
output by the master thread. If the table name ends in "innodb_mem_validate",
...
@@ -464,6 +464,16 @@ row_check_table_for_mysql(
...
@@ -464,6 +464,16 @@ row_check_table_for_mysql(
row_prebuilt_t
*
prebuilt
);
/* in: prebuilt struct in MySQL
row_prebuilt_t
*
prebuilt
);
/* in: prebuilt struct in MySQL
handle */
handle */
/*************************************************************************
Determines if a table is a magic monitor table. */
ibool
row_is_magic_monitor_table
(
/*=======================*/
/* out: TRUE if monitor table */
const
char
*
table_name
);
/* in: name of the table, in the
form database/table_name */
/* A struct describing a place for an individual column in the MySQL
/* A struct describing a place for an individual column in the MySQL
row format which is presented to the table handler in ha_innobase.
row format which is presented to the table handler in ha_innobase.
This template struct is used to speed up row transformations between
This template struct is used to speed up row transformations between
...
...
storage/innobase/include/sync0arr.h
View file @
12d03195
...
@@ -66,26 +66,21 @@ sync_array_wait_event(
...
@@ -66,26 +66,21 @@ sync_array_wait_event(
sync_array_t
*
arr
,
/* in: wait array */
sync_array_t
*
arr
,
/* in: wait array */
ulint
index
);
/* in: index of the reserved cell */
ulint
index
);
/* in: index of the reserved cell */
/**********************************************************************
/**********************************************************************
Frees the cell
safely by reserving the sync array mutex and decrementing
Frees the cell
. NOTE! sync_array_wait_event frees the cell
n_reserved if necessary. Should only be called from mutex_spin_wait.
*/
automatically!
*/
void
void
sync_array_free_cell
_protected
(
sync_array_free_cell
(
/*=================
==========
*/
/*=================*/
sync_array_t
*
arr
,
/* in: wait array */
sync_array_t
*
arr
,
/* in: wait array */
ulint
index
);
/* in: index of the cell in array */
ulint
index
);
/* in: index of the cell in array */
/**************************************************************************
/**************************************************************************
Looks for the cells in the wait array which refer
Note that one of the wait objects was signalled. */
to the wait object specified,
and sets their corresponding events to the signaled state. In this
way releases the threads waiting for the object to contend for the object.
It is possible that no such cell is found, in which case does nothing. */
void
void
sync_array_signal_object
(
sync_array_object_signalled
(
/*=====================*/
/*========================*/
sync_array_t
*
arr
,
/* in: wait array */
sync_array_t
*
arr
);
/* in: wait array */
void
*
object
);
/* in: wait object */
/**************************************************************************
/**************************************************************************
If the wakeup algorithm does not work perfectly at semaphore relases,
If the wakeup algorithm does not work perfectly at semaphore relases,
this function will do the waking (see the comment in mutex_exit). This
this function will do the waking (see the comment in mutex_exit). This
...
...
storage/innobase/include/sync0rw.h
View file @
12d03195
...
@@ -421,6 +421,18 @@ blocked by readers, a writer may queue for the lock by setting the writer
...
@@ -421,6 +421,18 @@ blocked by readers, a writer may queue for the lock by setting the writer
field. Then no new readers are allowed in. */
field. Then no new readers are allowed in. */
struct
rw_lock_struct
{
struct
rw_lock_struct
{
os_event_t
event
;
/* Used by sync0arr.c for thread queueing */
#ifdef __WIN__
os_event_t
wait_ex_event
;
/* This windows specific event is
used by the thread which has set the
lock state to RW_LOCK_WAIT_EX. The
rw_lock design guarantees that this
thread will be the next one to proceed
once the current the event gets
signalled. See LEMMA 2 in sync0sync.c */
#endif
ulint
reader_count
;
/* Number of readers who have locked this
ulint
reader_count
;
/* Number of readers who have locked this
lock in the shared mode */
lock in the shared mode */
ulint
writer
;
/* This field is set to RW_LOCK_EX if there
ulint
writer
;
/* This field is set to RW_LOCK_EX if there
...
...
storage/innobase/include/sync0rw.ic
View file @
12d03195
...
@@ -381,7 +381,11 @@ rw_lock_s_unlock_func(
...
@@ -381,7 +381,11 @@ rw_lock_s_unlock_func(
mutex_exit(mutex);
mutex_exit(mutex);
if (UNIV_UNLIKELY(sg)) {
if (UNIV_UNLIKELY(sg)) {
sync_array_signal_object(sync_primary_wait_array, lock);
#ifdef __WIN__
os_event_set(lock->wait_ex_event);
#endif
os_event_set(lock->event);
sync_array_object_signalled(sync_primary_wait_array);
}
}
ut_ad(rw_lock_validate(lock));
ut_ad(rw_lock_validate(lock));
...
@@ -461,7 +465,11 @@ rw_lock_x_unlock_func(
...
@@ -461,7 +465,11 @@ rw_lock_x_unlock_func(
mutex_exit(&(lock->mutex));
mutex_exit(&(lock->mutex));
if (UNIV_UNLIKELY(sg)) {
if (UNIV_UNLIKELY(sg)) {
sync_array_signal_object(sync_primary_wait_array, lock);
#ifdef __WIN__
os_event_set(lock->wait_ex_event);
#endif
os_event_set(lock->event);
sync_array_object_signalled(sync_primary_wait_array);
}
}
ut_ad(rw_lock_validate(lock));
ut_ad(rw_lock_validate(lock));
...
...
storage/innobase/include/sync0sync.h
View file @
12d03195
...
@@ -470,6 +470,7 @@ Do not use its fields directly! The structure used in the spin lock
...
@@ -470,6 +470,7 @@ Do not use its fields directly! The structure used in the spin lock
implementation of a mutual exclusion semaphore. */
implementation of a mutual exclusion semaphore. */
struct
mutex_struct
{
struct
mutex_struct
{
os_event_t
event
;
/* Used by sync0arr.c for the wait queue */
ulint
lock_word
;
/* This ulint is the target of the atomic
ulint
lock_word
;
/* This ulint is the target of the atomic
test-and-set instruction in Win32 */
test-and-set instruction in Win32 */
#if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)
#if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)
...
...
storage/innobase/include/sync0sync.ic
View file @
12d03195
...
@@ -211,7 +211,7 @@ mutex_exit(
...
@@ -211,7 +211,7 @@ mutex_exit(
perform the read first, which could leave a waiting
perform the read first, which could leave a waiting
thread hanging indefinitely.
thread hanging indefinitely.
Our current solution call every
10 seconds
Our current solution call every
second
sync_arr_wake_threads_if_sema_free()
sync_arr_wake_threads_if_sema_free()
to wake up possible hanging threads if
to wake up possible hanging threads if
they are missed in mutex_signal_object. */
they are missed in mutex_signal_object. */
...
...
storage/innobase/os/os0sync.c
View file @
12d03195
...
@@ -21,6 +21,7 @@ Created 9/6/1995 Heikki Tuuri
...
@@ -21,6 +21,7 @@ Created 9/6/1995 Heikki Tuuri
/* Type definition for an operating system mutex struct */
/* Type definition for an operating system mutex struct */
struct
os_mutex_struct
{
struct
os_mutex_struct
{
os_event_t
event
;
/* Used by sync0arr.c for queing threads */
void
*
handle
;
/* OS handle to mutex */
void
*
handle
;
/* OS handle to mutex */
ulint
count
;
/* we use this counter to check
ulint
count
;
/* we use this counter to check
that the same thread does not
that the same thread does not
...
@@ -35,6 +36,7 @@ struct os_mutex_struct{
...
@@ -35,6 +36,7 @@ struct os_mutex_struct{
/* Mutex protecting counts and the lists of OS mutexes and events */
/* Mutex protecting counts and the lists of OS mutexes and events */
os_mutex_t
os_sync_mutex
;
os_mutex_t
os_sync_mutex
;
ibool
os_sync_mutex_inited
=
FALSE
;
ibool
os_sync_mutex_inited
=
FALSE
;
ibool
os_sync_free_called
=
FALSE
;
/* This is incremented by 1 in os_thread_create and decremented by 1 in
/* This is incremented by 1 in os_thread_create and decremented by 1 in
os_thread_exit */
os_thread_exit */
...
@@ -50,6 +52,10 @@ ulint os_event_count = 0;
...
@@ -50,6 +52,10 @@ ulint os_event_count = 0;
ulint
os_mutex_count
=
0
;
ulint
os_mutex_count
=
0
;
ulint
os_fast_mutex_count
=
0
;
ulint
os_fast_mutex_count
=
0
;
/* Because a mutex is embedded inside an event and there is an
event embedded inside a mutex, on free, this generates a recursive call.
This version of the free event function doesn't acquire the global lock */
static
void
os_event_free_internal
(
os_event_t
event
);
/*************************************************************
/*************************************************************
Initializes global event and OS 'slow' mutex lists. */
Initializes global event and OS 'slow' mutex lists. */
...
@@ -76,6 +82,7 @@ os_sync_free(void)
...
@@ -76,6 +82,7 @@ os_sync_free(void)
os_event_t
event
;
os_event_t
event
;
os_mutex_t
mutex
;
os_mutex_t
mutex
;
os_sync_free_called
=
TRUE
;
event
=
UT_LIST_GET_FIRST
(
os_event_list
);
event
=
UT_LIST_GET_FIRST
(
os_event_list
);
while
(
event
)
{
while
(
event
)
{
...
@@ -99,6 +106,7 @@ os_sync_free(void)
...
@@ -99,6 +106,7 @@ os_sync_free(void)
mutex
=
UT_LIST_GET_FIRST
(
os_mutex_list
);
mutex
=
UT_LIST_GET_FIRST
(
os_mutex_list
);
}
}
os_sync_free_called
=
FALSE
;
}
}
/*************************************************************
/*************************************************************
...
@@ -144,17 +152,31 @@ os_event_create(
...
@@ -144,17 +152,31 @@ os_event_create(
ut_a
(
0
==
pthread_cond_init
(
&
(
event
->
cond_var
),
NULL
));
ut_a
(
0
==
pthread_cond_init
(
&
(
event
->
cond_var
),
NULL
));
#endif
#endif
event
->
is_set
=
FALSE
;
event
->
is_set
=
FALSE
;
event
->
signal_count
=
0
;
/* We return this value in os_event_reset(), which can then be
be used to pass to the os_event_wait_low(). The value of zero
is reserved in os_event_wait_low() for the case when the
caller does not want to pass any signal_count value. To
distinguish between the two cases we initialize signal_count
to 1 here. */
event
->
signal_count
=
1
;
#endif
/* __WIN__ */
#endif
/* __WIN__ */
/* Put to the list of events */
/* The os_sync_mutex can be NULL because during startup an event
can be created [ because it's embedded in the mutex/rwlock ] before
this module has been initialized */
if
(
os_sync_mutex
!=
NULL
)
{
os_mutex_enter
(
os_sync_mutex
);
os_mutex_enter
(
os_sync_mutex
);
}
/* Put to the list of events */
UT_LIST_ADD_FIRST
(
os_event_list
,
os_event_list
,
event
);
UT_LIST_ADD_FIRST
(
os_event_list
,
os_event_list
,
event
);
os_event_count
++
;
os_event_count
++
;
if
(
os_sync_mutex
!=
NULL
)
{
os_mutex_exit
(
os_sync_mutex
);
os_mutex_exit
(
os_sync_mutex
);
}
return
(
event
);
return
(
event
);
}
}
...
@@ -231,13 +253,20 @@ os_event_set(
...
@@ -231,13 +253,20 @@ os_event_set(
/**************************************************************
/**************************************************************
Resets an event semaphore to the nonsignaled state. Waiting threads will
Resets an event semaphore to the nonsignaled state. Waiting threads will
stop to wait for the event. */
stop to wait for the event.
The return value should be passed to os_even_wait_low() if it is desired
that this thread should not wait in case of an intervening call to
os_event_set() between this os_event_reset() and the
os_event_wait_low() call. See comments for os_event_wait_low(). */
void
ib_longlong
os_event_reset
(
os_event_reset
(
/*===========*/
/*===========*/
/* out: current signal_count. */
os_event_t
event
)
/* in: event to reset */
os_event_t
event
)
/* in: event to reset */
{
{
ib_longlong
ret
=
0
;
#ifdef __WIN__
#ifdef __WIN__
ut_a
(
event
);
ut_a
(
event
);
...
@@ -252,9 +281,40 @@ os_event_reset(
...
@@ -252,9 +281,40 @@ os_event_reset(
}
else
{
}
else
{
event
->
is_set
=
FALSE
;
event
->
is_set
=
FALSE
;
}
}
ret
=
event
->
signal_count
;
os_fast_mutex_unlock
(
&
(
event
->
os_mutex
));
os_fast_mutex_unlock
(
&
(
event
->
os_mutex
));
#endif
#endif
return
(
ret
);
}
/**************************************************************
Frees an event object, without acquiring the global lock. */
static
void
os_event_free_internal
(
/*===================*/
os_event_t
event
)
/* in: event to free */
{
#ifdef __WIN__
ut_a
(
event
);
ut_a
(
CloseHandle
(
event
->
handle
));
#else
ut_a
(
event
);
/* This is to avoid freeing the mutex twice */
os_fast_mutex_free
(
&
(
event
->
os_mutex
));
ut_a
(
0
==
pthread_cond_destroy
(
&
(
event
->
cond_var
)));
#endif
/* Remove from the list of events */
UT_LIST_REMOVE
(
os_event_list
,
os_event_list
,
event
);
os_event_count
--
;
ut_free
(
event
);
}
}
/**************************************************************
/**************************************************************
...
@@ -293,18 +353,38 @@ os_event_free(
...
@@ -293,18 +353,38 @@ os_event_free(
Waits for an event object until it is in the signaled state. If
Waits for an event object until it is in the signaled state. If
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
waiting thread when the event becomes signaled (or immediately if the
waiting thread when the event becomes signaled (or immediately if the
event is already in the signaled state). */
event is already in the signaled state).
Typically, if the event has been signalled after the os_event_reset()
we'll return immediately because event->is_set == TRUE.
There are, however, situations (e.g.: sync_array code) where we may
lose this information. For example:
thread A calls os_event_reset()
thread B calls os_event_set() [event->is_set == TRUE]
thread C calls os_event_reset() [event->is_set == FALSE]
thread A calls os_event_wait() [infinite wait!]
thread C calls os_event_wait() [infinite wait!]
Where such a scenario is possible, to avoid infinite wait, the
value returned by os_event_reset() should be passed in as
reset_sig_count. */
void
void
os_event_wait
(
os_event_wait_low
(
/*==========*/
/*==============*/
os_event_t
event
)
/* in: event to wait */
os_event_t
event
,
/* in: event to wait */
ib_longlong
reset_sig_count
)
/* in: zero or the value
returned by previous call of
os_event_reset(). */
{
{
#ifdef __WIN__
#ifdef __WIN__
DWORD
err
;
DWORD
err
;
ut_a
(
event
);
ut_a
(
event
);
UT_NOT_USED
(
reset_sig_count
);
/* Specify an infinite time limit for waiting */
/* Specify an infinite time limit for waiting */
err
=
WaitForSingleObject
(
event
->
handle
,
INFINITE
);
err
=
WaitForSingleObject
(
event
->
handle
,
INFINITE
);
...
@@ -318,7 +398,11 @@ os_event_wait(
...
@@ -318,7 +398,11 @@ os_event_wait(
os_fast_mutex_lock
(
&
(
event
->
os_mutex
));
os_fast_mutex_lock
(
&
(
event
->
os_mutex
));
if
(
reset_sig_count
)
{
old_signal_count
=
reset_sig_count
;
}
else
{
old_signal_count
=
event
->
signal_count
;
old_signal_count
=
event
->
signal_count
;
}
for
(;;)
{
for
(;;)
{
if
(
event
->
is_set
==
TRUE
if
(
event
->
is_set
==
TRUE
...
@@ -458,6 +542,7 @@ os_mutex_create(
...
@@ -458,6 +542,7 @@ os_mutex_create(
mutex_str
->
handle
=
mutex
;
mutex_str
->
handle
=
mutex
;
mutex_str
->
count
=
0
;
mutex_str
->
count
=
0
;
mutex_str
->
event
=
os_event_create
(
NULL
);
if
(
os_sync_mutex_inited
)
{
if
(
os_sync_mutex_inited
)
{
/* When creating os_sync_mutex itself we cannot reserve it */
/* When creating os_sync_mutex itself we cannot reserve it */
...
@@ -534,6 +619,10 @@ os_mutex_free(
...
@@ -534,6 +619,10 @@ os_mutex_free(
{
{
ut_a
(
mutex
);
ut_a
(
mutex
);
if
(
!
os_sync_free_called
)
{
os_event_free_internal
(
mutex
->
event
);
}
if
(
os_sync_mutex_inited
)
{
if
(
os_sync_mutex_inited
)
{
os_mutex_enter
(
os_sync_mutex
);
os_mutex_enter
(
os_sync_mutex
);
}
}
...
...
storage/innobase/read/read0read.c
View file @
12d03195
...
@@ -212,7 +212,6 @@ read_view_oldest_copy_or_open_new(
...
@@ -212,7 +212,6 @@ read_view_oldest_copy_or_open_new(
view_copy
->
low_limit_no
=
old_view
->
low_limit_no
;
view_copy
->
low_limit_no
=
old_view
->
low_limit_no
;
view_copy
->
low_limit_id
=
old_view
->
low_limit_id
;
view_copy
->
low_limit_id
=
old_view
->
low_limit_id
;
view_copy
->
can_be_too_old
=
FALSE
;
if
(
n
>
0
)
{
if
(
n
>
0
)
{
/* The last active transaction has the smallest id: */
/* The last active transaction has the smallest id: */
...
@@ -258,8 +257,6 @@ read_view_open_now(
...
@@ -258,8 +257,6 @@ read_view_open_now(
view
->
low_limit_no
=
trx_sys
->
max_trx_id
;
view
->
low_limit_no
=
trx_sys
->
max_trx_id
;
view
->
low_limit_id
=
view
->
low_limit_no
;
view
->
low_limit_id
=
view
->
low_limit_no
;
view
->
can_be_too_old
=
FALSE
;
n
=
0
;
n
=
0
;
trx
=
UT_LIST_GET_FIRST
(
trx_sys
->
trx_list
);
trx
=
UT_LIST_GET_FIRST
(
trx_sys
->
trx_list
);
...
@@ -432,8 +429,6 @@ read_cursor_view_create_for_mysql(
...
@@ -432,8 +429,6 @@ read_cursor_view_create_for_mysql(
view
->
low_limit_no
=
trx_sys
->
max_trx_id
;
view
->
low_limit_no
=
trx_sys
->
max_trx_id
;
view
->
low_limit_id
=
view
->
low_limit_no
;
view
->
low_limit_id
=
view
->
low_limit_no
;
view
->
can_be_too_old
=
FALSE
;
n
=
0
;
n
=
0
;
trx
=
UT_LIST_GET_FIRST
(
trx_sys
->
trx_list
);
trx
=
UT_LIST_GET_FIRST
(
trx_sys
->
trx_list
);
...
...
storage/innobase/row/row0mysql.c
View file @
12d03195
...
@@ -57,6 +57,12 @@ static const char S_innodb_tablespace_monitor[] = "innodb_tablespace_monitor";
...
@@ -57,6 +57,12 @@ static const char S_innodb_tablespace_monitor[] = "innodb_tablespace_monitor";
static
const
char
S_innodb_table_monitor
[]
=
"innodb_table_monitor"
;
static
const
char
S_innodb_table_monitor
[]
=
"innodb_table_monitor"
;
static
const
char
S_innodb_mem_validate
[]
=
"innodb_mem_validate"
;
static
const
char
S_innodb_mem_validate
[]
=
"innodb_mem_validate"
;
/* Evaluates to true if str1 equals str2_onstack, used for comparing
the above strings. */
#define STR_EQ(str1, str1_len, str2_onstack) \
((str1_len) == sizeof(str2_onstack) \
&& memcmp(str1, str2_onstack, sizeof(str2_onstack)) == 0)
/***********************************************************************
/***********************************************************************
Determine if the given name is a name reserved for MySQL system tables. */
Determine if the given name is a name reserved for MySQL system tables. */
static
static
...
@@ -1728,7 +1734,7 @@ row_mysql_unlock_data_dictionary(
...
@@ -1728,7 +1734,7 @@ row_mysql_unlock_data_dictionary(
}
}
/*************************************************************************
/*************************************************************************
Drop
s a table for MySQL. If the name of the table ends in
Create
s a table for MySQL. If the name of the table ends in
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
"innodb_table_monitor", then this will also start the printing of monitor
"innodb_table_monitor", then this will also start the printing of monitor
output by the master thread. If the table name ends in "innodb_mem_validate",
output by the master thread. If the table name ends in "innodb_mem_validate",
...
@@ -1809,9 +1815,7 @@ row_create_table_for_mysql(
...
@@ -1809,9 +1815,7 @@ row_create_table_for_mysql(
table_name
++
;
table_name
++
;
table_name_len
=
strlen
(
table_name
)
+
1
;
table_name_len
=
strlen
(
table_name
)
+
1
;
if
(
table_name_len
==
sizeof
S_innodb_monitor
if
(
STR_EQ
(
table_name
,
table_name_len
,
S_innodb_monitor
))
{
&&
!
memcmp
(
table_name
,
S_innodb_monitor
,
sizeof
S_innodb_monitor
))
{
/* Table equals "innodb_monitor":
/* Table equals "innodb_monitor":
start monitor prints */
start monitor prints */
...
@@ -1822,28 +1826,24 @@ row_create_table_for_mysql(
...
@@ -1822,28 +1826,24 @@ row_create_table_for_mysql(
of InnoDB monitor prints */
of InnoDB monitor prints */
os_event_set
(
srv_lock_timeout_thread_event
);
os_event_set
(
srv_lock_timeout_thread_event
);
}
else
if
(
table_name_len
==
sizeof
S_innodb_lock_monitor
}
else
if
(
STR_EQ
(
table_name
,
table_name_len
,
&&
!
memcmp
(
table_name
,
S_innodb_lock_monitor
,
S_innodb_lock_monitor
))
{
sizeof
S_innodb_lock_monitor
))
{
srv_print_innodb_monitor
=
TRUE
;
srv_print_innodb_monitor
=
TRUE
;
srv_print_innodb_lock_monitor
=
TRUE
;
srv_print_innodb_lock_monitor
=
TRUE
;
os_event_set
(
srv_lock_timeout_thread_event
);
os_event_set
(
srv_lock_timeout_thread_event
);
}
else
if
(
table_name_len
==
sizeof
S_innodb_tablespace_monitor
}
else
if
(
STR_EQ
(
table_name
,
table_name_len
,
&&
!
memcmp
(
table_name
,
S_innodb_tablespace_monitor
,
S_innodb_tablespace_monitor
))
{
sizeof
S_innodb_tablespace_monitor
))
{
srv_print_innodb_tablespace_monitor
=
TRUE
;
srv_print_innodb_tablespace_monitor
=
TRUE
;
os_event_set
(
srv_lock_timeout_thread_event
);
os_event_set
(
srv_lock_timeout_thread_event
);
}
else
if
(
table_name_len
==
sizeof
S_innodb_table_monitor
}
else
if
(
STR_EQ
(
table_name
,
table_name_len
,
&&
!
memcmp
(
table_name
,
S_innodb_table_monitor
,
S_innodb_table_monitor
))
{
sizeof
S_innodb_table_monitor
))
{
srv_print_innodb_table_monitor
=
TRUE
;
srv_print_innodb_table_monitor
=
TRUE
;
os_event_set
(
srv_lock_timeout_thread_event
);
os_event_set
(
srv_lock_timeout_thread_event
);
}
else
if
(
table_name_len
==
sizeof
S_innodb_mem_validate
}
else
if
(
STR_EQ
(
table_name
,
table_name_len
,
&&
!
memcmp
(
table_name
,
S_innodb_mem_validate
,
S_innodb_mem_validate
))
{
sizeof
S_innodb_mem_validate
))
{
/* We define here a debugging feature intended for
/* We define here a debugging feature intended for
developers */
developers */
...
@@ -4130,3 +4130,33 @@ row_check_table_for_mysql(
...
@@ -4130,3 +4130,33 @@ row_check_table_for_mysql(
return
(
ret
);
return
(
ret
);
}
}
/*************************************************************************
Determines if a table is a magic monitor table. */
ibool
row_is_magic_monitor_table
(
/*=======================*/
/* out: TRUE if monitor table */
const
char
*
table_name
)
/* in: name of the table, in the
form database/table_name */
{
const
char
*
name
;
/* table_name without database/ */
ulint
len
;
name
=
strchr
(
table_name
,
'/'
);
ut_a
(
name
!=
NULL
);
name
++
;
len
=
strlen
(
name
)
+
1
;
if
(
STR_EQ
(
name
,
len
,
S_innodb_monitor
)
||
STR_EQ
(
name
,
len
,
S_innodb_lock_monitor
)
||
STR_EQ
(
name
,
len
,
S_innodb_tablespace_monitor
)
||
STR_EQ
(
name
,
len
,
S_innodb_table_monitor
)
||
STR_EQ
(
name
,
len
,
S_innodb_mem_validate
))
{
return
(
TRUE
);
}
return
(
FALSE
);
}
storage/innobase/srv/srv0srv.c
View file @
12d03195
...
@@ -1904,12 +1904,6 @@ loop:
...
@@ -1904,12 +1904,6 @@ loop:
os_thread_sleep
(
1000000
);
os_thread_sleep
(
1000000
);
/* In case mutex_exit is not a memory barrier, it is
theoretically possible some threads are left waiting though
the semaphore is already released. Wake up those threads: */
sync_arr_wake_threads_if_sema_free
();
current_time
=
time
(
NULL
);
current_time
=
time
(
NULL
);
time_elapsed
=
difftime
(
current_time
,
last_monitor_time
);
time_elapsed
=
difftime
(
current_time
,
last_monitor_time
);
...
@@ -2106,9 +2100,15 @@ loop:
...
@@ -2106,9 +2100,15 @@ loop:
srv_refresh_innodb_monitor_stats
();
srv_refresh_innodb_monitor_stats
();
}
}
/* In case mutex_exit is not a memory barrier, it is
theoretically possible some threads are left waiting though
the semaphore is already released. Wake up those threads: */
sync_arr_wake_threads_if_sema_free
();
if
(
sync_array_print_long_waits
())
{
if
(
sync_array_print_long_waits
())
{
fatal_cnt
++
;
fatal_cnt
++
;
if
(
fatal_cnt
>
5
)
{
if
(
fatal_cnt
>
10
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"InnoDB: Error: semaphore wait has lasted"
"InnoDB: Error: semaphore wait has lasted"
...
@@ -2128,7 +2128,7 @@ loop:
...
@@ -2128,7 +2128,7 @@ loop:
fflush
(
stderr
);
fflush
(
stderr
);
os_thread_sleep
(
2
000000
);
os_thread_sleep
(
1
000000
);
if
(
srv_shutdown_state
<
SRV_SHUTDOWN_CLEANUP
)
{
if
(
srv_shutdown_state
<
SRV_SHUTDOWN_CLEANUP
)
{
...
...
storage/innobase/sync/sync0arr.c
View file @
12d03195
...
@@ -40,24 +40,23 @@ because we can do with a very small number of OS events,
...
@@ -40,24 +40,23 @@ because we can do with a very small number of OS events,
say 200. In NT 3.51, allocating events seems to be a quadratic
say 200. In NT 3.51, allocating events seems to be a quadratic
algorithm, because 10 000 events are created fast, but
algorithm, because 10 000 events are created fast, but
100 000 events takes a couple of minutes to create.
100 000 events takes a couple of minutes to create.
*/
As of 5.0.30 the above mentioned design is changed. Since now
OS can handle millions of wait events efficiently, we no longer
have this concept of each cell of wait array having one event.
Instead, now the event that a thread wants to wait on is embedded
in the wait object (mutex or rw_lock). We still keep the global
wait array for the sake of diagnostics and also to avoid infinite
wait The error_monitor thread scans the global wait array to signal
any waiting threads who have missed the signal. */
/* A cell where an individual thread may wait suspended
/* A cell where an individual thread may wait suspended
until a resource is released. The suspending is implemented
until a resource is released. The suspending is implemented
using an operating system event semaphore. */
using an operating system event semaphore. */
struct
sync_cell_struct
{
struct
sync_cell_struct
{
/* State of the cell. SC_WAKING_UP means
sync_array_struct->n_reserved has been decremented, but the thread
in this cell has not waken up yet. When it does, it will set the
state to SC_FREE. Note that this is done without the protection of
any mutex. */
enum
{
SC_FREE
,
SC_RESERVED
,
SC_WAKING_UP
}
state
;
void
*
wait_object
;
/* pointer to the object the
void
*
wait_object
;
/* pointer to the object the
thread is waiting for; this is not
thread is waiting for; if NULL
reseted to NULL when a cell is
the cell is free for use */
freed. */
mutex_t
*
old_wait_mutex
;
/* the latest wait mutex in cell */
mutex_t
*
old_wait_mutex
;
/* the latest wait mutex in cell */
rw_lock_t
*
old_wait_rw_lock
;
/* the latest wait rw-lock in cell */
rw_lock_t
*
old_wait_rw_lock
;
/* the latest wait rw-lock in cell */
ulint
request_type
;
/* lock type requested on the
ulint
request_type
;
/* lock type requested on the
...
@@ -71,13 +70,23 @@ struct sync_cell_struct {
...
@@ -71,13 +70,23 @@ struct sync_cell_struct {
ibool
waiting
;
/* TRUE if the thread has already
ibool
waiting
;
/* TRUE if the thread has already
called sync_array_event_wait
called sync_array_event_wait
on this cell */
on this cell */
ibool
event_set
;
/* TRUE if the event is set */
ib_longlong
signal_count
;
/* We capture the signal_count
os_event_t
event
;
/* operating system event
of the wait_object when we
semaphore handle */
reset the event. This value is
then passed on to os_event_wait
and we wait only if the event
has not been signalled in the
period between the reset and
wait call. */
time_t
reservation_time
;
/* time when the thread reserved
time_t
reservation_time
;
/* time when the thread reserved
the wait cell */
the wait cell */
};
};
/* NOTE: It is allowed for a thread to wait
for an event allocated for the array without owning the
protecting mutex (depending on the case: OS or database mutex), but
all changes (set or reset) to the state of the event must be made
while owning the mutex. */
struct
sync_array_struct
{
struct
sync_array_struct
{
ulint
n_reserved
;
/* number of currently reserved
ulint
n_reserved
;
/* number of currently reserved
cells in the wait array */
cells in the wait array */
...
@@ -220,12 +229,9 @@ sync_array_create(
...
@@ -220,12 +229,9 @@ sync_array_create(
for
(
i
=
0
;
i
<
n_cells
;
i
++
)
{
for
(
i
=
0
;
i
<
n_cells
;
i
++
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
->
state
=
SC_FREE
;
cell
->
wait_object
=
NULL
;
cell
->
wait_object
=
NULL
;
cell
->
waiting
=
FALSE
;
/* Create an operating system event semaphore with no name */
cell
->
signal_count
=
0
;
cell
->
event
=
os_event_create
(
NULL
);
cell
->
event_set
=
FALSE
;
/* it is created in reset state */
}
}
return
(
arr
);
return
(
arr
);
...
@@ -239,19 +245,12 @@ sync_array_free(
...
@@ -239,19 +245,12 @@ sync_array_free(
/*============*/
/*============*/
sync_array_t
*
arr
)
/* in, own: sync wait array */
sync_array_t
*
arr
)
/* in, own: sync wait array */
{
{
ulint
i
;
sync_cell_t
*
cell
;
ulint
protection
;
ulint
protection
;
ut_a
(
arr
->
n_reserved
==
0
);
ut_a
(
arr
->
n_reserved
==
0
);
sync_array_validate
(
arr
);
sync_array_validate
(
arr
);
for
(
i
=
0
;
i
<
arr
->
n_cells
;
i
++
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
os_event_free
(
cell
->
event
);
}
protection
=
arr
->
protection
;
protection
=
arr
->
protection
;
/* Release the mutex protecting the wait array complex */
/* Release the mutex protecting the wait array complex */
...
@@ -285,8 +284,7 @@ sync_array_validate(
...
@@ -285,8 +284,7 @@ sync_array_validate(
for
(
i
=
0
;
i
<
arr
->
n_cells
;
i
++
)
{
for
(
i
=
0
;
i
<
arr
->
n_cells
;
i
++
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
if
(
cell
->
wait_object
!=
NULL
)
{
if
(
cell
->
state
==
SC_RESERVED
)
{
count
++
;
count
++
;
}
}
}
}
...
@@ -296,6 +294,29 @@ sync_array_validate(
...
@@ -296,6 +294,29 @@ sync_array_validate(
sync_array_exit
(
arr
);
sync_array_exit
(
arr
);
}
}
/***********************************************************************
Puts the cell event in reset state. */
static
ib_longlong
sync_cell_event_reset
(
/*==================*/
/* out: value of signal_count
at the time of reset. */
ulint
type
,
/* in: lock type mutex/rw_lock */
void
*
object
)
/* in: the rw_lock/mutex object */
{
if
(
type
==
SYNC_MUTEX
)
{
return
(
os_event_reset
(((
mutex_t
*
)
object
)
->
event
));
#ifdef __WIN__
}
else
if
(
type
==
RW_LOCK_WAIT_EX
)
{
return
(
os_event_reset
(
((
rw_lock_t
*
)
object
)
->
wait_ex_event
));
#endif
}
else
{
return
(
os_event_reset
(((
rw_lock_t
*
)
object
)
->
event
));
}
}
/**********************************************************************
/**********************************************************************
Reserves a wait array cell for waiting for an object.
Reserves a wait array cell for waiting for an object.
The event of the cell is reset to nonsignalled state. */
The event of the cell is reset to nonsignalled state. */
...
@@ -324,21 +345,9 @@ sync_array_reserve_cell(
...
@@ -324,21 +345,9 @@ sync_array_reserve_cell(
for
(
i
=
0
;
i
<
arr
->
n_cells
;
i
++
)
{
for
(
i
=
0
;
i
<
arr
->
n_cells
;
i
++
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
if
(
cell
->
state
==
SC_FREE
)
{
if
(
cell
->
wait_object
==
NULL
)
{
/* We do not check cell->event_set because it is
set outside the protection of the sync array mutex
and we had a bug regarding it, and since resetting
an event when it is not needed does no harm it is
safer always to do it. */
cell
->
event_set
=
FALSE
;
os_event_reset
(
cell
->
event
);
cell
->
state
=
SC_RESERVED
;
cell
->
reservation_time
=
time
(
NULL
);
cell
->
thread
=
os_thread_get_curr_id
();
cell
->
waiting
=
FALSE
;
cell
->
wait_object
=
object
;
cell
->
wait_object
=
object
;
if
(
type
==
SYNC_MUTEX
)
{
if
(
type
==
SYNC_MUTEX
)
{
...
@@ -348,7 +357,6 @@ sync_array_reserve_cell(
...
@@ -348,7 +357,6 @@ sync_array_reserve_cell(
}
}
cell
->
request_type
=
type
;
cell
->
request_type
=
type
;
cell
->
waiting
=
FALSE
;
cell
->
file
=
file
;
cell
->
file
=
file
;
cell
->
line
=
line
;
cell
->
line
=
line
;
...
@@ -359,6 +367,16 @@ sync_array_reserve_cell(
...
@@ -359,6 +367,16 @@ sync_array_reserve_cell(
sync_array_exit
(
arr
);
sync_array_exit
(
arr
);
/* Make sure the event is reset and also store
the value of signal_count at which the event
was reset. */
cell
->
signal_count
=
sync_cell_event_reset
(
type
,
object
);
cell
->
reservation_time
=
time
(
NULL
);
cell
->
thread
=
os_thread_get_curr_id
();
return
;
return
;
}
}
}
}
...
@@ -368,68 +386,6 @@ sync_array_reserve_cell(
...
@@ -368,68 +386,6 @@ sync_array_reserve_cell(
return
;
return
;
}
}
/**********************************************************************
Frees the cell. Note that we don't have any mutex reserved when calling
this. */
static
void
sync_array_free_cell
(
/*=================*/
sync_array_t
*
arr
,
/* in: wait array */
ulint
index
)
/* in: index of the cell in array */
{
sync_cell_t
*
cell
;
cell
=
sync_array_get_nth_cell
(
arr
,
index
);
ut_a
(
cell
->
state
==
SC_WAKING_UP
);
ut_a
(
cell
->
wait_object
!=
NULL
);
cell
->
state
=
SC_FREE
;
}
/**********************************************************************
Frees the cell safely by reserving the sync array mutex and decrementing
n_reserved if necessary. Should only be called from mutex_spin_wait. */
void
sync_array_free_cell_protected
(
/*===========================*/
sync_array_t
*
arr
,
/* in: wait array */
ulint
index
)
/* in: index of the cell in array */
{
sync_cell_t
*
cell
;
sync_array_enter
(
arr
);
cell
=
sync_array_get_nth_cell
(
arr
,
index
);
ut_a
(
cell
->
state
!=
SC_FREE
);
ut_a
(
cell
->
wait_object
!=
NULL
);
/* We only need to decrement n_reserved if it has not already been
done by sync_array_signal_object. */
if
(
cell
->
state
==
SC_RESERVED
)
{
ut_a
(
arr
->
n_reserved
>
0
);
arr
->
n_reserved
--
;
}
else
if
(
cell
->
state
==
SC_WAKING_UP
)
{
/* This is tricky; if we don't wait for the event to be
signaled, signal_object can set the state of a cell to
SC_WAKING_UP, mutex_spin_wait can call this and set the
state to SC_FREE, and then signal_object gets around to
calling os_set_event for the cell but since it's already
been freed things break horribly. */
sync_array_exit
(
arr
);
os_event_wait
(
cell
->
event
);
sync_array_enter
(
arr
);
}
cell
->
state
=
SC_FREE
;
sync_array_exit
(
arr
);
}
/**********************************************************************
/**********************************************************************
This function should be called when a thread starts to wait on
This function should be called when a thread starts to wait on
a wait array cell. In the debug version this function checks
a wait array cell. In the debug version this function checks
...
@@ -447,14 +403,27 @@ sync_array_wait_event(
...
@@ -447,14 +403,27 @@ sync_array_wait_event(
ut_a
(
arr
);
ut_a
(
arr
);
sync_array_enter
(
arr
);
cell
=
sync_array_get_nth_cell
(
arr
,
index
);
cell
=
sync_array_get_nth_cell
(
arr
,
index
);
ut_a
((
cell
->
state
==
SC_RESERVED
)
||
(
cell
->
state
==
SC_WAKING_UP
));
ut_a
(
cell
->
wait_object
);
ut_a
(
cell
->
wait_object
);
ut_a
(
!
cell
->
waiting
);
ut_a
(
!
cell
->
waiting
);
ut_ad
(
os_thread_get_curr_id
()
==
cell
->
thread
);
ut_ad
(
os_thread_get_curr_id
()
==
cell
->
thread
);
event
=
cell
->
event
;
if
(
cell
->
request_type
==
SYNC_MUTEX
)
{
event
=
((
mutex_t
*
)
cell
->
wait_object
)
->
event
;
#ifdef __WIN__
/* On windows if the thread about to wait is the one which
has set the state of the rw_lock to RW_LOCK_WAIT_EX, then
it waits on a special event i.e.: wait_ex_event. */
}
else
if
(
cell
->
request_type
==
RW_LOCK_WAIT_EX
)
{
event
=
((
rw_lock_t
*
)
cell
->
wait_object
)
->
wait_ex_event
;
#endif
}
else
{
event
=
((
rw_lock_t
*
)
cell
->
wait_object
)
->
event
;
}
cell
->
waiting
=
TRUE
;
cell
->
waiting
=
TRUE
;
#ifdef UNIV_SYNC_DEBUG
#ifdef UNIV_SYNC_DEBUG
...
@@ -464,7 +433,6 @@ sync_array_wait_event(
...
@@ -464,7 +433,6 @@ sync_array_wait_event(
recursively sync_array routines, leading to trouble.
recursively sync_array routines, leading to trouble.
rw_lock_debug_mutex freezes the debug lists. */
rw_lock_debug_mutex freezes the debug lists. */
sync_array_enter
(
arr
);
rw_lock_debug_mutex_enter
();
rw_lock_debug_mutex_enter
();
if
(
TRUE
==
sync_array_detect_deadlock
(
arr
,
cell
,
cell
,
0
))
{
if
(
TRUE
==
sync_array_detect_deadlock
(
arr
,
cell
,
cell
,
0
))
{
...
@@ -474,16 +442,16 @@ sync_array_wait_event(
...
@@ -474,16 +442,16 @@ sync_array_wait_event(
}
}
rw_lock_debug_mutex_exit
();
rw_lock_debug_mutex_exit
();
sync_array_exit
(
arr
);
#endif
#endif
os_event_wait
(
event
);
sync_array_exit
(
arr
);
os_event_wait_low
(
event
,
cell
->
signal_count
);
sync_array_free_cell
(
arr
,
index
);
sync_array_free_cell
(
arr
,
index
);
}
}
/**********************************************************************
/**********************************************************************
Reports info of a wait array cell. Note: sync_array_print_long_waits()
Reports info of a wait array cell. */
calls this without mutex protection. */
static
static
void
void
sync_array_cell_print
(
sync_array_cell_print
(
...
@@ -503,17 +471,8 @@ sync_array_cell_print(
...
@@ -503,17 +471,8 @@ sync_array_cell_print(
(
ulong
)
os_thread_pf
(
cell
->
thread
),
cell
->
file
,
(
ulong
)
os_thread_pf
(
cell
->
thread
),
cell
->
file
,
(
ulong
)
cell
->
line
,
(
ulong
)
cell
->
line
,
difftime
(
time
(
NULL
),
cell
->
reservation_time
));
difftime
(
time
(
NULL
),
cell
->
reservation_time
));
fprintf
(
file
,
"Wait array cell state %lu
\n
"
,
(
ulong
)
cell
->
state
);
/* If the memory area pointed to by old_wait_mutex /
old_wait_rw_lock has been freed, this can crash. */
if
(
cell
->
state
!=
SC_RESERVED
)
{
/* If cell has this state, then even if we are holding the sync
array mutex, the wait object may get freed meanwhile. Do not
print the wait object then. */
}
else
if
(
type
==
SYNC_MUTEX
)
{
if
(
type
==
SYNC_MUTEX
)
{
/* We use old_wait_mutex in case the cell has already
/* We use old_wait_mutex in case the cell has already
been freed meanwhile */
been freed meanwhile */
mutex
=
cell
->
old_wait_mutex
;
mutex
=
cell
->
old_wait_mutex
;
...
@@ -531,7 +490,11 @@ sync_array_cell_print(
...
@@ -531,7 +490,11 @@ sync_array_cell_print(
#endif
/* UNIV_SYNC_DEBUG */
#endif
/* UNIV_SYNC_DEBUG */
(
ulong
)
mutex
->
waiters
);
(
ulong
)
mutex
->
waiters
);
}
else
if
(
type
==
RW_LOCK_EX
||
type
==
RW_LOCK_SHARED
)
{
}
else
if
(
type
==
RW_LOCK_EX
#ifdef __WIN__
||
type
==
RW_LOCK_WAIT_EX
#endif
||
type
==
RW_LOCK_SHARED
)
{
fputs
(
type
==
RW_LOCK_EX
?
"X-lock on"
:
"S-lock on"
,
file
);
fputs
(
type
==
RW_LOCK_EX
?
"X-lock on"
:
"S-lock on"
,
file
);
...
@@ -565,8 +528,8 @@ sync_array_cell_print(
...
@@ -565,8 +528,8 @@ sync_array_cell_print(
ut_error
;
ut_error
;
}
}
if
(
cell
->
event_set
)
{
if
(
!
cell
->
waiting
)
{
fputs
(
"wait
is ending
\n
"
,
file
);
fputs
(
"wait
has ended
\n
"
,
file
);
}
}
}
}
...
@@ -589,7 +552,7 @@ sync_array_find_thread(
...
@@ -589,7 +552,7 @@ sync_array_find_thread(
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
if
(
(
cell
->
state
==
SC_RESERVED
)
if
(
cell
->
wait_object
!=
NULL
&&
os_thread_eq
(
cell
->
thread
,
thread
))
{
&&
os_thread_eq
(
cell
->
thread
,
thread
))
{
return
(
cell
);
/* Found */
return
(
cell
);
/* Found */
...
@@ -679,7 +642,7 @@ sync_array_detect_deadlock(
...
@@ -679,7 +642,7 @@ sync_array_detect_deadlock(
depth
++
;
depth
++
;
if
(
cell
->
event_set
||
!
cell
->
waiting
)
{
if
(
!
cell
->
waiting
)
{
return
(
FALSE
);
/* No deadlock here */
return
(
FALSE
);
/* No deadlock here */
}
}
...
@@ -704,10 +667,8 @@ sync_array_detect_deadlock(
...
@@ -704,10 +667,8 @@ sync_array_detect_deadlock(
depth
);
depth
);
if
(
ret
)
{
if
(
ret
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Mutex %p owned by thread %lu"
"Mutex %p owned by thread %lu file %s line %lu
\n
"
,
" file %s line %lu
\n
"
,
mutex
,
(
ulong
)
os_thread_pf
(
mutex
->
thread_id
),
(
void
*
)
mutex
,
(
ulong
)
os_thread_pf
(
mutex
->
thread_id
),
mutex
->
file_name
,
(
ulong
)
mutex
->
line
);
mutex
->
file_name
,
(
ulong
)
mutex
->
line
);
sync_array_cell_print
(
stderr
,
cell
);
sync_array_cell_print
(
stderr
,
cell
);
...
@@ -717,7 +678,8 @@ sync_array_detect_deadlock(
...
@@ -717,7 +678,8 @@ sync_array_detect_deadlock(
return
(
FALSE
);
/* No deadlock */
return
(
FALSE
);
/* No deadlock */
}
else
if
(
cell
->
request_type
==
RW_LOCK_EX
)
{
}
else
if
(
cell
->
request_type
==
RW_LOCK_EX
||
cell
->
request_type
==
RW_LOCK_WAIT_EX
)
{
lock
=
cell
->
wait_object
;
lock
=
cell
->
wait_object
;
...
@@ -816,7 +778,8 @@ sync_arr_cell_can_wake_up(
...
@@ -816,7 +778,8 @@ sync_arr_cell_can_wake_up(
return
(
TRUE
);
return
(
TRUE
);
}
}
}
else
if
(
cell
->
request_type
==
RW_LOCK_EX
)
{
}
else
if
(
cell
->
request_type
==
RW_LOCK_EX
||
cell
->
request_type
==
RW_LOCK_WAIT_EX
)
{
lock
=
cell
->
wait_object
;
lock
=
cell
->
wait_object
;
...
@@ -845,101 +808,47 @@ sync_arr_cell_can_wake_up(
...
@@ -845,101 +808,47 @@ sync_arr_cell_can_wake_up(
return
(
FALSE
);
return
(
FALSE
);
}
}
/**************************************************************************
/**********************************************************************
Looks for the cells in the wait array which refer to the wait object
Frees the cell. NOTE! sync_array_wait_event frees the cell
specified, and sets their corresponding events to the signaled state. In this
automatically! */
way releases the threads waiting for the object to contend for the object.
It is possible that no such cell is found, in which case does nothing. */
void
void
sync_array_
signal_object
(
sync_array_
free_cell
(
/*=================
====
*/
/*=================*/
sync_array_t
*
arr
,
/* in: wait array */
sync_array_t
*
arr
,
/* in: wait array */
void
*
object
)
/* in: wait object
*/
ulint
index
)
/* in: index of the cell in array
*/
{
{
sync_cell_t
*
cell
;
sync_cell_t
*
cell
;
ulint
count
;
ulint
i
;
ulint
res_count
;
/* We store the addresses of cells we need to signal and signal
them only after we have released the sync array's mutex (for
performance reasons). cell_count is the number of such cells, and
cell_ptr points to the first one. If there are less than
UT_ARR_SIZE(cells) of them, cell_ptr == &cells[0], otherwise
cell_ptr points to malloc'd memory that we must free. */
sync_cell_t
*
cells
[
100
];
sync_cell_t
**
cell_ptr
=
&
cells
[
0
];
ulint
cell_count
=
0
;
ulint
cell_max_count
=
UT_ARR_SIZE
(
cells
);
ut_a
(
100
==
cell_max_count
);
sync_array_enter
(
arr
);
sync_array_enter
(
arr
);
arr
->
sg_count
++
;
cell
=
sync_array_get_nth_cell
(
arr
,
index
);
i
=
0
;
count
=
0
;
/* We need to store this to a local variable because it is modified
inside the loop */
res_count
=
arr
->
n_reserved
;
while
(
count
<
res_count
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
if
(
cell
->
state
==
SC_RESERVED
)
{
ut_a
(
cell
->
wait_object
!=
NULL
);
count
++
;
cell
->
waiting
=
FALSE
;
if
(
cell
->
wait_object
==
object
)
{
cell
->
wait_object
=
NULL
;
cell
->
state
=
SC_WAKING_UP
;
cell
->
signal_count
=
0
;
ut_a
(
arr
->
n_reserved
>
0
);
ut_a
(
arr
->
n_reserved
>
0
);
arr
->
n_reserved
--
;
arr
->
n_reserved
--
;
if
(
cell_count
==
cell_max_count
)
{
sync_array_exit
(
arr
);
sync_cell_t
**
old_cell_ptr
=
cell_ptr
;
}
size_t
old_size
,
new_size
;
old_size
=
cell_max_count
*
sizeof
(
sync_cell_t
*
);
cell_max_count
*=
2
;
new_size
=
cell_max_count
*
sizeof
(
sync_cell_t
*
);
cell_ptr
=
malloc
(
new_size
);
ut_a
(
cell_ptr
);
memcpy
(
cell_ptr
,
old_cell_ptr
,
old_size
);
if
(
old_cell_ptr
!=
&
cells
[
0
])
{
/**************************************************************************
free
(
old_cell_ptr
);
Increments the signalled count. */
}
}
cell_ptr
[
cell_count
]
=
cell
;
void
cell_count
++
;
sync_array_object_signalled
(
}
/*========================*/
}
sync_array_t
*
arr
)
/* in: wait array */
{
sync_array_enter
(
arr
);
i
++
;
arr
->
sg_count
++
;
}
sync_array_exit
(
arr
);
sync_array_exit
(
arr
);
for
(
i
=
0
;
i
<
cell_count
;
i
++
)
{
cell
=
cell_ptr
[
i
];
cell
->
event_set
=
TRUE
;
os_event_set
(
cell
->
event
);
}
if
(
cell_ptr
!=
&
cells
[
0
])
{
free
(
cell_ptr
);
}
}
}
/**************************************************************************
/**************************************************************************
...
@@ -959,33 +868,41 @@ sync_arr_wake_threads_if_sema_free(void)
...
@@ -959,33 +868,41 @@ sync_arr_wake_threads_if_sema_free(void)
sync_cell_t
*
cell
;
sync_cell_t
*
cell
;
ulint
count
;
ulint
count
;
ulint
i
;
ulint
i
;
ulint
res_count
;
sync_array_enter
(
arr
);
sync_array_enter
(
arr
);
i
=
0
;
i
=
0
;
count
=
0
;
count
=
0
;
/* We need to store this to a local variable because it is modified
while
(
count
<
arr
->
n_reserved
)
{
inside the loop */
res_count
=
arr
->
n_reserved
;
while
(
count
<
res_count
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
if
(
cell
->
state
==
SC_RESERVED
)
{
if
(
cell
->
wait_object
!=
NULL
)
{
count
++
;
count
++
;
if
(
sync_arr_cell_can_wake_up
(
cell
))
{
if
(
sync_arr_cell_can_wake_up
(
cell
))
{
cell
->
state
=
SC_WAKING_UP
;
cell
->
event_set
=
TRUE
;
os_event_set
(
cell
->
event
);
ut_a
(
arr
->
n_reserved
>
0
);
if
(
cell
->
request_type
==
SYNC_MUTEX
)
{
arr
->
n_reserved
--
;
mutex_t
*
mutex
;
mutex
=
cell
->
wait_object
;
os_event_set
(
mutex
->
event
);
#ifdef __WIN__
}
else
if
(
cell
->
request_type
==
RW_LOCK_WAIT_EX
)
{
rw_lock_t
*
lock
;
lock
=
cell
->
wait_object
;
os_event_set
(
lock
->
wait_ex_event
);
#endif
}
else
{
rw_lock_t
*
lock
;
lock
=
cell
->
wait_object
;
os_event_set
(
lock
->
event
);
}
}
}
}
}
...
@@ -1015,7 +932,7 @@ sync_array_print_long_waits(void)
...
@@ -1015,7 +932,7 @@ sync_array_print_long_waits(void)
cell
=
sync_array_get_nth_cell
(
sync_primary_wait_array
,
i
);
cell
=
sync_array_get_nth_cell
(
sync_primary_wait_array
,
i
);
if
(
(
cell
->
state
!=
SC_FREE
)
if
(
cell
->
wait_object
!=
NULL
&&
cell
->
waiting
&&
difftime
(
time
(
NULL
),
cell
->
reservation_time
)
>
240
)
{
&&
difftime
(
time
(
NULL
),
cell
->
reservation_time
)
>
240
)
{
fputs
(
"InnoDB: Warning: a long semaphore wait:
\n
"
,
fputs
(
"InnoDB: Warning: a long semaphore wait:
\n
"
,
stderr
);
stderr
);
...
@@ -1023,7 +940,7 @@ sync_array_print_long_waits(void)
...
@@ -1023,7 +940,7 @@ sync_array_print_long_waits(void)
noticed
=
TRUE
;
noticed
=
TRUE
;
}
}
if
(
(
cell
->
state
!=
SC_FREE
)
if
(
cell
->
wait_object
!=
NULL
&&
cell
->
waiting
&&
difftime
(
time
(
NULL
),
cell
->
reservation_time
)
&&
difftime
(
time
(
NULL
),
cell
->
reservation_time
)
>
fatal_timeout
)
{
>
fatal_timeout
)
{
fatal
=
TRUE
;
fatal
=
TRUE
;
...
@@ -1072,20 +989,25 @@ sync_array_output_info(
...
@@ -1072,20 +989,25 @@ sync_array_output_info(
mutex */
mutex */
{
{
sync_cell_t
*
cell
;
sync_cell_t
*
cell
;
ulint
count
;
ulint
i
;
ulint
i
;
fprintf
(
file
,
fprintf
(
file
,
"OS WAIT ARRAY INFO: reservation count %ld,"
"OS WAIT ARRAY INFO: reservation count %ld, signal count %ld
\n
"
,
" signal count %ld
\n
"
,
(
long
)
arr
->
res_count
,
(
long
)
arr
->
sg_count
);
(
long
)
arr
->
res_count
,
i
=
0
;
(
long
)
arr
->
sg_count
);
count
=
0
;
for
(
i
=
0
;
i
<
arr
->
n_cells
;
i
++
)
{
while
(
count
<
arr
->
n_reserved
)
{
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
cell
=
sync_array_get_nth_cell
(
arr
,
i
);
if
(
cell
->
state
!=
SC_FREE
)
{
if
(
cell
->
wait_object
!=
NULL
)
{
count
++
;
sync_array_cell_print
(
file
,
cell
);
sync_array_cell_print
(
file
,
cell
);
}
}
i
++
;
}
}
}
}
...
...
storage/innobase/sync/sync0rw.c
View file @
12d03195
...
@@ -151,6 +151,11 @@ rw_lock_create_func(
...
@@ -151,6 +151,11 @@ rw_lock_create_func(
lock
->
last_x_file_name
=
"not yet reserved"
;
lock
->
last_x_file_name
=
"not yet reserved"
;
lock
->
last_s_line
=
0
;
lock
->
last_s_line
=
0
;
lock
->
last_x_line
=
0
;
lock
->
last_x_line
=
0
;
lock
->
event
=
os_event_create
(
NULL
);
#ifdef __WIN__
lock
->
wait_ex_event
=
os_event_create
(
NULL
);
#endif
mutex_enter
(
&
rw_lock_list_mutex
);
mutex_enter
(
&
rw_lock_list_mutex
);
...
@@ -184,6 +189,11 @@ rw_lock_free(
...
@@ -184,6 +189,11 @@ rw_lock_free(
mutex_free
(
rw_lock_get_mutex
(
lock
));
mutex_free
(
rw_lock_get_mutex
(
lock
));
mutex_enter
(
&
rw_lock_list_mutex
);
mutex_enter
(
&
rw_lock_list_mutex
);
os_event_free
(
lock
->
event
);
#ifdef __WIN__
os_event_free
(
lock
->
wait_ex_event
);
#endif
if
(
UT_LIST_GET_PREV
(
list
,
lock
))
{
if
(
UT_LIST_GET_PREV
(
list
,
lock
))
{
ut_a
(
UT_LIST_GET_PREV
(
list
,
lock
)
->
magic_n
==
RW_LOCK_MAGIC_N
);
ut_a
(
UT_LIST_GET_PREV
(
list
,
lock
)
->
magic_n
==
RW_LOCK_MAGIC_N
);
...
@@ -544,7 +554,15 @@ lock_loop:
...
@@ -544,7 +554,15 @@ lock_loop:
rw_x_system_call_count
++
;
rw_x_system_call_count
++
;
sync_array_reserve_cell
(
sync_primary_wait_array
,
sync_array_reserve_cell
(
sync_primary_wait_array
,
lock
,
RW_LOCK_EX
,
lock
,
#ifdef __WIN__
/* On windows RW_LOCK_WAIT_EX signifies
that this thread should wait on the
special wait_ex_event. */
(
state
==
RW_LOCK_WAIT_EX
)
?
RW_LOCK_WAIT_EX
:
#endif
RW_LOCK_EX
,
file_name
,
line
,
file_name
,
line
,
&
index
);
&
index
);
...
...
storage/innobase/sync/sync0sync.c
View file @
12d03195
...
@@ -95,17 +95,47 @@ have happened that the thread which was holding the mutex has just released
...
@@ -95,17 +95,47 @@ have happened that the thread which was holding the mutex has just released
it and did not see the waiters byte set to 1, a case which would lead the
it and did not see the waiters byte set to 1, a case which would lead the
other thread to an infinite wait.
other thread to an infinite wait.
LEMMA 1: After a thread resets the event of
the cell it reserves for waiting
LEMMA 1: After a thread resets the event of
a mutex (or rw_lock), some
=======
=
=======
for a mutex, some thread will eventually call sync_array_signal_object with
thread will eventually call os_event_set() on that particular event.
the mutex as an argument. Thus no infinite wait is possibl
e.
Thus no infinite wait is possible in this cas
e.
Proof: After making the reservation the thread sets the waiters field in the
Proof: After making the reservation the thread sets the waiters field in the
mutex to 1. Then it checks that the mutex is still reserved by some thread,
mutex to 1. Then it checks that the mutex is still reserved by some thread,
or it reserves the mutex for itself. In any case, some thread (which may be
or it reserves the mutex for itself. In any case, some thread (which may be
also some earlier thread, not necessarily the one currently holding the mutex)
also some earlier thread, not necessarily the one currently holding the mutex)
will set the waiters field to 0 in mutex_exit, and then call
will set the waiters field to 0 in mutex_exit, and then call
sync_array_signal_object with the mutex as an argument.
os_event_set() with the mutex as an argument.
Q.E.D.
LEMMA 2: If an os_event_set() call is made after some thread has called
=======
the os_event_reset() and before it starts wait on that event, the call
will not be lost to the second thread. This is true even if there is an
intervening call to os_event_reset() by another thread.
Thus no infinite wait is possible in this case.
Proof (non-windows platforms): os_event_reset() returns a monotonically
increasing value of signal_count. This value is increased at every
call of os_event_set() If thread A has called os_event_reset() followed
by thread B calling os_event_set() and then some other thread C calling
os_event_reset(), the is_set flag of the event will be set to FALSE;
but now if thread A calls os_event_wait_low() with the signal_count
value returned from the earlier call of os_event_reset(), it will
return immediately without waiting.
Q.E.D.
Proof (windows): If there is a writer thread which is forced to wait for
the lock, it may be able to set the state of rw_lock to RW_LOCK_WAIT_EX
The design of rw_lock ensures that there is one and only one thread
that is able to change the state to RW_LOCK_WAIT_EX and this thread is
guaranteed to acquire the lock after it is released by the current
holders and before any other waiter gets the lock.
On windows this thread waits on a separate event i.e.: wait_ex_event.
Since only one thread can wait on this event there is no chance
of this event getting reset before the writer starts wait on it.
Therefore, this thread is guaranteed to catch the os_set_event()
signalled unconditionally at the release of the lock.
Q.E.D. */
Q.E.D. */
/* The number of system calls made in this module. Intended for performance
/* The number of system calls made in this module. Intended for performance
...
@@ -217,6 +247,7 @@ mutex_create_func(
...
@@ -217,6 +247,7 @@ mutex_create_func(
os_fast_mutex_init
(
&
(
mutex
->
os_fast_mutex
));
os_fast_mutex_init
(
&
(
mutex
->
os_fast_mutex
));
mutex
->
lock_word
=
0
;
mutex
->
lock_word
=
0
;
#endif
#endif
mutex
->
event
=
os_event_create
(
NULL
);
mutex_set_waiters
(
mutex
,
0
);
mutex_set_waiters
(
mutex
,
0
);
#ifdef UNIV_DEBUG
#ifdef UNIV_DEBUG
mutex
->
magic_n
=
MUTEX_MAGIC_N
;
mutex
->
magic_n
=
MUTEX_MAGIC_N
;
...
@@ -300,6 +331,8 @@ mutex_free(
...
@@ -300,6 +331,8 @@ mutex_free(
mutex_exit
(
&
mutex_list_mutex
);
mutex_exit
(
&
mutex_list_mutex
);
}
}
os_event_free
(
mutex
->
event
);
#if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)
#if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)
os_fast_mutex_free
(
&
(
mutex
->
os_fast_mutex
));
os_fast_mutex_free
(
&
(
mutex
->
os_fast_mutex
));
#endif
#endif
...
@@ -509,8 +542,7 @@ spin_loop:
...
@@ -509,8 +542,7 @@ spin_loop:
if
(
mutex_test_and_set
(
mutex
)
==
0
)
{
if
(
mutex_test_and_set
(
mutex
)
==
0
)
{
/* Succeeded! Free the reserved wait cell */
/* Succeeded! Free the reserved wait cell */
sync_array_free_cell_protected
(
sync_primary_wait_array
,
sync_array_free_cell
(
sync_primary_wait_array
,
index
);
index
);
ut_d
(
mutex
->
thread_id
=
os_thread_get_curr_id
());
ut_d
(
mutex
->
thread_id
=
os_thread_get_curr_id
());
#ifdef UNIV_SYNC_DEBUG
#ifdef UNIV_SYNC_DEBUG
...
@@ -591,8 +623,8 @@ mutex_signal_object(
...
@@ -591,8 +623,8 @@ mutex_signal_object(
/* The memory order of resetting the waiters field and
/* The memory order of resetting the waiters field and
signaling the object is important. See LEMMA 1 above. */
signaling the object is important. See LEMMA 1 above. */
os_event_set
(
mutex
->
event
);
sync_array_
signal_object
(
sync_primary_wait_array
,
mutex
);
sync_array_
object_signalled
(
sync_primary_wait_array
);
}
}
#ifdef UNIV_SYNC_DEBUG
#ifdef UNIV_SYNC_DEBUG
...
@@ -1130,6 +1162,7 @@ sync_thread_add_level(
...
@@ -1130,6 +1162,7 @@ sync_thread_add_level(
break
;
break
;
case
SYNC_TREE_NODE
:
case
SYNC_TREE_NODE
:
ut_a
(
sync_thread_levels_contain
(
array
,
SYNC_INDEX_TREE
)
ut_a
(
sync_thread_levels_contain
(
array
,
SYNC_INDEX_TREE
)
||
sync_thread_levels_contain
(
array
,
SYNC_DICT_OPERATION
)
||
sync_thread_levels_g
(
array
,
SYNC_TREE_NODE
-
1
));
||
sync_thread_levels_g
(
array
,
SYNC_TREE_NODE
-
1
));
break
;
break
;
case
SYNC_TREE_NODE_NEW
:
case
SYNC_TREE_NODE_NEW
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment