Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3579,6 +3579,21 @@ bool ha_flush_logs()
}


static my_bool rotate_logs_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
handlerton *hton= plugin_hton(plugin);
return hton->rotate_logs && hton->rotate_logs(hton);
}


bool ha_rotate_logs()
{
return plugin_foreach(NULL, rotate_logs_handlerton,
MYSQL_STORAGE_ENGINE_PLUGIN, 0);
}
Comment on lines +3590 to +3594

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be dead code. I don’t see any caller of it. Was an SQL interface to this forgotten? I do not see any SQL test case being added either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: @montywi suggested that this be mapped to FLUSH LOGS. If I understand correctly, the added code should be invoked from translog_purge_at_flush() in that case.



/**
@brief make canonical filename

Expand Down
7 changes: 7 additions & 0 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,12 @@ struct handlerton : public transaction_participant
void (*disable_internal_writes)(bool disable);

bool (*flush_logs)(handlerton *hton);
/*
Finish the current log file and continue in a new one, so that
the finished files are not written to anymore and can be copied
(used by backup).
*/
bool (*rotate_logs)(handlerton *hton);
bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
uint (*partition_flags)();
alter_table_operations (*alter_table_flags)(alter_table_operations flags);
Expand Down Expand Up @@ -5859,6 +5865,7 @@ void ha_kill_query(THD* thd, enum thd_kill_levels level);
void ha_signal_ddl_recovery_done();
void ha_signal_tc_log_recovery_done();
bool ha_flush_logs();
bool ha_rotate_logs();
void ha_drop_database(const char* path);
void ha_commit_checkpoint_request(void *cookie, void (*pre_hook)(void *));
int ha_create_table(THD *thd, const char *path, const char *db,
Expand Down
20 changes: 20 additions & 0 deletions storage/maria/ha_maria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3721,6 +3721,25 @@ bool maria_flush_logs(handlerton *hton)
}


/**
@brief switch the log handler to a new log file

@param hton maria handlerton (unused)

@retval FALSE OK
@retval TRUE Error
*/

static bool maria_rotate_logs(handlerton *hton)
{
if (!translog_rotate())
return false;
my_error(ER_GET_ERRMSG, MYF(0), my_errno ? my_errno : HA_ERR_GENERIC,
"Can't switch to a new log file", "Aria");
return true;
}


