Skip to content

Commit 2fc29e4

Browse files
Added support for Oracle Database 23c feature that can improve the
performance of connection creation by reducing the number of round trips required for all connections created.
1 parent d41a08e commit 2fc29e4

File tree

8 files changed

+72
-161
lines changed

8 files changed

+72
-161
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ oracledb 2.1.0 (TBD)
1313
Thin Mode Changes
1414
+++++++++++++++++
1515

16+
#) Added support for Oracle Database 23c feature that can improve the
17+
performance of connection creation by reducing the number of round trips
18+
required for all connections created.
1619
#) Added support for writing UTF-8 encoded bytes to CLOB and NCLOB values and
1720
writing strings to BLOB values in order to be consistent with what is done
1821
for string variables.

src/oracledb/impl/thin/capabilities.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cdef class Capabilities:
3939
bytearray compile_caps
4040
bytearray runtime_caps
4141
uint32_t max_string_size
42+
bint supports_fast_auth
4243
bint supports_oob
4344
uint32_t sdu
4445

src/oracledb/impl/thin/connection.pyx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,10 @@ cdef class ThinConnImpl(BaseThinConnImpl):
273273
Internal method used for connecting with the given description and
274274
address.
275275
"""
276-
cdef:
277-
Protocol protocol = <Protocol> self._protocol
278-
ConnectionCookie cookie
276+
cdef Protocol protocol = <Protocol> self._protocol
279277
try:
280-
cookie = protocol._connect_phase_one(self, params, description,
281-
address, connect_string)
278+
protocol._connect_phase_one(self, params, description,
279+
address, connect_string)
282280
except (exceptions.DatabaseError, socket.gaierror,
283281
ConnectionRefusedError) as e:
284282
if raise_exception:
@@ -289,7 +287,7 @@ cdef class ThinConnImpl(BaseThinConnImpl):
289287
errors._raise_err(errors.ERR_CONNECTION_FAILED, cause=e,
290288
connection_id=description.connection_id)
291289
self._post_connect_phase_one(description, params)
292-
protocol._connect_phase_two(self, cookie, description, params)
290+
protocol._connect_phase_two(self, description, params)
293291

294292
cdef int _connect_with_description(self, Description description,
295293
ConnectParamsImpl params,
@@ -424,11 +422,9 @@ cdef class AsyncThinConnImpl(BaseThinConnImpl):
424422
"""
425423
cdef:
426424
BaseAsyncProtocol protocol = <BaseAsyncProtocol> self._protocol
427-
ConnectionCookie cookie
428425
try:
429-
cookie = await protocol._connect_phase_one(self, params,
430-
description, address,
431-
connect_string)
426+
await protocol._connect_phase_one(self, params, description,
427+
address, connect_string)
432428
except (exceptions.DatabaseError, socket.gaierror,
433429
ConnectionRefusedError) as e:
434430
if raise_exception:
@@ -439,8 +435,7 @@ cdef class AsyncThinConnImpl(BaseThinConnImpl):
439435
errors._raise_err(errors.ERR_CONNECTION_FAILED, cause=e,
440436
connection_id=description.connection_id)
441437
self._post_connect_phase_one(description, params)
442-
await self._protocol._connect_phase_two(self, cookie, description,
443-
params)
438+
await self._protocol._connect_phase_two(self, description, params)
444439

