Skip to content

Commit 8fb31b0

Browse files
authored
Update project version to 7.1.3 and modify indexer grouping logic to move only dependent indexers to their dependency's group (#94)
1 parent 0eaba67 commit 8fb31b0

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jacoco {
2020

2121
group = "org.vechain"
2222

23-
val projectVersion = System.getenv("PROJECT_VERSION") ?: "7.1.2"
23+
val projectVersion = System.getenv("PROJECT_VERSION") ?: "7.1.3"
2424
version = projectVersion
2525

2626
val isSnapshot = version.toString().endsWith("SNAPSHOT")

src/main/kotlin/org.vechain.indexer/IndexerRunner.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlinx.coroutines.channels.Channel
1111
import kotlinx.coroutines.coroutineScope
1212
import kotlinx.coroutines.delay
1313
import kotlinx.coroutines.isActive
14+
import kotlinx.coroutines.joinAll
1415
import kotlinx.coroutines.launch
1516
import kotlinx.coroutines.withTimeoutOrNull
1617
import org.slf4j.Logger
@@ -181,7 +182,7 @@ open class IndexerRunner {
181182
}
182183

183184
// Wait for all fast syncs, then cancel early processing
184-
fastSyncJobs.forEach { it.join() }
185+
fastSyncJobs.joinAll()
185186
processingJob.cancel()
186187
}
187188

src/main/kotlin/org.vechain.indexer/utils/IndexerOrderUtils.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ internal object IndexerOrderUtils {
5959

6060
/**
6161
* Groups indexers by block number proximity. Indexers within [threshold] blocks of each other
62-
* are placed in the same group. Dependencies are forced into the same group even if far apart.
63-
* Each group is topologically ordered internally.
62+
* are placed in the same group. When a dependency spans groups, only the dependent indexer is
63+
* moved to its dependency's group (not the entire group). Each group is topologically ordered
64+
* internally.
6465
*
6566
* @param indexers The list of indexers to group
6667
* @param threshold Maximum block gap allowed within a group
@@ -77,7 +78,7 @@ internal object IndexerOrderUtils {
7778
var currentGroup = mutableListOf(sorted[0])
7879
groups.add(currentGroup)
7980

80-
for (i in 1 until sorted.size) {
81+
for (i in 1 ..< sorted.size) {
8182
val gap = sorted[i].getCurrentBlockNumber() - sorted[i - 1].getCurrentBlockNumber()
8283
if (gap > threshold) {
8384
currentGroup = mutableListOf()
@@ -86,26 +87,23 @@ internal object IndexerOrderUtils {
8687
currentGroup.add(sorted[i])
8788
}
8889

89-
// Force dependent indexers into the same group
90+
// Move dependent indexers to their dependency's group
9091
val indexerToGroup = mutableMapOf<Indexer, Int>()
9192
groups.forEachIndexed { idx, group -> group.forEach { indexerToGroup[it] = idx } }
9293

93-
// Merge groups when a dependency relationship spans groups
94-
var merged = true
95-
while (merged) {
96-
merged = false
94+
var moved = true
95+
while (moved) {
96+
moved = false
9797
for (indexer in indexers) {
9898
val dep = indexer.dependsOn ?: continue
9999
val indexerGroupIdx = indexerToGroup[indexer] ?: continue
100100
val depGroupIdx = indexerToGroup[dep] ?: continue
101101
if (indexerGroupIdx != depGroupIdx) {
102-
// Merge into the lower-numbered group (earlier blocks)
103-
val targetIdx = minOf(indexerGroupIdx, depGroupIdx)
104-
val sourceIdx = maxOf(indexerGroupIdx, depGroupIdx)
105-
groups[targetIdx].addAll(groups[sourceIdx])
106-
groups[sourceIdx].forEach { indexerToGroup[it] = targetIdx }
107-
groups[sourceIdx].clear()
108-
merged = true
102+
// Move only the dependent indexer to its dependency's group
103+
groups[indexerGroupIdx].remove(indexer)
104+
groups[depGroupIdx].add(indexer)
105+
indexerToGroup[indexer] = depGroupIdx
106+
moved = true
109107
}
110108
}
111109
}

src/test/kotlin/org/vechain/indexer/utils/IndexerOrderUtilsTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,21 @@ internal class IndexerOrderUtilsTest {
347347
expectThat(result.size).isEqualTo(1)
348348
}
349349

350+
@Test
351+
fun `should move only dependent indexer not entire group`() {
352+
// parent@100, child@1000 depends on parent, independent@1050
353+
val parent = createMockIndexer("parent", currentBlock = 100L)
354+
val child = createMockIndexer("child", dependsOn = parent, currentBlock = 1000L)
355+
val independent = createMockIndexer("independent", currentBlock = 1050L)
356+
357+
val result = IndexerOrderUtils.proximityGroups(listOf(parent, child, independent), 100)
358+
359+
// child moves to parent's group, independent stays in its own group
360+
expectThat(result.size).isEqualTo(2)
361+
expectThat(result[0]).containsExactly(parent, child)
362+
expectThat(result[1]).containsExactly(independent)
363+
}
364+
350365
@Test
351366
fun `should merge transitive dependency groups`() {
352367
// A depends on B, B is far from A but close to C

0 commit comments

Comments
 (0)