Skip to content

Commit c922ddc

Browse files
authored
Merge branch 'beta' into janusgraphOptimisation
2 parents b79aebd + baae3be commit c922ddc

File tree

23 files changed

+369
-104
lines changed

23 files changed

+369
-104
lines changed

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- name: Build with Maven
6666
run: |
6767
branch_name=${{ steps.get_branch.outputs.branch }}
68-
if [[ $branch_name == 'main' || $branch_name == 'master' || $branch_name == 'lineageondemand' ]]
68+
if [[ $branch_name == 'main' || $branch_name == 'master' || $branch_name == 'dg1908' ]]
6969
then
7070
echo "build without dashboard"
7171
chmod +x ./build.sh && ./build.sh build_without_dashboard
@@ -78,7 +78,7 @@ jobs:
7878
shell: bash
7979

8080
- name: Get version tag
81-
run: echo "##[set-output name=version;]$(echo `git ls-remote https://${{ secrets.ORG_PAT_GITHUB }}@github.com/atlanhq/${REPOSITORY_NAME}.git ${{ steps.get_branch.outputs.branch }} | awk '{ print $1}' | cut -c1-7`)abcd"
81+
run: echo "##[set-output name=version;]$(echo `git ls-remote https://${{ secrets.ORG_PAT_GITHUB }}@github.com/atlanhq/${REPOSITORY_NAME}.git refs/heads/${{ steps.get_branch.outputs.branch }} | awk '{ print $1}' | cut -c1-7`)abcd"
8282
id: get_version
8383

8484
- name: Set up Buildx

