Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.

Commit 6bf67a0

Browse files
committed
Merge pull request #26 from mikrosimage/hotfix/archive_render_node
Hotfix/archive render node
2 parents b082596 + 617aefa commit 6bf67a0

File tree

2 files changed

+98
-12
lines changed

2 files changed

+98
-12
lines changed

src/octopus/dispatcher/db/pulidb.py

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ def archiveElements(self, elements):
578578
conn.cache.clear()
579579
elif isinstance(element, RenderNode):
580580
StatDB.archiveRenderNode(self, element)
581+
conn = RenderNodes._connection
581582
conn.query(conn.sqlrepr(Delete(RenderNodes.q, where=(RenderNodes.q.id == element.id))))
582583
conn.cache.clear()
583584

@@ -1168,43 +1169,80 @@ def restoreStateFromDb(self, tree, rnsAlreadyLoaded):
11681169

11691170
### calculate the correct max ids for all elements, get them from db in case of archived elements that would not appear in the dispatchtree
11701171
prevTimer = time.time()
1172+
statConn = StatDB.createConnection()
11711173
try:
1172-
tree.nodeMaxId = int(max([FolderNodes.select().max(FolderNodes.q.id), TaskNodes.select().max(TaskNodes.q.id)]))
1174+
folderConn = FolderNodes._connection
1175+
taskConn = TaskNodes._connection
1176+
FolderNodes._connection = statConn
1177+
TaskNodes._connection = statConn
1178+
#adding 0 to max([...]) to avoid TypeError if stat table is empty
1179+
statMaxId = int(max([FolderNodes.select().max(FolderNodes.q.id), TaskNodes.select().max(TaskNodes.q.id), 0]))
1180+
FolderNodes._connection = folderConn
1181+
TaskNodes._connection = taskConn
1182+
tree.nodeMaxId = int(max([FolderNodes.select().max(FolderNodes.q.id), TaskNodes.select().max(TaskNodes.q.id), statMaxId]))
11731183
except:
11741184
tree.nodeMaxId = 0
11751185
LOGGER.warning(" - Set max id for nodes in %.3f s" % (time.time()-prevTimer))
11761186

11771187
prevTimer = time.time()
11781188
try:
1179-
tree.poolMaxId = int(Pools.select().max(Pools.q.id))
1189+
conn = Pools._connection
1190+
Pools._connection = statConn
1191+
#adding 0 to max([...]) to avoid TypeError if stat table is empty
1192+
statMaxId = int(max([Pools.select().max(Pools.q.id),0]))
1193+
Pools._connection = conn
1194+
tree.poolMaxId = int(max([Pools.select().max(Pools.q.id), statMaxId]))
11801195
except:
11811196
tree.poolMaxId = 0
11821197
LOGGER.warning(" - Set max id for pools in %.3f s" % (time.time()-prevTimer))
11831198

11841199
prevTimer = time.time()
11851200
try:
1186-
tree.renderNodeMaxId = int(RenderNodes.select().max(RenderNodes.q.id))
1201+
conn = RenderNodes._connection
1202+
RenderNodes._connection = statConn
1203+
#adding 0 to max([...]) to avoid TypeError if stat table is empty
1204+
statMaxId = int(max([RenderNodes.select().max(RenderNodes.q.id),0]))
1205+
RenderNodes._connection = conn
1206+
tree.renderNodeMaxId = int(max([RenderNodes.select().max(RenderNodes.q.id),statMaxId ]))
11871207
except:
11881208
tree.renderNodeMaxId = 0
11891209
LOGGER.warning(" - Set max id for render nodes in %.3f s" % (time.time()-prevTimer))
11901210

11911211
prevTimer = time.time()
11921212
try:
1193-
tree.taskMaxId = int(Tasks.select().max(Tasks.q.id))
1213+
taskConn = Tasks._connection
1214+
taskGroupConn = TaskGroups._connection
1215+
Tasks._connection = statConn
1216+
TaskGroups._connection = statConn
1217+
#adding 0 to max([...]) to avoid TypeError if stat table is empty
1218+
statMaxId = int(max([Tasks.select().max(Tasks.q.id), TaskGroups.select().max(TaskGroups.q.id),0]))
1219+
Tasks._connection = taskConn
1220+
TaskGroups._connection = taskGroupConn
1221+
tree.taskMaxId = int(max([Tasks.select().max(Tasks.q.id), TaskGroups.select().max(TaskGroups.q.id), statMaxId ]))
11941222
except:
11951223
tree.taskMaxId = 0
11961224
LOGGER.warning(" - Set max id for tasks in %.3f s" % (time.time()-prevTimer))
11971225

