1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Intermediate commit - just to make new files visible to bk in the new

tree


server-tools/instance-manager/Makefile.am:
  Fixed IM linking to avoid using both mysys and libmysql as the define the
  same symbols and therefore conflict
server-tools/instance-manager/listener.cc:
  Added ability to listen network ports
server-tools/instance-manager/listener.h:
  Various additions to the Listener_thread_args
server-tools/instance-manager/log.cc:
  merge
server-tools/instance-manager/log.h:
  merge
server-tools/instance-manager/manager.cc:
  Fixes and additions to enable guardian functionality
server-tools/instance-manager/manager.h:
  Changed manager() signature
server-tools/instance-manager/mysqlmanager.cc:
  Various fixes
server-tools/instance-manager/options.cc:
  Added handling of default values for new options in the Options struct. (such
  as default_user, default_password, monitoring_interval e.t.c)
server-tools/instance-manager/options.h:
  Added new options to the Options struct
sql/net_serv.cc:
  Added MYSQL_INSTANCE_MANAGER defines to enable alarm handling in the IM
server-tools/instance-manager/buffer.cc:
  Simple implementation of variable-length buffer
server-tools/instance-manager/command.cc:
  Abstract command. All commands are derived from Command class
server-tools/instance-manager/commands.h:
  Interfaces for all commands we have
