diff options
author | unknown <petr@mysql.com> | 2004-10-26 23:22:12 +0400 |
---|---|---|
committer | unknown <petr@mysql.com> | 2004-10-26 23:22:12 +0400 |
commit | 234ca309b9e1e49b6425fbf0dfd662e7d0f7b383 (patch) | |
tree | 84047e5c9807f54931f2d0793890253e8b140755 /server-tools/instance-manager/instance_map.cc | |
parent | a3d9a1eb066d7cca01bef104d065864f2a7c65ec (diff) | |
download | mariadb-git-234ca309b9e1e49b6425fbf0dfd662e7d0f7b383.tar.gz |
Various post-review fixes
server-tools/instance-manager/buffer.cc:
simplified buffer interface
server-tools/instance-manager/buffer.h:
simplified buffer interface
server-tools/instance-manager/command.cc:
Command class now uses instance_map directly
server-tools/instance-manager/command.h:
Made Command to use instance_map directly (not through the factory,
which is not needed here in fact)
server-tools/instance-manager/commands.cc:
Moved mysql client/server protocol-specific functions to the commands
server-tools/instance-manager/commands.h:
Added a comment for Syntax_error command, fixed classes to use instance
map instead of the factory
server-tools/instance-manager/factory.cc:
Fixed factory to give appropriate class to the commands
server-tools/instance-manager/guardian.cc:
Fixed guardian to delay start of new instances monitoring.
Moved guardian initialization to the class from Instance map.
server-tools/instance-manager/guardian.h:
interface fixed
server-tools/instance-manager/instance.cc:
added some loging
server-tools/instance-manager/instance_map.cc:
All non-instance map specific functions moved from the class. Added
iterator for instance_map
server-tools/instance-manager/instance_map.h:
All non-instance map related functions moved from the class. Added
iterator for instance_map.
server-tools/instance-manager/listener.cc:
Added FD_CLOEXEC flag to sockets, as we don't want instances to inherit
them after exec.
server-tools/instance-manager/manager.cc:
use guardian method moved from the instance map
server-tools/instance-manager/mysql_connection.cc:
cleanup
server-tools/instance-manager/protocol.cc:
fix according to the changes in the Buffer class
Diffstat (limited to 'server-tools/instance-manager/instance_map.cc')
-rw-r--r-- | server-tools/instance-manager/instance_map.cc | 273 |
1 files changed, 37 insertions, 236 deletions
diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index 89731eb27b9..aa81194b1d4 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -127,253 +127,29 @@ Instance_map::~Instance_map() } -int Instance_map::flush_instances() +int Instance_map::lock() { - int rc; - pthread_mutex_lock(&LOCK_instance_map); - hash_free(&hash); - hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0, - get_instance_key, delete_instance, 0); - rc= load(); - pthread_mutex_unlock(&LOCK_instance_map); - return rc; } -int Instance_map::show_instance_options(struct st_net *net, - const char *instance_name) +int Instance_map::unlock() { - enum { MAX_VERSION_LENGTH= 40 }; - Buffer send_buff; /* buffer for packets */ - LIST name, option; - LIST *field_list; - NAME_WITH_LENGTH name_field, option_field; - uint position=0; - - /* create list of the fileds to be passed to send_fields */ - name_field.name= (char *) "option_name"; - name_field.length= 20; - name.data= &name_field; - option_field.name= (char *) "value"; - option_field.length= 20; - option.data= &option_field; - field_list= list_add(NULL, &option); - field_list= list_add(field_list, &name); - - send_fields(net, field_list); - - { - Instance *instance; - - if ((instance= find(instance_name, strlen(instance_name))) == NULL) - goto err; - store_to_string(&send_buff, (char *) "instance_name", &position); - store_to_string(&send_buff, (char *) instance_name, &position); - my_net_write(net, send_buff.buffer, (uint) position); - if (instance->options.mysqld_path != NULL) - { - position= 0; - store_to_string(&send_buff, (char *) "mysqld_path", &position); - store_to_string(&send_buff, - (char *) instance->options.mysqld_path, - &position); - my_net_write(net, send_buff.buffer, (uint) position); - } - - if (instance->options.mysqld_user != NULL) - { - position= 0; - store_to_string(&send_buff, (char *) "admin_user", &position); - store_to_string(&send_buff, - (char *) instance->options.mysqld_user, - &position); - my_net_write(net, send_buff.buffer, (uint) position); - } - - if (instance->options.mysqld_password != NULL) - { - position= 0; - store_to_string(&send_buff, (char *) "admin_password", &position); - store_to_string(&send_buff, - (char *) instance->options.mysqld_password, - &position); - my_net_write(net, send_buff.buffer, (uint) position); - } - - /* loop through the options stored in DYNAMIC_ARRAY */ - for (int i= 0; i < instance->options.options_array.elements; i++) - { - char *tmp_option, *option_value; - get_dynamic(&(instance->options.options_array), (gptr) &tmp_option, i); - option_value= strchr(tmp_option, '='); - /* split the option string into two parts */ - *option_value= 0; - position= 0; - store_to_string(&send_buff, tmp_option + 2, &position); - store_to_string(&send_buff, option_value + 1, &position); - /* join name and the value into the same option again */ - *option_value= '='; - my_net_write(net, send_buff.buffer, (uint) position); - } - } - - send_eof(net); - net_flush(net); - - return 0; - -err: - return 1; -} - -/* return the list of running guarded instances */ -int Instance_map::init_guardian() -{ - Instance *instance; - uint i= 0; - - while (i < hash.records) - { - instance= (Instance *) hash_element(&hash, i); - if ((instance->options.is_guarded != NULL) && (instance->is_running())) - if (guardian->guard(instance->options.instance_name, - instance->options.instance_name_len)) - return 1; - i++; - } - - return 0; -} - - -/* - The method sends a list of instances in the instance map to the client. - - SYNOPSYS - show_instances() - net The network connection to the client. - - RETURN - 0 - ok - 1 - error occured -*/ - -int Instance_map::show_instances(struct st_net *net) -{ - Buffer send_buff; /* buffer for packets */ - LIST name, status; - NAME_WITH_LENGTH name_field, status_field; - LIST *field_list; - uint position=0; - - name_field.name= (char *) "instance_name"; - name_field.length= 20; - name.data= &name_field; - status_field.name= (char *) "status"; - status_field.length= 20; - status.data= &status_field; - field_list= list_add(NULL, &status); - field_list= list_add(field_list, &name); - - send_fields(net, field_list); - - { - Instance *instance; - uint i= 0; - - pthread_mutex_lock(&LOCK_instance_map); - while (i < hash.records) - { - position= 0; - instance= (Instance *) hash_element(&hash, i); - store_to_string(&send_buff, instance->options.instance_name, &position); - if (instance->is_running()) - store_to_string(&send_buff, (char *) "online", &position); - else - store_to_string(&send_buff, (char *) "offline", &position); - if (my_net_write(net, send_buff.buffer, (uint) position)) - goto err; - i++; - } - pthread_mutex_unlock(&LOCK_instance_map); - } - if (send_eof(net)) - goto err; - if (net_flush(net)) - goto err; - - return 0; -err: - return 1; + pthread_mutex_unlock(&LOCK_instance_map); } -/* - The method sends a table with a status of requested instance to the client. - - SYNOPSYS - show_instance_status() - net The network connection to the client. - instance_name The name of the instance. - - RETURN - 0 - ok - 1 - error occured -*/ - -int Instance_map::show_instance_status(struct st_net *net, - const char *instance_name) +int Instance_map::flush_instances() { - enum { MAX_VERSION_LENGTH= 40 }; - Buffer send_buff; /* buffer for packets */ - LIST name, status, version; - LIST *field_list; - NAME_WITH_LENGTH name_field, status_field, version_field; - uint position=0; - - /* create list of the fileds to be passed to send_fields */ - name_field.name= (char *) "instance_name"; - name_field.length= 20; - name.data= &name_field; - status_field.name= (char *) "status"; - status_field.length= 20; - status.data= &status_field; - version_field.name= (char *) "version"; - version_field.length= MAX_VERSION_LENGTH; - version.data= &version_field; - field_list= list_add(NULL, &version); - field_list= list_add(field_list, &status); - field_list= list_add(field_list, &name); - - send_fields(net, field_list); - - { - Instance *instance; - - store_to_string(&send_buff, (char *) instance_name, &position); - if ((instance= find(instance_name, strlen(instance_name))) == NULL) - goto err; - if (instance->is_running()) - { - store_to_string(&send_buff, (char *) "online", &position); - store_to_string(&send_buff, mysql_get_server_info(&(instance->mysql)), &position); - } - else - { - store_to_string(&send_buff, (char *) "offline", &position); - store_to_string(&send_buff, (char *) "unknown", &position); - } - - - my_net_write(net, send_buff.buffer, (uint) position); - } - - send_eof(net); - net_flush(net); + int rc; -err: - return 0; + pthread_mutex_lock(&LOCK_instance_map); + hash_free(&hash); + hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0, + get_instance_key, delete_instance, 0); + rc= load(); + pthread_mutex_unlock(&LOCK_instance_map); + return rc; } @@ -448,3 +224,28 @@ int Instance_map::load() return error; } + + +Instance *Instance_map::get_instance(uint instance_number) +{ + if (instance_number < hash.records) + return (Instance *) hash_element(&hash, instance_number); + else + return NULL; +} + + +/*--- Implementaton of the Instance map iterator class (Imap_iterator) ---*/ + + +void Imap_iterator::go_to_first() +{ + current_instance=0; +} + + +Instance *Imap_iterator::next() +{ + return instance_map->get_instance(current_instance++); +} + |