Skip to content

Commit 71ca7cd

Browse files
benedekhslisson
authored andcommitted
fix(model-client): sort the uploadable objects to avoid freezing the model server
1 parent 7f338b5 commit 71ca7cd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ class ModelClientV2(
253253

254254
private suspend fun uploadObjects(repository: RepositoryId, objects: Sequence<Pair<String, String>>) {
255255
LOG.debug { "${clientId.toString(16)}.pushObjects($repository)" }
256-
objects.chunked(100_000).forEach { chunk ->
256+
objects.chunked(100_000).forEach { unsortedChunk ->
257+
// Entries are sorted to avoid deadlocks on the server side between transactions.
258+
// Since ignite locks individual entries, this is equivalent to a lock ordering.
259+
// This is also fixed on the server side, but there might an old version of the server running that doesn't
260+
// contain this fix. This client-side sorting could be removed in a future version when all servers
261+
// are upgraded.
262+
val chunk = unsortedChunk.sortedBy { it.first }
257263
httpClient.put {
258264
url {
259265
takeFrom(baseUrl)

0 commit comments

Comments
 (0)