Skip to content

Commit ffdf962

Browse files
Added support for TCP fast open used with ADB-S.
1 parent 3962459 commit ffdf962

File tree

11 files changed

+91
-6
lines changed

11 files changed

+91
-6
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Thin Mode Changes
1717
#) Added support for Oracle Database 23c feature that can improve the
1818
performance of connection creation by reducing the number of round trips
1919
required for all connections created.
20+
#) Added support for Oracle Database 23c feature: use of TCP fast open for
21+
clients connecting from within the OCI Cloud network.
2022
#) Added support for Easy Connect strings found in tnsnames.ora files.
2123
#) Added support for writing UTF-8 encoded bytes to CLOB and NCLOB values and
2224
writing strings to BLOB values in order to be consistent with what is done

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ cdef class Description(ConnectParamsNode):
349349
public str pool_boundary
350350
public uint32_t purity
351351
public bint ssl_server_dn_match
352+
public bint use_tcp_fast_open
352353
public str ssl_server_cert_dn
353354
public str wallet_location
354355
str connection_id

src/oracledb/connect_params.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(
9595
ssl_context: Any = None,
9696
sdu: int = 8192,
9797
pool_boundary: str = None,
98+
use_tcp_fast_open: bool = False,
9899
handle: int = 0,
99100
):
100101
"""
@@ -261,6 +262,11 @@ def __init__(
261262
This requires the use of DRCP with Oracle Database 23.4 or higher
262263
(default: None)
263264
265+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open.
266+
This is an ADB-S specific property for clients connecting from within
267+
OCI Cloud network. Please refer to the ADB-S documentation for more
268+
information (default: False)
269+
264270
- handle: an integer representing a pointer to a valid service context
265271
handle. This value is only used in thick mode. It should be used with
266272
extreme caution (default: 0)
@@ -306,7 +312,8 @@ def __repr__(self):
306312
+ f"connection_id_prefix={self.connection_id_prefix!r}, "
307313
+ f"ssl_context={self.ssl_context!r}, "
308314
+ f"sdu={self.sdu!r}, "
309-
+ f"pool_boundary={self.pool_boundary!r}"
315+
+ f"pool_boundary={self.pool_boundary!r}, "
316+
+ f"use_tcp_fast_open={self.use_tcp_fast_open!r}"
310317
+ ")"
311318
)
312319

@@ -648,6 +655,16 @@ def user(self) -> str:
648655
"""
649656
return self._impl.user
650657

