Skip to content

Commit fc1ca55

Browse files
committed
Merge remote-tracking branch 'origin/2.0-wl10008' into 2.0
2 parents ceefe25 + ca20717 commit fc1ca55

File tree

11 files changed

+313
-526
lines changed

11 files changed

+313
-526
lines changed

cdk/extra/uuid/doc/uuid.txt

Lines changed: 52 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
2-
#
3-
# The MySQL Connector/C++ is licensed under the terms of the GPLv2
4-
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
5-
# MySQL Connectors. There are special exceptions to the terms and
6-
# conditions of the GPLv2 as it is applied to this software, see the
7-
# FLOSS License Exception
8-
# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
9-
#
10-
# This program is free software; you can redistribute it and/or modify
11-
# it under the terms of the GNU General Public License as published
12-
# by the Free Software Foundation; version 2 of the License.
13-
#
14-
# This program is distributed in the hope that it will be useful, but
15-
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16-
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17-
# for more details.
18-
#
19-
# You should have received a copy of the GNU General Public License along
20-
# with this program; if not, write to the Free Software Foundation, Inc.,
21-
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22-
231
.. uuid_doc documentation master file, created by
242
sphinx-quickstart on Fri Feb 6 18:39:23 2015.
253
You can adapt this file completely to your liking, but it should at least
@@ -44,37 +22,36 @@ UUID has the following structure:
4422

4523
.. uml::
4624

47-
object TIME_LOW
48-
object TIME_MID
25+
object NODE
26+
object CLOCK_SEQ
4927
object TIME_HI_VER
50-
object PROCESS_ID
51-
object HW_MAC_ADDR
28+
object TIME_MID
29+
object TIME_LOW
5230

53-
TIME_LOW : 32-bit
54-
TIME_MID : 16-bit
31+
NODE : 48-bit
32+
CLOCK_SEQ : 16-bit
5533
TIME_HI_VER : 16-bit
56-
PROCESS_ID : 16-bit
57-
HW_MAC_ADDR : 48-bit
34+
TIME_MID : 16-bit
35+
TIME_LOW : 32-bit
5836

5937

60-
TIME_LOW -down-> TIME_MID
61-
TIME_MID -down-> TIME_HI_VER
62-
TIME_HI_VER -down-> PROCESS_ID
63-
PROCESS_ID -down-> HW_MAC_ADDR
38+
NODE -down-> CLOCK_SEQ
39+
CLOCK_SEQ -down-> TIME_HI_VER
40+
TIME_HI_VER -down-> TIME_MID
41+
TIME_MID -down-> TIME_LOW
6442

65-
note right of TIME_LOW
66-
<b>represents the lower 32 bits of system timestamp
67-
in order not to generate the same value the lower bits
68-
can be "borrowed" from the future when two UUIDs generate
69-
within the clock granularity
70-
71-
this protects against generating similar values within
72-
the same process
43+
note right of NODE
44+
<b>6 bytes randomly generated using a user-provided seed.
45+
The same node values are used within a process.
46+
Changing the random generator seed causes generating of
47+
new node.
7348
end note
7449

75-
note right of TIME_MID
76-
<b>represents the medium 16 bits of system timestamp
77-
this component changes when TIME_LOW reaches its maximum
50+
note right of CLOCK_SEQ
51+
<b>randomly generated 16-bit value also containing the
52+
UUID variant. This value changes on setting a new seed
53+
for the generator or if two time values within the same
54+
process have same time values.
7855
end note
7956

8057
note right of TIME_HI_VER
@@ -85,23 +62,19 @@ UUID has the following structure:
8562
<b>timestamp >> 48 | UUID_VERSION
8663
end note
8764

88-
note right of PROCESS_ID
89-
<b>represents the lower 16 bits of the current Process ID
90-
to make sure the duplicate values would not be generated if
91-
two independent processes running on the same host
92-
getting UUID at the same time
65+
note right of TIME_MID
66+
<b>represents the medium 16 bits of system timestamp
67+
this component changes when TIME_LOW reaches its maximum
9368
end note
9469

95-
note right of HW_MAC_ADDR
96-
<b>6 bytes from Hardware MAC address of the network adapter
97-
this component eliminates the possibility of duplication on
98-
two or more UUIDs generated on separate hosts at the same
99-
moment of time
70+
note right of TIME_LOW
71+
<b>represents the lower 32 bits of system timestamp
72+
in order not to generate the same value the lower bits
73+
can be "borrowed" from the future when two UUIDs generate
74+
within the clock granularity
10075

