Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
2bd6f469
Commit
2bd6f469
authored
6 years ago
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3276: Fix stale transactions in atlas due to ATLAS-3246 (Free-text search)
parent
a097bed3
master
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
23 deletions
+83
-23
AtlasJanusGraphIndexClient.java
.../repository/graphdb/janus/AtlasJanusGraphIndexClient.java
+53
-23
MetricsService.java
...c/main/java/org/apache/atlas/services/MetricsService.java
+2
-0
AtlasMetricsUtil.java
...src/main/java/org/apache/atlas/util/AtlasMetricsUtil.java
+28
-0
No files found.
graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphIndexClient.java
View file @
2bd6f469
...
...
@@ -135,7 +135,8 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
@Override
public
Map
<
String
,
List
<
AtlasAggregationEntry
>>
getAggregatedMetrics
(
String
queryString
,
Set
<
String
>
propertyKeyNames
)
{
SolrClient
solrClient
=
null
;
SolrClient
solrClient
=
null
;
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
try
{
solrClient
=
Solr6Index
.
getSolrClient
();
// get solr client using same settings as that of Janus Graph
...
...
@@ -153,7 +154,6 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
}
SolrQuery
solrQuery
=
new
SolrQuery
();
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
Map
<
String
,
String
>
indexFieldName2PropertyKeyNameMap
=
new
HashMap
<>();
solrQuery
.
setQuery
(
queryString
);
...
...
@@ -192,7 +192,9 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
}
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Error enocunted in getting the aggregation metrics. Will return empty agregation."
,
e
);
}
finally
{
}
finally
{
graphManagementCommit
(
management
);
Solr6Index
.
releaseSolrClient
(
solrClient
);
}
...
...
@@ -214,7 +216,7 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
//update the request handler
performRequestHandlerAction
(
collectionName
,
solrClient
,
generatePayLoadForSuggestions
(
generateSuggestionsString
(
collectionName
,
graph
.
getManagementSystem
(),
suggestionProperties
)));
generatePayLoadForSuggestions
(
generateSuggestionsString
(
collectionName
,
suggestionProperties
)));
}
catch
(
Throwable
t
)
{
String
msg
=
String
.
format
(
"Error encountered in creating the request handler '%s' for collection '%s'"
,
Constants
.
TERMS_REQUEST_HANDLER
,
collectionName
);
...
...
@@ -282,6 +284,24 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
return
Collections
.
EMPTY_LIST
;
}
private
void
graphManagementCommit
(
AtlasGraphManagement
management
)
{
try
{
management
.
commit
();
}
catch
(
Exception
ex
)
{
LOG
.
warn
(
"Graph transaction management commit failed; attempting rollback: {}"
,
ex
);
graphManagementRollback
(
management
);
}
}
private
void
graphManagementRollback
(
AtlasGraphManagement
management
)
{
try
{
management
.
rollback
();
}
catch
(
Exception
ex
)
{
LOG
.
warn
(
"Graph transaction management rollback failed: {}"
,
ex
);
}
}
@VisibleForTesting
static
List
<
String
>
getTopTerms
(
Map
<
String
,
TermFreq
>
termsMap
)
{
final
List
<
String
>
ret
;
...
...
@@ -353,44 +373,54 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
}
private
String
generateSearchWeightString
(
AtlasGraphManagement
management
,
String
indexName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
{
StringBuilder
searchWeightBuilder
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
propertyName2SearchWeightMap
.
entrySet
())
{
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
entry
.
getKey
());
String
indexFieldName
=
management
.
getIndexFieldName
(
indexName
,
propertyKey
);
private
String
generateSearchWeightString
(
String
indexName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
{
StringBuilder
searchWeightBuilder
=
new
StringBuilder
();
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
searchWeightBuilder
.
append
(
" "
)
.
append
(
indexFieldName
)
.
append
(
"^"
)
.
append
(
entry
.
getValue
().
intValue
());
try
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
propertyName2SearchWeightMap
.
entrySet
())
{
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
entry
.
getKey
());
String
indexFieldName
=
management
.
getIndexFieldName
(
indexName
,
propertyKey
);
searchWeightBuilder
.
append
(
" "
)
.
append
(
indexFieldName
)
.
append
(
"^"
)
.
append
(
entry
.
getValue
().
intValue
());
}
}
finally
{
graphManagementCommit
(
management
);
}
return
searchWeightBuilder
.
toString
();
}
private
String
generateSuggestionsString
(
String
collectionName
,
AtlasGraphManagement
management
,
List
<
String
>
suggestionProperties
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
private
String
generateSuggestionsString
(
String
collectionName
,
List
<
String
>
suggestionProperties
)
{
StringBuilder
ret
=
new
StringBuilder
();
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
for
(
String
propertyName:
suggestionProperties
)
{
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
propertyName
);
String
indexFieldName
=
management
.
getIndexFieldName
(
collectionName
,
propertyKey
);
try
{
for
(
String
propertyName
:
suggestionProperties
)
{
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
propertyName
);
String
indexFieldName
=
management
.
getIndexFieldName
(
collectionName
,
propertyKey
);
stringBuilder
.
append
(
"'"
).
append
(
indexFieldName
).
append
(
"', "
);
ret
.
append
(
"'"
).
append
(
indexFieldName
).
append
(
"', "
);
}
}
finally
{
graphManagementCommit
(
management
);
}
return
stringBuilder
.
toString
();
return
ret
.
toString
();
}
private
V2Response
updateFreeTextRequestHandler
(
SolrClient
solrClient
,
String
collectionName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
throws
IOException
,
SolrServerException
,
AtlasBaseException
{
String
searchWeightString
=
generateSearchWeightString
(
graph
.
getManagementSystem
(),
collectionName
,
propertyName2SearchWeightMap
);
String
searchWeightString
=
generateSearchWeightString
(
collectionName
,
propertyName2SearchWeightMap
);
String
payLoadString
=
generatePayLoadForFreeText
(
"update-requesthandler"
,
searchWeightString
);
return
performRequestHandlerAction
(
collectionName
,
solrClient
,
payLoadString
);
}
private
V2Response
createFreeTextRequestHandler
(
SolrClient
solrClient
,
String
collectionName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
throws
IOException
,
SolrServerException
,
AtlasBaseException
{
String
searchWeightString
=
generateSearchWeightString
(
graph
.
getManagementSystem
(),
collectionName
,
propertyName2SearchWeightMap
);
String
searchWeightString
=
generateSearchWeightString
(
collectionName
,
propertyName2SearchWeightMap
);
String
payLoadString
=
generatePayLoadForFreeText
(
"create-requesthandler"
,
searchWeightString
);
return
performRequestHandlerAction
(
collectionName
,
solrClient
,
payLoadString
);
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/services/MetricsService.java
View file @
2bd6f469
...
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
.
services
;
import
org.apache.atlas.annotation.AtlasService
;
import
org.apache.atlas.annotation.GraphTransaction
;
import
org.apache.atlas.model.instance.AtlasEntity.Status
;
import
org.apache.atlas.model.metrics.AtlasMetrics
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
...
...
@@ -74,6 +75,7 @@ public class MetricsService {
}
@SuppressWarnings
(
"unchecked"
)
@GraphTransaction
public
AtlasMetrics
getMetrics
()
{
Collection
<
String
>
entityDefNames
=
typeRegistry
.
getAllEntityDefNames
();
Collection
<
String
>
classificationDefNames
=
typeRegistry
.
getAllClassificationDefNames
();
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/util/AtlasMetricsUtil.java
View file @
2bd6f469
...
...
@@ -165,10 +165,15 @@ public class AtlasMetricsUtil {
@Override
public
void
run
()
{
graph
.
query
().
has
(
TYPE_NAME_PROPERTY_KEY
,
TYPE_NAME_INTERNAL
).
vertices
(
1
);
graphCommit
();
}
},
10
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
getMessage
());
graphRollback
();
return
false
;
}
...
...
@@ -183,10 +188,15 @@ public class AtlasMetricsUtil {
@Override
public
void
run
()
{
graph
.
indexQuery
(
Constants
.
VERTEX_INDEX
,
query
).
vertices
(
0
,
1
);
graphCommit
();
}
},
10
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
getMessage
());
graphRollback
();
return
false
;
}
...
...
@@ -228,6 +238,24 @@ public class AtlasMetricsUtil {
}
}
private
void
graphCommit
()
{
try
{
graph
.
commit
();
}
catch
(
Exception
ex
)
{
LOG
.
warn
(
"Graph transaction commit failed: {}; attempting to rollback graph transaction."
,
ex
);
graphRollback
();
}
}
private
void
graphRollback
()
{
try
{
graph
.
rollback
();
}
catch
(
Exception
ex
)
{
LOG
.
warn
(
"Graph transaction rollback failed: {}"
,
ex
);
}
}
private
String
millisToTimeDiff
(
long
msDiff
)
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment