airbyte-cdk 6.27.0__py3-none-any.whl → 6.27.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,6 +95,7 @@ class ConcurrentPerPartitionCursor(Cursor):
95
95
  self._lookback_window: int = 0
96
96
  self._parent_state: Optional[StreamState] = None
97
97
  self._over_limit: int = 0
98
+ self._use_global_cursor: bool = False
98
99
  self._partition_serializer = PerPartitionKeySerializer()
99
100
 
100
101
  self._set_initial_state(stream_state)
@@ -105,16 +106,18 @@ class ConcurrentPerPartitionCursor(Cursor):
105
106
 
106
107
  @property
107
108
  def state(self) -> MutableMapping[str, Any]:
108
- states = []
109
- for partition_tuple, cursor in self._cursor_per_partition.items():
110
- if cursor.state:
111
- states.append(
112
- {
113
- "partition": self._to_dict(partition_tuple),
114
- "cursor": copy.deepcopy(cursor.state),
115
- }
116
- )
117
- state: dict[str, Any] = {self._PERPARTITION_STATE_KEY: states}
109
+ state: dict[str, Any] = {"use_global_cursor": self._use_global_cursor}
110
+ if not self._use_global_cursor:
111
+ states = []
112
+ for partition_tuple, cursor in self._cursor_per_partition.items():
113
+ if cursor.state:
114
+ states.append(
115
+ {
116
+ "partition": self._to_dict(partition_tuple),
117
+ "cursor": copy.deepcopy(cursor.state),
118
+ }
119
+ )
120
+ state[self._PERPARTITION_STATE_KEY] = states
118
121
 
119
122
  if self._global_cursor:
120
123
  state[self._GLOBAL_STATE_KEY] = self._global_cursor
@@ -147,7 +150,8 @@ class ConcurrentPerPartitionCursor(Cursor):
147
150
  < cursor.state[self.cursor_field.cursor_field_key]
148
151
  ):
149
152
  self._new_global_cursor = copy.deepcopy(cursor.state)
150
- self._emit_state_message()
153
+ if not self._use_global_cursor:
154
+ self._emit_state_message()
151
155
 
152
156
  def ensure_at_least_one_state_emitted(self) -> None:
153
157
  """
@@ -225,14 +229,15 @@ class ConcurrentPerPartitionCursor(Cursor):
225
229
  """
226
230
  with self._lock:
227
231
  while len(self._cursor_per_partition) > self.DEFAULT_MAX_PARTITIONS_NUMBER - 1:
232
+ self._over_limit += 1
228
233
  # Try removing finished partitions first
229
234
  for partition_key in list(self._cursor_per_partition.keys()):
230
- if partition_key in self._finished_partitions:
235
+ if partition_key in self._finished_partitions and self._semaphore_per_partition[partition_key]._value == 0:
231
236
  oldest_partition = self._cursor_per_partition.pop(
232
237
  partition_key
233
238
  ) # Remove the oldest partition
234
239
  logger.warning(
235
- f"The maximum number of partitions has been reached. Dropping the oldest partition: {oldest_partition}. Over limit: {self._over_limit}."
240
+ f"The maximum number of partitions has been reached. Dropping the oldest finished partition: {oldest_partition}. Over limit: {self._over_limit}."
236
241
  )
237
242
  break
238
243
  else:
@@ -297,6 +302,8 @@ class ConcurrentPerPartitionCursor(Cursor):
297
302
  self._new_global_cursor = deepcopy(stream_state)
298
303
 
299
304
  else:
305
+ self._use_global_cursor = stream_state.get("use_global_cursor", False)
306
+
300
307
  self._lookback_window = int(stream_state.get("lookback_window", 0))
301
308
 
302
309
  for state in stream_state.get(self._PERPARTITION_STATE_KEY, []):
@@ -320,6 +327,9 @@ class ConcurrentPerPartitionCursor(Cursor):
320
327
  self._partition_router.set_initial_state(stream_state)
321
328
 
322
329
  def observe(self, record: Record) -> None:
330
+ if not self._use_global_cursor and self.limit_reached():
331
+ self._use_global_cursor = True
332
+
323
333
  if not record.associated_slice:
