1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

MDEV-3816 init-file stops getting executed if a long enough line is encountered; on a debug version, assertion `! is_set() || can_overwrite_status' fails

backport improved bootstrap error handling from 5.6

Was:
  revno: 3768.1.1
  committer: Christopher Powers <chris.powers@oracle.com>
  timestamp: Wed 2012-05-02 22:16:40 -0500
  message:
    Bug#11766342 INITIAL DB CREATION FAILS ON WINDOWS WITH AN ASSERT IN SQL_ERROR.CC
    Improved bootstrap error handling:
    - Detect and report file i/o errors
    - Report query size errors with nearest query text
This commit is contained in:
Sergei Golubchik
2012-12-16 21:11:24 +01:00
parent 1679fe1c3e
commit fe7c2aaeea
9 changed files with 127 additions and 30 deletions

View File

@ -634,10 +634,13 @@ void execute_init_command(THD *thd, LEX_STRING *init_command,
}
static char *fgets_fn(char *buffer, size_t size, fgets_input_t input)
static char *fgets_fn(char *buffer, size_t size, fgets_input_t input, int *error)
{
MYSQL_FILE *in= static_cast<MYSQL_FILE*> (input);
return mysql_file_fgets(buffer, size, in);
char *line= mysql_file_fgets(buffer, size, in);
if (error)
*error= (line == NULL) ? ferror(in->m_file) : 0;
return line;
}
@ -664,25 +667,53 @@ static void handle_bootstrap_impl(THD *thd)
for ( ; ; )
{
char buffer[MAX_BOOTSTRAP_QUERY_SIZE];
char buffer[MAX_BOOTSTRAP_QUERY_SIZE] = "";
int rc, length;
char *query;
int error= 0;
rc= read_bootstrap_query(buffer, &length, file, fgets_fn);
rc= read_bootstrap_query(buffer, &length, file, fgets_fn, &error);
if (rc == READ_BOOTSTRAP_ERROR)
if (rc == READ_BOOTSTRAP_EOF)
break;
/*
Check for bootstrap file errors. SQL syntax errors will be
caught below.
*/
if (rc != READ_BOOTSTRAP_SUCCESS)
{
thd->raise_error(ER_SYNTAX_ERROR);
/*
mysql_parse() may have set a successful error status for the previous
query. We must clear the error status to report the bootstrap error.
*/
thd->get_stmt_da()->reset_diagnostics_area();
/* Get the nearest query text for reference. */
char *err_ptr= buffer + (length <= MAX_BOOTSTRAP_ERROR_LEN ?
0 : (length - MAX_BOOTSTRAP_ERROR_LEN));
switch (rc)
{
case READ_BOOTSTRAP_ERROR:
my_printf_error(ER_UNKNOWN_ERROR, "Bootstrap file error, return code (%d). "
"Nearest query: '%s'", MYF(0), error, err_ptr);
break;
case READ_BOOTSTRAP_QUERY_SIZE:
my_printf_error(ER_UNKNOWN_ERROR, "Boostrap file error. Query size "
"exceeded %d bytes near '%s'.", MYF(0),
MAX_BOOTSTRAP_LINE_SIZE, err_ptr);
break;
default:
DBUG_ASSERT(false);
break;
}
thd->protocol->end_statement();
bootstrap_error= 1;
break;
}
if (rc == READ_BOOTSTRAP_EOF)
break;
DBUG_ASSERT(rc == 0);
query= (char *) thd->memdup_w_gap(buffer, length + 1,
thd->db_length + 1 +
QUERY_CACHE_DB_LENGTH_SIZE +