summaryrefslogtreecommitdiff
path: root/sql/sql_servers.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_servers.cc')
-rw-r--r--sql/sql_servers.cc93
1 files changed, 49 insertions, 44 deletions
diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc
index 36147fc47fc..8f0f08da075 100644
--- a/sql/sql_servers.cc
+++ b/sql/sql_servers.cc
@@ -33,7 +33,7 @@
currently running transactions etc will not be disrupted.
*/
-#include <my_global.h>
+#include "mariadb.h"
#include "sql_priv.h"
#include "sql_servers.h"
#include "unireg.h"
@@ -54,6 +54,8 @@
static HASH servers_cache;
static MEM_ROOT mem;
static mysql_rwlock_t THR_LOCK_servers;
+static LEX_CSTRING MYSQL_SERVERS_NAME= {STRING_WITH_LEN("servers") };
+
static bool get_server_from_table_to_cache(TABLE *table);
@@ -64,7 +66,7 @@ static int insert_server_record_into_cache(FOREIGN_SERVER *server);
static FOREIGN_SERVER *
prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options);
/* drop functions */
-static int delete_server_record(TABLE *table, LEX_STRING *name);
+static int delete_server_record(TABLE *table, LEX_CSTRING *name);
static int delete_server_record_in_cache(LEX_SERVER_OPTIONS *server_options);
/* update functions */
@@ -83,7 +85,7 @@ static uchar *servers_cache_get_key(FOREIGN_SERVER *server, size_t *length,
my_bool not_used __attribute__((unused)))
{
DBUG_ENTER("servers_cache_get_key");
- DBUG_PRINT("info", ("server_name_length %d server_name %s",
+ DBUG_PRINT("info", ("server_name_length %zd server_name %s",
server->server_name_length,
server->server_name));
@@ -154,7 +156,8 @@ bool servers_init(bool dont_read_servers_table)
}
/* Initialize the mem root for data */
- init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC));
+ init_sql_alloc(&mem, "servers", ACL_ALLOC_BLOCK_SIZE, 0,
+ MYF(MY_THREAD_SPECIFIC));
if (dont_read_servers_table)
goto end;
@@ -203,12 +206,12 @@ static bool servers_load(THD *thd, TABLE_LIST *tables)
my_hash_reset(&servers_cache);
free_root(&mem, MYF(0));
- init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0));
+ init_sql_alloc(&mem, "servers_load", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0));
if (init_read_record(&read_record_info,thd,table=tables[0].table, NULL, NULL,
1,0, FALSE))
DBUG_RETURN(1);
- while (!(read_record_info.read_record(&read_record_info)))
+ while (!(read_record_info.read_record()))
{
/* return_val is already TRUE, so no need to set */
if ((get_server_from_table_to_cache(table)))
@@ -251,9 +254,10 @@ bool servers_reload(THD *thd)
DBUG_PRINT("info", ("locking servers_cache"));
mysql_rwlock_wrlock(&THR_LOCK_servers);
- tables[0].init_one_table("mysql", 5, "servers", 7, "servers", TL_READ);
+ tables[0].init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_READ);
- if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
+ if (unlikely(open_and_lock_tables(thd, tables, FALSE,
+ MYSQL_LOCK_IGNORE_TIMEOUT)))
{
/*
Execution might have been interrupted; only print the error message
@@ -383,21 +387,20 @@ insert_server(THD *thd, FOREIGN_SERVER *server)
int error= -1;
TABLE_LIST tables;
TABLE *table;
-
DBUG_ENTER("insert_server");
- tables.init_one_table("mysql", 5, "servers", 7, "servers", TL_WRITE);
+ tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_WRITE);
/* need to open before acquiring THR_LOCK_plugin or it will deadlock */
if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
goto end;
/* insert the server into the table */
- if ((error= insert_server_record(table, server)))
+ if (unlikely(error= insert_server_record(table, server)))
goto end;
/* insert the server into the cache */
- if ((error= insert_server_record_into_cache(server)))
+ if (unlikely((error= insert_server_record_into_cache(server))))
goto end;
end:
@@ -431,7 +434,7 @@ insert_server_record_into_cache(FOREIGN_SERVER *server)
We succeded in insertion of the server to the table, now insert
the server to the cache
*/
- DBUG_PRINT("info", ("inserting server %s at %p, length %d",
+ DBUG_PRINT("info", ("inserting server %s at %p, length %zd",
server->server_name, server,
server->server_name_length));
if (my_hash_insert(&servers_cache, (uchar*) server))
@@ -540,10 +543,12 @@ int insert_server_record(TABLE *table, FOREIGN_SERVER *server)
system_charset_info);
/* read index until record is that specified in server_name */
- if ((error= table->file->ha_index_read_idx_map(table->record[0], 0,
- (uchar *)table->field[0]->ptr,
- HA_WHOLE_KEY,
- HA_READ_KEY_EXACT)))
+ if (unlikely((error=
+ table->file->ha_index_read_idx_map(table->record[0], 0,
+ (uchar *)table->field[0]->
+ ptr,
+ HA_WHOLE_KEY,
+ HA_READ_KEY_EXACT))))
{
/* if not found, err */
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
@@ -557,12 +562,8 @@ int insert_server_record(TABLE *table, FOREIGN_SERVER *server)
DBUG_PRINT("info",("record for server '%s' not found!",
server->server_name));
/* write/insert the new server */
- if ((error=table->file->ha_write_row(table->record[0])))
- {
+ if (unlikely(error=table->file->ha_write_row(table->record[0])))
table->file->print_error(error, MYF(0));
- }
- else
- error= 0;
}
else
error= ER_FOREIGN_SERVER_EXISTS;
@@ -603,13 +604,14 @@ static int drop_server_internal(THD *thd, LEX_SERVER_OPTIONS *server_options)
DBUG_PRINT("info", ("server name server->server_name %s",
server_options->server_name.str));
- tables.init_one_table("mysql", 5, "servers", 7, "servers", TL_WRITE);
+ tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_WRITE);
/* hit the memory hit first */
- if ((error= delete_server_record_in_cache(server_options)))
+ if (unlikely((error= delete_server_record_in_cache(server_options))))
goto end;
- if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
+ if (unlikely(!(table= open_ltable(thd, &tables, TL_WRITE,
+ MYSQL_LOCK_IGNORE_TIMEOUT))))
{
error= my_errno;
goto end;
@@ -687,7 +689,7 @@ delete_server_record_in_cache(LEX_SERVER_OPTIONS *server_options)
We succeded in deletion of the server to the table, now delete
the server from the cache
*/
- DBUG_PRINT("info",("deleting server %s length %d",
+ DBUG_PRINT("info",("deleting server %s length %zd",
server->server_name,
server->server_name_length));
@@ -734,8 +736,7 @@ int update_server(THD *thd, FOREIGN_SERVER *existing, FOREIGN_SERVER *altered)
TABLE_LIST tables;
DBUG_ENTER("update_server");
- tables.init_one_table("mysql", 5, "servers", 7, "servers",
- TL_WRITE);
+ tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_WRITE);
if (!(table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
{
@@ -743,7 +744,7 @@ int update_server(THD *thd, FOREIGN_SERVER *existing, FOREIGN_SERVER *altered)
goto end;
}
- if ((error= update_server_record(table, altered)))
+ if (unlikely((error= update_server_record(table, altered))))
goto end;
error= update_server_record_in_cache(existing, altered);
@@ -891,10 +892,12 @@ update_server_record(TABLE *table, FOREIGN_SERVER *server)
server->server_name_length,
system_charset_info);
- if ((error= table->file->ha_index_read_idx_map(table->record[0], 0,
- (uchar *)table->field[0]->ptr,
- ~(longlong)0,
- HA_READ_KEY_EXACT)))
+ if (unlikely((error=
+ table->file->ha_index_read_idx_map(table->record[0], 0,
+ (uchar *)table->field[0]->
+ ptr,
+ ~(longlong)0,
+ HA_READ_KEY_EXACT))))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
table->file->print_error(error, MYF(0));
@@ -906,9 +909,9 @@ update_server_record(TABLE *table, FOREIGN_SERVER *server)
/* ok, so we can update since the record exists in the table */
store_record(table,record[1]);
store_server_fields(table, server);
- if ((error=table->file->ha_update_row(table->record[1],
- table->record[0])) &&
- error != HA_ERR_RECORD_IS_THE_SAME)
+ if (unlikely((error=table->file->ha_update_row(table->record[1],
+ table->record[0])) &&
+ error != HA_ERR_RECORD_IS_THE_SAME))
{
DBUG_PRINT("info",("problems with ha_update_row %d", error));
goto end;
@@ -939,7 +942,7 @@ end:
*/
static int
-delete_server_record(TABLE *table, LEX_STRING *name)
+delete_server_record(TABLE *table, LEX_CSTRING *name)
{
int error;
DBUG_ENTER("delete_server_record");
@@ -949,10 +952,12 @@ delete_server_record(TABLE *table, LEX_STRING *name)
/* set the field that's the PK to the value we're looking for */
table->field[0]->store(name->str, name->length, system_charset_info);
- if ((error= table->file->ha_index_read_idx_map(table->record[0], 0,
- (uchar *)table->field[0]->ptr,
- HA_WHOLE_KEY,
- HA_READ_KEY_EXACT)))
+ if (unlikely((error=
+ table->file->ha_index_read_idx_map(table->record[0], 0,
+ (uchar *)table->field[0]->
+ ptr,
+ HA_WHOLE_KEY,
+ HA_READ_KEY_EXACT))))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
table->file->print_error(error, MYF(0));
@@ -961,7 +966,7 @@ delete_server_record(TABLE *table, LEX_STRING *name)
}
else
{
- if ((error= table->file->ha_delete_row(table->record[0])))
+ if (unlikely((error= table->file->ha_delete_row(table->record[0]))))
table->file->print_error(error, MYF(0));
}
@@ -1000,7 +1005,7 @@ int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options)
{
if (thd->lex->create_info.or_replace())
{
- if ((error= drop_server_internal(thd, server_options)))
+ if (unlikely((error= drop_server_internal(thd, server_options))))
goto end;
}
else if (thd->lex->create_info.if_not_exists())
@@ -1031,7 +1036,7 @@ int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options)
end:
mysql_rwlock_unlock(&THR_LOCK_servers);
- if (error)
+ if (unlikely(error))
{
DBUG_PRINT("info", ("problem creating server <%s>",
server_options->server_name.str));