Skip to content

Commit 57d3222

Browse files
pedrolgomesltangvald
authored andcommitted
BUG#32212353: IMPROVE WRITE SET COLLECTION MEMORY USAGE HANDLING
When collecting write sets for transactions, the server might run out of memory. This failure shall be handled gracefully and the transaction shall fail for lack of resources. ReviewBoard: 25572 (cherry picked from commit be0fb117b842d34a7c3725dfa2f346b33ae4aa73)
1 parent 4f7738b commit 57d3222

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

sql/handler.cc

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7931,31 +7931,39 @@ int binlog_log_row(TABLE* table,
79317931
{
79327932
if (thd->variables.transaction_write_set_extraction != HASH_ALGORITHM_OFF)
79337933
{
7934-
if (before_record && after_record)
7934+
try
79357935
{
7936-
size_t length= table->s->reclength;
7937-
uchar* temp_image=(uchar*) my_malloc(PSI_NOT_INSTRUMENTED,
7938-
length,
7939-
MYF(MY_WME));
7940-
if (!temp_image)
7936+
if (before_record && after_record)
79417937
{
7942-
sql_print_error("Out of memory on transaction write set extraction");
7943-
return 1;
7944-
}
7945-
add_pke(table, thd);
7938+
size_t length= table->s->reclength;
7939+
uchar* temp_image=(uchar*) my_malloc(PSI_NOT_INSTRUMENTED,
7940+
length,
7941+
MYF(MY_WME));
7942+
if (!temp_image)
7943+
{
7944+
sql_print_error("Out of memory on transaction write set extraction");
7945+
return 1;
7946+
}
7947+
add_pke(table, thd);
79467948

7947-
memcpy(temp_image, table->record[0],(size_t) table->s->reclength);
7948-
memcpy(table->record[0],table->record[1],(size_t) table->s->reclength);
7949+
memcpy(temp_image, table->record[0],(size_t) table->s->reclength);
7950+
memcpy(table->record[0],table->record[1],(size_t) table->s->reclength);
79497951

7950-
add_pke(table, thd);
7952+
add_pke(table, thd);
79517953

7952-
memcpy(table->record[0], temp_image, (size_t) table->s->reclength);
7954+
memcpy(table->record[0], temp_image, (size_t) table->s->reclength);
79537955

7954-
my_free(temp_image);
7956+
my_free(temp_image);
7957+
}
7958+
else
7959+
{
7960+
add_pke(table, thd);
7961+
}
79557962
}
7956-
else
7963+
catch (const std::bad_alloc &)
79577964
{
7958-
add_pke(table, thd);
7965+
my_error(ER_OUT_OF_RESOURCES, MYF(0));
7966+
return HA_ERR_RBR_LOGGING_FAILED;
79597967
}
79607968
}
79617969
DBUG_DUMP("read_set 10", (uchar*) table->read_set->bitmap,

sql/rpl_transaction_write_set_ctx.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -45,10 +45,10 @@ Rpl_transaction_write_set_ctx::Rpl_transaction_write_set_ctx():
4545

4646
void Rpl_transaction_write_set_ctx::add_write_set(uint64 hash)
4747
{
48-
DBUG_ENTER("Rpl_transaction_write_set_ctx::add_write_set");
48+
//Do not use DBUG_ENTER here due to memory allocation exceptions
49+
DBUG_EXECUTE_IF("add_write_set_no_memory", throw std::bad_alloc(););
4950
write_set.push_back(hash);
5051
write_set_unique.insert(hash);
51-
DBUG_VOID_RETURN;
5252
}
5353

5454
std::set<uint64>* Rpl_transaction_write_set_ctx::get_write_set()

sql/rpl_write_set_handler.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ static void generate_hash_pke(const std::string &pke, uint collation_conversion_
576576
#endif
577577
)
578578
{
579-
DBUG_ENTER("generate_hash_pke");
580579
DBUG_ASSERT(thd->variables.transaction_write_set_extraction !=
581580
HASH_ALGORITHM_OFF);
582581

@@ -591,13 +590,11 @@ static void generate_hash_pke(const std::string &pke, uint collation_conversion_
591590
hash_list.push_back(hash);
592591
#endif
593592
DBUG_PRINT("info", ("pke: %s; hash: %llu", pke.c_str(), hash));
594-
DBUG_VOID_RETURN;
595593
}
596594

597595

598596
void add_pke(TABLE *table, THD *thd)
599597
{
600-
DBUG_ENTER("add_pke");
601598
/*
602599
The next section extracts the primary key equivalent of the rows that are
603600
changing during the current transaction.
@@ -896,6 +893,4 @@ void add_pke(TABLE *table, THD *thd)
896893

897894
if (writeset_hashes_added == 0)
898895
ws_ctx->set_has_missing_keys();
899-
900-
DBUG_VOID_RETURN;
901896
}

0 commit comments

Comments
 (0)