324
334
  raise ValueError(
325
335
  "Invalid state as stream slices that are emitted should refer to an existing cursor"
@@ -358,3 +368,6 @@ class ConcurrentPerPartitionCursor(Cursor):
358
368
  )
359
369
  cursor = self._cursor_per_partition[partition_key]
360
370
  return cursor
371
+
372
+ def limit_reached(self) -> bool:
373
+ return self._over_limit > self.DEFAULT_MAX_PARTITIONS_NUMBER
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: airbyte-cdk
3
- Version: 6.27.0
3
+ Version: 6.27.0.dev0
4
4
  Summary: A framework for writing Airbyte Connectors.
5
5
  License: MIT
6
6
  Keywords: airbyte,connector-development-kit,cdk
@@ -88,7 +88,7 @@ airbyte_cdk/sources/declarative/extractors/record_selector.py,sha256=tjNwcURmlyD
88
88
  airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py,sha256=LhqGDfX06_dDYLKsIVnwQ_nAWCln-v8PV7Wgt_QVeTI,6533
89
89
  airbyte_cdk/sources/declarative/extractors/type_transformer.py,sha256=d6Y2Rfg8pMVEEnHllfVksWZdNVOU55yk34O03dP9muY,1626
90
90
  airbyte_cdk/sources/declarative/incremental/__init__.py,sha256=U1oZKtBaEC6IACmvziY9Wzg7Z8EgF4ZuR7NwvjlB_Sk,1255
91
- airbyte_cdk/sources/declarative/incremental/concurrent_partition_cursor.py,sha256=4Z8qZ5DccF0fw163KR5fWW83O-3-84AlaZKPajZ0ZZI,15945
91
+ airbyte_cdk/sources/declarative/incremental/concurrent_partition_cursor.py,sha256=TnlwShqF_3JxY8j6mUHeUO3rm1PtkC1N8nL7189Dohs,16588
92
92
  airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py,sha256=_UzUnSIUsDbRgbFTXgSyZEFb4ws-KdhdQPWO8mFbV7U,22028
93
93
  airbyte_cdk/sources/declarative/incremental/declarative_cursor.py,sha256=5Bhw9VRPyIuCaD0wmmq_L3DZsa-rJgtKSEUzSd8YYD0,536
94
94
  airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py,sha256=9HO-QbL9akvjq2NP7l498RwLA4iQZlBMQW1tZbt34I8,15943
@@ -350,8 +350,8 @@ airbyte_cdk/utils/slice_hasher.py,sha256=EDxgROHDbfG-QKQb59m7h_7crN1tRiawdf5uU7G
350
350
  airbyte_cdk/utils/spec_schema_transformations.py,sha256=-5HTuNsnDBAhj-oLeQXwpTGA0HdcjFOf2zTEMUTTg_Y,816
351
351
  airbyte_cdk/utils/stream_status_utils.py,sha256=ZmBoiy5HVbUEHAMrUONxZvxnvfV9CesmQJLDTAIWnWw,1171
352
352
  airbyte_cdk/utils/traced_exception.py,sha256=C8uIBuCL_E4WnBAOPSxBicD06JAldoN9fGsQDp463OY,6292
353
- airbyte_cdk-6.27.0.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
354
- airbyte_cdk-6.27.0.dist-info/METADATA,sha256=JLRDR-Ds7n-AEubbCyoOdpqY2g8pTQkcfZA2dN9HDmU,5996
355
- airbyte_cdk-6.27.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
356
- airbyte_cdk-6.27.0.dist-info/entry_points.txt,sha256=fj-e3PAQvsxsQzyyq8UkG1k8spunWnD4BAH2AwlR6NM,95
357
- airbyte_cdk-6.27.0.dist-info/RECORD,,
353
+ airbyte_cdk-6.27.0.dev0.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
354
+ airbyte_cdk-6.27.0.dev0.dist-info/METADATA,sha256=uVSlbLjqWio7gWy4AiOJ82IrCtjS1e8Fd2ZCcCj-zvI,6001
355
+ airbyte_cdk-6.27.0.dev0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
356
+ airbyte_cdk-6.27.0.dev0.dist-info/entry_points.txt,sha256=fj-e3PAQvsxsQzyyq8UkG1k8spunWnD4BAH2AwlR6NM,95
357
+ airbyte_cdk-6.27.0.dev0.dist-info/RECORD,,