Merge branch 'develop' into mon_script_test

This commit is contained in:
Markus Makela
2015-05-05 18:30:08 +03:00
14 changed files with 248 additions and 178 deletions

1
.gitignore vendored
View File

@ -34,3 +34,4 @@ depend.mk
# Vi swap files
.*.swp
/build/

View File

@ -446,6 +446,7 @@ backend_write_timeout=2
# galeramon specific options
disable_master_failback=0
available_when_donor=0
disable_master_role_setting=0
```
#### `module`
@ -518,6 +519,13 @@ This option if set to 1 will allow Galera monitor to keep a node in `Donor` stat
As xtrabackup is a non-locking SST method, a node in `Donor` status can still be considered in sync. This option is not enabled by default and should be used as the administrator's discretion.
#### `disable_master_role_setting`
This option if set to 1 will stop the Galera monitor from setting the status of
backend servers to master or slave. It is applicable when the Galera router is
being used to spread writes across multiple nodes, so that no server is to be
nominated as the master.
#### `backend_connect_timeout`
This option, with default value of `3` sets the monitor connect timeout to backends.
@ -1377,11 +1385,11 @@ Example:
```
[Galera Listener]
type=listener
address=192.1681.3.33
address=192.168.3.33
port=4408
socket=/servers/maxscale/galera.sock
```
TCP/IP Traffic must be permitted to 192.1681.3.33 port 4408
TCP/IP Traffic must be permitted to 192.168.3.33 port 4408
For Unix socket, the socket file path (example: `/servers/maxscale/galera.sock`) must be writable by the Unix user MaxScale runs as.

View File

@ -54,7 +54,7 @@ static simple_mutex_t msg_mutex;
static int highprec = 0;
static int do_syslog = 1;
static int do_maxscalelog = 1;
static int use_stdout = 0;
/**
* Variable holding the enabled logfiles information.
* Used from log users to check enabled logs prior calling
@ -1331,12 +1331,14 @@ static bool logfile_set_enabled(
}
lf = &lm->lm_logfile[id];
CHK_LOGFILE(lf);
if(use_stdout == 0)
{
if (val) {
logstr = strdup("---\tLogging to file is enabled\t--");
} else {
logstr = strdup("---\tLogging to file is disabled\t--");
}
if (val) {
logstr = strdup("---\tLogging to file is enabled\t--");
} else {
logstr = strdup("---\tLogging to file is disabled\t--");
}
oldval = lf->lf_enabled;
lf->lf_enabled = val;
err = logmanager_write_log(id,
@ -1348,7 +1350,7 @@ static bool logfile_set_enabled(
logstr,
notused);
free(logstr);
}
if (err != 0) {
lf->lf_enabled = oldval;
fprintf(stderr,
@ -1445,7 +1447,7 @@ int skygw_log_write(
* Find out the length of log string (to be formatted str).
*/
va_start(valist, str);
len = vsnprintf(NULL, 0, str, valist);
len = vsnprintf(NULL, 0, str, valist);
va_end(valist);
/**
* Add one for line feed.
@ -1695,9 +1697,12 @@ static bool fnames_conf_init(
fn->fn_chk_tail = CHK_NUM_FNAMES;
#endif
optind = 1; /**<! reset getopt index */
while ((opt = getopt(argc, argv, "+a:b:c:d:e:f:g:h:i:j:l:m:s:")) != -1)
while ((opt = getopt(argc, argv, "+a:b:c:d:e:f:g:h:i:j:l:m:s:o")) != -1)
{
switch (opt) {
case 'o':
use_stdout = 1;
break;
case 'a':
fn->fn_debug_prefix = strndup(optarg, MAX_PREFIXLEN);
break;
@ -2154,7 +2159,13 @@ static bool logfile_open_file(
char* start_msg_str;
int err;
if (lf->lf_store_shmem)
if(use_stdout)
{
fw->fwr_file[lf->lf_id] = skygw_file_alloc (
lf->lf_full_file_name);
fw->fwr_file[lf->lf_id]->sf_file = stdout;
}
else if (lf->lf_store_shmem)
{
/** Create symlink pointing to log file */
fw->fwr_file[lf->lf_id] = skygw_file_init(
@ -2178,31 +2189,34 @@ static bool logfile_open_file(
goto return_succp;
}
if (lf->lf_enabled)
{
if(use_stdout == 0)
{
if (lf->lf_enabled)
{
start_msg_str = strdup("---\tLogging is enabled.\n");
}
else
{
}
else
{
start_msg_str = strdup("---\tLogging is disabled.\n");
}
err = skygw_file_write(fw->fwr_file[lf->lf_id],
(void *)start_msg_str,
strlen(start_msg_str),
true);
}
err = skygw_file_write(fw->fwr_file[lf->lf_id],
(void *)start_msg_str,
strlen(start_msg_str),
true);
if (err != 0)
{
if (err != 0)
{
fprintf(stderr,
"Error : writing to file %s failed due to %d, %s. "
"Error : writing to file %s failed due to %d, %s. "
"Exiting MaxScale.\n",
lf->lf_full_file_name,
err,
strerror(err));
lf->lf_full_file_name,
err,
strerror(err));
succp = false;
goto return_succp;
}
free(start_msg_str);
}
free(start_msg_str);
}
succp = true;
return_succp:
@ -2727,7 +2741,10 @@ static void filewriter_done(
for (i=LOGFILE_FIRST; i<=LOGFILE_LAST; i++)
{
id = (logfile_id_t)i;
skygw_file_close(fw->fwr_file[id], true);
if(use_stdout)
skygw_file_free(fw->fwr_file[id]);
else
skygw_file_close(fw->fwr_file[id], true);
}
fw->fwr_state = DONE;
case DONE:
@ -2859,6 +2876,9 @@ static void* thr_filewriter_fun(
}
else if ((succp = logfile_open_file(fwr, lf)))
{
if(use_stdout)
skygw_file_free (file);
else
skygw_file_close(file, false); /*< close old file */
}

View File

@ -43,6 +43,7 @@
* 20/02/15 Markus Mäkelä Added connection_timeout parameter for services
* 05/03/15 Massimiliano Pinto Added notification_feedback support
* 20/04/15 Guillaume Lefranc Added available_when_donor parameter
* 22/04/15 Martin Brampton Added disable_master_role_setting parameter
*
* @endverbatim
*/
@ -301,7 +302,15 @@ process_config_context(CONFIG_CONTEXT *context)
{
CONFIG_CONTEXT *obj;
int error_count = 0;
HASHTABLE* monitorhash;
if((monitorhash = hashtable_alloc(5,simple_str_hash,strcmp)) == NULL)
{
skygw_log_write(LOGFILE_ERROR,"Error: Failed to allocate ,onitor configuration check hashtable.");
return 0;
}
hashtable_memory_fns(monitorhash,strdup,NULL,free,NULL);
/**
* Process the data and create the services and servers defined
* in the data.
@ -953,6 +962,13 @@ int error_count = 0;
obj->element && obj1->element)
{
found = 1;
if(hashtable_add(monitorhash,obj1->object,"") == 0)
{
skygw_log_write(LOGFILE_ERROR,
"Warning: Multiple monitors are monitoring server [%s]. "
"This will cause undefined behavior.",
obj1->object);
}
monitorAddServer(
obj->element,
obj1->element);
@ -1014,6 +1030,7 @@ int error_count = 0;
} /*< while */
/** TODO: consistency check function */
hashtable_free(monitorhash);
/**
* error_count += consistency_checks();
*/
@ -1920,6 +1937,7 @@ static char *monitor_params[] =
"backend_read_timeout",
"backend_write_timeout",
"available_when_donor",
"disable_master_role_setting",
NULL
};
/**
@ -2033,15 +2051,18 @@ bool config_set_qualified_param(
int
config_truth_value(char *str)
{
if (strcasecmp(str, "true") == 0 || strcasecmp(str, "on") == 0 || strcasecmp(str, "yes") == 0)
if (strcasecmp(str, "true") == 0 || strcasecmp(str, "on") == 0 ||
strcasecmp(str, "yes") == 0 || strcasecmp(str, "1") == 0)
{
return 1;
}
if (strcasecmp(str, "false") == 0 || strcasecmp(str, "off") == 0 || strcasecmp(str, "no") == 0)
if (strcasecmp(str, "false") == 0 || strcasecmp(str, "off") == 0 ||
strcasecmp(str, "no") == 0|| strcasecmp(str, "0") == 0)
{
return 0;
}
return atoi(str);
skygw_log_write(LOGFILE_ERROR,"Error: Not a boolean value: %s",str);
return -1;
}

View File

@ -33,7 +33,7 @@
#include <log_manager.h>
int main(int argc, char **argv)
{
int arg_count = 3;
int arg_count = 4;
char *home;
char** arg_vector;
@ -44,7 +44,7 @@ int main(int argc, char **argv)
exit(1);
}
arg_vector = malloc(sizeof(char*)*4);
arg_vector = malloc(sizeof(char*)*5);
if(arg_vector == NULL)
{
@ -64,8 +64,8 @@ int main(int argc, char **argv)
{
arg_vector[2] = strdup("/usr/local/mariadb-maxscale/log");
}
arg_vector[3] = NULL;
arg_vector[3] = "-o";
arg_vector[4] = NULL;
skygw_logmanager_init(arg_count,arg_vector);
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOGFILE_DEBUG);

View File

@ -41,7 +41,7 @@ int
main(int argc, char **argv)
{
char *enc, *pw;
int arg_count = 3;
int arg_count = 4;
char *home;
char** arg_vector;
@ -52,7 +52,7 @@ main(int argc, char **argv)
exit(1);
}
arg_vector = malloc(sizeof(char*)*4);
arg_vector = malloc(sizeof(char*)*5);
if(arg_vector == NULL)
{
@ -73,7 +73,8 @@ main(int argc, char **argv)
arg_vector[2] = strdup("/usr/local/mariadb-maxscale/log");
}
arg_vector[3] = NULL;
arg_vector[3] = "-o";
arg_vector[4] = NULL;
skygw_logmanager_init(arg_count,arg_vector);
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOGFILE_DEBUG);

View File

@ -96,7 +96,11 @@ HASHTABLE *hashtable_alloc_flat(HASHTABLE* target,
int (*hashfn)(),
int (*cmpfn)());
/**< Allocate a hashtable */
extern void hashtable_memory_fns(HASHTABLE *, HASHMEMORYFN, HASHMEMORYFN, HASHMEMORYFN, HASHMEMORYFN);
extern void hashtable_memory_fns(HASHTABLE *table,
HASHMEMORYFN kcopyfn,
HASHMEMORYFN vcopyfn,
HASHMEMORYFN kfreefn,
HASHMEMORYFN vfreefn);
/**< Provide an interface to control key/value memory
* manipulation
*/

View File

@ -2225,15 +2225,11 @@ int main(int argc, char** argv)
}
printf("Log files written to: %s\n",home?home:"/tpm");
int argc_ = 11;
int argc_ = 2;
char* argv_[] =
{
"log_manager",
"-j",home?home:"/tmp",
"-a","ruleparser_debug",
"-c","ruleparser_trace",
"-e","ruleparser_message",
"-g","ruleparser_error",
"-o",
NULL
};

View File

@ -32,7 +32,8 @@
* 24/06/14 Massimiliano Pinto Added depth level 0 for each node
* 30/10/14 Massimiliano Pinto Added disableMasterFailback feature
* 10/11/14 Massimiliano Pinto Added setNetworkTimeout for connect,read,write
* 20/05/15 Guillaume Lefranc Added availableWhenDonor feature
* 20/04/15 Guillaume Lefranc Added availableWhenDonor feature
* 22/04/15 Martin Brampton Addition of disableMasterRoleSetting
*
* @endverbatim
*/
@ -160,6 +161,7 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
handle->interval = MONITOR_INTERVAL;
handle->disableMasterFailback = 0;
handle->availableWhenDonor = 0;
handle->disableMasterRoleSetting = 0;
handle->master = NULL;
handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT;
handle->read_timeout=DEFAULT_READ_TIMEOUT;
@ -172,8 +174,10 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
{
if(!strcmp(params->name,"disable_master_failback"))
handle->disableMasterFailback = config_truth_value(params->value);
if(!strcmp(params->name,"available_when_donor"))
else if(!strcmp(params->name,"available_when_donor"))
handle->availableWhenDonor = config_truth_value(params->value);
else if(!strcmp(params->name,"disable_master_role_setting"))
handle->disableMasterRoleSetting = config_truth_value(params->value);
params = params->next;
}
@ -294,6 +298,7 @@ char *sep;
dcb_printf(dcb,"\tSampling interval:\t%lu milliseconds\n", handle->interval);
dcb_printf(dcb,"\tMaster Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
dcb_printf(dcb,"\tAvailable when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
dcb_printf(dcb,"\tMaster Role Setting Disabled:\t%s\n", (handle->disableMasterRoleSetting == 1) ? "on" : "off");
dcb_printf(dcb,"\tConnect Timeout:\t%i seconds\n", handle->connect_timeout);
dcb_printf(dcb,"\tRead Timeout:\t\t%i seconds\n", handle->read_timeout);
dcb_printf(dcb,"\tWrite Timeout:\t\t%i seconds\n", handle->write_timeout);
@ -596,40 +601,47 @@ int log_no_members = 1;
* Decision depends on master_stickiness value set in configuration
*/
/* get the candidate master, followinf MIN(node_id) rule */
/* get the candidate master, following MIN(node_id) rule */
candidate_master = get_candidate_master(handle->databases);
/* Select the master, based on master_stickiness */
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
if (1 == handle->disableMasterRoleSetting) {
handle->master = NULL;
}
else {
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
}
ptr = handle->databases;
while (ptr && handle->master) {
while (ptr) {
if (!SERVER_IS_JOINED(ptr->server) || SERVER_IN_MAINT(ptr->server)) {
ptr = ptr->next;
continue;
}
if (ptr != handle->master) {
if (handle->master) {
if (ptr != handle->master) {
/* set the Slave role */
server_set_status(ptr->server, SERVER_SLAVE);
server_clear_status(ptr->server, SERVER_MASTER);
/* clear master stickyness */
/* clear master stickiness */
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
} else {
} else {
/* set the Master role */
server_set_status(handle->master->server, SERVER_MASTER);
server_clear_status(handle->master->server, SERVER_SLAVE);
if (candidate_master && handle->master->server->node_id != candidate_master->server->node_id) {
/* set master stickyness */
/* set master stickiness */
server_set_status(handle->master->server, SERVER_MASTER_STICKINESS);
} else {
/* clear master stickyness */
/* clear master stickiness */
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
}
}
}
}
is_cluster++;

View File

@ -35,7 +35,8 @@
* 28/08/14 Massimiliano Pinto Addition of detectStaleMaster
* 30/10/14 Massimiliano Pinto Addition of disableMasterFailback
* 07/11/14 Massimiliano Pinto Addition of NetworkTimeout: connect, read, write
* 20/05/15 Guillaume Lefranc Addition of availableWhenDonor
* 20/04/15 Guillaume Lefranc Addition of availableWhenDonor
* 22/04/15 Martin Brampton Addition of disableMasterRoleSetting
*
* @endverbatim
*/
@ -70,6 +71,7 @@ typedef struct {
int detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */
MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */
int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */

View File

@ -238,24 +238,23 @@ static int hashcmpfun(
/**
* Convert a length encoded string into a C string.
* @param data Pointer to the first byte of the string
* @param len Pointer to an integer where the length of the string will be stored. On errors this will be set to -1.
* @return Pointer to the newly allocated string or NULL if the value is NULL or an error occurred
*/
char* get_lenenc_str(void* data, int* len)
char* get_lenenc_str(void* data)
{
unsigned char* ptr = (unsigned char*)data;
char* rval;
unsigned long size, offset;
uintptr_t size;
long offset;
if(data == NULL || len == NULL)
if(data == NULL)
{
*len = -1;
return NULL;
}
if(*ptr < 251)
{
size = *ptr;
size = (uintptr_t)*ptr;
offset = 1;
}
else
@ -263,7 +262,6 @@ char* get_lenenc_str(void* data, int* len)
switch(*(ptr))
{
case 0xfb:
*len = 1;
return NULL;
case 0xfc:
size = *(ptr + 1) + (*(ptr + 2) << 8);
@ -274,14 +272,9 @@ char* get_lenenc_str(void* data, int* len)
offset = 3;
break;
case 0xfe:
size = *ptr +
((*(ptr + 2) << 8)) +
(*(ptr + 3) << 16) +
(*(ptr + 4) << 24) +
((unsigned long)*(ptr + 5) << 32) +
((unsigned long)*(ptr + 6) << 40) +
((unsigned long)*(ptr + 7) << 48) +
((unsigned long)*(ptr + 8) << 56);
size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) +
(*(ptr + 4) << 24) + ((uintptr_t)*(ptr + 5) << 32) + ((uintptr_t)*(ptr + 6) << 40) +
((uintptr_t)*(ptr + 7) << 48) + ((uintptr_t)*(ptr + 8) << 56);
offset = 8;
break;
default:
@ -297,7 +290,6 @@ char* get_lenenc_str(void* data, int* len)
memset(rval + size,0,1);
}
*len = size + offset;
return rval;
}
@ -360,8 +352,7 @@ bool parse_showdb_response(ROUTER_CLIENT_SES* rses, backend_ref_t* bref, GWBUF**
{
int payloadlen = gw_mysql_get_byte3(ptr);
int packetlen = payloadlen + 4;
int len = 0;
char* data = get_lenenc_str(ptr+4,&len);
char* data = get_lenenc_str(ptr+4);
if(data)
{

View File

@ -246,25 +246,23 @@ hashcmpfun(
/**
* Convert a length encoded string into a C string.
* @param data Pointer to the first byte of the string
* @param len Pointer to an integer where the length of the string will be stored. On errors this will be set to -1.
* @return Pointer to the newly allocated string or NULL if the value is NULL or an error occurred
*/
char* get_lenenc_str(void* data, int* len)
char* get_lenenc_str(void* data)
{
unsigned char* ptr = (unsigned char*)data;
char* rval;
long size, offset;
uintptr_t size;
long offset;
if(data == NULL || len == NULL)
if(data == NULL)
{
if(len)
*len = -1;
return NULL;
}
if(*ptr < 251)
{
size = *ptr;
size = (uintptr_t)*ptr;
offset = 1;
}
else
@ -272,7 +270,6 @@ char* get_lenenc_str(void* data, int* len)
switch(*(ptr))
{
case 0xfb:
*len = 1;
return NULL;
case 0xfc:
size = *(ptr + 1) + (*(ptr + 2) << 8);
@ -284,8 +281,8 @@ char* get_lenenc_str(void* data, int* len)
break;
case 0xfe:
size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) +
(*(ptr + 4) << 24) + ((long)*(ptr + 5) << 32) + ((long)*(ptr + 6) << 40) +
((long)*(ptr + 7) << 48) + ((long)*(ptr + 8) << 56);
(*(ptr + 4) << 24) + ((uintptr_t)*(ptr + 5) << 32) + ((uintptr_t)*(ptr + 6) << 40) +
((uintptr_t)*(ptr + 7) << 48) + ((uintptr_t)*(ptr + 8) << 56);
offset = 8;
break;
default:
@ -301,7 +298,6 @@ char* get_lenenc_str(void* data, int* len)
memset(rval + size,0,1);
}
*len = size + offset;
return rval;
}
@ -344,8 +340,7 @@ parse_mapping_response(ROUTER_CLIENT_SES* rses, char* target, GWBUF* buf)
{
int payloadlen = gw_mysql_get_byte3(ptr);
int packetlen = payloadlen + 4;
int len = 0;
char* data = get_lenenc_str(ptr+4,&len);
char* data = get_lenenc_str(ptr+4);
if(data)
{

View File

@ -30,76 +30,6 @@
#include <sys/time.h>
#include "skygw_utils.h"
const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
/** One for terminating '\0' */
const size_t timestamp_len = (4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1) * sizeof(char);
const char* timestamp_formatstr_hp = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
/** One for terminating '\0' */
const size_t timestamp_len_hp = (4+1 +2+1 +2+1 +2+1 +2+1 +2+1+3+3 +1) * sizeof(char);
/** Single-linked list for storing test cases */
struct slist_node_st {
skygw_chk_t slnode_chk_top;
slist_t* slnode_list;
slist_node_t* slnode_next;
void* slnode_data;
size_t slnode_cursor_refcount;
skygw_chk_t slnode_chk_tail;
};
struct slist_st {
skygw_chk_t slist_chk_top;
slist_node_t* slist_head;
slist_node_t* slist_tail;
int slist_nelems;
slist_t* slist_cursors_list;
skygw_chk_t slist_chk_tail;
};
struct slist_cursor_st {
skygw_chk_t slcursor_chk_top;
slist_t* slcursor_list;
slist_node_t* slcursor_pos;
skygw_chk_t slcursor_chk_tail;
};
struct skygw_thread_st {
skygw_chk_t sth_chk_top;
bool sth_must_exit;
simple_mutex_t* sth_mutex;
pthread_t sth_parent;
pthread_t sth_thr;
int sth_errno;
#if defined(SS_DEBUG)
skygw_thr_state_t sth_state;
#endif
char* sth_name;
void* (*sth_thrfun)(void* data);
void* sth_data;
skygw_chk_t sth_chk_tail;
};
struct skygw_message_st {
skygw_chk_t mes_chk_top;
bool mes_sent;
pthread_mutex_t mes_mutex;
pthread_cond_t mes_cond;
skygw_chk_t mes_chk_tail;
};
struct skygw_file_st {
skygw_chk_t sf_chk_top;
char* sf_fname;
FILE* sf_file;
int sf_fd;
skygw_chk_t sf_chk_tail;
};
/** End of structs and types */
#if defined(MLIST)
@ -1952,24 +1882,37 @@ return_rc:
return rc;
}
skygw_file_t* skygw_file_alloc(
char* fname)
{
skygw_file_t* file;
if ((file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t))) == NULL)
{
fprintf(stderr,
"* Error : Memory allocation for file %s failed.\n",
fname);
perror("SkyGW file allocation\n");
return NULL;
}
ss_dassert(file != NULL);
file->sf_chk_top = CHK_NUM_FILE;
file->sf_chk_tail = CHK_NUM_FILE;
file->sf_fname = strdup(fname);
return file;
}
skygw_file_t* skygw_file_init(
char* fname,
char* symlinkname)
{
skygw_file_t* file;
if ((file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t))) == NULL)
if ((file = skygw_file_alloc (fname)) == NULL)
{
fprintf(stderr,
"* Error : Memory allocation for file %s failed.\n",
fname);
perror("SkyGW file allocation\n");
/** Error was reported in skygw_file_alloc */
goto return_file;
}
ss_dassert(file != NULL);
file->sf_chk_top = CHK_NUM_FILE;
file->sf_chk_tail = CHK_NUM_FILE;
file->sf_fname = strdup(fname);
if ((file->sf_file = fopen(file->sf_fname, "a")) == NULL)
{
@ -2033,6 +1976,12 @@ return_file:
return file;
}
void skygw_file_free(skygw_file_t* file)
{
free(file->sf_fname);
free(file);
}
void skygw_file_close(
skygw_file_t* file,
bool shutdown)
@ -2065,8 +2014,7 @@ void skygw_file_close(
else
{
ss_dfprintf(stderr, "Closed %s\n", file->sf_fname);
free(file->sf_fname);
free(file);
skygw_file_free (file);
}
}
}

View File

@ -80,6 +80,75 @@ struct mlist_node_st {
typedef enum { THR_INIT, THR_RUNNING, THR_STOPPED, THR_DONE } skygw_thr_state_t;
typedef enum { MES_RC_FAIL, MES_RC_SUCCESS, MES_RC_TIMEOUT } skygw_mes_rc_t;
static const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
/** One for terminating '\0' */
static const size_t timestamp_len = (4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1) * sizeof(char);
static const char* timestamp_formatstr_hp = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
/** One for terminating '\0' */
static const size_t timestamp_len_hp = (4+1 +2+1 +2+1 +2+1 +2+1 +2+1+3+3 +1) * sizeof(char);
/** Single-linked list for storing test cases */
struct slist_node_st {
skygw_chk_t slnode_chk_top;
slist_t* slnode_list;
slist_node_t* slnode_next;
void* slnode_data;
size_t slnode_cursor_refcount;
skygw_chk_t slnode_chk_tail;
};
struct slist_st {
skygw_chk_t slist_chk_top;
slist_node_t* slist_head;
slist_node_t* slist_tail;
int slist_nelems;
slist_t* slist_cursors_list;
skygw_chk_t slist_chk_tail;
};
struct slist_cursor_st {
skygw_chk_t slcursor_chk_top;
slist_t* slcursor_list;
slist_node_t* slcursor_pos;
skygw_chk_t slcursor_chk_tail;
};
struct skygw_thread_st {
skygw_chk_t sth_chk_top;
bool sth_must_exit;
simple_mutex_t* sth_mutex;
pthread_t sth_parent;
pthread_t sth_thr;
int sth_errno;
#if defined(SS_DEBUG)
skygw_thr_state_t sth_state;
#endif
char* sth_name;
void* (*sth_thrfun)(void* data);
void* sth_data;
skygw_chk_t sth_chk_tail;
};
struct skygw_message_st {
skygw_chk_t mes_chk_top;
bool mes_sent;
pthread_mutex_t mes_mutex;
pthread_cond_t mes_cond;
skygw_chk_t mes_chk_tail;
};
struct skygw_file_st {
skygw_chk_t sf_chk_top;
char* sf_fname;
FILE* sf_file;
int sf_fd;
skygw_chk_t sf_chk_tail;
};
EXTERN_C_BLOCK_BEGIN
slist_cursor_t* slist_init(void);
@ -147,6 +216,8 @@ EXTERN_C_BLOCK_END
/** Skygw thread routines */
/** Skygw file routines */
skygw_file_t* skygw_file_alloc(char* fname);
void skygw_file_free(skygw_file_t* file);
skygw_file_t* skygw_file_init(char* fname, char* symlinkname);
void skygw_file_close(skygw_file_t* file, bool shutdown);
int skygw_file_write(