Ks 20211202 fix major reindex bug (#3211)
* begin with failing test * fix bug * change log * change log
This commit is contained in:
parent
aa09e59255
commit
2fbbf31431
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
jira: SMILE-3472
|
||||||
|
title: "Fixed a serious performance issue with the `$reindex` operation."
|
|
@ -56,7 +56,7 @@ public class ReindexWriter implements ItemWriter<List<Long>> {
|
||||||
|
|
||||||
// Note that since our chunk size is 1, there will always be exactly one list
|
// Note that since our chunk size is 1, there will always be exactly one list
|
||||||
for (List<Long> pidList : thePidLists) {
|
for (List<Long> pidList : thePidLists) {
|
||||||
partitionRunner.runInPartitionedThreads(new SliceImpl<>(pidList), pids -> reindexPids(pidList));
|
partitionRunner.runInPartitionedThreads(new SliceImpl<>(pidList), pids -> reindexPids(pids));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package ca.uhn.fhir.jpa.reindex.job;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.api.config.DaoConfig;
|
||||||
|
import ca.uhn.fhir.jpa.search.reindex.ResourceReindexer;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
public class ReindexWriterTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DaoConfig myDaoConfig;
|
||||||
|
@Mock
|
||||||
|
private PlatformTransactionManager myPlatformTransactionManager;
|
||||||
|
@Mock
|
||||||
|
ResourceReindexer myResourceReindexer;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private ReindexWriter myReindexWriter;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReindexSplitsPidList() throws Exception {
|
||||||
|
when(myDaoConfig.getReindexBatchSize()).thenReturn(5);
|
||||||
|
when(myDaoConfig.getReindexThreadCount()).thenReturn(4);
|
||||||
|
|
||||||
|
List<Long> pidList = new ArrayList<>();
|
||||||
|
int count = 20;
|
||||||
|
for (long i = 0; i < count; ++i) {
|
||||||
|
pidList.add(i);
|
||||||
|
}
|
||||||
|
List<List<Long>> pidListList = new ArrayList<>();
|
||||||
|
pidListList.add(pidList);
|
||||||
|
myReindexWriter.write(pidListList);
|
||||||
|
|
||||||
|
verify(myResourceReindexer, times(count)).readAndReindexResourceByPid(anyLong());
|
||||||
|
verifyNoMoreInteractions(myResourceReindexer);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue