Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DIRAC/Core/Utilities/MySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def _createTables(self, tableDict, force=False):
# cmdList.append( '`%s` %s' % ( forTable, tableDict[forTable]['Fields'][forKey] )
cmdList.append(
"FOREIGN KEY ( `%s` ) REFERENCES `%s` ( `%s` )"
" ON DELETE RESTRICT" % (key, forTable, forKey)
" ON DELETE CASCADE" % (key, forTable, forKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not be the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elaborate why. It only affects TaskQueueDB and SandboxMetadataDB

)

engine = thisTable.get("Engine", "InnoDB")
Expand Down
12 changes: 3 additions & 9 deletions src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,13 @@ def deletePilots(self, pilotIDs, conn=False):
if not isinstance(pilotIDs, list):
return S_ERROR("Input argument is not a List")

failed = []

result = self._escapeValues(pilotIDs)
if not result["OK"]:
return S_ERROR(f"Failed to remove pilot: {result['Value']}")
stringIDs = ",".join(result["Value"])
for table in ["PilotOutput", "JobToPilotMapping", "PilotAgents"]:
result = self._update(f"DELETE FROM {table} WHERE PilotID in ({stringIDs})", conn=conn)
if not result["OK"]:
failed.append(table)

if failed:
return S_ERROR(f"Failed to remove pilot from {', '.join(failed)} tables")
result = self._update(f"DELETE FROM PilotAgents WHERE PilotID in ({stringIDs})", conn=conn)
if not result["OK"]:
return S_ERROR("Failed to remove pilots: ", result["Message"])
return S_OK(pilotIDs)

##########################################################################################
Expand Down
7 changes: 4 additions & 3 deletions src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ CREATE TABLE `JobToPilotMapping` (
`PilotID` INT(11) UNSIGNED NOT NULL,
`JobID` INT(11) UNSIGNED NOT NULL,
`StartTime` DATETIME NOT NULL,
KEY `JobID` (`JobID`),
KEY `PilotID` (`PilotID`)
PRIMARY KEY (`PilotID`, `JobID`),
FOREIGN KEY (`PilotID`) REFERENCES `PilotAgents`(`PilotID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DROP TABLE IF EXISTS `PilotOutput`;
CREATE TABLE `PilotOutput` (
`PilotID` INT(11) UNSIGNED NOT NULL,
`StdOutput` MEDIUMTEXT,
`StdError` MEDIUMTEXT,
PRIMARY KEY (`PilotID`)
PRIMARY KEY (`PilotID`),
FOREIGN KEY (`PilotID`) REFERENCES `PilotAgents`(`PilotID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
11 changes: 4 additions & 7 deletions src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ def __initializeDB(self):
"Fields": {
"SBId": "INTEGER(10) UNSIGNED NOT NULL",
"EntityId": "VARCHAR(128) NOT NULL",
"Type": "VARCHAR(64) NOT NULL",
"Type": "ENUM('Input', 'Output') NOT NULL",
},
"Indexes": {"Entity": ["EntityId"], "SBIndex": ["SBId"]},
"UniqueIndexes": {"Mapping": ["SBId", "EntityId", "Type"]},
"ForeignKeys": {"SBId": "sb_SandBoxes.SBId"},
}

for tableName in self.__tablesDesc:
Expand Down Expand Up @@ -323,12 +324,8 @@ def deleteSandboxes(self, SBIdList):
Delete sandboxes
"""
sqlSBList = ", ".join([str(sbid) for sbid in SBIdList])
for table in ("sb_SandBoxes", "sb_EntityMapping"):
sqlCmd = f"DELETE FROM `{table}` WHERE SBId IN ( {sqlSBList} )"
result = self._update(sqlCmd)
if not result["OK"]:
return result
return S_OK()
sqlCmd = f"DELETE FROM sb_SandBoxes WHERE SBId IN ( {sqlSBList} )"
return self._update(sqlCmd)

def getSandboxId(self, SEName, SEPFN, requesterName, requesterGroup, field="SBId", requesterDN=None):
"""
Expand Down
17 changes: 1 addition & 16 deletions src/DIRAC/WorkloadManagementSystem/DB/TaskQueueDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,7 @@ def cleanOrphanedTaskQueues(self, connObj=False):
if not orphanedTQs:
return S_OK()
orphanedTQs = [str(otq[0]) for otq in orphanedTQs]

for mvField in multiValueDefFields:
result = self._update(
f"DELETE FROM `tq_TQTo{mvField}` WHERE TQId in ( {','.join(orphanedTQs)} )", conn=connObj
)
if not result["OK"]:
return result

result = self._update(f"DELETE FROM `tq_TaskQueues` WHERE TQId in ( {','.join(orphanedTQs)} )", conn=connObj)
if not result["OK"]:
return result
return S_OK()
return self._update(f"DELETE FROM `tq_TaskQueues` WHERE TQId in ( {','.join(orphanedTQs)} )", conn=connObj)

def __setTaskQueueEnabled(self, tqId, enabled=True, connObj=False):
if enabled:
Expand Down Expand Up @@ -990,10 +979,6 @@ def deleteTaskQueueIfEmpty(self, tqId, tqOwner=False, tqOwnerGroup=False, connOb
tqToDel = retVal["Value"]

if tqToDel:
for mvField in multiValueDefFields:
retVal = self._update(f"DELETE FROM `tq_TQTo{mvField}` WHERE TQId = {tqId}", conn=connObj)
if not retVal["OK"]:
return retVal
retVal = self._update(f"DELETE FROM `tq_TaskQueues` WHERE TQId = {tqId}", conn=connObj)
if not retVal["OK"]:
return retVal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_SandboxMetadataDB():
print(f"sbId:{sbId}")
print(f"newSandbox:{newSandbox}")

assignTo = {owner: [(f"SB:{sbSE}|{sbPFN}", ownerGroup)]}
assignTo = {123: [(f"SB:{sbSE}|{sbPFN}", "Input")]}
res = smDB.assignSandboxesToEntities(assignTo, owner, ownerGroup)
assert res["OK"], res["Message"]
assert res["Value"] == 1
Expand Down
Loading