Merge branch 'develop' into MXS-1603

This commit is contained in:
dapeng
2018-01-19 20:59:49 +08:00
committed by GitHub
42 changed files with 2521 additions and 512 deletions

View File

@ -152,7 +152,7 @@ bool runtime_create_server(const char *name, const char *address, const char *po
}
if (protocol == NULL)
{
protocol = "MySQLBackend";
protocol = "mariadbbackend";
}
if (authenticator == NULL && (authenticator = get_default_authenticator(protocol)) == NULL)
{
@ -808,7 +808,7 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add
}
if (proto == NULL || strcasecmp(proto, CN_DEFAULT) == 0)
{
proto = "MySQLClient";
proto = "mariadbclient";
}
if (auth && strcasecmp(auth, CN_DEFAULT) == 0)

View File

@ -1398,15 +1398,15 @@ int main(int argc, char **argv)
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
THREAD log_flush_thr;
char* tmp_path;
char* tmp_var;
int option_index;
int *syslog_enabled = &config_get_global_options()->syslog; /** Log to syslog */
int *maxlog_enabled = &config_get_global_options()->maxlog; /** Log with MaxScale */
int *log_to_shm = &config_get_global_options()->log_to_shm; /** Log to shared memory */
MXS_CONFIG* cnf = config_get_global_options();
ss_dassert(cnf);
int *syslog_enabled = &cnf->syslog; /** Log to syslog */
int *maxlog_enabled = &cnf->maxlog; /** Log with MaxScale */
int *log_to_shm = &cnf->log_to_shm; /** Log to shared memory */
ssize_t log_flush_timeout_ms = 0;
sigset_t sigpipe_mask;
sigset_t saved_mask;
bool config_check = false;
bool to_stdout = false;
void (*exitfunp[4])(void) = { mxs_log_finish, cleanup_process_datadir, write_footer, NULL };
int numlocks = 0;
@ -1415,7 +1415,6 @@ int main(int argc, char **argv)
const char* specified_user = NULL;
config_set_global_defaults();
MXS_CONFIG* cnf = config_get_global_options();
ss_dassert(cnf);
maxscale_reset_starttime();
@ -1719,7 +1718,7 @@ int main(int argc, char **argv)
goto return_main;
case 'c':
config_check = true;
cnf->config_check = true;
break;
case 'p':
@ -1753,7 +1752,7 @@ int main(int argc, char **argv)
goto return_main;
}
if (config_check)
if (cnf->config_check)
{
daemon_mode = false;
to_stdout = true;
@ -1918,7 +1917,7 @@ int main(int argc, char **argv)
{
bool succp;
if (mkdir(get_logdir(), 0777) != 0 && errno != EEXIST)
if (!cnf->config_check && mkdir(get_logdir(), 0777) != 0 && errno != EEXIST)
{
fprintf(stderr,
"Error: Cannot create log directory: %s\n",
@ -1965,19 +1964,23 @@ int main(int argc, char **argv)
MXS_NOTICE("Commit: %s", MAXSCALE_COMMIT);
#endif
/*
* Set the data directory. We use a unique directory name to avoid conflicts
* if multiple instances of MaxScale are being run on the same machine.
*/
if (create_datadir(get_datadir(), datadir))
if (!cnf->config_check)
{
set_process_datadir(datadir);
}
else
{
MXS_ERROR("Cannot create data directory '%s': %d %s\n",
datadir, errno, mxs_strerror(errno));
goto return_main;
/*
* Set the data directory. We use a unique directory name to avoid conflicts
* if multiple instances of MaxScale are being run on the same machine.
*/
if (create_datadir(get_datadir(), datadir))
{
set_process_datadir(datadir);
}
else
{
char errbuf[MXS_STRERROR_BUFLEN];
MXS_ERROR("Cannot create data directory '%s': %d %s\n",
datadir, errno, strerror_r(errno, errbuf, sizeof(errbuf)));
goto return_main;
}
}
if (!daemon_mode)
@ -2027,9 +2030,7 @@ int main(int argc, char **argv)
goto return_main;
}
cnf->config_check = config_check;
if (!config_check)
if (!cnf->config_check)
{
/** Check if a MaxScale process is already running */
if (pid_file_exists())
@ -2130,7 +2131,7 @@ int main(int argc, char **argv)
goto return_main;
}
if (config_check)
if (cnf->config_check)
{
MXS_NOTICE("Configuration was successfully verified.");
rc = MAXSCALE_SHUTDOWN;

View File

@ -21,6 +21,7 @@
#include <maxscale/semaphore.h>
#include <maxscale/spinlock.h>
#include <maxscale/thread.h>
#include <maxscale/query_classifier.h>
#include <maxscale/json_api.h>
/**
@ -52,20 +53,30 @@ static THREAD hk_thr_handle;
static void hkthread(void *);
bool hkinit()
struct hkinit_result
{
bool inited = false;
sem_t sem;
bool ok;
};
if (thread_start(&hk_thr_handle, hkthread, NULL, 0) != NULL)
bool
hkinit()
{
struct hkinit_result res;
sem_init(&res.sem, 0, 0);
res.ok = false;
if (thread_start(&hk_thr_handle, hkthread, &res, 0) != NULL)
{
inited = true;
sem_wait(&res.sem);
}
else
{
MXS_ALERT("Failed to start housekeeper thread.");
}
return inited;
sem_destroy(&res.sem);
return res.ok;
}
int hktask_add(const char *name, void (*taskfn)(void *), void *data, int frequency)
@ -214,6 +225,16 @@ void hkthread(void *data)
void *taskdata;
int i;
struct hkinit_result* res = (struct hkinit_result*)data;
res->ok = qc_thread_init(QC_INIT_BOTH);
if (!res->ok)
{
MXS_ERROR("Could not initialize housekeeper thread.");
}
sem_post(&res->sem);
while (!do_shutdown)
{
for (i = 0; i < 10; i++)
@ -253,6 +274,7 @@ void hkthread(void *data)
spinlock_release(&tasklock);
}
qc_thread_end(QC_INIT_BOTH);
MXS_NOTICE("Housekeeper shutting down.");
}

View File

@ -259,7 +259,7 @@ size_t datetime_sizes[] =
*/
static void unpack_datetime(uint8_t *ptr, int length, struct tm *dest)
{
int64_t val = 0;
uint64_t val = 0;
uint32_t second, minute, hour, day, month, year;
if (length == -1)
@ -717,6 +717,7 @@ size_t unpack_decimal_field(uint8_t *ptr, uint8_t *metadata, double *val_float)
int fpart2 = decimals - fpart1 * dec_dig;
int ibytes = ipart1 * 4 + dig_bytes[ipart2];
int fbytes = fpart1 * 4 + dig_bytes[fpart2];
int field_size = ibytes + fbytes;
/** Remove the sign bit and store it locally */
bool negative = (ptr[0] & 0x80) == 0;
@ -735,7 +736,17 @@ size_t unpack_decimal_field(uint8_t *ptr, uint8_t *metadata, double *val_float)
}
}
int64_t val_i = unpack_bytes(ptr, ibytes);
int64_t val_i = 0;
if (ibytes > 8)
{
int extra = ibytes - 8;
ptr += extra;
ibytes -= extra;
ss_dassert(ibytes == 8);
}
val_i = unpack_bytes(ptr, ibytes);
int64_t val_f = fbytes ? unpack_bytes(ptr + ibytes, fbytes) : 0;
if (negative)
@ -746,5 +757,5 @@ size_t unpack_decimal_field(uint8_t *ptr, uint8_t *metadata, double *val_float)
*val_float = (double)val_i + ((double)val_f / (pow(10.0, decimals)));
return ibytes + fbytes;
return field_size;
}

View File

@ -20,6 +20,11 @@
#include <maxscale/maxscale_test.h>
#include <maxscale/log_manager.h>
#include <maxscale/config.h>
#include <maxscale/query_classifier.h>
#include <maxscale/paths.h>
#include <maxscale/alloc.h>
#include <sys/stat.h>
#include "../internal/poll.h"
#include "../internal/statistics.h"
@ -28,15 +33,17 @@
void init_test_env(char *path)
{
int argc = 3;
const char* logdir = path ? path : TEST_LOG_DIR;
config_get_global_options()->n_threads = 1;
ts_stats_init();
mxs_log_init(NULL, logdir, MXS_LOG_TARGET_DEFAULT);
if (!mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT))
{
exit(1);
}
dcb_global_init();
set_libdir(MXS_STRDUP(TEST_DIR "/query_classifier/qc_sqlite/"));
qc_setup(NULL, QC_SQL_MODE_DEFAULT, NULL);
qc_process_init(QC_INIT_BOTH);
poll_init();
maxscale::MessageQueue::init();
maxscale::Worker::init();