Skip to content

Commit

Permalink
Merge pull request #755 from modelix/fix/modelix-910
Browse files Browse the repository at this point in the history
fix(model-client): sort the uploadable objects to avoid freezing the model server
  • Loading branch information
benedekh authored May 20, 2024
2 parents 386ba03 + 852a0c5 commit caddd60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ class ModelClientV2(

private suspend fun uploadObjects(repository: RepositoryId, objects: Sequence<Pair<String, String>>) {
LOG.debug { "${clientId.toString(16)}.pushObjects($repository)" }
objects.chunked(100_000).forEach { chunk ->
objects.chunked(100_000).forEach { unsortedChunk ->
// Entries are sorted to avoid deadlocks on the server side between transactions.
// Since ignite locks individual entries, this is equivalent to a lock ordering.
// This is also fixed on the server side, but there might an old version of the server running that doesn't
// contain this fix. This client-side sorting could be removed in a future version when all servers
// are upgraded.
val chunk = unsortedChunk.sortedBy { it.first }
httpClient.put {
url {
takeFrom(baseUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ class IgniteStoreClient(jdbcConfFile: File? = null, inmemory: Boolean = false) :
}

override fun putAll(entries: Map<String, String?>, silent: Boolean) {
val deletes = entries.filterValues { it == null }
val puts = entries.filterValues { it != null }
// Sorting is important to avoid deadlocks (lock ordering).
// The documentation of IgniteCache.putAll also states that this a requirement.
val sortedEntries = entries.toSortedMap()
val deletes = sortedEntries.filterValues { it == null }
val puts = sortedEntries.filterValues { it != null }
runTransaction {
if (deletes.isNotEmpty()) cache.removeAll(deletes.keys)
if (puts.isNotEmpty()) cache.putAll(puts)
if (!silent) {
for (key in entries.keys) {
for (key in sortedEntries.keys) {
if (HashUtil.isSha256(key)) continue
pendingChangeMessages.entryChanged(key)
}
Expand Down

0 comments on commit caddd60

Please sign in to comment.