WL#9503: mysql string functionalities as a service for mysql_server component

Affects: Server-8.0   —   Status: Complete

What is the problem ? 

MySQL has a platform independent character set implementation. To minimize
string conversions all strings in the server core have a character set attached
to them that's carried along as further as possible. This is done through a
special C++ class (String). Components may need to manipulate some of these
String instances. But due to the fact that C++ classes don't travel well across
heap boundaries (dll/exe etc) we need a C API for these class instances.

Why only this much ?

The full API for that would be very large. So this worklog implements only the
minimum subset that the password validation component (and plugin) needs.

How ?

We take the existing composite plugin service (a wrapper around String methods)
and break it up into multiple logically separate component services. This is a
typical example for how re-engineering of existing plugin APIs into service APIs
should go.

User Documentation
==================

* https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-2.html
* https://dev.mysql.com/doc/refman/8.0/en/component-plugin-services.html
1) Make mysql string functions as services to mysql_server component.
As of now mysql string functions are written as plugin service. With the help of
this wl, making them as component service.

2) The component string services are loaded into registry service at the server
start up time along with remaining core services in mysql_server component.

3) Other components will consume these string services through registry service.

4) Current plugins will consume these string services through WL#4989.
    WL#4989 has implemented two methods as new plugin service, those are
Registry::acquire and Registry::release(). With the help of aquire() method the
string services will be consumed in that particular plugin. And with the help of
release() method the string services are released.

5) Below are the list of component string services, each service has methods to
perform some string functionalities.
    a)string_factory b)string_converter c)string_case d)string_character_access 
    e)string_byte_access f)string_iterator g)string_ctype

6) Since these services are part of mysql_server core component, these string
services are unloaded, when the server shutdown.
Prerequisites:
-------------
The password validation plugin is the sole user of the string plugin service.
And we are converting this to a component service. And making the password
validation component use the component service instead of the plugin service.
So, any additional consumers of that plugin service will have to move to the
component service as the password validation component is going to do.

Parts being removed: 
--------------------
The existing string service code will be removed.

Parts being added: 
------------------
New string services are added to the mysql_server component.

Parts being altered: 
--------------------
In the existing code(password_validation plugin code) the plugin string services
will be updated with the new component string services with the help of
Registry::aquire() api.
And if any other components wants to use this component string services they can
consume from  my_service.

Implementation sequence: 
------------------------
This will be implemented by seven services along with sub-methods in them. Below
are the string service.
BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_factory)
  mysql_string_imp::create,
  mysql_string_imp::destroy
END_SERVICE_IMPLEMENTATION()

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_case)
  mysql_string_imp::tolower,
  mysql_string_imp::toupper
END_SERVICE_IMPLEMENTATION()

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_converter)
  mysql_string_imp::convert_from_buffer
  mysql_string_imp::convert_to_buffer,
END_SERVICE_IMPLEMENTATION()

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_character_access)
  mysql_string_imp::get_char,
  mysql_string_imp::get_char_length
END_SERVICE_IMPLEMENTATION()

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_byte_access)
  mysql_string_imp::get_byte,
  mysql_string_imp::get_byte_length
END_SERVICE_IMPLEMENTATION()

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_iterator)
  mysql_string_imp::iterator_create,
  mysql_string_imp::iterator_get_next,
  mysql_string_imp::iterator_destroy
END_SERVICE_IMPLEMENTATION()

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, string_ctype)
  mysql_string_imp::is_upper,
  mysql_string_imp::is_lower,
  mysql_string_imp::is_digit
END_SERVICE_IMPLEMENTATION()

