e6data-python-connector 2.2.5rc1__tar.gz → 2.2.5rc5__tar.gz

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.
Files changed (38) hide show
  1. {e6data_python_connector-2.2.5rc1/e6data_python_connector.egg-info → e6data_python_connector-2.2.5rc5}/PKG-INFO +157 -3
  2. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/README.md +156 -2
  3. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/cluster_manager.py +173 -37
  4. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/dialect.py +2 -5
  5. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/e6data_grpc.py +552 -42
  6. e6data_python_connector-2.2.5rc5/e6data_python_connector/server/e6x_engine_pb2.py +141 -0
  7. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/server/e6x_engine_pb2.pyi +127 -73
  8. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/server/e6x_engine_pb2_grpc.py +432 -116
  9. e6data_python_connector-2.2.5rc5/e6data_python_connector/strategy.py +201 -0
  10. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5/e6data_python_connector.egg-info}/PKG-INFO +157 -3
  11. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector.egg-info/SOURCES.txt +1 -0
  12. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/setup.py +1 -1
  13. e6data_python_connector-2.2.5rc1/e6data_python_connector/server/e6x_engine_pb2.py +0 -140
  14. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/LICENSE +0 -0
  15. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/MANIFEST.in +0 -0
  16. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/__init__.py +0 -0
  17. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/cluster_server/__init__.py +0 -0
  18. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/cluster_server/cluster_pb2.py +0 -0
  19. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/cluster_server/cluster_pb2_grpc.py +0 -0
  20. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/common.py +0 -0
  21. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/constants.py +0 -0
  22. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/datainputstream.py +0 -0
  23. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/date_time_utils.py +0 -0
  24. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/e6x_vector/__init__.py +0 -0
  25. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/e6x_vector/constants.py +0 -0
  26. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/e6x_vector/ttypes.py +0 -0
  27. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/exceptions.py +0 -0
  28. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/server/QueryEngineService.py +0 -0
  29. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/server/__init__.py +0 -0
  30. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/server/constants.py +0 -0
  31. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/server/ttypes.py +0 -0
  32. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector/typeId.py +0 -0
  33. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector.egg-info/dependency_links.txt +0 -0
  34. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector.egg-info/entry_points.txt +0 -0
  35. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector.egg-info/requires.txt +0 -0
  36. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/e6data_python_connector.egg-info/top_level.txt +0 -0
  37. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/pyproject.toml +0 -0
  38. {e6data_python_connector-2.2.5rc1 → e6data_python_connector-2.2.5rc5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: e6data-python-connector
3
- Version: 2.2.5rc1
3
+ Version: 2.2.5rc5
4
4
  Summary: Client for the e6data distributed SQL Engine.
5
5
  Home-page: https://github.com/e6x-labs/e6data-python-connector
6
6
  Author: e6data, Inc.
@@ -38,11 +38,11 @@ Dynamic: summary
38
38
 
39
39
  # e6data Python Connector
40
40
 
41
- ![version](https://img.shields.io/badge/version-2.2.5rc1-blue.svg)
41
+ ![version](https://img.shields.io/badge/version-2.2.5rc5-blue.svg)
42
42
 
43
43
  ## Introduction
44
44
 
45
- The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations.
45
+ The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations. It includes automatic support for blue-green deployments, ensuring seamless failover during server updates without query interruption.
46
46
 
47
47
  ### Dependencies
48
48
  Make sure to install below dependencies and wheel before install e6data-python-connector.
@@ -241,3 +241,157 @@ cursor.clear()
241
241
  cursor.close()
242
242
  conn.close()
243
243
  ```
244
+
245
+ ## Zero Downtime Deployment
246
+
247
+ ### 🚀 Zero Downtime Features
248
+
249
+ The e6data Python Connector provides **automatic zero downtime deployment** support through intelligent blue-green deployment strategy management:
250
+
251
+ #### ✅ **No Code Changes Required**
252
+ Your existing applications automatically benefit from zero downtime deployment without any modifications:
253
+
254
+ ```python
255
+ # Your existing code works exactly the same
256
+ from e6data_python_connector import Connection
257
+
258
+ conn = Connection(
259
+ host='your-host',
260
+ port=80,
261
+ username='your-email',
262
+ password='your-token',
263
+ database='your-database'
264
+ )
265
+
266
+ cursor = conn.cursor()
267
+ cursor.execute("SELECT * FROM your_table")
268
+ results = cursor.fetchall()
269
+ ```
270
+
271
+ #### 🔄 **Automatic Strategy Detection**
272
+ - Detects active deployment strategy (blue/green) on connection
273
+ - Caches strategy information for optimal performance
274
+ - Automatically switches strategies when deployments occur
275
+
276
+ #### 🛡️ **Seamless Query Protection**
277
+ - **Running queries continue uninterrupted** during deployments
278
+ - New queries automatically use the new deployment strategy
279
+ - Graceful transitions ensure no query loss or failures
280
+
281
+ #### ⚡ **Performance Optimized**
282
+ - **< 100ms** additional latency on first connection (one-time cost)
283
+ - **0ms overhead** for 95% of queries (cached strategy)
284
+ - **< 1KB** additional memory usage per connection
285
+
286
+ #### 🔧 **Thread & Process Safe**
287
+ - Full support for multi-threaded applications
288
+ - Process-safe shared memory management
289
+ - Concurrent query execution without conflicts
290
+
291
+ ### Advanced Configuration (Optional)
292
+
293
+ For enhanced monitoring and performance tuning:
294
+
295
+ ```python
296
+ # Enhanced gRPC configuration for zero downtime
297
+ grpc_options = {
298
+ 'keepalive_timeout_ms': 60000, # 1 minute keepalive timeout
299
+ 'keepalive_time_ms': 30000, # 30 seconds keepalive interval
300
+ 'max_receive_message_length': 100 * 1024 * 1024, # 100MB
301
+ 'max_send_message_length': 100 * 1024 * 1024, # 100MB
302
+ }
303
+
304
+ conn = Connection(
305
+ host='your-host',
306
+ port=80,
307
+ username='your-email',
308
+ password='your-token',
309
+ database='your-database',
310
+ grpc_options=grpc_options
311
+ )
312
+ ```
313
+
314
+ ### Environment Configuration
315
+
316
+ Configure zero downtime features using environment variables:
317
+
318
+ ```bash
319
+ # Strategy cache timeout (default: 300 seconds)
320
+ export E6DATA_STRATEGY_CACHE_TIMEOUT=300
321
+
322
+ # Maximum retry attempts (default: 5)
323
+ export E6DATA_MAX_RETRY_ATTEMPTS=5
324
+
325
+ # Enable debug logging for strategy operations
326
+ export E6DATA_STRATEGY_LOG_LEVEL=INFO
327
+ ```
328
+
329
+ ### Testing Zero Downtime
330
+
331
+ Use the included mock server for testing and development:
332
+
333
+ ```bash
334
+ # Terminal 1: Start mock server
335
+ python mock_grpc_server.py
336
+
337
+ # Terminal 2: Run test client
338
+ python test_mock_server.py
339
+
340
+ # Or use the convenience script
341
+ ./run_mock_test.sh
342
+ ```
343
+
344
+ ### 📚 **Comprehensive Documentation**
345
+
346
+ Explore detailed documentation in the [`docs/zero-downtime/`](docs/zero-downtime/) directory:
347
+
348
+ - **[📋 Overview](docs/zero-downtime/README.md)** - Complete guide and feature overview
349
+ - **[🔧 API Reference](docs/zero-downtime/api-reference.md)** - Detailed API documentation
350
+ - **[🌊 Flow Documentation](docs/zero-downtime/flow-documentation.md)** - Process flows and diagrams
351
+ - **[💼 Business Logic](docs/zero-downtime/business-logic.md)** - Business rules and decisions
352
+ - **[🏗️ Architecture](docs/zero-downtime/architecture.md)** - System architecture and design
353
+ - **[⚙️ Configuration](docs/zero-downtime/configuration.md)** - Complete configuration guide
354
+ - **[🧪 Testing](docs/zero-downtime/testing.md)** - Testing strategies and tools
355
+ - **[🔍 Troubleshooting](docs/zero-downtime/troubleshooting.md)** - Common issues and solutions
356
+ - **[🚀 Migration Guide](docs/zero-downtime/migration-guide.md)** - Step-by-step migration instructions
357
+
358
+ ### Key Benefits
359
+
360
+ | Feature | Benefit |
361
+ |---------|---------|
362
+ | **Zero Downtime** | Applications continue running during e6data deployments |
363
+ | **Automatic** | No code changes or manual intervention required |
364
+ | **Reliable** | Robust error handling and automatic recovery |
365
+ | **Fast** | Minimal performance impact with intelligent caching |
366
+ | **Safe** | Thread-safe and process-safe operation |
367
+ | **Monitored** | Comprehensive logging and monitoring capabilities |
368
+
369
+ ### Migration
370
+
371
+ Existing applications automatically benefit from zero downtime deployment:
372
+
373
+ 1. **Update connector**: `pip install --upgrade e6data-python-connector`
374
+ 2. **No code changes**: Your existing code works without modifications
375
+ 3. **Monitor**: Use enhanced logging to monitor strategy transitions
376
+ 4. **Validate**: Test with your existing applications
377
+
378
+ For detailed migration instructions, see the [Migration Guide](docs/zero-downtime/migration-guide.md).
379
+
380
+ ## Performance Optimization
381
+
382
+ ### Memory Efficiency
383
+ - Use `fetchall_buffer()` for memory-efficient large result sets
384
+ - Automatic cleanup of query-strategy mappings
385
+ - Bounded memory usage with TTL-based caching
386
+
387
+ ### Network Performance
388
+ - Configure gRPC options for optimal network performance
389
+ - Intelligent keepalive settings for connection stability
390
+ - Message size optimization for large queries
391
+
392
+ ### Connection Management
393
+ - Enable connection pooling for better resource utilization
394
+ - Automatic connection health monitoring
395
+ - Graceful connection recovery and retry logic
396
+
397
+ See [TECH_DOC.md](TECH_DOC.md) for detailed technical documentation.
@@ -1,10 +1,10 @@
1
1
  # e6data Python Connector
2
2
 
3
- ![version](https://img.shields.io/badge/version-2.2.5rc1-blue.svg)
3
+ ![version](https://img.shields.io/badge/version-2.2.5rc5-blue.svg)
4
4
 
5
5
  ## Introduction
6
6
 
7
- The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations.
7
+ The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations. It includes automatic support for blue-green deployments, ensuring seamless failover during server updates without query interruption.
8
8
 
9
9
  ### Dependencies
10
10
  Make sure to install below dependencies and wheel before install e6data-python-connector.
@@ -203,3 +203,157 @@ cursor.clear()
203
203
  cursor.close()
204
204
  conn.close()
205
205
  ```
206
+
207
+ ## Zero Downtime Deployment
208
+
209
+ ### 🚀 Zero Downtime Features
210
+
211
+ The e6data Python Connector provides **automatic zero downtime deployment** support through intelligent blue-green deployment strategy management:
212
+
213
+ #### ✅ **No Code Changes Required**
214
+ Your existing applications automatically benefit from zero downtime deployment without any modifications:
215
+
216
+ ```python
217
+ # Your existing code works exactly the same
218
+ from e6data_python_connector import Connection
219
+
220
+ conn = Connection(
221
+ host='your-host',
222
+ port=80,
223
+ username='your-email',
224
+ password='your-token',
225
+ database='your-database'
226
+ )
227
+
228
+ cursor = conn.cursor()
229
+ cursor.execute("SELECT * FROM your_table")
230
+ results = cursor.fetchall()
231
+ ```
232
+
233
+ #### 🔄 **Automatic Strategy Detection**
234
+ - Detects active deployment strategy (blue/green) on connection
235
+ - Caches strategy information for optimal performance
236
+ - Automatically switches strategies when deployments occur
237
+
238
+ #### 🛡️ **Seamless Query Protection**
239
+ - **Running queries continue uninterrupted** during deployments
240
+ - New queries automatically use the new deployment strategy
241
+ - Graceful transitions ensure no query loss or failures
242
+
243
+ #### ⚡ **Performance Optimized**
244
+ - **< 100ms** additional latency on first connection (one-time cost)
245
+ - **0ms overhead** for 95% of queries (cached strategy)
246
+ - **< 1KB** additional memory usage per connection
247
+
248
+ #### 🔧 **Thread & Process Safe**
249
+ - Full support for multi-threaded applications
250
+ - Process-safe shared memory management
251
+ - Concurrent query execution without conflicts
252
+
253
+ ### Advanced Configuration (Optional)
254
+
255
+ For enhanced monitoring and performance tuning:
256
+
257
+ ```python
258
+ # Enhanced gRPC configuration for zero downtime
259
+ grpc_options = {
260
+ 'keepalive_timeout_ms': 60000, # 1 minute keepalive timeout
261
+ 'keepalive_time_ms': 30000, # 30 seconds keepalive interval
262
+ 'max_receive_message_length': 100 * 1024 * 1024, # 100MB
263
+ 'max_send_message_length': 100 * 1024 * 1024, # 100MB
264
+ }
265
+
266
+ conn = Connection(
267
+ host='your-host',
268
+ port=80,
269
+ username='your-email',
270
+ password='your-token',
271
+ database='your-database',
272
+ grpc_options=grpc_options
273
+ )
274
+ ```
275
+
276
+ ### Environment Configuration
277
+
278
+ Configure zero downtime features using environment variables:
279
+
280
+ ```bash
281
+ # Strategy cache timeout (default: 300 seconds)
282
+ export E6DATA_STRATEGY_CACHE_TIMEOUT=300
283
+
284
+ # Maximum retry attempts (default: 5)
285
+ export E6DATA_MAX_RETRY_ATTEMPTS=5
286
+
287
+ # Enable debug logging for strategy operations
288
+ export E6DATA_STRATEGY_LOG_LEVEL=INFO
289
+ ```
290
+
291
+ ### Testing Zero Downtime
292
+
293
+ Use the included mock server for testing and development:
294
+
295
+ ```bash
296
+ # Terminal 1: Start mock server
297
+ python mock_grpc_server.py
298
+
299
+ # Terminal 2: Run test client
300
+ python test_mock_server.py
301
+
302
+ # Or use the convenience script
303
+ ./run_mock_test.sh
304
+ ```
305
+
306
+ ### 📚 **Comprehensive Documentation**
307
+
308
+ Explore detailed documentation in the [`docs/zero-downtime/`](docs/zero-downtime/) directory:
309
+
310
+ - **[📋 Overview](docs/zero-downtime/README.md)** - Complete guide and feature overview
311
+ - **[🔧 API Reference](docs/zero-downtime/api-reference.md)** - Detailed API documentation
312
+ - **[🌊 Flow Documentation](docs/zero-downtime/flow-documentation.md)** - Process flows and diagrams
313
+ - **[💼 Business Logic](docs/zero-downtime/business-logic.md)** - Business rules and decisions
314
+ - **[🏗️ Architecture](docs/zero-downtime/architecture.md)** - System architecture and design
315
+ - **[⚙️ Configuration](docs/zero-downtime/configuration.md)** - Complete configuration guide
316
+ - **[🧪 Testing](docs/zero-downtime/testing.md)** - Testing strategies and tools
317
+ - **[🔍 Troubleshooting](docs/zero-downtime/troubleshooting.md)** - Common issues and solutions
318
+ - **[🚀 Migration Guide](docs/zero-downtime/migration-guide.md)** - Step-by-step migration instructions
319
+
320
+ ### Key Benefits
321
+
322
+ | Feature | Benefit |
323
+ |---------|---------|
324
+ | **Zero Downtime** | Applications continue running during e6data deployments |
325
+ | **Automatic** | No code changes or manual intervention required |
326
+ | **Reliable** | Robust error handling and automatic recovery |
327
+ | **Fast** | Minimal performance impact with intelligent caching |
328
+ | **Safe** | Thread-safe and process-safe operation |
329
+ | **Monitored** | Comprehensive logging and monitoring capabilities |
330
+
331
+ ### Migration
332
+
333
+ Existing applications automatically benefit from zero downtime deployment:
334
+
335
+ 1. **Update connector**: `pip install --upgrade e6data-python-connector`
336
+ 2. **No code changes**: Your existing code works without modifications
337
+ 3. **Monitor**: Use enhanced logging to monitor strategy transitions
338
+ 4. **Validate**: Test with your existing applications
339
+
340
+ For detailed migration instructions, see the [Migration Guide](docs/zero-downtime/migration-guide.md).
341
+
342
+ ## Performance Optimization
343
+
344
+ ### Memory Efficiency
345
+ - Use `fetchall_buffer()` for memory-efficient large result sets
346
+ - Automatic cleanup of query-strategy mappings
347
+ - Bounded memory usage with TTL-based caching
348
+
349
+ ### Network Performance
350
+ - Configure gRPC options for optimal network performance
351
+ - Intelligent keepalive settings for connection stability
352
+ - Message size optimization for large queries
353
+
354
+ ### Connection Management
355
+ - Enable connection pooling for better resource utilization
356
+ - Automatic connection health monitoring
357
+ - Graceful connection recovery and retry logic
358
+
359
+ See [TECH_DOC.md](TECH_DOC.md) for detailed technical documentation.
@@ -5,28 +5,32 @@ import e6data_python_connector.cluster_server.cluster_pb2_grpc as cluster_pb2_gr
5
5
  import grpc
6
6
  from grpc._channel import _InactiveRpcError
7
7
  import multiprocessing
8
+ import logging
8
9
 
10
+ # Import strategy management functions
11
+ from e6data_python_connector.strategy import _get_active_strategy, _set_active_strategy, _set_pending_strategy, _get_grpc_header as _get_strategy_header
9
12
 
10
- def _get_grpc_header(engine_ip=None, cluster=None):
13
+ # Set up logging
14
+ _logger = logging.getLogger(__name__)
15
+
16
+
17
+ def _get_grpc_header(engine_ip=None, cluster=None, strategy=None):
11
18
  """
12
19
  Generate gRPC metadata headers for the request.
13
20
 
14
21
  This function creates a list of metadata headers to be used in gRPC requests.
15
- It includes optional headers for the engine IP and cluster UUID.
22
+ It includes optional headers for the engine IP, cluster UUID, and deployment strategy.
16
23
 
17
24
  Args:
18
25
  engine_ip (str, optional): The IP address of the engine. Defaults to None.
19
26
  cluster (str, optional): The UUID of the cluster. Defaults to None.
27
+ strategy (str, optional): The deployment strategy (blue/green). Defaults to None.
20
28
 
21
29
  Returns:
22
30
  list: A list of tuples representing the gRPC metadata headers.
23
31
  """
24
- metadata = []
25
- if engine_ip:
26
- metadata.append(('plannerip', engine_ip))
27
- if cluster:
28
- metadata.append(('cluster-uuid', cluster))
29
- return metadata
32
+ # Use the strategy module's implementation
33
+ return _get_strategy_header(engine_ip=engine_ip, cluster=cluster, strategy=strategy)
30
34
 
31
35
 
32
36
  class _StatusLock:
@@ -187,22 +191,162 @@ class ClusterManager:
187
191
  )
188
192
  return cluster_pb2_grpc.ClusterServiceStub(self._channel)
189
193
 
190
- def _check_cluster_status(self):
191
- while True:
192
- try:
193
- # Create a status request payload with user credentials
194
- status_payload = cluster_pb2.ClusterStatusRequest(
194
+ def _try_cluster_request(self, request_type, payload=None):
195
+ """
196
+ Execute a cluster request with strategy fallback for 456 errors.
197
+
198
+ For efficiency:
199
+ - If we have an active strategy, use it first
200
+ - Only try authentication sequence (blue -> green) if no active strategy
201
+ - On 456 error, switch to alternative strategy and update active strategy
202
+
203
+ Args:
204
+ request_type: Type of request ('status' or 'resume')
205
+ payload: Request payload (optional, will be created if not provided)
206
+
207
+ Returns:
208
+ The response from the successful request
209
+ """
210
+ current_strategy = _get_active_strategy()
211
+
212
+ # Create payload if not provided
213
+ if payload is None:
214
+ if request_type == "status":
215
+ payload = cluster_pb2.ClusterStatusRequest(
195
216
  user=self._user,
196
217
  password=self._password
197
218
  )
198
- # Send the status request to the cluster service
199
- response = self._get_connection.status(
200
- status_payload,
201
- metadata=_get_grpc_header(cluster=self.cluster_uuid)
219
+ elif request_type == "resume":
220
+ payload = cluster_pb2.ResumeRequest(
221
+ user=self._user,
222
+ password=self._password
202
223
  )
203
- # Yield the current status
204
- yield response.status
224
+
225
+ # If we have an active strategy, use it first
226
+ if current_strategy is not None:
227
+ try:
228
+ _logger.info(f"ClusterManager: Trying {request_type} with established strategy: {current_strategy}")
229
+
230
+ if request_type == "status":
231
+ response = self._get_connection.status(
232
+ payload,
233
+ metadata=_get_grpc_header(cluster=self.cluster_uuid, strategy=current_strategy)
234
+ )
235
+ elif request_type == "resume":
236
+ response = self._get_connection.resume(
237
+ payload,
238
+ metadata=_get_grpc_header(cluster=self.cluster_uuid, strategy=current_strategy)
239
+ )
240
+ else:
241
+ raise ValueError(f"Unknown request type: {request_type}")
242
+
243
+ # Check for new strategy in response
244
+ if hasattr(response, 'new_strategy') and response.new_strategy:
245
+ new_strategy = response.new_strategy.lower()
246
+ if new_strategy != current_strategy:
247
+ _logger.info(f"ClusterManager: Server indicated new strategy during {request_type}: {new_strategy}")
248
+ _set_pending_strategy(new_strategy)
249
+
250
+ return response
251
+
252
+ except _InactiveRpcError as e:
253
+ if e.code() == grpc.StatusCode.UNKNOWN and 'status: 456' in e.details():
254
+ # 456 error - switch to alternative strategy
255
+ alternative_strategy = 'green' if current_strategy == 'blue' else 'blue'
256
+ _logger.info(f"ClusterManager: {request_type} failed with 456 error on {current_strategy}, switching to: {alternative_strategy}")
257
+
258
+ try:
259
+ if request_type == "status":
260
+ response = self._get_connection.status(
261
+ payload,
262
+ metadata=_get_grpc_header(cluster=self.cluster_uuid, strategy=alternative_strategy)
263
+ )
264
+ elif request_type == "resume":
265
+ response = self._get_connection.resume(
266
+ payload,
267
+ metadata=_get_grpc_header(cluster=self.cluster_uuid, strategy=alternative_strategy)
268
+ )
269
+
270
+ # Update active strategy since the alternative worked
271
+ _set_active_strategy(alternative_strategy)
272
+ _logger.info(f"ClusterManager: {request_type} succeeded with alternative strategy: {alternative_strategy}")
273
+
274
+ # Check for new strategy in response
275
+ if hasattr(response, 'new_strategy') and response.new_strategy:
276
+ new_strategy = response.new_strategy.lower()
277
+ if new_strategy != alternative_strategy:
278
+ _logger.info(f"ClusterManager: Server indicated new strategy during {request_type}: {new_strategy}")
279
+ _set_pending_strategy(new_strategy)
280
+
281
+ return response
282
+
283
+ except _InactiveRpcError as e2:
284
+ _logger.error(f"ClusterManager: Both strategies failed for {request_type}. Original error: {e}, Alternative error: {e2}")
285
+ raise e # Raise the original error
286
+ else:
287
+ # Non-456 error - don't retry
288
+ _logger.error(f"ClusterManager: {request_type} failed with non-456 error: {e}")
289
+ raise e
290
+
291
+ # No active strategy - start with authentication logic (blue first, then green)
292
+ _logger.info(f"ClusterManager: No active strategy, starting authentication sequence for {request_type}")
293
+ strategies_to_try = ['blue', 'green']
294
+
295
+ for i, strategy in enumerate(strategies_to_try):
296
+ try:
297
+ _logger.info(f"ClusterManager: Trying {request_type} with strategy: {strategy}")
298
+
299
+ if request_type == "status":
300
+ response = self._get_connection.status(
301
+ payload,
302
+ metadata=_get_grpc_header(cluster=self.cluster_uuid, strategy=strategy)
303
+ )
304
+ elif request_type == "resume":
305
+ response = self._get_connection.resume(
306
+ payload,
307
+ metadata=_get_grpc_header(cluster=self.cluster_uuid, strategy=strategy)
308
+ )
309
+ else:
310
+ raise ValueError(f"Unknown request type: {request_type}")
311
+
312
+ # Set the working strategy as active
313
+ _set_active_strategy(strategy)
314
+ _logger.info(f"ClusterManager: {request_type} succeeded with strategy: {strategy}")
315
+
316
+ # Check for new strategy in response
317
+ if hasattr(response, 'new_strategy') and response.new_strategy:
318
+ new_strategy = response.new_strategy.lower()
319
+ if new_strategy != strategy:
320
+ _logger.info(f"ClusterManager: Server indicated new strategy during {request_type}: {new_strategy}")
321
+ _set_pending_strategy(new_strategy)
322
+
323
+ return response
324
+
205
325
  except _InactiveRpcError as e:
326
+ if e.code() == grpc.StatusCode.UNKNOWN and 'status: 456' in e.details():
327
+ # 456 error - try next strategy
328
+ if i < len(strategies_to_try) - 1:
329
+ _logger.info(f"ClusterManager: {request_type} failed with 456 error on {strategy}, trying next strategy: {strategies_to_try[i + 1]}")
330
+ continue
331
+ else:
332
+ _logger.error(f"ClusterManager: {request_type} failed with 456 error on all strategies")
333
+ raise e
334
+ else:
335
+ # Non-456 error - don't retry
336
+ _logger.error(f"ClusterManager: {request_type} failed with non-456 error: {e}")
337
+ raise e
338
+
339
+ # If we get here, all strategies failed
340
+ _logger.error(f"ClusterManager: All strategies failed for {request_type}")
341
+ raise e
342
+
343
+ def _check_cluster_status(self):
344
+ while True:
345
+ try:
346
+ # Use the unified strategy-aware request method
347
+ response = self._try_cluster_request("status")
348
+ yield response.status
349
+ except _InactiveRpcError:
206
350
  yield None
207
351
 
208
352
  def resume(self) -> bool:
@@ -237,25 +381,17 @@ class ClusterManager:
237
381
  if lock.is_active:
238
382
  return True
239
383
 
240
- # Retrieve the current cluster status
241
- status_payload = cluster_pb2.ClusterStatusRequest(
242
- user=self._user,
243
- password=self._password
244
- )
245
- current_status = self._get_connection.status(
246
- status_payload,
247
- metadata=_get_grpc_header(cluster=self.cluster_uuid)
248
- )
384
+ # Retrieve the current cluster status with strategy header
385
+ try:
386
+ current_status = self._try_cluster_request("status")
387
+ except _InactiveRpcError:
388
+ return False
249
389
  if current_status.status == 'suspended':
250
- # Send the resume request
251
- payload = cluster_pb2.ResumeRequest(
252
- user=self._user,
253
- password=self._password
254
- )
255
- response = self._get_connection.resume(
256
- payload,
257
- metadata=_get_grpc_header(cluster=self.cluster_uuid)
258
- )
390
+ # Send the resume request with strategy header
391
+ try:
392
+ response = self._try_cluster_request("resume")
393
+ except _InactiveRpcError:
394
+ return False
259
395
  elif current_status.status == 'active':
260
396
  return True
261
397
  elif current_status.status != 'resuming':
@@ -10,15 +10,12 @@ from __future__ import unicode_literals
10
10
  import datetime
11
11
  import decimal
12
12
  import logging
13
- import re
14
13
  from decimal import Decimal
15
14
 
16
15
  from dateutil.parser import parse
17
16
  from sqlalchemy import exc
18
17
  from sqlalchemy import processors
19
18
  from sqlalchemy import types
20
- from sqlalchemy import util
21
- # TODO shouldn't use mysql type
22
19
  from sqlalchemy.databases import mysql
23
20
  from sqlalchemy.engine import default, Engine, Connection
24
21
  from sqlalchemy.sql import compiler
@@ -230,8 +227,8 @@ class E6dataDialect(default.DefaultDialect):
230
227
  database = url.query.get("schema")
231
228
  self.catalog_name = url.query.get("catalog")
232
229
  self.cluster_uuid = url.query.get("cluster-uuid")
233
- self.secure = url.query.get("secure") == 'true'
234
- self.auto_resume = url.query.get("auto-resume") == 'true'
230
+ self.secure = url.query.get("secure") == "true"
231
+ self.auto_resume = url.query.get("auto-resume", "true") == "true" # default to True
235
232
  if not self.catalog_name:
236
233
  raise Exception('Please specify catalog in query parameter.')
237
234