Skip to content

Commit

Permalink
Prevent false version mismatches when saving annotations (#4591)
Browse files Browse the repository at this point in the history
* Fix false version mismatches

* pretty

* changelog

* use emptyFallback also during applyPendingUpdates
  • Loading branch information
fm3 authored May 6, 2020
1 parent cd378cc commit 40a90ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Fixed

-
- Fixed retrying of failed save requests sent during tracingstore restart. [#4591](https://github.com/scalableminds/webknossos/pull/4591)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,20 @@ class FossilDBClient(collection: String, config: TracingStoreConfig) extends Fox
case e: Exception => Fox.failure("Could not get from FossilDB: " + e.getMessage)
}

def getVersion(key: String, version: Option[Long] = None, mayBeEmpty: Option[Boolean] = None): Fox[Long] =
def getVersion(key: String,
version: Option[Long] = None,
mayBeEmpty: Option[Boolean],
emptyFallback: Option[Long] = None): Fox[Long] =
try {
val reply = blockingStub.get(GetRequest(collection, key, version, mayBeEmpty))
if (!reply.success) throw new Exception(reply.errorMessage.getOrElse(""))
Fox.successful(reply.actualVersion)
if (reply.success) Fox.successful(reply.actualVersion)
else {
if (mayBeEmpty.contains(true) && emptyFallback.isDefined && reply.errorMessage.contains("No such element")) {
emptyFallback.toFox
} else {
throw new Exception(reply.errorMessage.getOrElse(""))
}
}
} catch {
case e: Exception => Fox.failure("Could not get from FossilDB: " + e.getMessage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SkeletonTracingService @Inject()(tracingDataStore: TracingDataStore,
implicit val updateActionJsonFormat = SkeletonUpdateAction.skeletonUpdateActionFormat

def currentVersion(tracingId: String): Fox[Long] =
tracingDataStore.skeletonUpdates.getVersion(tracingId, mayBeEmpty = Some(true)).getOrElse(0L)
tracingDataStore.skeletonUpdates.getVersion(tracingId, mayBeEmpty = Some(true), emptyFallback = Some(0L))

def handleUpdateGroup(tracingId: String,
updateActionGroup: UpdateActionGroup[SkeletonTracing],
Expand Down Expand Up @@ -70,14 +70,21 @@ class SkeletonTracingService @Inject()(tracingDataStore: TracingDataStore,
private def findDesiredOrNewestPossibleVersion(tracing: SkeletonTracing,
tracingId: String,
desiredVersion: Option[Long]): Fox[Long] =
(for {
newestUpdateVersion <- tracingDataStore.skeletonUpdates.getVersion(tracingId, mayBeEmpty = Some(true))
/*
* Determines the newest saved version from the updates column.
* if there are no updates at all, assume tracing is brand new (possibly created from NML,
* hence the emptyFallbck tracing.version)
*/
for {
newestUpdateVersion <- tracingDataStore.skeletonUpdates.getVersion(tracingId,
mayBeEmpty = Some(true),
emptyFallback = Some(tracing.version))
} yield {
desiredVersion match {
case None => newestUpdateVersion
case Some(desiredSome) => math.min(desiredSome, newestUpdateVersion)
}
}).getOrElse(tracing.version) //if there are no updates at all, assume tracing is brand new (possibly created from NML)
}

private def findPendingUpdates(tracingId: String,
existingVersion: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class VolumeTracingService @Inject()(
val binaryDataService = new BinaryDataService(Paths.get(""), 10 seconds, 100, null)

override def currentVersion(tracingId: String): Fox[Long] =
tracingDataStore.volumes.getVersion(tracingId).getOrElse(0L)
tracingDataStore.volumes.getVersion(tracingId, mayBeEmpty = Some(true), emptyFallback = Some(0L))

def handleUpdateGroup(tracingId: String,
updateGroup: UpdateActionGroup[VolumeTracing],
Expand Down

0 comments on commit 40a90ea

Please sign in to comment.