Skip to content

Commit

Permalink
Fix transaction management bug (#7329)
Browse files Browse the repository at this point in the history
* fix transaction management bug

* cleanup

* info does not need concatenating

* cleanup

* cleaner version check

* disable transactions for editable mappings in front-end

---------

Co-authored-by: Philipp Otto <[email protected]>
  • Loading branch information
fm3 and philippotto authored Sep 12, 2023
1 parent 18a042d commit 06c8002
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed reading sharded Zarr 3 data from the local file system. [#7321](https://github.com/scalableminds/webknossos/pull/7321)
- Fixed no-bucket data zipfile when downloading volume annotations. [#7323](https://github.com/scalableminds/webknossos/pull/7323)
- Fixed too tight assertions when saving annotations, leading to failed save requests. [#7326](https://github.com/scalableminds/webknossos/pull/7326)
- Fixed a bug when saving large amounts of skeleton annotation data at once. [#7329](https://github.com/scalableminds/webknossos/pull/7329)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const SETTINGS_MAX_RETRY_COUNT = 20; // 20 * 15s == 5m
export const MAXIMUM_ACTION_COUNT_PER_BATCH = {
skeleton: 5000,
volume: 1000, // Since volume saving is slower, use a lower value here.
mapping: 5000,
mapping: Infinity, // The back-end does not accept transactions for mappings.
} as const;

export const MAXIMUM_ACTION_COUNT_PER_SAVE = {
skeleton: 15000,
volume: 3000,
mapping: 15000,
mapping: Infinity, // The back-end does not accept transactions for mappings.
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,29 @@ trait TracingController[T <: GeneratedMessage, Ts <: GeneratedMessage] extends C
_ <- bool2Fox(
previousActionGroupsToCommit
.exists(_.transactionGroupIndex == 0) || updateGroup.transactionGroupCount == 1) ?~> s"Trying to commit a transaction without a group that has transactionGroupIndex 0."
commitResult <- commitUpdates(tracingId, previousActionGroupsToCommit :+ updateGroup, userToken)
concatenatedGroup = concatenateUpdateGroupsOfTransaction(previousActionGroupsToCommit, updateGroup)
commitResult <- commitUpdates(tracingId, List(concatenatedGroup), userToken)
_ <- tracingService.removeAllUncommittedFor(tracingId, updateGroup.transactionId)
} yield commitResult

private def concatenateUpdateGroupsOfTransaction(previousActionGroups: List[UpdateActionGroup[T]],
lastActionGroup: UpdateActionGroup[T]): UpdateActionGroup[T] =
if (previousActionGroups.isEmpty) lastActionGroup
else {
val allActionGroups = previousActionGroups :+ lastActionGroup
UpdateActionGroup[T](
version = lastActionGroup.version,
timestamp = lastActionGroup.timestamp,
authorId = lastActionGroup.authorId,
actions = allActionGroups.flatMap(_.actions),
stats = lastActionGroup.stats, // the latest stats do count
info = lastActionGroup.info, // frontend sets this identically for all groups of transaction
transactionId = f"${lastActionGroup.transactionId}-concatenated",
transactionGroupCount = 1,
transactionGroupIndex = 0,
)
}

// Perform version check and commit the passed updates
private def commitUpdates(tracingId: String,
updateGroups: List[UpdateActionGroup[T]],
Expand All @@ -207,8 +226,7 @@ trait TracingController[T <: GeneratedMessage, Ts <: GeneratedMessage] extends C
remoteWebKnossosClient.reportTracingUpdates(report).flatMap { _ =>
updateGroups.foldLeft(currentCommittedVersion) { (previousVersion, updateGroup) =>
previousVersion.flatMap { prevVersion: Long =>
val versionIncrement = if (updateGroup.transactionGroupIndex == 0) 1 else 0 // version increment happens at the start of each transaction
if (prevVersion + versionIncrement == updateGroup.version) {
if (prevVersion + 1 == updateGroup.version) {
tracingService
.handleUpdateGroup(tracingId, updateGroup, prevVersion, userToken)
.flatMap(
Expand Down

0 comments on commit 06c8002

Please sign in to comment.