Please see below low level design section for each function details.
  /**
    Creates a new instance of string object

    @param out_string holds pointer to newly created string object.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(create,
        (my_h_string *out_string));

  /**
    Destroys specified string object and data contained by it.

    @param string String object handle to release.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_METHOD(void, destroy,
    (my_h_string string));

  /**
    Convert a String pointed by handle to lower case. Conversion depends on the
    character set info

    @param out_string Holds the converted lower case string object.
    @param in_string Pointer to string object to be converted.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(tolower,
        (my_h_string *out_string, my_h_string in_string));

  /**
    Convert a String pointed by handle to upper case. Conversion depends on the
    character set info

    @param out_string Holds the converted lower case string object.
    @param in_string Pointer to string object to be converted.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(toupper,
        (my_h_string *out_string, my_h_string in_string));

  /**
    allocates a string object and converts the character buffer to string
    of specified charset_name.
    please call destroy() api to free the allocated string after this api.

    @param [out] out_string Pointer to string object handle to set new string
      to.
    @param in_buffer Pointer to the buffer with data to be interpreted as
      string.
    @param length Length of the buffer to copy into string, in bytes, not in
      character count.
    @param charset_name Handle to charset that is used for convertion.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(convert_from_buffer,
    (my_h_string out_string, const char* in_buffer, uint64 length,
      my_h_charset charset_name));

  /**
    converts the mysql_string to the character set specified by
    charset_name parameter.

    @param in_string Pointer to string object handle to set new string
      to.
    @param [out] out_buffer Pointer to the buffer with data to be interpreted
      as characters.
    @param length Length of the buffer to hold out put in characters.
    @param charset_name Handle to charset that is used for convertion.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(convert_to_buffer,
    (my_h_string in_string, char* out_buffer, uint64 length,
      my_h_charset charset_name));

  /**
    Gets character code of character on specified index position in
    string to a specified 32-bit buffer.

    @param string String object handle to get character from.
    @param index Index, position of character to query.
    @param [out] out_char Pointer to 32bit value to store character to.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(get_char,
    (my_h_string string, uint index, uint* out_char));

  /**
    Gets length of specified string expressed as number of characters.

    @param string String object handle to get length of.
    @param [out] out_length Pointer to 64bit value to store length of string to.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(get_char_length,
    (my_h_string string, uint64* out_length));

  /**
    Gets byte code of string at specified index position to a
    specified 32-bit buffer.

    @param string String object handle to get character from.
    @param index Index, position of character to query.
    @param [out] out_char Pointer to 32bit value to store character to.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(get_byte,
    (my_h_string string, uint index, uint* out_char));

  /**
    Gets number of bytes of specified string.

    @param string String object handle to get length of.
    @param [out] out_length Pointer to 64bit value to store length of string to.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(get_byte_length,
    (my_h_string string, uint64* out_length));

  /**
    Creates an iterator for a specified string to allow iteration through all
      characters in the string.

    @param string String object handle to get iterator to.
    @param [out] out_iterator Pointer to string iterator handle to store result
      object to.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(iterator_create,
    (my_h_string string, my_h_string_iterator* out_iterator));

  /**
    Retrieves character code at current iterator position and advances the
      iterator.

    @param iter String iterator object handle to advance.
    @param [out] out_char Pointer to 64bit value to store character to. May be
      NULL to omit retrieval of character and just advance the iterator.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(iterator_get_next,
    (my_h_string_iterator iter, uint* out_char));

  /**
    Releases the string iterator object specified.

    @param iter String iterator object handle te release.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_METHOD(void, iterator_destroy,
    (my_h_string_iterator iter));

  /**
    Checks if character on current position the iterator points to is an upper
    case.

    @param iter String iterator object handle to advance.
    @param [out] out Pointer to bool value to store if character is an upper
      case.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(is_upper,
    (my_h_string_iterator iter, bool* out));

  /**
    Checks if character on current position the iterator points to is a lower
      case.

    @param iter String iterator object handle to advance.
    @param [out] out Pointer to bool value to store if character is a lower
      case.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(is_lower,
    (my_h_string_iterator iter, bool* out));

  /**
    Checks if character on current position the iterator points to is a digit.

    @param iter String iterator object handle to advance.
    @param [out] out Pointer to bool value to store if character is a digit.
    @return Status of performed operation
    @retval false success
    @retval true failure
  */
  static DEFINE_BOOL_METHOD(is_digit,
    (my_h_string_iterator iter, bool* out));