@@ -38,7 +38,7 @@ def __init__(self, client: CrateDBClient):
3838 self .shards : List [ShardInfo ] = []
3939
4040 # Initialize session-based caches for performance.
41- self ._zone_conflict_cache : Dict [Tuple [str , int , str ], Union [str , None ]] = {}
41+ self ._zone_conflict_cache : Dict [Tuple [str , str , int , str ], Union [str , None ]] = {}
4242 self ._node_lookup_cache : Dict [str , Union [NodeInfo , None ]] = {}
4343 self ._target_nodes_cache : Dict [Tuple [float , frozenset [Any ], float , float ], List [NodeInfo ]] = {}
4444 self ._cache_hits = 0
@@ -206,7 +206,7 @@ def generate_rebalancing_recommendations(
206206 # Get moveable shards (only healthy ones for actual operations)
207207 moveable_shards = self .find_moveable_shards (constraints .min_size , constraints .max_size , constraints .table_name )
208208
209- print (
209+ logger . info (
210210 f"Analyzing { len (moveable_shards )} candidate shards "
211211 f"in size range { constraints .min_size } -{ constraints .max_size } GB..."
212212 )
@@ -239,12 +239,11 @@ def generate_rebalancing_recommendations(
239239 # Optimize processing: if filtering by source node, only process those shards
240240 if constraints .source_node :
241241 processing_shards = [s for s in moveable_shards if s .node_name == constraints .source_node ]
242- print (f"Focusing on { len (processing_shards )} shards from node { constraints .source_node } " )
242+ logger . info (f"Focusing on { len (processing_shards )} shards from node { constraints .source_node } " )
243243 else :
244244 processing_shards = moveable_shards
245245
246246 # Generate move recommendations
247- safe_recommendations = 0 # noqa: F841
248247 total_evaluated = 0
249248
250249 for i , shard in enumerate (processing_shards ):
@@ -368,12 +367,12 @@ def generate_rebalancing_recommendations(
368367
369368 if len (processing_shards ) > 100 :
370369 print () # New line after progress dots
371- print (f"Generated { len (recommendations )} move recommendations (evaluated { total_evaluated } shards)" )
372- print (f"Performance: { self .get_cache_stats ()} " )
370+ logger . info (f"Generated { len (recommendations )} move recommendations (evaluated { total_evaluated } shards)" )
371+ logger . info (f"Performance: { self .get_cache_stats ()} " )
373372 return recommendations
374373
375374 def validate_move_safety (
376- self , recommendation : ShardRelocationResponse , max_disk_usage_percent : float = 90.0
375+ self , recommendation : ShardRelocationResponse , max_disk_usage_percent : float = 90.0 , buffer_gb : float = 50.0
377376 ) -> Tuple [bool , str ]:
378377 """Validate that a move recommendation is safe to execute"""
379378 # Find target node (with caching)
@@ -388,7 +387,7 @@ def validate_move_safety(
388387 return False , zone_conflict
389388
390389 # Check available space
391- required_space_gb = recommendation .size_gb + 50 # 50GB buffer
390+ required_space_gb = recommendation .size_gb + buffer_gb
392391 if target_node .available_space_gb < required_space_gb :
393392 return (
394393 False ,
@@ -423,7 +422,7 @@ def _check_zone_conflict_cached(self, recommendation: ShardRelocationResponse) -
423422 """Check zone conflicts with caching"""
424423 # Create cache key: table, shard, target zone
425424 target_zone = self ._get_node_zone (recommendation .to_node )
426- cache_key = (recommendation .table_name , recommendation .shard_id , target_zone )
425+ cache_key = (recommendation .schema_name , recommendation . table_name , recommendation .shard_id , target_zone )
427426
428427 if cache_key in self ._zone_conflict_cache :
429428 self ._cache_hits += 1
0 commit comments