445440
async def _connect_with_description(self, Description description,
446441
ConnectParamsImpl params,

src/oracledb/impl/thin/constants.pxi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ cdef enum:
410410
TNS_MSG_TYPE_ONEWAY_FN = 26
411411
TNS_MSG_TYPE_IMPLICIT_RESULTSET = 27
412412
TNS_MSG_TYPE_RENEGOTIATE = 28
413-
TNS_MSG_TYPE_COOKIE = 30
413+
TNS_MSG_TYPE_FAST_AUTH = 34
414414

415415
# parameter keyword numbers
416416
cdef enum:
@@ -724,6 +724,10 @@ cdef enum:
724724
TNS_UDS_FLAGS_IS_JSON = 0x00000100
725725
TNS_UDS_FLAGS_IS_OSON = 0x00000800
726726

727+
# accept flags
728+
cdef enum:
729+
TNS_ACCEPT_FLAG_FAST_AUTH = 0x10000000
730+
727731
# other constants
728732
cdef enum:
729733
TNS_ESCAPE_CHAR = 253
@@ -734,6 +738,7 @@ cdef enum:
734738
TNS_TXN_IN_PROGRESS = 0x00000002
735739
TNS_MAX_CONNECT_DATA = 230
736740
TNS_MAX_UROWID_LENGTH = 5267
741+
TNS_SERVER_CONVERTS_CHARS = 0x01
737742
TNS_JSON_MAX_LENGTH = 32 * 1024 * 1024
738743

739744
# base 64 encoding alphabet

src/oracledb/impl/thin/cookie.pyx

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/oracledb/impl/thin/messages.pyx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,6 @@ cdef class ConnectMessage(Message):
17981798
bytes connect_string_bytes
17991799
uint16_t connect_string_len, redirect_data_len
18001800
bint read_redirect_data_len
1801-
ConnectionCookie cookie
18021801
Description description
18031802
uint8_t packet_flags
18041803
str redirect_data
@@ -1809,6 +1808,7 @@ cdef class ConnectMessage(Message):
18091808
cdef:
18101809
uint16_t protocol_version, protocol_options
18111810
const char_type *redirect_data
1811+
uint32_t flags
18121812
bytes db_uuid
18131813
if buf._current_packet.packet_type == TNS_PACKET_TYPE_REDIRECT:
18141814
if not self.read_redirect_data_len:
@@ -1825,11 +1825,11 @@ cdef class ConnectMessage(Message):
18251825
buf.read_uint16(&protocol_options)
18261826
buf.skip_raw_bytes(20)
18271827
buf.read_uint32(&buf._caps.sdu)
1828-
if protocol_version >= TNS_VERSION_MIN_UUID:
1829-
buf.skip_raw_bytes(9)
1830-
db_uuid = buf.read_raw_bytes(16)[:16]
1831-
self.cookie = get_connection_cookie_by_uuid(db_uuid,
1832-
self.description)
1828+
if protocol_version >= TNS_VERSION_MIN_OOB_CHECK:
1829+
buf.skip_raw_bytes(5)
1830+
buf.read_uint32(&flags)
1831+
if flags & TNS_ACCEPT_FLAG_FAST_AUTH:
1832+
buf._caps.supports_fast_auth = True
18331833
buf._caps._adjust_for_protocol(protocol_version, protocol_options)
18341834
buf._transport._full_packet_size = True
18351835
elif buf._current_packet.packet_type == TNS_PACKET_TYPE_REFUSE:
@@ -2345,9 +2345,7 @@ cdef class ProtocolMessage(Message):
23452345

23462346
cdef int _process_protocol_info(self, ReadBuffer buf) except -1:
23472347
"""
2348-
Processes the response to the protocol request and stores the
2349-
information that is used to identify the server in a connection cookie
2350-
(which is used in 23c and higher to optimize the connection packets).
2348+
Processes the response to the protocol request.
23512349
"""
23522350
cdef:
23532351
uint16_t num_elem, fdo_length
@@ -2380,12 +2378,12 @@ cdef class ProtocolMessage(Message):
23802378

23812379

23822380
@cython.final
2383-
cdef class ConnectionCookieMessage(Message):
2381+
cdef class FastAuthMessage(Message):
23842382
cdef:
23852383
DataTypesMessage data_types_message
23862384
ProtocolMessage protocol_message
23872385
AuthMessage auth_message
2388-
ConnectionCookie cookie
2386+
bint renegotiate
23892387

23902388
cdef bint _has_more_data(self, ReadBuffer buf):
23912389
return not self.end_of_request
@@ -2396,8 +2394,7 @@ cdef class ConnectionCookieMessage(Message):
23962394
Processes the messages returned from the server response.
23972395
"""
23982396
if message_type == TNS_MSG_TYPE_RENEGOTIATE:
2399-
self.cookie.populated = False
2400-
self.end_of_request = True
2397+
self.renegotiate = True
24012398
elif message_type == TNS_MSG_TYPE_PROTOCOL:
24022399
ProtocolMessage._process_message(self.protocol_message, buf,
24032400
message_type)
@@ -2410,21 +2407,24 @@ cdef class ConnectionCookieMessage(Message):
24102407

24112408
cdef int _write_message(self, WriteBuffer buf) except -1:
24122409
"""
2413-
Writes the message to the buffer. This includes not just the cookie but
2414-
also the protocol, data types and auth message information as well!
2410+
Writes the message to the buffer. This includes not just this message
2411+
but also the protocol, data types and auth messages. This reduces the
2412+
number of round-trips to the database and thereby increases
2413+
performance.
24152414
"""
2415+
buf.write_uint8(TNS_MSG_TYPE_FAST_AUTH)
2416+
buf.write_uint8(1) # fast auth version
2417+
buf.write_uint8(TNS_SERVER_CONVERTS_CHARS) # flag 1
2418+
buf.write_uint8(0) # flag 2
24162419
ProtocolMessage._write_message(self.protocol_message, buf)
2417-
buf.write_uint8(TNS_MSG_TYPE_COOKIE)
2418-
buf.write_uint8(1) # cookie version
2419-
buf.write_uint8(self.cookie.protocol_version)
2420-
buf.write_uint16(self.cookie.charset_id, BYTE_ORDER_LSB)
2421-
buf.write_uint8(self.cookie.flags)
2422-
buf.write_uint16(self.cookie.ncharset_id, BYTE_ORDER_LSB)
2423-
buf.write_bytes_with_length(self.cookie.server_banner)
2424-
buf.write_bytes_with_length(self.cookie.compile_caps)
2425-
buf.write_bytes_with_length(self.cookie.runtime_caps)
2420+
buf.write_uint16(0) # server charset (unused)
2421+
buf.write_uint8(0) # server charset flag (unused)
2422+
buf.write_uint16(0) # server ncharset (unused)
2423+
buf._caps.ttc_field_version = TNS_CCAP_FIELD_VERSION_19_1_EXT_1
2424+
buf.write_uint8(buf._caps.ttc_field_version)
24262425
DataTypesMessage._write_message(self.data_types_message, buf)
24272426
AuthMessage._write_message(self.auth_message, buf)
2427+
buf._caps.ttc_field_version = TNS_CCAP_FIELD_VERSION_MAX
24282428

24292429

24302430
@cython.final

0 commit comments

Comments
 (0)