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
-
23
1
.. uuid_doc documentation master file, created by
24
2
sphinx-quickstart on Fri Feb 6 18:39:23 2015.
25
3
You can adapt this file completely to your liking, but it should at least
@@ -44,37 +22,36 @@ UUID has the following structure:
44
22
45
23
.. uml::
46
24
47
- object TIME_LOW
48
- object TIME_MID
25
+ object NODE
26
+ object CLOCK_SEQ
49
27
object TIME_HI_VER
50
- object PROCESS_ID
51
- object HW_MAC_ADDR
28
+ object TIME_MID
29
+ object TIME_LOW
52
30
53
- TIME_LOW : 32 -bit
54
- TIME_MID : 16-bit
31
+ NODE : 48 -bit
32
+ CLOCK_SEQ : 16-bit
55
33
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
58
36
59
37
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
64
42
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.
73
48
end note
74
49
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.
78
55
end note
79
56
80
57
note right of TIME_HI_VER
@@ -85,23 +62,19 @@ UUID has the following structure:
85
62
<b>timestamp >> 48 | UUID_VERSION
86
63
end note
87
64
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
93
68
end note
94
69
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
100
75
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
105
78
end note
106
79
107
80
How to use UUID generator
@@ -114,6 +87,8 @@ To start using the ``UUID`` generator the client code has to use the header:
114
87
115
88
#include <uuid_gen.h>
116
89
90
+ The classes and declarations for the ``UUID`` generator are inside ``uuid`` name space.
91
+
117
92
The header file contains the definitions for ``uuid_type`` as:
118
93
119
94
.. code-block:: c
@@ -122,47 +97,45 @@ The header file contains the definitions for ``uuid_type`` as:
122
97
typedef unsigned char uuid_type[UUID_LENGTH_BIN];
123
98
124
99
125
- UUID functions
126
- --------------
100
+ UUID structures
101
+ ---------------
127
102
128
103
.. |vspace| raw:: latex
129
104
130
105
\vspace{5mm}
131
106
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.
136
110
137
111
|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.
138
116
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.
140
121
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`.
142
122
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.
147
123
148
124
Usage example
149
125
-------------
150
126
151
127
.. code-block:: c
152
128
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"
156
130
...
131
+ uuid::uuid_type uuid;
157
132
/*
158
133
Use the generator.
159
134
The result formatted and converted to text could look as:
160
- bf17975b -4e44-d011-4c6b00268312fb20
135
+ 4c6b00268312fb20 -4e44-d011-bf17975b
161
136
*/
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);
166
139
167
140
168
141
Contents:
0 commit comments