11981226
prevTimer = time.time()
11991227
try:
1200-
tree.commandMaxId = int(Commands.select().max(Commands.q.id))
1228+
conn = Commands._connection
1229+
Commands._connection = statConn
1230+
#adding 0 to max([...]) to avoid TypeError if stat table is empty
1231+
statMaxId = int(max([Commands.select().max(Commands.q.id),0]))
1232+
Commands._connection = conn
1233+
tree.commandMaxId = int(max([Commands.select().max(Commands.q.id),statMaxId ]))
12011234
except:
12021235
tree.commandMaxId = 0
12031236
LOGGER.warning(" - Set max id for commands in %.3f s" % (time.time()-prevTimer))
12041237

12051238
prevTimer = time.time()
12061239
try:
1207-
tree.poolShareMaxId = int(PoolShares.select().max(PoolShares.q.id))
1240+
conn = PoolShares._connection
1241+
PoolShares._connection = statConn
1242+
#adding 0 to max([...]) to avoid TypeError if stat table is empty
1243+
statMaxId = int(max([PoolShares.select().max(PoolShares.q.id),0]))
1244+
PoolShares._connection = conn
1245+
tree.poolShareMaxId = int(max([PoolShares.select().max(PoolShares.q.id),statMaxId ]))
12081246
except:
12091247
tree.poolShareMaxId = 0
12101248
LOGGER.warning(" - Set max id for pool shares in %.3f s" % (time.time()-prevTimer))
@@ -1411,3 +1449,44 @@ def archivePoolShare(pulidb, element):
14111449
PoolShares.q.archived.fieldName: True}
14121450
conn.query(conn.sqlrepr(Insert(PoolShares.q, values=fields)))
14131451

1452+
@staticmethod
1453+
def getMaxID(Table):
1454+
conn = Table._connection
1455+
Table._connection = StatDB.createConnection()
1456+
result = Table.select().max(Table.q.id)
1457+
Table._connection = conn
1458+
if result:
1459+
return int(result)
1460+
return 0
1461+
1462+
@staticmethod
1463+
def getRenderNodesMaxId():
1464+
return StatDB.getMaxID(RenderNodes)
1465+
1466+
@staticmethod
1467+
def getFolderNodesMaxId():
1468+
return StatDB.getMaxID(FolderNodes)
1469+
1470+
@staticmethod
1471+
def getTaskNodesMaxId():
1472+
return StatDB.getMaxID(TaskNodes)
1473+
1474+
@staticmethod
1475+
def getTasksMaxId():
1476+
return StatDB.getMaxID(Tasks)
1477+
1478+
@staticmethod
1479+
def getTaskGroupsMaxId():
1480+
return getMaxID(TaskGroups)
1481+
1482+
@staticmethod
1483+
def getPoolsMaxId():
1484+
return StatDB.getMaxID(Pools)
1485+
1486+
@staticmethod
1487+
def getPoolSharesMaxId():
1488+
return StatDB.getMaxID(PoolShares)
1489+
1490+
@staticmethod
1491+
def getCommandsMaxId():
1492+
return StatDB.getMaxID(Commands)

src/octopus/dispatcher/model/dispatchtree.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from octopus.dispatcher.strategies import FifoStrategy, loadStrategyClass
1111
from octopus.core.enums.command import *
1212
from octopus.dispatcher.rules import RuleError
13+
from octopus.dispatcher.db.pulidb import StatDB
1314

1415
logger = logging.getLogger('main.dispatcher.dispatchtree')
1516