void maria_checkpoint_state(bool disabled)
{
maria_checkpoint_disabled= (my_bool) disabled;
Expand Down Expand Up @@ -3951,6 +3970,7 @@ static int ha_maria_init(void *p)
maria_hton->rollback= maria_rollback;
maria_hton->disable_internal_writes= maria_checkpoint_state;
maria_hton->flush_logs= maria_flush_logs;
maria_hton->rotate_logs= maria_rotate_logs;
maria_hton->show_status= maria_show_status;
maria_hton->prepare_for_backup= maria_prepare_for_backup;
maria_hton->end_backup= maria_end_backup;
Expand Down
151 changes: 118 additions & 33 deletions storage/maria/ma_loghandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,18 +1650,28 @@ static my_bool translog_create_new_file()

TRANSLOG_FILE *old= get_current_logfile();
uint32 file_no= LSN_FILE_NO(log_descriptor.horizon);
LSN max_lsn= log_descriptor.max_lsn;
DBUG_ENTER("translog_create_new_file");

if (file == NULL)
goto error;

/*
No record was written since start (an empty log, or a file continued
after restart), but LSN_IMPOSSIBLE in the header would mean "file in
writing" and stop translog_purge() at this file forever. Every LSN of
the finished file is below the start of the new one.
*/
if (max_lsn == LSN_IMPOSSIBLE)
max_lsn= MAKE_LSN(file_no, 0) - 1;

/*
Writes max_lsn to the file header before finishing it (there is no need
to lock file header buffer because it is still unfinished file, so only
one thread can finish the file and nobody interested of LSN of current
(unfinished) file, because no one can purge it).
*/
if (translog_max_lsn_to_header(old->handler.file, log_descriptor.max_lsn))
if (translog_max_lsn_to_header(old->handler.file, max_lsn))
goto error;

mysql_rwlock_wrlock(&log_descriptor.open_files_lock);
Expand All @@ -1677,7 +1687,11 @@ static my_bool translog_create_new_file()
goto error_lock;

if ((file->handler.file= create_logfile_by_number_no_cache(file_no)) == -1)
{
/* do not leave a pointer to the freed file in open_files */
pop_dynamic(&log_descriptor.open_files);
goto error_lock;
}
translog_file_init(file, file_no, 0);

log_descriptor.max_file++;
Expand All @@ -1697,15 +1711,20 @@ static my_bool translog_create_new_file()
DBUG_PRINT("info", ("file_no: %lu", (ulong)file_no));

if (translog_write_file_header())
goto error;
goto error_registered;

if (ma_control_file_write_and_force(last_checkpoint_lsn, file_no,
max_trid_in_control_file,
recovery_failures))
goto error;
goto error_registered;

DBUG_RETURN(0);

error_registered:
/* the file is in open_files now, translog_destroy() closes it */
translog_stop_writing();
DBUG_RETURN(1);

error_lock:
mysql_rwlock_unlock(&log_descriptor.open_files_lock);
error:
Expand Down Expand Up @@ -4174,6 +4193,7 @@ my_bool translog_init_with_table(const char *directory,
It is beginning of the log => there is no LSNs in the log =>
There is no harm in leaving it "as-is".
*/
translog_destroy_scanner(&scanner);
log_descriptor.previous_flush_horizon= log_descriptor.horizon;
DBUG_PRINT("info", ("previous_flush_horizon: " LSN_FMT,
LSN_IN_PARTS(log_descriptor.
Expand Down Expand Up @@ -7358,19 +7378,14 @@ int translog_read_next_record_header(TRANSLOG_SCANNER_DATA *scanner,
LSN_IN_PARTS(scanner->page_addr),
(ulong) scanner->page_offset,
(uint) scanner->page[scanner->page_offset]));
} while (!translog_is_LSN_chunk(scanner->page[scanner->page_offset]) &&
scanner->page[scanner->page_offset] != TRANSLOG_FILLER);
/*
A filler only ends its page, the log can continue after it (for
example after files finished by translog_rotate() before any record
was written), the end of the log is found by the horizon above.
*/
} while (!translog_is_LSN_chunk(scanner->page[scanner->page_offset]));

if (scanner->page[scanner->page_offset] == TRANSLOG_FILLER)
{
DBUG_PRINT("info", ("End of file"));
/* Last record was read */
buff->lsn= LSN_IMPOSSIBLE;
/* Return 'end of log' marker */
res= RECHEADER_READ_EOF;
}
else
res= translog_read_record_header_scan(scanner, buff, 0);
res= translog_read_record_header_scan(scanner, buff, 0);
DBUG_RETURN(res);
}

Expand Down Expand Up @@ -8559,8 +8574,12 @@ LSN translog_next_LSN(TRANSLOG_ADDRESS addr, TRANSLOG_ADDRESS horizon)
}
}

while (!translog_is_LSN_chunk(scanner.page[scanner.page_offset]) &&
scanner.page[scanner.page_offset] != TRANSLOG_FILLER)
/*
A filler only ends its page (translog_get_next_chunk() goes to the
next one), the log can continue after it, for example after files
finished by translog_rotate() before any record was written
*/
while (!translog_is_LSN_chunk(scanner.page[scanner.page_offset]))
{
if (translog_get_next_chunk(&scanner))
{
Expand All @@ -8574,10 +8593,7 @@ LSN translog_next_LSN(TRANSLOG_ADDRESS addr, TRANSLOG_ADDRESS horizon)
}
}

if (scanner.page[scanner.page_offset] == TRANSLOG_FILLER)
result= LSN_IMPOSSIBLE; /* reached page filler */
else
result= scanner.page_addr + scanner.page_offset;
result= scanner.page_addr + scanner.page_offset;
out:
translog_destroy_scanner(&scanner);
DBUG_RETURN(result);
Expand Down Expand Up @@ -8862,6 +8878,42 @@ uint32 translog_get_file_size()
}


/**
@brief Finishes the current log file, starts the next one and writes the
buffer with the end of the finished file

@note the loghandler must be locked, it is unlocked on return

@retval 0 OK
@retval 1 Error (the log is read only after it)
*/

