WL#3558: UDP send function

Affects: WorkLog-3.4   —   Status: Un-Assigned   —   Priority: Medium

This is a simple, but effective, idea: Have a function in the server that allows
sending of a structured message through UDP. There are many uses for such a
function, but among the interesting ones are:
- Sending trace messages.
- Sending debugging messages.
- Integration with other system.
- Logging through triggers.

The nice thing with UDP is that it has very good performance. Drawbacks of UDP
are that it has limited routability, and does not guarantee packet ordering or
proper reception of packets. Theses disadvantages are, in this case, not very
relevant are are to an extent advantagous.

Integration with other software packages and systems a nice use for UDP, as it
is a well known and simple protocol. Providing trace information, sending
messages, emails etc gets simple, all that is needed is a receiver of the UDP
messages and some procedure that sends the UDP messages to this receiver. There
are many many uses for this simple facility, and is a simple means of extending
the MySQL Server without requiring a UDF and without affecting the stability of
the MySQL Server itself.
The following is added to the MySQL Server and API's

SQL Functions
Two SQL functions, the return values of both of them is an integer: either 0
(success) or 1 (failure).

The SEND_UDP() function takes three or four arguments:
- A short with the port number to send the message to.
- A 32-bit application specific integer.
- One or two VARCHAR application specific strings.

The SEND_HOST_UDP() function takes four or five arguments:
- A string with the hostname to send the message to.
- A short with the port number to send the message to.
- A 32-bit application specific integer.
- One or two VARCHAR application specific strings.

mysqld parameters
The following mysqld configuration values are added:
--enable_send_udp - For security reasons, the use of the SEND_UDP() function can
be limited. Possible values are: ON (1) OFF (0) and IGNORE (2). The difference
between the two latter ones is that if the function is called OFF will cause an
error, whereas IGNORE will just ignore call and return success. Default is ON.

--send_udp_host - Host that the messages sent by SEND_UDP() will be sent to.
Default is localhost.

--enable_send_host_udp - Same as above but for SEND_HOST_UDP(). Default is OFF.

--max_udp_message_size - This controls the max total size of a UDP message, in
bytes. Default is 1024, 0 means no limit. The reason 0 is not the default is
that this could be a potential security issue.

A new includefile that defines the structure of the message sent my the
functions above is also needed. The reason this is in a separate file is that
this will be included by the receiver of the UDP message, which will not usually
connect to MySQL or use any MySQL functionality. To separate this definition
into a separate file makes life easier in that case. This file will define the
structure of the message being sent and a few other constants, possibly. The
message will look something like this:
struct mysql_udp_message
   uint32 message_size;
   uint32 message_id;
   char *message_part1;
   char *message_part2;
The message_size is the size, in bytes, of the whole message. The message id is
the value of the first parameter, and message_part1 and message_part2 of the
following two. A possible addition would be some kind of sequence number.

UNICODE issues
Any UNICODE processing is left to the implementer. If the sending system sends
UTF-8, the receiver gets UTF-8 just like that. It is up to th developer of the
receiver or the caller of the SEND_UDP() functions to do any transformations.

UDP message sending is a slight issue here, which is why the ability to call
these functions may be turned off.

There should be limits to how much data is packed into each field of the
message, possibly. But first and foremost there is a limit in the configuration
parameter max_udp_message_size as seen above.

UDP has limitations of it's own, not guarateeing message order etc. It is up the
the implementer of the receiver to resolve such issues, the SEND_UDP() and
SEND_HOST_UDP() just sends the specified messages.

Using these function might (I guess) limit the # of available filehandles to the
MySQL Server. If this is an issue, then either use of these functions have to be
disabled or the max filehandles limit increased.