Skip to content

Commit 4f2f85e

Browse files
committed
chore: add comments back
1 parent 01a3b80 commit 4f2f85e

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎aws_advanced_python_wrapper/read_write_splitting_plugin.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def execute(
137137
return execute_func()
138138
except Exception as ex:
139139
if isinstance(ex, FailoverFailedError):
140+
# Evict the current connection from the pool right away since it is not reusable
140141
self._close_connections(False)
141142
if isinstance(ex, FailoverError):
142143
logger.debug(
@@ -253,6 +254,7 @@ def _switch_to_writer_connection(self):
253254
and self._is_writer(current_host)
254255
and self._is_connection_usable(current_conn, driver_dialect)
255256
):
257+
# Already connected to the intended writer.
256258
return
257259

258260
self._in_read_write_split = True
@@ -280,6 +282,7 @@ def _switch_to_reader_connection(self):
280282
and self._is_reader(current_host)
281283
and self._is_connection_usable(current_conn, driver_dialect)
282284
):
285+
# Already connected to the intended reader.
283286
return
284287

285288
self._close_reader_if_necessary()
@@ -318,12 +321,14 @@ def _close_connection(self, internal_conn: Optional[Connection], close_only_if_i
318321
driver_dialect = self._plugin_service.driver_dialect
319322

320323
if close_only_if_idle and internal_conn == current_conn:
324+
# Connection is in use, do not close
321325
return
322326

323327
try:
324328
if self._is_connection_usable(internal_conn, driver_dialect):
325329
driver_dialect.execute(DbApiMethod.CONNECTION_CLOSE.method_name, lambda: internal_conn.close())
326330
except Exception:
331+
# Ignore exceptions during cleanup - connection might already be dead
327332
pass
328333
finally:
329334
if internal_conn == self._writer_connection:
@@ -350,6 +355,7 @@ def _is_connection_usable(conn: Optional[Connection], driver_dialect: DriverDial
350355
try:
351356
return not driver_dialect.is_closed(conn)
352357
except Exception:
358+
# If we cannot determine connection state, assume unavailable.
353359
return False
354360

355361
@staticmethod
@@ -358,6 +364,7 @@ def close_connection(conn: Optional[Connection], driver_dialect: DriverDialect):
358364
try:
359365
driver_dialect.execute(DbApiMethod.CONNECTION_CLOSE.method_name, lambda: conn.close())
360366
except Exception:
367+
# Swallow exception
361368
return
362369

363370
# --- Abstract methods that concrete subclasses must implement ---
@@ -415,6 +422,7 @@ class ReadWriteSplittingPlugin(AbstractReadWriteSplittingPlugin):
415422
"""
416423

417424
def __init__(self, plugin_service: PluginService, props: Properties):
425+
# The read/write splitting plugin handles connections based on topology.
418426
super().__init__(plugin_service, props)
419427
strategy = WrapperProperties.READER_HOST_SELECTOR_STRATEGY.get(props)
420428
if strategy is not None:
@@ -559,6 +567,7 @@ def _initialize_reader_connection(self):
559567
)
560568

561569
def _close_reader_if_necessary(self):
570+
# The old reader cannot be used anymore, close it.
562571
if (
563572
self._reader_host_info is not None
564573
and self._reader_connection is not None

‎aws_advanced_python_wrapper/simple_read_write_splitting_plugin.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class SimpleReadWriteSplittingPlugin(AbstractReadWriteSplittingPlugin):
4646
T = TypeVar('T')
4747

4848
def __init__(self, plugin_service: PluginService, props: Properties):
49+
# The simple read/write splitting plugin handles connections based on configuration parameter endpoints.
4950
super().__init__(plugin_service, props)
5051

5152
read_endpoint: str = SimpleReadWriteSplittingPlugin._verify_parameter(

0 commit comments

Comments
 (0)