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
8eeaebc6
Commit
8eeaebc6
authored
Feb 28, 2020
by
Isaac Ackerman
Committed by
Sergei Petrunia
Mar 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup of allocation strategy
parent
37a5b125
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
85 deletions
+47
-85
storage/xpand/ha_xpand.cc
storage/xpand/ha_xpand.cc
+16
-24
storage/xpand/xpand_connection.cc
storage/xpand/xpand_connection.cc
+18
-45
storage/xpand/xpand_connection.h
storage/xpand/xpand_connection.h
+13
-16
No files found.
storage/xpand/ha_xpand.cc
View file @
8eeaebc6
...
...
@@ -75,15 +75,7 @@ static MYSQL_SYSVAR_ENUM
//current list of clx hosts
static
PSI_rwlock_key
key_xpand_hosts
;
mysql_rwlock_t
xpand_hosts_lock
;
xpand_host_list
*
xpand_hosts
;
//only call while holding lock
static
void
clear_hosts
()
{
delete
xpand_hosts
;
xpand_hosts
=
NULL
;
my_atomic_store32
(
&
xpand_hosts_cur
,
0
);
}
xpand_host_list
xpand_hosts
;
static
int
check_hosts
(
MYSQL_THD
thd
,
struct
st_mysql_sys_var
*
var
,
void
*
save
,
struct
st_mysql_value
*
value
)
...
...
@@ -91,37 +83,38 @@ static int check_hosts(MYSQL_THD thd, struct st_mysql_sys_var *var,
char
b
;
int
len
=
0
;
const
char
*
val
=
value
->
val_str
(
value
,
&
b
,
&
len
);
if
(
!
val
)
return
HA_ERR_OUT_OF_MEM
;
xpand_host_list
*
list
=
static_cast
<
xpand_host_list
*>
(
thd_calloc
(
thd
,
sizeof
(
xpand_host_list
)));
if
(
!
list
)
return
HA_ERR_OUT_OF_MEM
;
int
error_code
=
0
;
xpand_host_list
*
host_list
=
xpand_host_list
::
create
(
val
,
thd
,
&
error_code
);
if
(
error_code
)
if
((
error_code
=
list
->
fill
(
val
)))
return
error_code
;
list
->
empty
();
*
static_cast
<
xpand_host_list
**>
(
save
)
=
host_list
;
*
static_cast
<
char
**>
(
save
)
=
thd_strdup
(
thd
,
val
)
;
return
0
;
}
static
void
update_hosts
(
MYSQL_THD
thd
,
struct
st_mysql_sys_var
*
var
,
void
*
var_ptr
,
const
void
*
save
)
{
mysql_rwlock_wrlock
(
&
xpand_hosts_lock
);
char
*
from_save
=
*
static_cast
<
char
*
const
*>
(
save
);
xpand_host_list
*
from_save
=
*
static_cast
<
xpand_host_list
*
const
*>
(
save
);
char
*
raw
=
from_save
->
full_list
;
mysql_rwlock_wrlock
(
&
xpand_hosts_lock
);
int
error_code
=
0
;
xpand_host_list
*
new_hosts
=
xpand_host_list
::
create
(
raw
,
&
error_cod
e
);
xpand_hosts
.
empty
()
;
int
error_code
=
xpand_hosts
.
fill
(
from_sav
e
);
if
(
error_code
)
{
my_printf_error
(
error_code
,
"Unhandled error setting xpand hostlist"
,
MYF
(
0
));
return
;
}
clear_hosts
();
xpand_hosts
=
new_hosts
;
*
static_cast
<
char
**>
(
var_ptr
)
=
new_hosts
->
full_list
;
*
static_cast
<
char
**>
(
var_ptr
)
=
my_strdup
(
from_save
,
MYF
(
MY_WME
));
mysql_rwlock_unlock
(
&
xpand_hosts_lock
);
}
...
...
@@ -1481,8 +1474,7 @@ static int xpand_init(void *p)
mysql_rwlock_init
(
key_xpand_hosts
,
&
xpand_hosts_lock
);
mysql_rwlock_wrlock
(
&
xpand_hosts_lock
);
int
error_code
=
0
;
xpand_hosts
=
xpand_host_list
::
create
(
xpand_hosts_str
,
&
error_code
);
int
error_code
=
xpand_hosts
.
fill
(
xpand_hosts_str
);
mysql_rwlock_unlock
(
&
xpand_hosts_lock
);
DBUG_RETURN
(
error_code
);
}
...
...
@@ -1491,7 +1483,7 @@ static int xpand_deinit(void *p)
{
DBUG_ENTER
(
"xpand_deinit"
);
mysql_rwlock_wrlock
(
&
xpand_hosts_lock
);
delete
xpand_hosts
;
xpand_hosts
.
empty
()
;
mysql_rwlock_destroy
(
&
xpand_hosts_lock
);
DBUG_RETURN
(
0
);
}
...
...
storage/xpand/xpand_connection.cc
View file @
8eeaebc6
...
...
@@ -21,7 +21,6 @@ Copyright (c) 2019, MariaDB Corporation.
extern
int
xpand_connect_timeout
;
extern
int
xpand_read_timeout
;
extern
int
xpand_write_timeout
;
extern
char
*
xpand_host
;
extern
char
*
xpand_username
;
extern
char
*
xpand_password
;
extern
uint
xpand_port
;
...
...
@@ -130,7 +129,7 @@ extern int xpand_hosts_cur;
extern
ulong
xpand_balance_algorithm
;
extern
mysql_rwlock_t
xpand_hosts_lock
;
extern
xpand_host_list
*
xpand_hosts
;
extern
xpand_host_list
xpand_hosts
;
int
xpand_connection
::
connect
()
{
...
...
@@ -142,9 +141,9 @@ int xpand_connection::connect()
mysql_rwlock_rdlock
(
&
xpand_hosts_lock
);
//search for available host
int
error_code
=
0
;
for
(
int
i
=
0
;
i
<
xpand_hosts
->
hosts_len
;
i
++
)
{
char
*
host
=
xpand_hosts
->
hosts
[(
start
+
i
)
%
xpand_hosts
->
hosts_len
];
int
error_code
=
ER_BAD_HOST_ERROR
;
for
(
int
i
=
0
;
i
<
xpand_hosts
.
hosts_len
;
i
++
)
{
char
*
host
=
xpand_hosts
.
hosts
[(
start
+
i
)
%
xpand_hosts
.
hosts_len
];
error_code
=
connect_direct
(
host
);
if
(
!
error_code
)
break
;
...
...
@@ -1290,31 +1289,11 @@ int xpand_connection::add_command_operand_bitmap(MY_BITMAP *bitmap)
** Class xpand_host_list
****************************************************************************/
xpand_host_list
*
xpand_host_list
::
create
(
const
char
*
hosts
,
int
*
error_code
)
int
xpand_host_list
::
fill
(
const
char
*
hosts
)
{
return
xpand_host_list
::
create
(
hosts
,
NULL
,
error_code
);
}
xpand_host_list
*
xpand_host_list
::
create
(
const
char
*
hosts
,
THD
*
thd
,
int
*
error_code
)
{
xpand_host_list
*
list
=
static_cast
<
xpand_host_list
*>
(
thd
?
thd_calloc
(
thd
,
sizeof
(
xpand_host_list
))
:
my_malloc
(
sizeof
(
xpand_host_list
),
MYF
(
MY_WME
|
MY_ZEROFILL
)));
if
(
!
list
)
{
*
error_code
=
HA_ERR_OUT_OF_MEM
;
return
NULL
;
}
list
->
full_list
=
thd
?
thd_strdup
(
thd
,
hosts
)
:
my_strdup
(
hosts
,
MYF
(
MY_WME
));
list
->
strtok_buf
=
thd
?
thd_strdup
(
thd
,
hosts
)
:
my_strdup
(
hosts
,
MYF
(
MY_WME
));
if
(
!
list
->
full_list
||
!
list
->
strtok_buf
)
{
*
error_code
=
HA_ERR_OUT_OF_MEM
;
return
NULL
;
strtok_buf
=
my_strdup
(
hosts
,
MYF
(
MY_WME
));
if
(
!
strtok_buf
)
{
return
HA_ERR_OUT_OF_MEM
;
}
const
char
*
sep
=
",; "
;
...
...
@@ -1322,32 +1301,26 @@ xpand_host_list *xpand_host_list::create(const char *hosts, THD *thd, int *error
int
i
=
0
;
char
*
cursor
=
NULL
;
char
*
token
=
NULL
;
for
(
token
=
strtok_r
(
list
->
strtok_buf
,
sep
,
&
cursor
);
for
(
token
=
strtok_r
(
strtok_buf
,
sep
,
&
cursor
);
token
&&
i
<
max_host_count
;
token
=
strtok_r
(
NULL
,
sep
,
&
cursor
))
{
list
->
hosts
[
i
]
=
token
;
this
->
hosts
[
i
]
=
token
;
i
++
;
}
//host count out of range
if
(
i
==
0
||
token
)
{
my_free
(
list
->
full_list
);
my_free
(
list
->
strtok_buf
);
my_free
(
list
);
*
error_code
=
ER_BAD_HOST_ERROR
;
return
NULL
;
my_free
(
strtok_buf
);
return
ER_BAD_HOST_ERROR
;
}
list
->
hosts_len
=
i
;
hosts_len
=
i
;
return
list
;
return
0
;
}
void
xpand_host_list
::
operator
delete
(
void
*
p
)
void
xpand_host_list
::
empty
(
)
{
xpand_host_list
*
list
=
static_cast
<
xpand_host_list
*>
(
p
);
if
(
list
)
{
my_free
(
list
->
full_list
);
my_free
(
list
->
strtok_buf
);
}
my_free
(
list
);
my_free
(
strtok_buf
);
strtok_buf
=
NULL
;
hosts_len
=
0
;
}
storage/xpand/xpand_connection.h
View file @
8eeaebc6
...
...
@@ -32,22 +32,6 @@ enum xpand_balance_algorithm_enum {
XPAND_BALANCE_ROUND_ROBIN
};
static
const
int
max_host_count
=
128
;
class
xpand_host_list
{
private:
char
*
strtok_buf
;
public:
char
*
full_list
;
int
hosts_len
;
char
*
hosts
[
max_host_count
];
static
xpand_host_list
*
create
(
const
char
*
hosts
,
int
*
error_code
);
static
xpand_host_list
*
create
(
const
char
*
hosts
,
THD
*
thd
,
int
*
error_code
);
xpand_host_list
()
=
delete
;
static
void
operator
delete
(
void
*
p
);
};
class
xpand_connection_cursor
;
class
xpand_connection
{
...
...
@@ -147,4 +131,17 @@ class xpand_connection
int
send_command
();
int
read_query_response
();
};
static
const
int
max_host_count
=
128
;
class
xpand_host_list
{
private:
char
*
strtok_buf
;
public:
int
hosts_len
;
char
*
hosts
[
max_host_count
];
int
fill
(
const
char
*
hosts
);
void
empty
();
};
#endif // _xpand_connection_h
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