Ks 20211202 fix major reindex bug (#3211)

* begin with failing test

* fix bug

* change log

* change log
This commit is contained in:
Ken Stevens 2021-12-02 16:38:54 -05:00 committed by GitHub
parent aa09e59255
commit 2fbbf31431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
jira: SMILE-3472
title: "Fixed a serious performance issue with the `$reindex` operation."

View File

@ -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));
} }
} }

View File

@ -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);
}
}