Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
3d61d2d9
Commit
3d61d2d9
authored
Mar 11, 2003
by
gluh@gluh.mysql.r18.ru
Browse files
Options
Browse Files
Download
Plain Diff
Conflicts relsolving
parents
9c883874
e7f4bf5b
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
177 additions
and
22 deletions
+177
-22
mysql-test/r/rpl_rotate_logs.result
mysql-test/r/rpl_rotate_logs.result
+6
-1
mysql-test/t/rpl_rotate_logs.test
mysql-test/t/rpl_rotate_logs.test
+3
-1
sql/lex.h
sql/lex.h
+1
-0
sql/log.cc
sql/log.cc
+81
-6
sql/mysql_priv.h
sql/mysql_priv.h
+1
-0
sql/mysqld.cc
sql/mysqld.cc
+14
-0
sql/set_var.cc
sql/set_var.cc
+4
-0
sql/sql_class.h
sql/sql_class.h
+2
-0
sql/sql_lex.h
sql/sql_lex.h
+2
-1
sql/sql_parse.cc
sql/sql_parse.cc
+16
-1
sql/sql_repl.cc
sql/sql_repl.cc
+18
-7
sql/sql_repl.h
sql/sql_repl.h
+1
-0
sql/sql_yacc.yy
sql/sql_yacc.yy
+28
-5
No files found.
mysql-test/r/rpl_rotate_logs.result
View file @
3d61d2d9
...
...
@@ -40,7 +40,12 @@ set insert_id=1234;
insert into t2 values(NULL);
set global sql_slave_skip_counter=1;
start slave;
purge master logs to 'master-bin.000003';
purge master logs to 'master-bin.000002';
show binary logs;
Log_name
master-bin.000002
master-bin.000003
purge logs before now();
show binary logs;
Log_name
master-bin.000003
...
...
mysql-test/t/rpl_rotate_logs.test
View file @
3d61d2d9
...
...
@@ -89,7 +89,9 @@ connection master;
#let slave catch up
sync_slave_with_master
;
connection
master
;
purge
master
logs
to
'master-bin.000003'
;
purge
master
logs
to
'master-bin.000002'
;
show
binary
logs
;
purge
logs
before
now
();
show
binary
logs
;
insert
into
t2
values
(
65
);
sync_slave_with_master
;
...
...
sql/lex.h
View file @
3d61d2d9
...
...
@@ -64,6 +64,7 @@ static SYMBOL symbols[] = {
{
"AVG_ROW_LENGTH"
,
SYM
(
AVG_ROW_LENGTH
),
0
,
0
},
{
"AUTO_INCREMENT"
,
SYM
(
AUTO_INC
),
0
,
0
},
{
"BACKUP"
,
SYM
(
BACKUP_SYM
),
0
,
0
},
{
"BEFORE"
,
SYM
(
BEFORE_SYM
),
0
,
0
},
{
"BEGIN"
,
SYM
(
BEGIN_SYM
),
0
,
0
},
{
"BERKELEYDB"
,
SYM
(
BERKELEY_DB_SYM
),
0
,
0
},
{
"BDB"
,
SYM
(
BERKELEY_DB_SYM
),
0
,
0
},
...
...
sql/log.cc
View file @
3d61d2d9
...
...
@@ -687,6 +687,19 @@ int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli)
DBUG_RETURN
(
error
);
}
/*
Update log index_file
*/
int
MYSQL_LOG
::
update_log_index
(
LOG_INFO
*
log_info
)
{
if
(
copy_up_file_and_fill
(
&
index_file
,
log_info
->
index_file_start_offset
))
return
LOG_INFO_IO
;
// now update offsets in index file for running threads
adjust_linfo_offsets
(
log_info
->
index_file_start_offset
);
return
0
;
}
/*
Remove all logs before the given log from disk and from the index file.
...
...
@@ -739,21 +752,76 @@ int MYSQL_LOG::purge_logs(THD* thd, const char* to_log)
If we get killed -9 here, the sysadmin would have to edit
the log index file after restart - otherwise, this should be safe
*/
error
=
update_log_index
(
&
log_info
);
if
(
copy_up_file_and_fill
(
&
index_file
,
log_info
.
index_file_start_offset
))
{
error
=
LOG_INFO_IO
;
err:
pthread_mutex_unlock
(
&
LOCK_index
);
DBUG_RETURN
(
error
);
}
/*
Remove all logs before the given file date from disk and from the
index file.
SYNOPSIS
purge_logs_before_date()
thd Thread pointer
before_date Delete all log files before given date.
NOTES
If any of the logs before the deleted one is in use,
only purge logs up to this one.
RETURN VALUES
0 ok
LOG_INFO_PURGE_NO_ROTATE Binary file that can't be rotated
*/
int
MYSQL_LOG
::
purge_logs_before_date
(
THD
*
thd
,
time_t
purge_time
)
{
int
error
;
LOG_INFO
log_info
;
MY_STAT
stat_area
;
DBUG_ENTER
(
"purge_logs_before_date"
);
if
(
no_rotate
)
DBUG_RETURN
(
LOG_INFO_PURGE_NO_ROTATE
);
pthread_mutex_lock
(
&
LOCK_index
);
/*
Delete until we find curren file
or a file that is used or a file
that is older than purge_time.
*/
if
((
error
=
find_log_pos
(
&
log_info
,
NullS
,
0
/*no mutex*/
)))
goto
err
;
while
(
strcmp
(
log_file_name
,
log_info
.
log_file_name
)
&&
!
log_in_use
(
log_info
.
log_file_name
))
{
/* It's not fatal even if we can't delete a log file */
if
(
!
my_stat
(
log_info
.
log_file_name
,
&
stat_area
,
MYF
(
0
))
||
stat_area
.
st_mtime
>=
purge_time
)
break
;
my_delete
(
log_info
.
log_file_name
,
MYF
(
0
));
if
(
find_next_log
(
&
log_info
,
0
))
break
;
}
// now update offsets in index file for running threads
adjust_linfo_offsets
(
log_info
.
index_file_start_offset
);
/*
If we get killed -9 here, the sysadmin would have to edit
the log index file after restart - otherwise, this should be safe
*/
error
=
update_log_index
(
&
log_info
);
err:
pthread_mutex_unlock
(
&
LOCK_index
);
DBUG_RETURN
(
error
);
}
#endif
/* HAVE_REPLICATION */
...
...
@@ -1043,6 +1111,7 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command,
bool
MYSQL_LOG
::
write
(
Log_event
*
event_info
)
{
bool
error
=
0
;
bool
should_rotate
=
0
;
DBUG_ENTER
(
"MYSQL_LOG::write(event)"
);
if
(
!
inited
)
// Can't use mutex if not init
...
...
@@ -1055,7 +1124,6 @@ bool MYSQL_LOG::write(Log_event* event_info)
/* In most cases this is only called if 'is_open()' is true */
if
(
is_open
())
{
bool
should_rotate
=
0
;
THD
*
thd
=
event_info
->
thd
;
const
char
*
local_db
=
event_info
->
get_db
();
#ifdef USING_TRANSACTIONS
...
...
@@ -1192,6 +1260,13 @@ bool MYSQL_LOG::write(Log_event* event_info)
}
pthread_mutex_unlock
(
&
LOCK_log
);
if
(
should_rotate
&&
expire_logs_days
)
{
long
purge_time
=
time
(
0
)
-
expire_logs_days
*
24
*
60
*
60
;
if
(
purge_time
>=
0
)
error
=
purge_logs_before_date
(
current_thd
,
purge_time
);
}
DBUG_RETURN
(
error
);
}
...
...
sql/mysql_priv.h
View file @
3d61d2d9
...
...
@@ -713,6 +713,7 @@ extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
extern
ulong
max_binlog_size
,
rpl_recovery_rank
,
thread_cache_size
;
extern
ulong
com_stat
[(
uint
)
SQLCOM_END
],
com_other
,
back_log
;
extern
ulong
specialflag
,
current_pid
;
extern
ulong
expire_logs_days
;
extern
uint
test_flags
,
select_errors
,
ha_open_options
;
extern
uint
protocol_version
,
dropping_tables
;
...
...
sql/mysqld.cc
View file @
3d61d2d9
...
...
@@ -413,6 +413,7 @@ ulong max_connections,max_insert_delayed_threads,max_used_connections,
max_connect_errors
,
max_user_connections
=
0
;
ulong
thread_id
=
1L
,
current_pid
;
ulong
slow_launch_threads
=
0
;
ulong
expire_logs_days
=
0
;
char
mysql_real_data_home
[
FN_REFLEN
],
language
[
LIBLEN
],
reg_ext
[
FN_EXTLEN
],
...
...
@@ -2175,6 +2176,12 @@ static int init_server_components()
open_log
(
&
mysql_bin_log
,
glob_hostname
,
opt_bin_logname
,
"-bin"
,
opt_binlog_index_name
,
LOG_BIN
);
using_update_log
=
1
;
if
(
expire_logs_days
)
{
long
purge_time
=
time
(
0
)
-
expire_logs_days
*
24
*
60
*
60
;
if
(
purge_time
>=
0
)
mysql_bin_log
.
purge_logs_before_date
(
current_thd
,
purge_time
);
}
}
if
(
opt_error_log
)
...
...
@@ -3469,6 +3476,7 @@ enum options
OPT_ENABLE_SHARED_MEMORY
,
OPT_SHARED_MEMORY_BASE_NAME
,
OPT_OLD_PASSWORDS
,
OPT_EXPIRE_LOGS_DAYS
,
OPT_DEFAULT_WEEK_FORMAT
};
...
...
@@ -4286,6 +4294,11 @@ struct my_option my_long_options[] =
(
gptr
*
)
&
global_system_variables
.
net_wait_timeout
,
(
gptr
*
)
&
max_system_variables
.
net_wait_timeout
,
0
,
GET_ULONG
,
REQUIRED_ARG
,
NET_WAIT_TIMEOUT
,
1
,
LONG_TIMEOUT
,
0
,
1
,
0
},
{
"expire_logs_days"
,
OPT_EXPIRE_LOGS_DAYS
,
"Logs will be rotated after expire-log-days days. "
,
(
gptr
*
)
&
expire_logs_days
,
(
gptr
*
)
&
expire_logs_days
,
0
,
GET_ULONG
,
REQUIRED_ARG
,
0
,
0
,
99
,
0
,
1
,
0
},
{
"default-week-format"
,
OPT_DEFAULT_WEEK_FORMAT
,
"The default week format used by WEEK() functions."
,
(
gptr
*
)
&
global_system_variables
.
default_week_format
,
...
...
@@ -4336,6 +4349,7 @@ struct show_var_st status_vars[]= {
{
"Com_lock_tables"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_LOCK_TABLES
),
SHOW_LONG
},
{
"Com_optimize"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_OPTIMIZE
),
SHOW_LONG
},
{
"Com_purge"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_PURGE
),
SHOW_LONG
},
{
"Com_purge_before_date"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_PURGE_BEFORE
),
SHOW_LONG
},
{
"Com_rename_table"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_RENAME_TABLE
),
SHOW_LONG
},
{
"Com_repair"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_REPAIR
),
SHOW_LONG
},
{
"Com_replace"
,
(
char
*
)
(
com_stat
+
(
uint
)
SQLCOM_REPLACE
),
SHOW_LONG
},
...
...
sql/set_var.cc
View file @
3d61d2d9
...
...
@@ -120,6 +120,8 @@ sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout",
&
delayed_insert_timeout
);
sys_var_long_ptr
sys_delayed_queue_size
(
"delayed_queue_size"
,
&
delayed_queue_size
);
sys_var_long_ptr
sys_expire_logs_days
(
"expire_logs_days"
,
&
expire_logs_days
);
sys_var_bool_ptr
sys_flush
(
"flush"
,
&
myisam_flush
);
sys_var_long_ptr
sys_flush_time
(
"flush_time"
,
&
flush_time
);
sys_var_thd_ulong
sys_interactive_timeout
(
"interactive_timeout"
,
...
...
@@ -342,6 +344,7 @@ sys_var *sys_variables[]=
&
sys_delayed_insert_timeout
,
&
sys_delayed_queue_size
,
&
sys_error_count
,
&
sys_expire_logs_days
,
&
sys_flush
,
&
sys_flush_time
,
&
sys_foreign_key_checks
,
...
...
@@ -449,6 +452,7 @@ struct show_var_st init_vars[]= {
{
sys_delayed_insert_limit
.
name
,
(
char
*
)
&
sys_delayed_insert_limit
,
SHOW_SYS
},
{
sys_delayed_insert_timeout
.
name
,
(
char
*
)
&
sys_delayed_insert_timeout
,
SHOW_SYS
},
{
sys_delayed_queue_size
.
name
,(
char
*
)
&
sys_delayed_queue_size
,
SHOW_SYS
},
{
sys_expire_logs_days
.
name
,
(
char
*
)
&
sys_expire_logs_days
,
SHOW_SYS
},
{
sys_flush
.
name
,
(
char
*
)
&
sys_flush
,
SHOW_SYS
},
{
sys_flush_time
.
name
,
(
char
*
)
&
sys_flush_time
,
SHOW_SYS
},
{
"ft_boolean_syntax"
,
(
char
*
)
ft_boolean_syntax
,
SHOW_CHAR
},
...
...
sql/sql_class.h
View file @
3d61d2d9
...
...
@@ -143,7 +143,9 @@ class MYSQL_LOG {
int
generate_new_name
(
char
*
new_name
,
const
char
*
old_name
);
void
make_log_name
(
char
*
buf
,
const
char
*
log_ident
);
bool
is_active
(
const
char
*
log_file_name
);
int
update_log_index
(
LOG_INFO
*
linfo
);
int
purge_logs
(
THD
*
thd
,
const
char
*
to_log
);
int
purge_logs_before_date
(
THD
*
thd
,
time_t
purge_time
);
int
purge_first_log
(
struct
st_relay_log_info
*
rli
);
bool
reset_logs
(
THD
*
thd
);
// if we are exiting, we also want to close the index file
...
...
sql/sql_lex.h
View file @
3d61d2d9
...
...
@@ -64,7 +64,7 @@ enum enum_sql_command {
SQLCOM_ROLLBACK
,
SQLCOM_COMMIT
,
SQLCOM_SLAVE_START
,
SQLCOM_SLAVE_STOP
,
SQLCOM_BEGIN
,
SQLCOM_LOAD_MASTER_TABLE
,
SQLCOM_CHANGE_MASTER
,
SQLCOM_RENAME_TABLE
,
SQLCOM_BACKUP_TABLE
,
SQLCOM_RESTORE_TABLE
,
SQLCOM_RESET
,
SQLCOM_PURGE
,
SQLCOM_SHOW_BINLOGS
,
SQLCOM_RESET
,
SQLCOM_PURGE
,
SQLCOM_
PURGE_BEFORE
,
SQLCOM_
SHOW_BINLOGS
,
SQLCOM_SHOW_OPEN_TABLES
,
SQLCOM_LOAD_MASTER_DATA
,
SQLCOM_HA_OPEN
,
SQLCOM_HA_CLOSE
,
SQLCOM_HA_READ
,
SQLCOM_SHOW_SLAVE_HOSTS
,
SQLCOM_DELETE_MULTI
,
SQLCOM_UPDATE_MULTI
,
...
...
@@ -436,6 +436,7 @@ typedef struct st_lex
char
*
length
,
*
dec
,
*
change
,
*
name
;
char
*
backup_dir
;
/* For RESTORE/BACKUP */
char
*
to_log
;
/* For PURGE MASTER LOGS TO */
time_t
purge_time
;
/* For PURGE MASTER LOGS BEFORE */
char
*
x509_subject
,
*
x509_issuer
,
*
ssl_cipher
;
char
*
found_colon
;
/* For multi queries - next query */
enum
SSL_type
ssl_type
;
/* defined in violite.h */
...
...
sql/sql_parse.cc
View file @
3d61d2d9
...
...
@@ -1744,9 +1744,18 @@ mysql_execute_command(THD *thd)
{
if
(
check_global_access
(
thd
,
SUPER_ACL
))
goto
error
;
// PURGE MASTER LOGS TO 'file'
res
=
purge_master_logs
(
thd
,
lex
->
to_log
);
break
;
}
case
SQLCOM_PURGE_BEFORE
:
{
if
(
check_global_access
(
thd
,
SUPER_ACL
))
goto
error
;
// PURGE MASTER LOGS BEFORE 'data'
res
=
purge_master_logs_before_date
(
thd
,
lex
->
purge_time
);
break
;
}
#endif
case
SQLCOM_SHOW_WARNS
:
...
...
@@ -2866,7 +2875,7 @@ mysql_execute_command(THD *thd)
if
(
check_global_access
(
thd
,
RELOAD_ACL
)
||
check_db_used
(
thd
,
tables
))
goto
error
;
/* error sending is deferred to reload_acl_and_cache */
reload_acl_and_cache
(
thd
,
lex
->
type
,
tables
)
;
reload_acl_and_cache
(
thd
,
lex
->
type
,
tables
);
break
;
case
SQLCOM_KILL
:
kill_one_thread
(
thd
,
lex
->
thread_id
);
...
...
@@ -3931,6 +3940,12 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
mysql_log
.
new_file
(
1
);
mysql_update_log
.
new_file
(
1
);
mysql_bin_log
.
new_file
(
1
);
if
(
expire_logs_days
)
{
long
purge_time
=
time
(
0
)
-
expire_logs_days
*
24
*
60
*
60
;
if
(
purge_time
>=
0
)
mysql_bin_log
.
purge_logs_before_date
(
thd
,
purge_time
);
}
mysql_slow_log
.
new_file
(
1
);
if
(
ha_flush_logs
())
result
=
1
;
...
...
sql/sql_repl.cc
View file @
3d61d2d9
...
...
@@ -257,15 +257,10 @@ bool log_in_use(const char* log_name)
return
result
;
}
int
purge_master_logs
(
THD
*
thd
,
const
char
*
to_log
)
int
purge_error_message
(
THD
*
thd
,
int
res
)
{
char
search_file_name
[
FN_REFLEN
];
const
char
*
errmsg
=
0
;
mysql_bin_log
.
make_log_name
(
search_file_name
,
to_log
);
int
res
=
mysql_bin_log
.
purge_logs
(
thd
,
search_file_name
);
switch
(
res
)
{
case
0
:
break
;
case
LOG_INFO_EOF
:
errmsg
=
"Target log not found in binlog index"
;
break
;
...
...
@@ -289,10 +284,26 @@ binlog purge"; break;
}
else
send_ok
(
thd
);
return
0
;
}
int
purge_master_logs
(
THD
*
thd
,
const
char
*
to_log
)
{
char
search_file_name
[
FN_REFLEN
];
mysql_bin_log
.
make_log_name
(
search_file_name
,
to_log
);
int
res
=
mysql_bin_log
.
purge_logs
(
thd
,
search_file_name
);
return
purge_error_message
(
thd
,
res
);
}
int
purge_master_logs_before_date
(
THD
*
thd
,
time_t
purge_time
)
{
int
res
=
mysql_bin_log
.
purge_logs_before_date
(
thd
,
purge_time
);
return
purge_error_message
(
thd
,
res
);
}
/*
TODO: Clean up loop to only have one call to send_file()
*/
...
...
sql/sql_repl.h
View file @
3d61d2d9
...
...
@@ -34,6 +34,7 @@ int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
int
reset_slave
(
THD
*
thd
,
MASTER_INFO
*
mi
);
int
reset_master
(
THD
*
thd
);
int
purge_master_logs
(
THD
*
thd
,
const
char
*
to_log
);
int
purge_master_logs_before_date
(
THD
*
thd
,
time_t
purge_time
);
bool
log_in_use
(
const
char
*
log_name
);
void
adjust_linfo_offsets
(
my_off_t
purge_offset
);
int
show_binlogs
(
THD
*
thd
);
...
...
sql/sql_yacc.yy
View file @
3d61d2d9
...
...
@@ -532,6 +532,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token SUBJECT_SYM
%token CIPHER_SYM
%token HELP
%token BEFORE_SYM
%left SET_VAR
%left OR_OR_CONCAT OR
%left AND
...
...
@@ -3683,13 +3685,34 @@ purge:
PURGE
{
LEX *lex=Lex;
lex->sql_command = SQLCOM_PURGE;
lex->type=0;
} purge_options
{}
;
purge_options:
LOGS_SYM purge_option
| MASTER_SYM LOGS_SYM purge_option
;
purge_option:
TO_SYM TEXT_STRING
{
Lex->sql_command = SQLCOM_PURGE;
Lex->to_log = $2.str;
}
MASTER_SYM LOGS_SYM TO_SYM TEXT_STRING
| BEFORE_SYM expr
{
Lex->to_log = $6.str;
} ;
if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2))
{
net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE");
YYABORT;
}
Item *tmp= new Item_func_unix_timestamp($2);
Lex->sql_command = SQLCOM_PURGE_BEFORE;
Lex->purge_time= tmp->val_int();
}
;
/* kill threads */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment