mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-26 09:26:22 +00:00
fix(scroll): fix scroll cache key for hazelcast (#8149)
This commit is contained in:
parent
abc2f85331
commit
4f50445d98
@ -22,6 +22,7 @@ import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument;
|
||||
import static com.linkedin.datahub.graphql.resolvers.search.SearchUtils.*;
|
||||
@ -50,8 +51,9 @@ public class ScrollAcrossEntitiesResolver implements DataFetcher<CompletableFutu
|
||||
(input.getTypes() == null || input.getTypes().isEmpty()) ? SEARCHABLE_ENTITY_TYPES : input.getTypes();
|
||||
final List<String> entityNames = entityTypes.stream().map(EntityTypeMapper::getName).collect(Collectors.toList());
|
||||
|
||||
// escape forward slash since it is a reserved character in Elasticsearch
|
||||
final String sanitizedQuery = ResolverUtils.escapeForwardSlash(input.getQuery());
|
||||
// escape forward slash since it is a reserved character in Elasticsearch, default to * if blank/empty
|
||||
final String sanitizedQuery = StringUtils.isNotBlank(input.getQuery())
|
||||
? ResolverUtils.escapeForwardSlash(input.getQuery()) : "*";
|
||||
|
||||
@Nullable
|
||||
final String scrollId = input.getScrollId();
|
||||
|
||||
@ -251,12 +251,13 @@ public class CachingEntitySearchService {
|
||||
filters != null ? toJsonString(filters) : null,
|
||||
sortCriterion != null ? toJsonString(sortCriterion) : null,
|
||||
scrollId, size);
|
||||
result = cache.get(cacheKey, ScrollResult.class);
|
||||
String json = cache.get(cacheKey, String.class);
|
||||
result = json != null ? toRecordTemplate(ScrollResult.class, json) : null;
|
||||
cacheAccess.stop();
|
||||
if (result == null) {
|
||||
Timer.Context cacheMiss = MetricUtils.timer(this.getClass(), "scroll_cache_miss").time();
|
||||
result = getRawScrollResults(entities, query, filters, sortCriterion, scrollId, keepAlive, size, isFullText);
|
||||
cache.put(cacheKey, result);
|
||||
cache.put(cacheKey, toJsonString(result));
|
||||
cacheMiss.stop();
|
||||
MetricUtils.counter(this.getClass(), "scroll_cache_miss_count").inc();
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ import com.linkedin.metadata.query.filter.CriterionArray;
|
||||
import com.linkedin.metadata.query.filter.Filter;
|
||||
import com.linkedin.metadata.query.filter.SortCriterion;
|
||||
import com.linkedin.metadata.search.EntityLineageResultCacheKey;
|
||||
import com.linkedin.metadata.search.ScrollResult;
|
||||
import com.linkedin.metadata.search.SearchEntity;
|
||||
import com.linkedin.metadata.search.SearchEntityArray;
|
||||
import com.linkedin.metadata.search.SearchResult;
|
||||
@ -92,10 +93,9 @@ public class CacheTest extends JetTestSupport {
|
||||
public void hazelcastTestScroll() {
|
||||
CorpuserUrn corpuserUrn = new CorpuserUrn("user");
|
||||
SearchEntity searchEntity = new SearchEntity().setEntity(corpuserUrn);
|
||||
SearchResult searchResult = new SearchResult()
|
||||
ScrollResult scrollResult = new ScrollResult()
|
||||
.setEntities(new SearchEntityArray(List.of(searchEntity)))
|
||||
.setNumEntities(1)
|
||||
.setFrom(0)
|
||||
.setPageSize(1)
|
||||
.setMetadata(new SearchResultMetadata());
|
||||
|
||||
@ -126,7 +126,7 @@ public class CacheTest extends JetTestSupport {
|
||||
Cache cache2 = cacheManager2.getCache(ENTITY_SEARCH_SERVICE_SCROLL_CACHE_NAME);
|
||||
|
||||
// Cache result
|
||||
String json = toJsonString(searchResult);
|
||||
String json = toJsonString(scrollResult);
|
||||
cache1.put(sextet, json);
|
||||
Assert.assertEquals(instance1.getMap(ENTITY_SEARCH_SERVICE_SCROLL_CACHE_NAME).get(sextet),
|
||||
instance2.getMap(ENTITY_SEARCH_SERVICE_SCROLL_CACHE_NAME).get(sextet));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user