revision-id: affdd79c69dfe443cb9fda06ef156243e1967ac3 (mariadb-10.2.16-63-gaffdd79c69d) parent(s): e6a808bec790fdbbf1dc0a6b03fb6c8b6e41dc01 701f0b8e366f957e8256e4741ca48424c84b7234 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-08-03 23:26:26 +0200 message: Merge branch '10.1' into 10.2 sql/opt_range.cc | 5 +++-- sql/sql_acl.cc | 4 +++- sql/sql_class.h | 4 ++++ sql/table.cc | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --cc sql/sql_acl.cc index f5c422cc5ea,3fab00a46df..75186bb502c --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@@ -3497,98 -2942,76 +3498,99 @@@ int acl_set_default_role(THD *thd, cons */ save_binlog_format= thd->set_current_stmt_binlog_format_stmt(); - mysql_mutex_lock(&acl_cache->lock); - ACL_USER *acl_user; - if (!(acl_user= find_user_exact(host, user))) + if (WSREP(thd) && !IF_WSREP(thd->wsrep_applier, 0)) { - mysql_mutex_unlock(&acl_cache->lock); - my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), - MYF(0)); - goto end; + thd->set_query(buff, query_length, system_charset_info); ++ // Attention!!! here is implicit goto error; + WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, (char*)"user", NULL); } - if (!clear_role) { - /* set new default_rolename */ - acl_user->default_rolename.str= safe_strdup_root(&acl_memroot, rolename); - acl_user->default_rolename.length= strlen(rolename); - } - else + /* + Extra block due to WSREP_TO_ISOLATION_BEGIN using goto. + TODO(cvicentiu) Should move this block out in a new function. + */ { - /* clear the default_rolename */ - acl_user->default_rolename.str = NULL; - acl_user->default_rolename.length = 0; - } + if ((result= tables.open_and_lock(thd))) + DBUG_RETURN(result != 1); - /* update the mysql.user table with the new default role */ - table->use_all_columns(); - if (table->s->fields <= DEFAULT_ROLE_COLUMN_IDX) - { - my_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE, MYF(0), - table->alias.c_ptr(), DEFAULT_ROLE_COLUMN_IDX + 1, table->s->fields, - static_cast<int>(table->s->mysql_version), MYSQL_VERSION_ID); - mysql_mutex_unlock(&acl_cache->lock); - goto end; - } - table->field[0]->store(host,(uint) strlen(host), system_charset_info); - table->field[1]->store(user,(uint) strlen(user), system_charset_info); - key_copy((uchar *) user_key, table->record[0], table->key_info, - table->key_info->key_length); + const User_table& user_table= tables.user_table(); + TABLE *table= user_table.table(); - if (table->file->ha_index_read_idx_map(table->record[0], 0, - (uchar *) user_key, HA_WHOLE_KEY, - HA_READ_KEY_EXACT)) - { - mysql_mutex_unlock(&acl_cache->lock); - my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), - MYF(0)); - goto end; - } - store_record(table, record[1]); - table->field[DEFAULT_ROLE_COLUMN_IDX]->store(acl_user->default_rolename.str, - acl_user->default_rolename.length, - system_charset_info); - if ((error=table->file->ha_update_row(table->record[1],table->record[0])) && - error != HA_ERR_RECORD_IS_THE_SAME) - { - mysql_mutex_unlock(&acl_cache->lock); - table->file->print_error(error,MYF(0)); /* purecov: deadcode */ - goto end; - } + result= 1; - acl_cache->clear(1); - mysql_mutex_unlock(&acl_cache->lock); - result= 0; - if (mysql_bin_log.is_open()) - { - DBUG_ASSERT(query_length); - thd->clear_error(); - result= thd->binlog_query(THD::STMT_QUERY_TYPE, buff, query_length, - FALSE, FALSE, FALSE, 0); + mysql_mutex_lock(&acl_cache->lock); + ACL_USER *acl_user; + if (!(acl_user= find_user_exact(host, user))) + { + mysql_mutex_unlock(&acl_cache->lock); + my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), + MYF(0)); + goto end; + } + + if (!clear_role) + { + /* set new default_rolename */ + acl_user->default_rolename.str= safe_strdup_root(&acl_memroot, rolename); + acl_user->default_rolename.length= strlen(rolename); + } + else + { + /* clear the default_rolename */ + acl_user->default_rolename.str = NULL; + acl_user->default_rolename.length = 0; + } + + /* update the mysql.user table with the new default role */ + tables.user_table().table()->use_all_columns(); + if (!tables.user_table().default_role()) + { + my_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE, MYF(0), + table->alias.c_ptr(), DEFAULT_ROLE_COLUMN_IDX + 1, + tables.user_table().num_fields(), + static_cast<int>(table->s->mysql_version), MYSQL_VERSION_ID); + mysql_mutex_unlock(&acl_cache->lock); + goto end; + } + user_table.host()->store(host,(uint) strlen(host), system_charset_info); + user_table.user()->store(user,(uint) strlen(user), system_charset_info); + key_copy((uchar *) user_key, table->record[0], table->key_info, + table->key_info->key_length); + + if (table->file->ha_index_read_idx_map(table->record[0], 0, + (uchar *) user_key, HA_WHOLE_KEY, + HA_READ_KEY_EXACT)) + { + mysql_mutex_unlock(&acl_cache->lock); + my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), + MYF(0)); + goto end; + } + store_record(table, record[1]); + user_table.default_role()->store(acl_user->default_rolename.str, + acl_user->default_rolename.length, + system_charset_info); + if ((error=table->file->ha_update_row(table->record[1],table->record[0])) && + error != HA_ERR_RECORD_IS_THE_SAME) + { + mysql_mutex_unlock(&acl_cache->lock); + table->file->print_error(error,MYF(0)); /* purecov: deadcode */ + goto end; + } + + acl_cache->clear(1); + mysql_mutex_unlock(&acl_cache->lock); + result= 0; + if (mysql_bin_log.is_open()) + { + DBUG_ASSERT(query_length); + thd->clear_error(); + result= thd->binlog_query(THD::STMT_QUERY_TYPE, buff, query_length, + FALSE, FALSE, FALSE, 0); + } + end: + close_mysql_tables(thd); } -end: - close_mysql_tables(thd); #ifdef WITH_WSREP error: // this label is used in WSREP_TO_ISOLATION_END