Ensured that soft link and physical file will have same sequence number. Prevented some unnecessary error printing and added more precise logs.
This commit is contained in:
VilhoRaatikka
2014-12-02 20:02:00 +02:00
parent 8dc49f4c60
commit d608eb2532
2 changed files with 84 additions and 28 deletions

View File

@ -286,7 +286,8 @@ static char* add_slash(char* str);
static bool check_file_and_path( static bool check_file_and_path(
char* filename, char* filename,
bool* writable); bool* writable,
bool do_log);
static bool file_is_symlink(char* filename); static bool file_is_symlink(char* filename);
static int skygw_log_disable_raw(logfile_id_t id, bool emergency); /*< no locking */ static int skygw_log_disable_raw(logfile_id_t id, bool emergency); /*< no locking */
@ -2053,7 +2054,7 @@ static bool logfile_create(
* If file exists but is different type, create fails and * If file exists but is different type, create fails and
* new, increased sequence number is added to file name. * new, increased sequence number is added to file name.
*/ */
if (check_file_and_path(lf->lf_full_file_name, &writable)) if (check_file_and_path(lf->lf_full_file_name, &writable, true))
{ {
/** Found similarly named file which isn't writable */ /** Found similarly named file which isn't writable */
if (!writable || file_is_symlink(lf->lf_full_file_name)) if (!writable || file_is_symlink(lf->lf_full_file_name))
@ -2077,13 +2078,12 @@ static bool logfile_create(
if (store_shmem) if (store_shmem)
{ {
if (check_file_and_path(lf->lf_full_file_name, &writable)) if (check_file_and_path(lf->lf_full_link_name, &writable, true))
{ {
/** Found similarly named file which isn't writable */ /** Found similarly named link which isn't writable */
if (!writable || if (!writable)
file_is_symlink(lf->lf_full_file_name))
{ {
unlink(lf->lf_full_file_name); unlink(lf->lf_full_link_name);
nameconflicts = true; nameconflicts = true;
} }
} }
@ -2214,7 +2214,6 @@ return_succp:
* *
* @return Pointer to filename, of NULL if failed. * @return Pointer to filename, of NULL if failed.
* *
*
*/ */
static char* form_full_file_name( static char* form_full_file_name(
strpart_t* parts, strpart_t* parts,
@ -2231,9 +2230,21 @@ static char* form_full_file_name(
if (lf->lf_name_seqno != -1) if (lf->lf_name_seqno != -1)
{ {
lf->lf_name_seqno = find_last_seqno(parts, int file_sn;
lf->lf_name_seqno, int link_sn = 0;
seqnoidx); char* tmp = parts[0].sp_string;
file_sn = find_last_seqno(parts, lf->lf_name_seqno, seqnoidx);
if (lf->lf_linkpath != NULL)
{
tmp = parts[0].sp_string;
parts[0].sp_string = lf->lf_linkpath;
link_sn = find_last_seqno(parts, lf->lf_name_seqno, seqnoidx);
parts[0].sp_string = tmp;
}
lf->lf_name_seqno = MAX(file_sn, link_sn);
seqno = lf->lf_name_seqno; seqno = lf->lf_name_seqno;
s = UINTLEN(seqno); s = UINTLEN(seqno);
seqnostr = (char *)malloc((int)s+1); seqnostr = (char *)malloc((int)s+1);
@ -2354,7 +2365,8 @@ static char* add_slash(
*/ */
static bool check_file_and_path( static bool check_file_and_path(
char* filename, char* filename,
bool* writable) bool* writable,
bool do_log)
{ {
int fd; int fd;
bool exists; bool exists;
@ -2381,12 +2393,24 @@ static bool check_file_and_path(
fd = open(filename, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG); fd = open(filename, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG);
if (fd == -1) if (fd == -1)
{
if (do_log && file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't access "
"file pointed to by %s due "
"to %s.\n",
filename,
strerror(errno));
}
else if (do_log)
{ {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Can't access %s due " "*\n* Error : Can't access %s due "
"to %s.\n", "to %s.\n",
filename, filename,
strerror(errno)); strerror(errno));
}
if (writable) if (writable)
{ {
*writable = false; *writable = false;
@ -2402,12 +2426,25 @@ static bool check_file_and_path(
*writable = true; *writable = true;
} }
else else
{
if (do_log &&
file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't write to "
"file pointed to by %s due to "
"%s.\n",
filename,
strerror(errno));
}
else if (do_log)
{ {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Can't write to " "*\n* Error : Can't write to "
"%s due to %s.\n", "%s due to %s.\n",
filename, filename,
strerror(errno)); strerror(errno));
}
*writable = false; *writable = false;
} }
} }
@ -2416,11 +2453,22 @@ static bool check_file_and_path(
exists = true; exists = true;
} }
else else
{
if (do_log && file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't access the file "
"pointed to by %s due to %s.\n",
filename,
strerror(errno));
}
else if (do_log)
{ {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Can't access %s due to %s.\n", "*\n* Error : Can't access %s due to %s.\n",
filename, filename,
strerror(errno)); strerror(errno));
}
exists = false; exists = false;
if (writable) if (writable)
@ -3061,7 +3109,7 @@ static int find_last_seqno(
} }
} }
if (check_file_and_path(filename, NULL)) if (check_file_and_path(filename, NULL, false))
{ {
seqno++; seqno++;
} }

View File

@ -31,7 +31,7 @@ threads=4
# backend_write_timeout=<timeout in seconds> # backend_write_timeout=<timeout in seconds>
# backend_read_timeout=<timeout in seconds> # backend_read_timeout=<timeout in seconds>
# #
## mysql_monitor specific options: ## MySQL monitor-specific options:
# #
# Enable detection of replication slaves lag via replication_heartbeat # Enable detection of replication slaves lag via replication_heartbeat
# table - optional. # table - optional.
@ -43,6 +43,13 @@ threads=4
# #
# detect_stale_master=[1|0] (default 0) # detect_stale_master=[1|0] (default 0)
# #
## Galera monitor-specific options:
#
# If disable_master_failback is not set, recovery of previously failed master
# causes mastership to be switched back to it. Enabling the option prevents it.
#
# disable_master_failback=[0|1] (default 0)
#
## Examples: ## Examples:
[MySQL Monitor] [MySQL Monitor]
@ -65,6 +72,7 @@ servers=server1,server2,server3
user=myuser user=myuser
passwd=mypwd passwd=mypwd
monitor_interval=10000 monitor_interval=10000
disable_master_failback=1
## Filter definition ## Filter definition
# #