101-
If MAC address could not be obtained this value is generated
102-
randomly depending on time, the number of bytes sent,
103-
Query ID (number), query performance frequency and
104-
query performance offset
76+
this protects against generating similar values within
77+
the same process
10578
end note
10679

10780
How to use UUID generator
@@ -114,6 +87,8 @@ To start using the ``UUID`` generator the client code has to use the header:
11487

11588
#include <uuid_gen.h>
11689

90+
The classes and declarations for the ``UUID`` generator are inside ``uuid`` name space.
91+
11792
The header file contains the definitions for ``uuid_type`` as:
11893

11994
.. code-block:: c
@@ -122,47 +97,45 @@ The header file contains the definitions for ``uuid_type`` as:
12297
typedef unsigned char uuid_type[UUID_LENGTH_BIN];
12398

12499

125-
UUID functions
126-
--------------
100+
UUID structures
101+
---------------
127102

128103
.. |vspace| raw:: latex
129104

130105
\vspace{5mm}
131106

132-
* ``init_uuid(unsigned long seed)`` - initialization function, which should
133-
be called only once before using the generator. The parameter `unsigned long seed` is
134-
used to generate the 6-byte `Hardware MAC address` if it could not be obtained.
135-
The seed can be a random value, system time, the query number, number of sent bytes, etc.
107+
* ``Uuid`` - a static structure with automatically called constructor and destructor
108+
initializing/freeing mutexes etc. The user code is not supposed to create instances of
109+
this structure.
136110

137111
|vspace|
112+
113+
* ``Uuid::set_seed(uint16_t seed)`` - Setting the seed for the UUID generator.
114+
The seed has to be set before generator can be used. Otherwise it throws
115+
an exception.
138116

139-
* ``generate_uuid(uuid_type& uuid)`` - generator returning the result into `uuid` parameter.
117+
* ``Uuid::set_seed_from_time_pid()`` - Converience function for setting the seed
118+
for the UUID generator using the current machine time and the process id.
119+
120+
* ``Uuid::generate_uuid(uuid_type& uuid)`` - generator returning the result into `uuid` parameter.
140121
Could be called many times, sequentially or concurrently from different threads.
141-
Requires `init_uuid()` function to be called before the first use of `generate_uuid`.
142122

143-
|vspace|
144-
145-
* ``end_uuid()`` - should be called when the application exists or when UUID generator is
146-
not needed. Destroys the mutexes used for synchronizing in concurrent threads.
147123

148124
Usage example
149125
-------------
150126

151127
.. code-block:: c
152128

153-
/* Initialize the UUID generator and create mutexes */
154-
unsigned long seed = <get a random value, time, nuber of sent bytes etc>;
155-
init_uuid(seed);
129+
#include "uuid_gen.h"
156130
...
131+
uuid::uuid_type uuid;
157132
/*
158133
Use the generator.
159134
The result formatted and converted to text could look as:
160-
bf17975b-4e44-d011-4c6b00268312fb20
135+
4c6b00268312fb20-4e44-d011-bf17975b
161136
*/
162-
generate_uuid(uuid);
163-
...
164-
/* Destroy mutexes */
165-
end_uuid();
137+
uuid::set_seed(set_seed((uint16_t)(time(0) ^ process_id));
138+
uuid::generate_uuid(uuid);
166139

167140

168141
Contents:

cdk/extra/uuid/include/uuid_gen.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -15,14 +15,27 @@
1515
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
*/
1717

18-
#ifndef UUID_GEN_INCLUDED
19-
#define UUID_GEN_INCLUDED
18+
#ifndef _UUID_GEN_H_
19+
#define _UUID_GEN_H_
20+
21+
#include <stdint.h>
2022

2123
#define UUID_LENGTH_BIN 16
24+
25+
namespace uuid {
26+
2227
typedef unsigned char uuid_type[UUID_LENGTH_BIN];
2328

24-
void init_uuid(unsigned long);
25-
void end_uuid();
29+
/* The seed must be set before using the generator. */
30+
void set_seed(uint16_t seed);
31+
32+
/* Convenience function, which sets the seed using the time and
33+
process id */
34+
void set_seed_from_time_pid();
35+
36+
/* UUID generator */
2637
void generate_uuid(uuid_type &uuid);
2738

39+
} // namespace uuid
40+
2841
#endif

0 commit comments

Comments
 (0)