Skip to content

Commit

Permalink
MID-8027: using offset from original paging for iterative search
Browse files Browse the repository at this point in the history
(cherry picked from commit 3417bb1)
  • Loading branch information
skublik authored and virgo47 committed Aug 9, 2022
1 parent b4729a0 commit 6619b63
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ private <T extends ObjectType> SearchResultMetadata executeSearchObjectsIterativ
ObjectPaging originalPaging = originalQuery != null ? originalQuery.getPaging() : null;
// this is total requested size of the search
Integer maxSize = originalPaging != null ? originalPaging.getMaxSize() : null;
Integer offset = originalPaging != null ? originalPaging.getOffset() : null;

List<? extends ObjectOrdering> providedOrdering = originalPaging != null
? originalPaging.getOrderingInstructions()
Expand All @@ -990,6 +991,7 @@ private <T extends ObjectType> SearchResultMetadata executeSearchObjectsIterativ
repositoryConfiguration().getIterativeSearchByPagingBatchSize(),
defaultIfNull(maxSize, Integer.MAX_VALUE));
pagedQuery.getPaging().setMaxSize(pageSize);
pagedQuery.getPaging().setOffset(offset);

PrismObject<T> lastProcessedObject = null;
int handledObjectsTotal = 0;
Expand Down Expand Up @@ -1034,6 +1036,7 @@ private <T extends ObjectType> SearchResultMetadata executeSearchObjectsIterativ
.pagingCookie(lastProcessedObject != null
? lastProcessedObject.getOid() : null);
}
pagedQuery.getPaging().setOffset(null);
}
} finally {
// This just counts the operation and adds zero/minimal time not to confuse user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ private SearchResultMetadata executeSearchObjectsIterative(
ObjectPaging originalPaging = originalQuery != null ? originalQuery.getPaging() : null;
// this is total requested size of the search
Integer maxSize = originalPaging != null ? originalPaging.getMaxSize() : null;
Integer offset = originalPaging != null ? originalPaging.getOffset() : null;

List<? extends ObjectOrdering> providedOrdering = originalPaging != null
? originalPaging.getOrderingInstructions()
Expand All @@ -657,6 +658,7 @@ private SearchResultMetadata executeSearchObjectsIterative(
repositoryConfiguration().getIterativeSearchByPagingBatchSize(),
defaultIfNull(maxSize, Integer.MAX_VALUE));
pagedQuery.getPaging().setMaxSize(pageSize);
pagedQuery.getPaging().setOffset(offset);

AuditEventRecordType lastProcessedObject = null;
int handledObjectsTotal = 0;
Expand Down Expand Up @@ -701,6 +703,7 @@ private SearchResultMetadata executeSearchObjectsIterative(
.pagingCookie(lastProcessedObject != null
? lastProcessedObject.getRepoId().toString() : null);
}
pagedQuery.getPaging().setOffset(null);
}
} finally {
// This just counts the operation and adds zero/minimal time not to confuse user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SqaleAuditSearchIterativeTest extends SqaleRepoBaseTest {

// default page size for iterative search, reset before each test
private static final int ITERATION_PAGE_SIZE = 100;
private static final int COUNT_OF_CREATED_RECORDS = ITERATION_PAGE_SIZE * 2;

private final long startTimestamp = System.currentTimeMillis();

Expand All @@ -70,7 +71,7 @@ public void initObjects() throws Exception {
long timestamp = startTimestamp;
Random random = new Random();
// we will create two full "pages" of data
for (int i = 1; i <= ITERATION_PAGE_SIZE * 2; i++) {
for (int i = 1; i <= COUNT_OF_CREATED_RECORDS; i++) {
AuditEventRecord record = new AuditEventRecord();
record.setParameter(paramString(i));
record.setTimestamp(timestamp);
Expand Down Expand Up @@ -260,6 +261,34 @@ public void test125SearchIterativeWithCustomOrdering() throws Exception {
}
}

@Test
public void test130SearchIterativeWithOffset() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();

given("query with offset specified");
ObjectQuery query = prismContext.queryFor(UserType.class)
.offset(100)
.build();

when("calling search iterative");
SearchResultMetadata metadata = searchObjectsIterative(query, operationResult);

then("result metadata is not null and reports partial result (because of the break)");
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.processedCount());
assertThat(metadata.isPartialResults()).isFalse();

and("search operations were called");
assertOperationRecordedCount(
AUDIT_OP_PREFIX + AuditService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);

and("specified amount of objects was processed");
assertThat(testHandler.processedCount()).isEqualTo(COUNT_OF_CREATED_RECORDS - 100);
}

@SafeVarargs
private SearchResultMetadata searchObjectsIterative(
ObjectQuery query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class SqaleRepoSearchIterativeTest extends SqaleRepoBaseTest {

// default page size for iterative search, reset before each test
private static final int ITERATION_PAGE_SIZE = 100;
private static final int COUNT_OF_CREATED_USERS = ITERATION_PAGE_SIZE * 2 + 1;

@BeforeClass
public void initObjects() throws Exception {
Expand Down Expand Up @@ -357,6 +358,34 @@ public void test130SearchIterativeWithCustomOrderingByName() throws Exception {
}
}

@Test
public void test135SearchIterativeWithOffset() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();

given("query with offset specified");
ObjectQuery query = prismContext.queryFor(UserType.class)
.offset(100)
.build();

when("calling search iterative");
SearchResultMetadata metadata = searchObjectsIterative(query, operationResult);

then("result metadata is not null and not partial result");
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
assertThat(metadata.isPartialResults()).isFalse();

and("search operations were called");
assertOperationRecordedCount(
REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);

and("specified amount of objects was processed");
assertThat(testHandler.getCounter()).isEqualTo(COUNT_OF_CREATED_USERS - 100);
}

@SafeVarargs
private SearchResultMetadata searchObjectsIterative(
ObjectQuery query,
Expand Down

0 comments on commit 6619b63

Please sign in to comment.