server-tools/instance-manager/factory.cc:
  Commands factory. This class hides command instantiation. The idea is to
  handle various protocols this way. (different commands for different
  protocols
server-tools/instance-manager/guardian.cc:
  Guardian thread implementation (monitor and restart instances in case of a
  failure
server-tools/instance-manager/guardian.h:
  Guardian_thread and Guardian_thread_args class interface. The
  Guardian_thread is responsible for monitoring and restarting instances
server-tools/instance-manager/instance.cc:
  Instance class contains methods and data to manage a single instance
server-tools/instance-manager/instance.h:
  This file contains class an instance class interface. The class is
  responsible for starting/stopping an instance
server-tools/instance-manager/instance_map.cc:
  The instance repository. This class is also responsible for initialization
  of Instance class objects.
server-tools/instance-manager/instance_options.cc:
  The Instance_options class contains all methods to get and  handle options
  of an instance
server-tools/instance-manager/mysql_connection.cc:
  The class responsible for handling MySQL client/server protocol connections
server-tools/instance-manager/mysql_manager_error.h:
  The list of Instance Manger-specific errors
server-tools/instance-manager/parse.cc:
  Simple query parser
server-tools/instance-manager/parse.h:
  Parser interface
server-tools/instance-manager/protocol.cc:
  Here implemented functions used to handle mysql client/server protocol
server-tools/instance-manager/protocol.h:
  Interface for MySQL client/server protocol
server-tools/instance-manager/thread_registry.cc:
  Thread registry stores information about every thread. It's main function is
  to provide graceful shutdown for all threads.
server-tools/instance-manager/user_map.h:
  User map contains hash with user names and passwords
This commit is contained in:
unknown
2004-10-23 11:32:52 +04:00
parent 746e6e53e7
commit a5435ea78a
42 changed files with 4261 additions and 148 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
/* Copyright (C) 2003 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -14,20 +14,21 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "manager.h"
#include "options.h"
#include "log.h"
#include <my_global.h>
#include <my_sys.h>
#include <string.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "manager.h"
#include "options.h"
#include "log.h"
/*
Few notes about the Instance Manager architecture:
Few notes about Instance Manager architecture:
Instance Manager consisits of two processes: the angel process, and the
instance manager process. Responsibilities of the angel process is to
monitor the instance manager process, and restart it in case of
@ -35,19 +36,19 @@
'--run-as-service' is provided.
The Instance Manager process consists of several
subsystems (thread sets):
- the signal handling thread: it's responsibilities are to handle
- the signal handling thread: it's responsibilities are to handle
user signals and propogate them to the other threads. All other threads
are accounted in the signal handler thread Thread Repository.
- the listener: listens all sockets. There is a listening
are accounted in the signal handler thread Thread Registry.
- the listener: listens all sockets. There is a listening
socket for each (mysql, http, snmp, rendezvous (?)) subsystem.
- mysql subsystem: Instance Manager acts like an ordinary MySQL Server,
but with very restricted command set. Each MySQL client connection is
but with very restricted command set. Each MySQL client connection is
handled in a separate thread. All MySQL client connections threads
constitute mysql subsystem.
- http subsystem: it is also possible to talk with Instance Manager via
- http subsystem: it is also possible to talk with Instance Manager via
http. One thread per http connection is used. Threads are pooled.
- 'snmp' connections (FIXME: I know nothing about it yet)
- rendezvous threads
- rendezvous threads
*/
static void init_environment(char *progname);
@ -70,11 +71,12 @@ int main(int argc, char *argv[])
options.load(argc, argv);
if (options.run_as_service)
{
/* forks, and returns only in child */
daemonize(options.log_file_name);
/* forks again, and returns only in child: parent becomes angel */
angel(options);
}
else
manager(options.log_file_name);
manager(options);
return 0;
}
@ -90,6 +92,7 @@ static void init_environment(char *progname)
MY_INIT(progname);
log_init();
umask(0117);
srand(time(0));
}
@ -109,8 +112,8 @@ static void daemonize(const char *log_file_name)
int fd;
/*
Become a session leader: setsid must succeed because child is
guaranteed not to be a process group leader (it belongs to the
process group of the parent.)
guaranteed not to be a process group leader (it belongs to the
process group of the parent.)
The goal is not to have a controlling terminal.
*/
setsid();
@ -121,7 +124,7 @@ static void daemonize(const char *log_file_name)
close(STDIN_FILENO);
fd= open(log_file_name, O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY,
fd= open(log_file_name, O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (fd < 0)
die("daemonize(): failed to open log file %s, %s", log_file_name,
@ -133,7 +136,7 @@ static void daemonize(const char *log_file_name)
/* TODO: chroot() and/or chdir() here */
break;
default:
default:
/* successfully exit from parent */
exit(0);
}
@ -144,13 +147,13 @@ enum { CHILD_OK= 0, CHILD_NEED_RESPAWN, CHILD_EXIT_ANGEL };
static volatile sig_atomic_t child_status= CHILD_OK;
/*
/*
Signal handler for SIGCHLD: reap child, analyze child exit status, and set
child_status appropriately.
*/
void reap_child(int __attribute__((unused)) signo)
{
{
int child_exit_status;
/* As we have only one child, no need to cycle waitpid */
if (waitpid(0, &child_exit_status, WNOHANG) > 0)
@ -159,16 +162,14 @@ void reap_child(int __attribute__((unused)) signo)
child_status= CHILD_NEED_RESPAWN;
else
/*
As we reap_child is not called for SIGSTOP, we should be here only
As reap_child is not called for SIGSTOP, we should be here only
if the child exited normally.
*/
child_status= CHILD_EXIT_ANGEL;
}
}
/* Not static to reuse it in childs */
volatile sig_atomic_t is_terminated= 0;
static volatile sig_atomic_t is_terminated= 0;
/*
Signal handler for terminate signals - SIGTERM, SIGHUP, SIGINT.
@ -215,18 +216,18 @@ spawn:
pid_t pid= fork();
switch (pid) {
case -1:
die("angel(): fork failed, %s", strerror(errno));
die("angel(): fork failed, %s", strerror(errno));
case 0: // child, success
/*
restore default actions for signals to let the manager work with
signals as he wishes
*/
*/
sigaction(SIGCHLD, &sa_chld_out, 0);
sigaction(SIGTERM, &sa_term_out, 0);
sigaction(SIGINT, &sa_int_out, 0);
sigaction(SIGHUP, &sa_hup_out, 0);
manager(options.socket_file_name);
/* Here we return to main, and fall into manager */
break;
default: // parent, success
while (child_status == CHILD_OK && is_terminated == 0)
sigsuspend(&zeromask);
@ -235,12 +236,18 @@ spawn:
log_info("angel got signal %d (%s), exiting",
is_terminated, sys_siglist[is_terminated]);
else if (child_status == CHILD_NEED_RESPAWN)
{
{
child_status= CHILD_OK;
log_error("angel(): mysqlmanager exited abnormally: respawning...");
sleep(1); /* don't respawn too fast */
goto spawn;
}
/* mysqlmanager successfully exited, let's silently evaporate */
/*
mysqlmanager successfully exited, let's silently evaporate
If we return to main we fall into the manager() function, so let's
simply exit().
*/
exit(0);
}
}