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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
f4f37533
Commit
f4f37533
authored
Mar 04, 2015
by
Sergey Vojtovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced lf-hash element_size hack with initializer function.
parent
5c6aa4de
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
27 deletions
+37
-27
mysys/lf_hash.c
mysys/lf_hash.c
+0
-1
mysys/waiting_threads.c
mysys/waiting_threads.c
+26
-23
sql/table_cache.cc
sql/table_cache.cc
+2
-3
sql/table_cache.h
sql/table_cache.h
+9
-0
No files found.
mysys/lf_hash.c
View file @
f4f37533
...
@@ -336,7 +336,6 @@ static void default_initializer(LF_HASH *hash, void *dst, const void *src)
...
@@ -336,7 +336,6 @@ static void default_initializer(LF_HASH *hash, void *dst, const void *src)
is expensive to initialize - for example if there is a mutex or
is expensive to initialize - for example if there is a mutex or
DYNAMIC_ARRAY. In this case they should be initialize in the
DYNAMIC_ARRAY. In this case they should be initialize in the
LF_ALLOCATOR::constructor, and lf_hash_insert should not overwrite them.
LF_ALLOCATOR::constructor, and lf_hash_insert should not overwrite them.
See wt_init() for example.
The above works well with PODS. For more complex cases (e.g. C++ classes
The above works well with PODS. For more complex cases (e.g. C++ classes
with private members) use initializer function.
with private members) use initializer function.
...
...
mysys/waiting_threads.c
View file @
f4f37533
...
@@ -253,11 +253,7 @@ struct st_wt_resource {
...
@@ -253,11 +253,7 @@ struct st_wt_resource {
#ifndef DBUG_OFF
#ifndef DBUG_OFF
mysql_mutex_t
*
cond_mutex
;
/* a mutex for the 'cond' below */
mysql_mutex_t
*
cond_mutex
;
/* a mutex for the 'cond' below */
#endif
#endif
/*
before the 'lock' all elements are mutable, after (and including) -
immutable in the sense that lf_hash_insert() won't memcpy() over them.
See wt_init().
*/
#ifdef WT_RWLOCKS_USE_MUTEXES
#ifdef WT_RWLOCKS_USE_MUTEXES
/*
/*
we need a special rwlock-like 'lock' to allow readers bypass
we need a special rwlock-like 'lock' to allow readers bypass
...
@@ -389,10 +385,10 @@ static LF_HASH reshash;
...
@@ -389,10 +385,10 @@ static LF_HASH reshash;
It's called from lf_hash and takes a pointer to an LF_SLIST instance.
It's called from lf_hash and takes a pointer to an LF_SLIST instance.
WT_RESOURCE is located at arg+sizeof(LF_SLIST)
WT_RESOURCE is located at arg+sizeof(LF_SLIST)
*/
*/
static
void
wt_resource_
init
(
uchar
*
arg
)
static
void
wt_resource_
create
(
uchar
*
arg
)
{
{
WT_RESOURCE
*
rc
=
(
WT_RESOURCE
*
)(
arg
+
LF_HASH_OVERHEAD
);
WT_RESOURCE
*
rc
=
(
WT_RESOURCE
*
)(
arg
+
LF_HASH_OVERHEAD
);
DBUG_ENTER
(
"wt_resource_
init
"
);
DBUG_ENTER
(
"wt_resource_
create
"
);
bzero
(
rc
,
sizeof
(
*
rc
));
bzero
(
rc
,
sizeof
(
*
rc
));
rc_rwlock_init
(
rc
);
rc_rwlock_init
(
rc
);
...
@@ -419,25 +415,37 @@ static void wt_resource_destroy(uchar *arg)
...
@@ -419,25 +415,37 @@ static void wt_resource_destroy(uchar *arg)
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
/**
WT_RESOURCE initializer
It's called from lf_hash when an element is inserted.
*/
static
void
wt_resource_init
(
LF_HASH
*
hash
__attribute__
((
unused
)),
WT_RESOURCE
*
rc
,
WT_RESOURCE_ID
*
id
)
{
DBUG_ENTER
(
"wt_resource_init"
);
rc
->
id
=
*
id
;
rc
->
waiter_count
=
0
;
rc
->
state
=
ACTIVE
;
#ifndef DBUG_OFF
rc
->
cond_mutex
=
0
;
#endif
DBUG_VOID_RETURN
;
}
static
int
wt_init_done
;
static
int
wt_init_done
;
void
wt_init
()
void
wt_init
()
{
{
DBUG_ENTER
(
"wt_init"
);
DBUG_ENTER
(
"wt_init"
);
DBUG_ASSERT
(
reshash
.
alloc
.
constructor
!=
wt_resource_
init
);
DBUG_ASSERT
(
reshash
.
alloc
.
constructor
!=
wt_resource_
create
);
lf_hash_init
(
&
reshash
,
sizeof
(
WT_RESOURCE
),
LF_HASH_UNIQUE
,
0
,
lf_hash_init
(
&
reshash
,
sizeof
(
WT_RESOURCE
),
LF_HASH_UNIQUE
,
0
,
sizeof_WT_RESOURCE_ID
,
0
,
0
);
sizeof_WT_RESOURCE_ID
,
0
,
0
);
reshash
.
alloc
.
constructor
=
wt_resource_
init
;
reshash
.
alloc
.
constructor
=
wt_resource_
create
;
reshash
.
alloc
.
destructor
=
wt_resource_destroy
;
reshash
.
alloc
.
destructor
=
wt_resource_destroy
;
/*
reshash
.
initializer
=
(
lf_hash_initializer
)
wt_resource_init
;
Note a trick: we initialize the hash with the real element size,
but fix it later to a shortened element size. This way
the allocator will allocate elements correctly, but
lf_hash_insert() will only overwrite part of the element with memcpy().
lock, condition, and dynamic array will be intact.
*/
reshash
.
element_size
=
offsetof
(
WT_RESOURCE
,
lock
);
bzero
(
wt_wait_stats
,
sizeof
(
wt_wait_stats
));
bzero
(
wt_wait_stats
,
sizeof
(
wt_wait_stats
));
bzero
(
wt_cycle_stats
,
sizeof
(
wt_cycle_stats
));
bzero
(
wt_cycle_stats
,
sizeof
(
wt_cycle_stats
));
wt_success_stats
=
0
;
wt_success_stats
=
0
;
...
@@ -930,14 +938,9 @@ int wt_thd_will_wait_for(WT_THD *thd, WT_THD *blocker,
...
@@ -930,14 +938,9 @@ int wt_thd_will_wait_for(WT_THD *thd, WT_THD *blocker,
retry:
retry:
while
((
rc
=
lf_hash_search
(
&
reshash
,
thd
->
pins
,
key
,
keylen
))
==
0
)
while
((
rc
=
lf_hash_search
(
&
reshash
,
thd
->
pins
,
key
,
keylen
))
==
0
)
{
{
WT_RESOURCE
tmp
;
DBUG_PRINT
(
"wt"
,
(
"failed to find rc in hash, inserting"
));
DBUG_PRINT
(
"wt"
,
(
"failed to find rc in hash, inserting"
));
bzero
(
&
tmp
,
sizeof
(
tmp
));
tmp
.
id
=
*
resid
;
tmp
.
state
=
ACTIVE
;
if
(
lf_hash_insert
(
&
reshash
,
thd
->
pins
,
&
tmp
)
==
-
1
)
/* if OOM */
if
(
lf_hash_insert
(
&
reshash
,
thd
->
pins
,
resid
)
==
-
1
)
/* if OOM */
DBUG_RETURN
(
WT_DEADLOCK
);
DBUG_RETURN
(
WT_DEADLOCK
);
/*
/*
Two cases: either lf_hash_insert() failed - because another thread
Two cases: either lf_hash_insert() failed - because another thread
...
...
sql/table_cache.cc
View file @
f4f37533
...
@@ -432,7 +432,7 @@ void tdc_init(void)
...
@@ -432,7 +432,7 @@ void tdc_init(void)
&
my_charset_bin
);
&
my_charset_bin
);
tdc_hash
.
alloc
.
constructor
=
TDC_element
::
lf_alloc_constructor
;
tdc_hash
.
alloc
.
constructor
=
TDC_element
::
lf_alloc_constructor
;
tdc_hash
.
alloc
.
destructor
=
TDC_element
::
lf_alloc_destructor
;
tdc_hash
.
alloc
.
destructor
=
TDC_element
::
lf_alloc_destructor
;
tdc_hash
.
element_size
=
offsetof
(
TDC_element
,
version
)
;
tdc_hash
.
initializer
=
(
lf_hash_initializer
)
TDC_element
::
lf_hash_initializer
;
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
...
@@ -616,7 +616,7 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name,
...
@@ -616,7 +616,7 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name,
while
(
!
(
element
=
(
TDC_element
*
)
lf_hash_search_using_hash_value
(
&
tdc_hash
,
while
(
!
(
element
=
(
TDC_element
*
)
lf_hash_search_using_hash_value
(
&
tdc_hash
,
thd
->
tdc_hash_pins
,
hash_value
,
(
uchar
*
)
key
,
key_length
)))
thd
->
tdc_hash_pins
,
hash_value
,
(
uchar
*
)
key
,
key_length
)))
{
{
TDC_element
tmp
(
key
,
key_length
)
;
LEX_STRING
tmp
=
{
const_cast
<
char
*>
(
key
),
key_length
}
;
int
res
=
lf_hash_insert
(
&
tdc_hash
,
thd
->
tdc_hash_pins
,
(
uchar
*
)
&
tmp
);
int
res
=
lf_hash_insert
(
&
tdc_hash
,
thd
->
tdc_hash_pins
,
(
uchar
*
)
&
tmp
);
if
(
res
==
-
1
)
if
(
res
==
-
1
)
...
@@ -628,7 +628,6 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name,
...
@@ -628,7 +628,6 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name,
thd
->
tdc_hash_pins
,
hash_value
,
(
uchar
*
)
key
,
key_length
);
thd
->
tdc_hash_pins
,
hash_value
,
(
uchar
*
)
key
,
key_length
);
lf_hash_search_unpin
(
thd
->
tdc_hash_pins
);
lf_hash_search_unpin
(
thd
->
tdc_hash_pins
);
DBUG_ASSERT
(
element
);
DBUG_ASSERT
(
element
);
element
->
assert_clean_share
();
if
(
!
(
share
=
alloc_table_share
(
db
,
table_name
,
key
,
key_length
)))
if
(
!
(
share
=
alloc_table_share
(
db
,
table_name
,
key
,
key_length
)))
{
{
...
...
sql/table_cache.h
View file @
f4f37533
...
@@ -166,6 +166,15 @@ class TDC_element
...
@@ -166,6 +166,15 @@ class TDC_element
}
}
static
void
lf_hash_initializer
(
LF_HASH
*
hash
__attribute__
((
unused
)),
TDC_element
*
element
,
LEX_STRING
*
key
)
{
memcpy
(
element
->
m_key
,
key
->
str
,
key
->
length
);
element
->
m_key_length
=
key
->
length
;
element
->
assert_clean_share
();
}
static
uchar
*
key
(
const
TDC_element
*
element
,
size_t
*
length
,
static
uchar
*
key
(
const
TDC_element
*
element
,
size_t
*
length
,
my_bool
not_used
__attribute__
((
unused
)))
my_bool
not_used
__attribute__
((
unused
)))
{
{
...
...
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