Fix deadlock issues in training 2
This commit is contained in:
@@ -801,12 +801,18 @@ class BakeryProphetManager:
|
|||||||
db_model.data_quality_score = float(training_metrics.get('data_quality_score')) if training_metrics.get('data_quality_score') is not None else None
|
db_model.data_quality_score = float(training_metrics.get('data_quality_score')) if training_metrics.get('data_quality_score') is not None else None
|
||||||
|
|
||||||
db_session.add(db_model)
|
db_session.add(db_model)
|
||||||
await db_session.commit()
|
|
||||||
|
# Only commit if using a new session, not if using parent session
|
||||||
logger.info(f"Model {model_id} stored in database successfully")
|
# Parent session commits will be handled by the calling method to prevent conflicts
|
||||||
|
if not use_parent_session:
|
||||||
|
await db_session.commit()
|
||||||
|
logger.info(f"Model {model_id} stored in database successfully")
|
||||||
|
else:
|
||||||
|
logger.debug(f"Added model {model_id} to parent session (commit deferred)")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# ✅ FIX: Use parent session if provided, otherwise create new one
|
# ✅ FIX: Use parent session if provided, otherwise create new one
|
||||||
|
# The parent session handles commits, so child sessions shouldn't commit
|
||||||
if use_parent_session:
|
if use_parent_session:
|
||||||
logger.debug(f"Using parent session for storing model {model_id}")
|
logger.debug(f"Using parent session for storing model {model_id}")
|
||||||
await _store_in_db(session)
|
await _store_in_db(session)
|
||||||
@@ -814,6 +820,9 @@ class BakeryProphetManager:
|
|||||||
logger.debug(f"Creating new session for storing model {model_id}")
|
logger.debug(f"Creating new session for storing model {model_id}")
|
||||||
async with self.database_manager.get_session() as new_session:
|
async with self.database_manager.get_session() as new_session:
|
||||||
await _store_in_db(new_session)
|
await _store_in_db(new_session)
|
||||||
|
# Commit only when using our own session (not parent)
|
||||||
|
await new_session.commit() # This is safe since new_session is dedicated
|
||||||
|
logger.info(f"Model {model_id} stored in database successfully")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to store model in database: {str(e)}")
|
logger.error(f"Failed to store model in database: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user