Skip to content
Snippets Groups Projects
Commit b7db7bfa authored by Koen's avatar Koen
Browse files

Properly throw exceptions when backfill fails.

parent 1079dd39
No related branches found
No related tags found
No related merge requests found
package com.futo.polycentric.core
class AggregateException(
val childExceptions: List<Throwable>,
message: String = "Multiple exceptions occurred.",
) : Throwable(message, childExceptions.firstOrNull())
\ No newline at end of file
......@@ -92,6 +92,7 @@ class Synchronization {
val systemProto = system.toProto()
var progress = false
val exceptions = arrayListOf<Throwable>()
for (server in systemState.servers) {
try {
val rangesForSystem = RangesForSystem.fromProto(ApiMethods.getRanges(server, systemProto))
......@@ -108,11 +109,15 @@ class Synchronization {
val processState = Store.instance.getProcessState(system, process)
val serverNeeds = Ranges.subtract(processState.ranges, rangesForProcess)
if (serverNeeds.isEmpty()) {
Log.i(TAG, "There is nothing to backfill")
break
}
for (range in serverNeeds) {
Log.i(TAG, "Backfilling range ${range.low}-${range.high}")
}
val batch = Ranges.takeRangesMaxItems(serverNeeds, 10L)
val events = loadRanges(system, process, batch)
......@@ -124,9 +129,17 @@ class Synchronization {
}
} catch (err: Throwable) {
Log.e(TAG, "An error occurred while backfilling server", err)
exceptions.add(err)
}
}
if (exceptions.isNotEmpty()) {
if (exceptions.size == 1)
throw exceptions.first()
throw AggregateException(exceptions)
}
return@withContext progress
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment