Fix Redis data migration error

• Use proper Redis connection context
• Fix namespace pattern for key scanning
• Propagate storage check exceptions
• Remove defensive error swallowing
This commit is contained in:
yangdx 2025-10-21 16:27:04 +08:00
parent 3ed2abd82c
commit e5e16b7bd1
2 changed files with 8 additions and 7 deletions

View file

@ -368,12 +368,13 @@ class RedisKVStorage(BaseKVStorage):
Returns:
bool: True if storage is empty, False otherwise
"""
pattern = f"{self.namespace}:{self.workspace}:*"
pattern = f"{self.final_namespace}:*"
try:
# Use scan to check if any keys exist
async for key in self.redis.scan_iter(match=pattern, count=1):
return False # Found at least one key
return True # No keys found
async with self._get_redis_connection() as redis:
# Use scan to check if any keys exist
async for key in redis.scan_iter(match=pattern, count=1):
return False # Found at least one key
return True # No keys found
except Exception as e:
logger.error(f"[{self.workspace}] Error checking if storage is empty: {e}")
return True

View file

@ -887,13 +887,13 @@ class LightRAG:
need_entity_migration = await self.entity_chunks.is_empty()
except Exception as exc: # pragma: no cover - defensive logging
logger.error(f"Failed to check entity chunks storage: {exc}")
need_entity_migration = True
raise exc
try:
need_relation_migration = await self.relation_chunks.is_empty()
except Exception as exc: # pragma: no cover - defensive logging
logger.error(f"Failed to check relation chunks storage: {exc}")
need_relation_migration = True
raise exc
if not need_entity_migration and not need_relation_migration:
return