@@ -338,11 +339,17 @@ def resetDbElements(self):
338339
#
339340
def recomputeMaxIds(self):
340341
self.nodeMaxId = max([n.id for n in self.nodes.values()]) if self.nodes else 0
342+
self.nodeMaxId = max(self.nodeMaxId, StatDB.getFolderNodesMaxId(), StatDB.getTaskNodesMaxId())
341343
self.poolMaxId = max([p.id for p in self.pools.values()]) if self.pools else 0
344+
self.poolMaxId = max(self.poolMaxId, StatDB.getPoolsMaxId())
342345
self.renderNodeMaxId = max([rn.id for rn in self.renderNodes.values()]) if self.renderNodes else 0
346+
self.renderNodeMaxId = max(self.renderNodeMaxId, StatDB.getRenderNodesMaxId())
343347
self.taskMaxId = max([t.id for t in self.tasks.values()]) if self.tasks else 0
348+
self.taskMaxId = max(self.taskMaxId , StatDB.getTasksMaxId())
344349
self.commandMaxId = max([c.id for c in self.commands.values()]) if self.commands else 0
350+
self.commandMaxId = max(self.commandMaxId, StatDB.getCommandsMaxId())
345351
self.poolShareMaxId = max([ps.id for ps in self.poolShares.values()]) if self.poolShares else 0
352+
self.poolShareMaxId = max(self.poolShareMaxId, StatDB.getPoolSharesMaxId())
346353

347354
## Removes from the dispatchtree the provided element and all its parents and children.
348355
#
@@ -419,7 +426,7 @@ def onTaskCreation(self, task):
419426
task.id = self.taskMaxId
420427
self.toCreateElements.append(task)
421428
else:
422-
self.taskMaxId = max(self.taskMaxId, task.id)
429+
self.taskMaxId = max(self.taskMaxId, task.id, StatDB.getTasksMaxId())
423430
self.tasks[task.id] = task
424431

425432
def onTaskDestruction(self, task):
@@ -446,7 +453,7 @@ def onNodeCreation(self, node):
446453
node.id = self.nodeMaxId
447454
self.toCreateElements.append(node)
448455
else:
449-
self.nodeMaxId = max(self.nodeMaxId, node.id)
456+
self.nodeMaxId = max(self.nodeMaxId, node.id, StatDB.getFolderNodesMaxId(), StatDB.getTaskNodesMaxId())
450457
if node.parent is None:
451458
node.parent = self.root
452459

@@ -470,7 +477,7 @@ def onRenderNodeCreation(self, renderNode):
470477
renderNode.id = self.renderNodeMaxId
471478
self.toCreateElements.append(renderNode)
472479
else:
473-
self.renderNodeMaxId = max(self.renderNodeMaxId, renderNode.id)
480+
self.renderNodeMaxId = max(self.renderNodeMaxId, renderNode.id, StatDB.getRenderNodesMaxId())
474481
self.renderNodes[renderNode.name] = renderNode
475482

476483
def onRenderNodeDestruction(self, rendernode):
@@ -493,7 +500,7 @@ def onPoolCreation(self, pool):
493500
pool.id = self.poolMaxId
494501
self.toCreateElements.append(pool)
495502
else:
496-
self.poolMaxId = max(self.poolMaxId, pool.id)
503+
self.poolMaxId = max(self.poolMaxId, pool.id, StatDB.getPoolsMaxId())
497504
self.pools[pool.name] = pool
498505

499506
def onPoolDestruction(self, pool):
@@ -512,7 +519,7 @@ def onCommandCreation(self, command):
512519
command.id = self.commandMaxId
513520
self.toCreateElements.append(command)
514521
else:
515-
self.commandMaxId = max(self.commandMaxId, command.id)
522+
self.commandMaxId = max(self.commandMaxId, command.id, StatDB.getCommandsMaxId())
516523
self.commands[command.id] = command
517524

518525
def onCommandChange(self, command, field, oldvalue, newvalue):
@@ -529,5 +536,5 @@ def onPoolShareCreation(self, poolShare):
529536
poolShare.id = self.poolShareMaxId
530537
self.toCreateElements.append(poolShare)
531538
else:
532-
self.poolShareMaxId = max(self.poolShareMaxId, poolShare.id)
539+
self.poolShareMaxId = max(self.poolShareMaxId, poolShare.id, StatDB.getPoolSharesMaxId())
533540
self.poolShares[poolShare.id] = poolShare

0 commit comments

Comments
 (0)