common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public interface MetricsRegistry {
1010

11-
void collect(String requestId, String requestUri, AtlasPerfMetrics metrics);
11+
void collect(String requestId, String requestUri, AtlasPerfMetrics metrics, String clientOrigin);
1212

1313
void collectApplicationMetrics(String requestId, String requestUri, List<AtlasPerfMetrics.Metric> applicationMetrics);
1414

common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class MetricsRegistryServiceImpl implements MetricsRegistry {
3030

3131
private static final String NAME = "name";
3232
private static final String URI = "uri";
33+
private static final String ORIGIN = "origin";
3334
private static final String METHOD_DIST_SUMMARY = "method_dist_summary";
3435
private static final String APPLICATION_LEVEL_METRICS_SUMMARY = "application_level_metrics_summary";
3536
private static final double[] PERCENTILES = {0.99};
@@ -43,7 +44,7 @@ public MetricsRegistryServiceImpl() throws AtlasException {
4344
}
4445

4546
@Override
46-
public void collect(String requestId, String requestUri, AtlasPerfMetrics metrics) {
47+
public void collect(String requestId, String requestUri, AtlasPerfMetrics metrics, String clientOrigin) {
4748
try {
4849
if (!ApplicationProperties.get().getBoolean(METHOD_LEVEL_METRICS_ENABLE, false)) {
4950
return;
@@ -52,7 +53,7 @@ public void collect(String requestId, String requestUri, AtlasPerfMetrics metric
5253
for (String name : this.filteredMethods) {
5354
if(metrics.hasMetric(name)) {
5455
AtlasPerfMetrics.Metric metric = metrics.getMetric(name);
55-
Timer.builder(METHOD_DIST_SUMMARY).tags(Tags.of(NAME, metric.getName(), URI, requestUri)).publishPercentiles(PERCENTILES)
56+
Timer.builder(METHOD_DIST_SUMMARY).tags(Tags.of(NAME, metric.getName(), URI, requestUri, ORIGIN, clientOrigin)).publishPercentiles(PERCENTILES)
5657
.register(getMeterRegistry()).record(metric.getTotalTimeMSecs(), TimeUnit.MILLISECONDS);
5758
}
5859
}

graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasElasticsearchDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static RestClient getLowLevelClient() {
8686
try {
8787
List<HttpHost> httpHosts = getHttpHosts();
8888

89-
RestClientBuilder builder = RestClient.builder(httpHosts.get(0));
89+
RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[0]));
9090
builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder.setKeepAliveStrategy(((httpResponse, httpContext) -> 3600000)));
9191
builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
9292
.setConnectTimeout(AtlasConfiguration.INDEX_CLIENT_CONNECTION_TIMEOUT.getInt())

intg/src/main/java/org/apache/atlas/AtlasConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public enum AtlasConfiguration {
9595
LINEAGE_ON_DEMAND_ENABLED("atlas.lineage.on.demand.enabled", true),
9696
LINEAGE_ON_DEMAND_DEFAULT_NODE_COUNT("atlas.lineage.on.demand.default.node.count", 3),
9797
LINEAGE_MAX_NODE_COUNT("atlas.lineage.max.node.count", 100),
98+
LINEAGE_TIMEOUT_MS("atlas.lineage.max.timeout.ms", 15000),
9899

99100
SUPPORTED_RELATIONSHIP_EVENTS("atlas.notification.relationships.filter", "asset_readme,asset_links"),
100101

intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
import javax.xml.bind.annotation.XmlAccessorType;
3232
import javax.xml.bind.annotation.XmlRootElement;
3333
import java.io.Serializable;
34-
import java.util.*;
34+
import java.util.ArrayList;
35+
import java.util.HashMap;
36+
import java.util.Iterator;
37+
import java.util.List;
38+
import java.util.Map;
39+
import java.util.Objects;
40+
import java.util.LinkedHashMap;
3541

3642
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
3743
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;

intg/src/main/java/org/apache/atlas/model/lineage/AtlasLineageOnDemandInfo.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AtlasLineageOnDemandInfo implements Serializable {
3333
private LineageOnDemandRequest lineageOnDemandPayload;
3434
private boolean upstreamEntityLimitReached;
3535
private boolean downstreamEntityLimitReached;
36+
private boolean timeoutOccurred;
3637

3738
public AtlasLineageOnDemandInfo() {
3839
}
@@ -135,6 +136,14 @@ public void setDownstreamEntityLimitReached(boolean downstreamEntityLimitReached
135136
this.downstreamEntityLimitReached = downstreamEntityLimitReached;
136137
}
137138

139+
public void setTimeoutOccurred(boolean timeoutOccurred) {
140+
this.timeoutOccurred = timeoutOccurred;
141+
}
142+
143+
public boolean isTimeoutOccurred() {
144+
return timeoutOccurred;
145+
}
146+
138147
@Override
139148
public boolean equals(Object o) {
140149
if (this == o) return true;

repository/src/main/java/org/apache/atlas/discovery/AtlasLineageOnDemandContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class AtlasLineageOnDemandContext {
2323
private Set<String> attributes;
2424
private Set<String> relationAttributes;
2525
private LineageOnDemandBaseParams defaultParams;
26+
private TimeoutChecker timeoutChecker;
2627

2728
public AtlasLineageOnDemandContext(LineageOnDemandRequest lineageOnDemandRequest, AtlasTypeRegistry typeRegistry) {
2829
this.constraints = lineageOnDemandRequest.getConstraints();
@@ -81,6 +82,14 @@ public void setDefaultParams(LineageOnDemandBaseParams defaultParams) {
8182
this.defaultParams = defaultParams;
8283
}
8384

85+
public TimeoutChecker getTimeoutChecker() {
86+
return timeoutChecker;
87+
}
88+
89+
public void setTimeoutChecker(TimeoutChecker timeoutChecker) {
90+
this.timeoutChecker = timeoutChecker;
91+
}
92+
8493
protected Predicate constructInMemoryPredicate(AtlasTypeRegistry typeRegistry, SearchParameters.FilterCriteria filterCriteria) {
8594
LineageSearchProcessor lineageSearchProcessor = new LineageSearchProcessor();
8695
return lineageSearchProcessor.constructInMemoryPredicate(typeRegistry, filterCriteria);

repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java

Lines changed: 58 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
import javax.script.ScriptEngine;
7171
import javax.script.ScriptException;
7272
import java.util.*;
73-
import java.util.concurrent.CompletableFuture;
74-
import java.util.concurrent.ConcurrentHashMap;
75-
import java.util.concurrent.ForkJoinPool;
7673
import java.util.stream.Collectors;
7774

7875
import static org.apache.atlas.AtlasErrorCode.*;
@@ -87,8 +84,6 @@
8784
public class EntityDiscoveryService implements AtlasDiscoveryService {
8885
private static final Logger LOG = LoggerFactory.getLogger(EntityDiscoveryService.class);
8986
private static final String DEFAULT_SORT_ATTRIBUTE_NAME = "name";
90-
private static final int AVAILABLEPROCESSORS = Runtime.getRuntime().availableProcessors();
91-
private static final ForkJoinPool CUSTOMTHREADPOOL = new ForkJoinPool(AVAILABLEPROCESSORS/2); // Use half of available cores
9287

9388
private final AtlasGraph graph;
9489
private final EntityGraphRetriever entityRetriever;
@@ -1076,108 +1071,78 @@ public SearchLogSearchResult searchLogs(SearchLogSearchParams searchParams) thro
10761071
}
10771072
}
10781073

1079-
@SuppressWarnings("rawtypes")
10801074
private void prepareSearchResult(AtlasSearchResult ret, DirectIndexQueryResult indexQueryResult, Set<String> resultAttributes, boolean fetchCollapsedResults) throws AtlasBaseException {
10811075
SearchParams searchParams = ret.getSearchParameters();
1082-
boolean showSearchScore = searchParams.getShowSearchScore();
1083-
List<Result> results = new ArrayList<>();
1076+
try {
1077+
if(LOG.isDebugEnabled()){
1078+
LOG.debug("Preparing search results for ({})", ret.getSearchParameters());
1079+
}
1080+
Iterator<Result> iterator = indexQueryResult.getIterator();
1081+
boolean showSearchScore = searchParams.getShowSearchScore();
1082+
if (iterator == null) {
1083+
return;
1084+
}
10841085

1085-
// Collect results for batch processing
1086-
Iterator<Result> iterator = indexQueryResult.getIterator();
1087-
while (iterator != null && iterator.hasNext()) {
1088-
results.add(iterator.next());
1089-
}
1086+
while (iterator.hasNext()) {
1087+
Result result = iterator.next();
1088+
AtlasVertex vertex = result.getVertex();
10901089

1091-
// Batch fetch vertices
1092-
List<AtlasVertex> vertices = results.stream()
1093-
.map(Result::getVertex)
1094-
.filter(Objects::nonNull)
1095-
.collect(Collectors.toList());
1096-
1097-
// Use ConcurrentHashMap for thread-safe access
1098-
ConcurrentHashMap<String, AtlasEntityHeader> headers = new ConcurrentHashMap<>();
1099-
ConcurrentHashMap<String, AtlasEntityHeader> entitiesSet = new ConcurrentHashMap<>();
1100-
1101-
// Run vertex processing in limited parallel threads
1102-
CompletableFuture.runAsync(() -> vertices.parallelStream().forEach(vertex -> {
1103-
String guid = vertex.getProperty("__guid", String.class);
1104-
headers.computeIfAbsent(guid, k -> {
1105-
try {
1106-
AtlasEntityHeader header = entityRetriever.toAtlasEntityHeader(vertex, resultAttributes);
1107-
if (RequestContext.get().includeClassifications()) {
1108-
header.setClassifications(entityRetriever.getAllClassifications(vertex));
1109-
}
1110-
return header;
1111-
} catch (AtlasBaseException e) {
1112-
throw new RuntimeException("Failed to process vertex with GUID: " + guid, e);
1090+
if (vertex == null) {
1091+
LOG.warn("vertex in null");
1092+
continue;
11131093
}
1114-
});
1115-
}), CUSTOMTHREADPOOL).join();
11161094

1117-
// Process results and handle collapse in parallel
1118-
results.parallelStream().forEach(result -> {
1119-
AtlasVertex vertex = result.getVertex();
1120-
if (vertex == null) return;
1095+
AtlasEntityHeader header = entityRetriever.toAtlasEntityHeader(vertex, resultAttributes);
1096+
if(RequestContext.get().includeClassifications()){
1097+
header.setClassifications(entityRetriever.getAllClassifications(vertex));
1098+
}
1099+
if (showSearchScore) {
1100+
ret.addEntityScore(header.getGuid(), result.getScore());
1101+
}
1102+
if (fetchCollapsedResults) {
1103+
Map<String, AtlasSearchResult> collapse = new HashMap<>();
1104+
1105+
Set<String> collapseKeys = result.getCollapseKeys();
1106+
for (String collapseKey : collapseKeys) {
1107+
AtlasSearchResult collapseRet = new AtlasSearchResult();
1108+
collapseRet.setSearchParameters(ret.getSearchParameters());
1109+
1110+
Set<String> collapseResultAttributes = new HashSet<>();
1111+
if (searchParams.getCollapseAttributes() != null) {
1112+
collapseResultAttributes.addAll(searchParams.getCollapseAttributes());
1113+
} else {
1114+
collapseResultAttributes = resultAttributes;
1115+
}
11211116

1122-
String guid = vertex.getProperty("__guid", String.class);
1123-
AtlasEntityHeader header = headers.get(guid);
1117+
if (searchParams.getCollapseRelationAttributes() != null) {
1118+
RequestContext.get().getRelationAttrsForSearch().clear();
1119+
RequestContext.get().setRelationAttrsForSearch(searchParams.getCollapseRelationAttributes());
1120+
}
11241121

1125-
if (showSearchScore) {
1126-
ret.addEntityScore(header.getGuid(), result.getScore());
1127-
}
1122+
DirectIndexQueryResult indexQueryCollapsedResult = result.getCollapseVertices(collapseKey);
1123+
collapseRet.setApproximateCount(indexQueryCollapsedResult.getApproximateCount());
1124+
prepareSearchResult(collapseRet, indexQueryCollapsedResult, collapseResultAttributes, false);
11281125

1129-
if (fetchCollapsedResults) {
1130-
Map<String, AtlasSearchResult> collapse;
1131-
try {
1132-
collapse = processCollapseResults(result, searchParams, resultAttributes);
1133-
} catch (AtlasBaseException e) {
1134-
throw new RuntimeException(e);
1126+
collapseRet.setSearchParameters(null);
1127+
collapse.put(collapseKey, collapseRet);
1128+
}
1129+
if (!collapse.isEmpty()) {
1130+
header.setCollapse(collapse);
1131+
}
11351132
}
1136-
if (!collapse.isEmpty()) {
1137-
header.setCollapse(collapse);
1133+
if (searchParams.getShowSearchMetadata()) {
1134+
ret.addHighlights(header.getGuid(), result.getHighLights());
1135+
ret.addSort(header.getGuid(), result.getSort());
1136+
} else if (searchParams.getShowHighlights()) {
1137+
ret.addHighlights(header.getGuid(), result.getHighLights());
11381138
}
1139-
}
11401139

1141-
if (searchParams.getShowSearchMetadata()) {
1142-
ret.addHighlights(header.getGuid(), result.getHighLights());
1143-
ret.addSort(header.getGuid(), result.getSort());
1144-
} else if (searchParams.getShowHighlights()) {
1145-
ret.addHighlights(header.getGuid(), result.getHighLights());
1140+
ret.addEntity(header);
11461141
}
1147-
1148-
if (header != null) {
1149-
entitiesSet.put(header.getGuid(), header);
1150-
}
1151-
});
1152-
}
1153-
1154-
// Non-recursive collapse processing
1155-
private Map<String, AtlasSearchResult> processCollapseResults(Result result, SearchParams searchParams, Set<String> resultAttributes) throws AtlasBaseException {
1156-
Map<String, AtlasSearchResult> collapse = new HashMap<>();
1157-
Set<String> collapseKeys = result.getCollapseKeys();
1158-
1159-
for (String collapseKey : collapseKeys) {
1160-
AtlasSearchResult collapseRet = new AtlasSearchResult();
1161-
collapseRet.setSearchParameters(searchParams);
1162-
Set<String> collapseResultAttributes = new HashSet<>(Optional.ofNullable(searchParams.getCollapseAttributes()).orElse(resultAttributes));
1163-
DirectIndexQueryResult indexQueryCollapsedResult = result.getCollapseVertices(collapseKey);
1164-
collapseRet.setApproximateCount(indexQueryCollapsedResult.getApproximateCount());
1165-
1166-
// Directly iterate over collapse vertices
1167-
Iterator<Result> iterator = indexQueryCollapsedResult.getIterator();
1168-
while (iterator != null && iterator.hasNext()) {
1169-
Result collapseResult = iterator.next();
1170-
AtlasVertex collapseVertex = collapseResult.getVertex();
1171-
if (collapseVertex == null) continue;
1172-
1173-
AtlasEntityHeader collapseHeader = entityRetriever.toAtlasEntityHeader(collapseVertex, collapseResultAttributes);
1174-
collapseRet.addEntity(collapseHeader);
1175-
}
1176-
1177-
collapse.put(collapseKey, collapseRet);
1142+
} catch (Exception e) {
1143+
throw e;
11781144
}
1179-
1180-
return collapse;
1145+
scrubSearchResults(ret, searchParams.getSuppressLogs());
11811146
}
11821147

11831148
private Map<String, Object> getMap(String key, Object value) {

0 commit comments

Comments
 (0)