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

Fix transaction management bug #7329

Merged
merged 6 commits into from
Sep 12, 2023
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
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