diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 51ecf3be3a..4562e5cb3d 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -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 diff --git a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/FossilDBClient.scala b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/FossilDBClient.scala index 056246c6db..8eeab048d5 100644 --- a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/FossilDBClient.scala +++ b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/FossilDBClient.scala @@ -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) } diff --git a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala index 29af7b95fe..91af926979 100644 --- a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala +++ b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala @@ -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], @@ -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, diff --git a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/volume/VolumeTracingService.scala b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/volume/VolumeTracingService.scala index ba22a0f7d8..270eb59427 100644 --- a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/volume/VolumeTracingService.scala +++ b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/volume/VolumeTracingService.scala @@ -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],