Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent false version mismatches when saving annotations #4591

Merged
merged 5 commits into from
May 6, 2020
Merged
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 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