static my_bool translog_next_file_and_unlock()
{
struct st_translog_buffer *old_buffer= log_descriptor.bc.buffer;
struct st_translog_buffer *new_buffer=
log_descriptor.buffers + ((log_descriptor.bc.buffer_no + 1) %
TRANSLOG_BUFFERS_NO);
my_bool rc;
translog_lock_assert_owner();

if (translog_buffer_next(&log_descriptor.horizon, &log_descriptor.bc, 1))
{
/* both buffers are still locked, the cursor is on the old one */
translog_buffer_unlock(new_buffer);
translog_unlock();
return 1;
}
translog_buffer_unlock(old_buffer);
translog_unlock();

translog_buffer_lock(old_buffer);
rc= translog_buffer_flush(old_buffer);
translog_buffer_unlock(old_buffer);
return rc;
}


/**
@brief Sets transaction log file size

Expand All @@ -8870,7 +8922,6 @@ uint32 translog_get_file_size()

void translog_set_file_size(uint32 size)
{
struct st_translog_buffer *old_buffer= NULL;
DBUG_ENTER("translog_set_file_size");
translog_lock();
DBUG_PRINT("enter", ("Size: %lu", (ulong) size));
Expand All @@ -8879,19 +8930,53 @@ void translog_set_file_size(uint32 size)
log_descriptor.log_file_max_size= size;
/* if current file longer then finish it*/
if (LSN_OFFSET(log_descriptor.horizon) >= log_descriptor.log_file_max_size)
translog_next_file_and_unlock();
else
translog_unlock();
DBUG_VOID_RETURN;
}


/**
@brief Finishes the current log file and continues logging in a new one

All records written before the call are flushed to disk, so the
finished files are not written to anymore and can be copied (for
example by backup).

If the log is read only (after an earlier write error) no file is
written anymore, so there is nothing to do.

@note On an error the log becomes read only, as on any other error
writing it.

@retval 0 OK
@retval 1 Error
*/

my_bool translog_rotate()
{
LSN last_lsn;
my_bool rc;
DBUG_ENTER("translog_rotate");

if (translog_status == TRANSLOG_READONLY)
DBUG_RETURN(0);
if (translog_status != TRANSLOG_OK)
DBUG_RETURN(1);

translog_lock();
/* translog_stop_writing() could be called after the check above */
if (unlikely(translog_status != TRANSLOG_OK))
{
old_buffer= log_descriptor.bc.buffer;
translog_buffer_next(&log_descriptor.horizon, &log_descriptor.bc, 1);
translog_buffer_unlock(old_buffer);
}
translog_unlock();
if (old_buffer)
{
translog_buffer_lock(old_buffer);
translog_buffer_flush(old_buffer);
translog_buffer_unlock(old_buffer);
translog_unlock();
DBUG_RETURN(translog_status != TRANSLOG_READONLY);
}
DBUG_VOID_RETURN;
last_lsn= log_descriptor.max_lsn;
rc= translog_next_file_and_unlock();
if (!rc && last_lsn != LSN_IMPOSSIBLE)
rc= translog_flush(last_lsn);
DBUG_RETURN(rc);
}


Expand Down
1 change: 1 addition & 0 deletions storage/maria/ma_loghandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ extern uint32 translog_get_first_file(TRANSLOG_ADDRESS horizon);
extern uint32 translog_get_first_needed_file();
extern char *translog_filename_by_fileno(uint32 file_no, char *path);
extern void translog_set_file_size(uint32 size);
extern my_bool translog_rotate();

/* record parts descriptor */
struct st_translog_parts
Expand Down
4 changes: 4 additions & 0 deletions storage/maria/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ ADD_EXECUTABLE(ma_test_loghandler_purge-t
ma_test_loghandler_purge-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
MY_ADD_TEST(ma_test_loghandler_purge)

ADD_EXECUTABLE(ma_test_loghandler_rotate-t
ma_test_loghandler_rotate-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
MY_ADD_TEST(ma_test_loghandler_rotate)

ADD_EXECUTABLE(ma_test_loghandler_readonly-t
ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c sequence_storage.c)
MY_ADD_TEST(ma_test_loghandler_readonly)
Expand Down
Loading
Loading