Skip to content

Commit

Permalink
switch off funny locking until needed
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-butcher committed Jan 14, 2025
1 parent 1cf1f97 commit b5e23f9
Showing 1 changed file with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,43 +381,46 @@ class WorkMatcherTest
//
var createdLocksHistory: List[String] = List()
var cHasReadGraph = false

var specialLockingBehaviour = false
val workGraphStore = new WorkGraphStore(workNodeDao) {
override def findAffectedWorks(
ids: Set[CanonicalId]
): Future[Set[WorkNode]] = {
if (ids == Set(idB, idC)) cHasReadGraph = true
if (specialLockingBehaviour) {
if (ids == Set(idB, idC)) cHasReadGraph = true
}
super.findAffectedWorks(ids)
}
}

implicit val lockDao: MemoryLockDao[String, UUID] =
new MemoryLockDao[String, UUID] {
override def lock(id: String, contextId: UUID): LockResult = {
// (*) We don't let the update to 'A' start writing graph updates until
// we know the update to 'C' has read the old state of the graph
if (
id == SubgraphId(idA, idB) && createdLocksHistory.count(
_ == SubgraphId(idA, idB)
) == 1
) {
while (!cHasReadGraph) {}
}
if (specialLockingBehaviour) {
// (*) We don't let the update to 'A' start writing graph updates until
// we know the update to 'C' has read the old state of the graph
if (
id == SubgraphId(idA, idB) && createdLocksHistory.count(
_ == SubgraphId(idA, idB)
) == 0
) {
while (!cHasReadGraph) {}
}

// (**) We don't let the update to 'C' start writing graph updates until
// we know the update to 'A' is finished
if (
(id == SubgraphId(idA, idB) || id == SubgraphId(
idA,
idB,
idC
)) &&
createdLocksHistory.count(_ == SubgraphId(idA, idB)) == 2
) {
while (locks.contains(idA.underlying)) {}
// (**) We don't let the update to 'C' start writing graph updates until
// we know the update to 'A' is finished
if (
(id == SubgraphId(idA, idB) || id == SubgraphId(
idA,
idB,
idC
)) &&
createdLocksHistory.count(_ == SubgraphId(idA, idB)) == 1
) {
while (locks.contains(idA.underlying)) {}
}
createdLocksHistory = createdLocksHistory :+ id
}

createdLocksHistory = createdLocksHistory :+ id
super.lock(id, contextId)
}
}
Expand All @@ -439,7 +442,7 @@ class WorkMatcherTest
//
// This will put two nodes in the graph: a node for B, and a stub for A.
Await.result(workMatcher.matchWork(workB), atMost = 5 seconds)

specialLockingBehaviour = true
// Now try to store works A and C simultaneously.
//
// Here's how this can go wrong: when we get work C, we know we need
Expand Down

0 comments on commit b5e23f9

Please sign in to comment.