658+
@property
659+
@_description_attr
660+
def use_tcp_fast_open(self) -> Union[list, bool]:
661+
"""
662+
Boolean indicating whether to use TCP fast open. This is an ADB-S
663+
specific property for clients connecting from within OCI Cloud network.
664+
Please refer to the ADB-S documentation for more information.
665+
"""
666+
return self._impl.use_tcp_fast_open
667+
651668
@property
652669
@_description_attr
653670
def wallet_location(self) -> Union[list, str]:
@@ -737,6 +754,7 @@ def set(
737754
ssl_context: Any = None,
738755
sdu: int = None,
739756
pool_boundary: str = None,
757+
use_tcp_fast_open: bool = None,
740758
handle: int = None,
741759
):
742760
"""
@@ -893,6 +911,11 @@ def set(
893911
indicating when pooled DRCP connections can be returned to the pool.
894912
This requires the use of DRCP with Oracle Database 23.4 or higher
895913
914+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open.
915+
This is an ADB-S specific property for clients connecting from within
916+
OCI Cloud network. Please refer to the ADB-S documentation for more
917+
information
918+
896919
- handle: an integer representing a pointer to a valid service context
897920
handle. This value is only used in thick mode. It should be used with
898921
extreme caution

src/oracledb/connection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ def connect(
11981198
ssl_context: Any = None,
11991199
sdu: int = 8192,
12001200
pool_boundary: str = None,
1201+
use_tcp_fast_open: bool = False,
12011202
handle: int = 0,
12021203
) -> Connection:
12031204
"""
@@ -1384,6 +1385,11 @@ def connect(
13841385
when pooled DRCP connections can be returned to the pool. This requires
13851386
the use of DRCP with Oracle Database 23.4 or higher (default: None)
13861387
1388+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open. This
1389+
is an ADB-S specific property for clients connecting from within OCI
1390+
Cloud network. Please refer to the ADB-S documentation for more
1391+
information (default: False)
1392+
13871393
- handle: an integer representing a pointer to a valid service context
13881394
handle. This value is only used in thick mode. It should be used with
13891395
extreme caution (default: 0)
@@ -1768,6 +1774,7 @@ def connect_async(
17681774
ssl_context: Any = None,
17691775
sdu: int = 8192,
17701776
pool_boundary: str = None,
1777+
use_tcp_fast_open: bool = False,
17711778
handle: int = 0,
17721779
) -> AsyncConnection:
17731780
"""
@@ -1954,6 +1961,11 @@ def connect_async(
19541961
when pooled DRCP connections can be returned to the pool. This requires
19551962
the use of DRCP with Oracle Database 23.4 or higher (default: None)
19561963
1964+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open. This
1965+
is an ADB-S specific property for clients connecting from within OCI
1966+
Cloud network. Please refer to the ADB-S documentation for more
1967+
information (default: False)
1968+
19571969
- handle: an integer representing a pointer to a valid service context
19581970
handle. This value is only used in thick mode. It should be used with
19591971
extreme caution (default: 0)

src/oracledb/impl/base/connect_params.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ cdef class Description(ConnectParamsNode):
871871
temp_parts.append(f"(SID={self.sid})")
872872
if self.server_type is not None:
873873
temp_parts.append(f"(SERVER={self.server_type})")
874+
if self.use_tcp_fast_open:
875+
temp_parts.append("(USE_TCP_FAST_OPEN=ON)")
874876
if self.pool_boundary is not None:
875877
temp_parts.append(f"(POOL_BOUNDARY={self.pool_boundary})")
876878
if cid is not None:
@@ -925,6 +927,7 @@ cdef class Description(ConnectParamsNode):
925927
description.ssl_server_cert_dn = self.ssl_server_cert_dn
926928
description.wallet_location = self.wallet_location
927929
description.connection_id_prefix = self.connection_id_prefix
930+
description.use_tcp_fast_open = self.use_tcp_fast_open
928931
return description
929932

930933
def set_from_connect_data_args(self, dict args):
@@ -939,6 +942,7 @@ cdef class Description(ConnectParamsNode):
939942
_set_purity_param(args, "purity", &self.purity)
940943
_set_pool_boundary_param(args, "pool_boundary", self)
941944
_set_str_param(args, "connection_id_prefix", self)
945+
_set_bool_param(args, "use_tcp_fast_open", &self.use_tcp_fast_open)
942946

943947
def set_from_description_args(self, dict args):
944948
"""

src/oracledb/impl/thin/protocol.pyx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ cdef class Protocol(BaseProtocol):
218218
# establish initial TCP connection and get initial connect string
219219
host = address.host
220220
port = address.port
221-
self._connect_tcp(params, description, address, host, port)
221+
self._connect_tcp(params, description, address, host, port,
222+
connect_string)
222223

223224
# send connect message and process response; this may request the
224225
# message to be resent multiple times; if a redirect packet is
@@ -251,7 +252,8 @@ cdef class Protocol(BaseProtocol):
251252
host = temp_address.host
252253
port = temp_address.port
253254
connect_string = redirect_data[pos + 1:]
254-
self._connect_tcp(params, description, address, host, port)
255+
self._connect_tcp(params, description, address, host, port,
256+
connect_string)
255257
connect_message = None
256258
packet_flags = TNS_PACKET_FLAG_REDIRECT
257259
elif packet_type == TNS_PACKET_TYPE_ACCEPT:
@@ -325,7 +327,7 @@ cdef class Protocol(BaseProtocol):
325327

326328
cdef int _connect_tcp(self, ConnectParamsImpl params,
327329
Description description, Address address, str host,
328-
int port) except -1:
330+
int port, str connect_string) except -1:
329331
"""
330332
Creates a socket on which to communicate using the provided parameters.
331333
If a proxy is configured, a connection to the proxy is established and
@@ -347,7 +349,12 @@ cdef class Protocol(BaseProtocol):
347349
if not use_tcps and (params._token is not None
348350
or params.access_token_callback is not None):
349351
errors._raise_err(errors.ERR_ACCESS_TOKEN_REQUIRES_TCPS)
350-
sock = socket.create_connection(connect_info, timeout)
352+
if description.use_tcp_fast_open:
353+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
354+
sock.sendto(connect_string.encode(), socket.MSG_FASTOPEN,
355+
connect_info)
356+
else:
357+
sock = socket.create_connection(connect_info, timeout)
351358

352359
# complete connection through proxy, if applicable
353360
if use_proxy:

src/oracledb/pool.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ def create_pool(
634634
ssl_context: Any = None,
635635
sdu: int = 8192,
636636
pool_boundary: str = None,
637+
use_tcp_fast_open: bool = False,
637638
handle: int = 0,
638639
) -> ConnectionPool:
639640
"""
@@ -866,6 +867,11 @@ def create_pool(
866867
when pooled DRCP connections can be returned to the pool. This requires
867868
the use of DRCP with Oracle Database 23.4 or higher (default: None)
868869
870+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open. This
871+
is an ADB-S specific property for clients connecting from within OCI
872+
Cloud network. Please refer to the ADB-S documentation for more
873+
information (default: False)
874+
869875
- handle: an integer representing a pointer to a valid service context
870876
handle. This value is only used in thick mode. It should be used with
871877
extreme caution (default: 0)
@@ -1086,6 +1092,7 @@ def create_pool_async(
10861092
ssl_context: Any = None,
10871093
sdu: int = 8192,
10881094
pool_boundary: str = None,
1095+
use_tcp_fast_open: bool = False,
10891096
handle: int = 0,
10901097
) -> AsyncConnectionPool:
10911098
"""
@@ -1318,6 +1325,11 @@ def create_pool_async(
13181325
when pooled DRCP connections can be returned to the pool. This requires
13191326
the use of DRCP with Oracle Database 23.4 or higher (default: None)
13201327
1328+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open. This
1329+
is an ADB-S specific property for clients connecting from within OCI
1330+
Cloud network. Please refer to the ADB-S documentation for more
1331+
information (default: False)
1332+
13211333
- handle: an integer representing a pointer to a valid service context
13221334
handle. This value is only used in thick mode. It should be used with
13231335
extreme caution (default: 0)

src/oracledb/pool_params.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(
107107
ssl_context: Any = None,
108108
sdu: int = 8192,
109109
pool_boundary: str = None,
110+
use_tcp_fast_open: bool = False,
110111
handle: int = 0,
111112
):
112113
"""
@@ -324,6 +325,11 @@ def __init__(
324325
This requires the use of DRCP with Oracle Database 23.4 or higher
325326
(default: None)
326327
328+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open.
329+
This is an ADB-S specific property for clients connecting from within
330+
OCI Cloud network. Please refer to the ADB-S documentation for more
331+
information (default: False)
332+
327333
- handle: an integer representing a pointer to a valid service context
328334
handle. This value is only used in thick mode. It should be used with
329335
extreme caution (default: 0)
@@ -382,7 +388,8 @@ def __repr__(self):
382388
+ f"connection_id_prefix={self.connection_id_prefix!r}, "
383389
+ f"ssl_context={self.ssl_context!r}, "
384390
+ f"sdu={self.sdu!r}, "
385-
+ f"pool_boundary={self.pool_boundary!r}"
391+
+ f"pool_boundary={self.pool_boundary!r}, "
392+
+ f"use_tcp_fast_open={self.use_tcp_fast_open!r}"
386393
+ ")"
387394
)
388395

@@ -562,6 +569,7 @@ def set(
562569
ssl_context: Any = None,
563570
sdu: int = None,
564571
pool_boundary: str = None,
572+
use_tcp_fast_open: bool = None,
565573
handle: int = None,
566574
):
567575
"""
@@ -765,6 +773,11 @@ def set(
765773
indicating when pooled DRCP connections can be returned to the pool.
766774
This requires the use of DRCP with Oracle Database 23.4 or higher
767775
776+
- use_tcp_fast_open: boolean indicating whether to use TCP fast open.
777+
This is an ADB-S specific property for clients connecting from within
778+
OCI Cloud network. Please refer to the ADB-S documentation for more
779+
information
780+
768781
- handle: an integer representing a pointer to a valid service context
769782
handle. This value is only used in thick mode. It should be used with
770783
extreme caution

tests/test_4500_connect_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ def test_4564(self):
713713
("ssl_context", None),
714714
("sdu", 16384),
715715
("pool_boundary", "statement"),
716+
("use_tcp_fast_open", True),
716717
]
717718
params = oracledb.ConnectParams(**dict(values))
718719
parts = [f"{name}={value!r}" for name, value in values]

tests/test_4700_pool_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def test_4701(self):
115115
("ssl_context", None),
116116
("sdu", 16384),
117117
("pool_boundary", "transaction"),
118+
("use_tcp_fast_open", True),
118119
]
119120
params = oracledb.PoolParams(**dict(values))
120121
parts = [f"{name}={value!r}" for name, value in values]

0 commit comments

Comments
 (0)