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
Jun 13, 2019
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
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 {
...
@@ -135,7 +135,8 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
@Override
@Override
public
Map
<
String
,
List
<
AtlasAggregationEntry
>>
getAggregatedMetrics
(
String
queryString
,
Set
<
String
>
propertyKeyNames
)
{
public
Map
<
String
,
List
<
AtlasAggregationEntry
>>
getAggregatedMetrics
(
String
queryString
,
Set
<
String
>
propertyKeyNames
)
{
SolrClient
solrClient
=
null
;
SolrClient
solrClient
=
null
;
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
try
{
try
{
solrClient
=
Solr6Index
.
getSolrClient
();
// get solr client using same settings as that of Janus Graph
solrClient
=
Solr6Index
.
getSolrClient
();
// get solr client using same settings as that of Janus Graph
...
@@ -153,7 +154,6 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
...
@@ -153,7 +154,6 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
}
}
SolrQuery
solrQuery
=
new
SolrQuery
();
SolrQuery
solrQuery
=
new
SolrQuery
();
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
Map
<
String
,
String
>
indexFieldName2PropertyKeyNameMap
=
new
HashMap
<>();
Map
<
String
,
String
>
indexFieldName2PropertyKeyNameMap
=
new
HashMap
<>();
solrQuery
.
setQuery
(
queryString
);
solrQuery
.
setQuery
(
queryString
);
...
@@ -192,7 +192,9 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
...
@@ -192,7 +192,9 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Error enocunted in getting the aggregation metrics. Will return empty agregation."
,
e
);
LOG
.
error
(
"Error enocunted in getting the aggregation metrics. Will return empty agregation."
,
e
);
}
finally
{
}
finally
{
graphManagementCommit
(
management
);
Solr6Index
.
releaseSolrClient
(
solrClient
);
Solr6Index
.
releaseSolrClient
(
solrClient
);
}
}
...
@@ -214,7 +216,7 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
...
@@ -214,7 +216,7 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
//update the request handler
//update the request handler
performRequestHandlerAction
(
collectionName
,
solrClient
,
performRequestHandlerAction
(
collectionName
,
solrClient
,
generatePayLoadForSuggestions
(
generateSuggestionsString
(
collectionName
,
graph
.
getManagementSystem
(),
suggestionProperties
)));
generatePayLoadForSuggestions
(
generateSuggestionsString
(
collectionName
,
suggestionProperties
)));
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
String
msg
=
String
.
format
(
"Error encountered in creating the request handler '%s' for collection '%s'"
,
Constants
.
TERMS_REQUEST_HANDLER
,
collectionName
);
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 {
...
@@ -282,6 +284,24 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
return
Collections
.
EMPTY_LIST
;
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
@VisibleForTesting
static
List
<
String
>
getTopTerms
(
Map
<
String
,
TermFreq
>
termsMap
)
{
static
List
<
String
>
getTopTerms
(
Map
<
String
,
TermFreq
>
termsMap
)
{
final
List
<
String
>
ret
;
final
List
<
String
>
ret
;
...
@@ -353,44 +373,54 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
...
@@ -353,44 +373,54 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
}
}
private
String
generateSearchWeightString
(
AtlasGraphManagement
management
,
String
indexName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
{
private
String
generateSearchWeightString
(
String
indexName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
{
StringBuilder
searchWeightBuilder
=
new
StringBuilder
();
StringBuilder
searchWeightBuilder
=
new
StringBuilder
();
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
propertyName2SearchWeightMap
.
entrySet
())
{
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
entry
.
getKey
());
String
indexFieldName
=
management
.
getIndexFieldName
(
indexName
,
propertyKey
);
searchWeightBuilder
.
append
(
" "
)
try
{
.
append
(
indexFieldName
)
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
propertyName2SearchWeightMap
.
entrySet
())
{
.
append
(
"^"
)
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
entry
.
getKey
());
.
append
(
entry
.
getValue
().
intValue
());
String
indexFieldName
=
management
.
getIndexFieldName
(
indexName
,
propertyKey
);
searchWeightBuilder
.
append
(
" "
)
.
append
(
indexFieldName
)
.
append
(
"^"
)
.
append
(
entry
.
getValue
().
intValue
());
}
}
finally
{
graphManagementCommit
(
management
);
}
}
return
searchWeightBuilder
.
toString
();
return
searchWeightBuilder
.
toString
();
}
}
private
String
generateSuggestionsString
(
String
collectionName
,
AtlasGraphManagement
management
,
List
<
String
>
suggestionProperties
)
{
private
String
generateSuggestionsString
(
String
collectionName
,
List
<
String
>
suggestionProperties
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
ret
=
new
StringBuilder
();
AtlasGraphManagement
management
=
graph
.
getManagementSystem
();
for
(
String
propertyName:
suggestionProperties
)
{
try
{
AtlasPropertyKey
propertyKey
=
management
.
getPropertyKey
(
propertyName
);
for
(
String
propertyName
:
suggestionProperties
)
{
String
indexFieldName
=
management
.
getIndexFieldName
(
collectionName
,
propertyKey
);
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
{
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
);
String
payLoadString
=
generatePayLoadForFreeText
(
"update-requesthandler"
,
searchWeightString
);
return
performRequestHandlerAction
(
collectionName
,
solrClient
,
payLoadString
);
return
performRequestHandlerAction
(
collectionName
,
solrClient
,
payLoadString
);
}
}
private
V2Response
createFreeTextRequestHandler
(
SolrClient
solrClient
,
String
collectionName
,
Map
<
String
,
Integer
>
propertyName2SearchWeightMap
)
throws
IOException
,
SolrServerException
,
AtlasBaseException
{
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
);
String
payLoadString
=
generatePayLoadForFreeText
(
"create-requesthandler"
,
searchWeightString
);
return
performRequestHandlerAction
(
collectionName
,
solrClient
,
payLoadString
);
return
performRequestHandlerAction
(
collectionName
,
solrClient
,
payLoadString
);
...
...
repository/src/main/java/org/apache/atlas/services/MetricsService.java
View file @
2bd6f469
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
.
services
;
package
org
.
apache
.
atlas
.
services
;
import
org.apache.atlas.annotation.AtlasService
;
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.instance.AtlasEntity.Status
;
import
org.apache.atlas.model.metrics.AtlasMetrics
;
import
org.apache.atlas.model.metrics.AtlasMetrics
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
...
@@ -74,6 +75,7 @@ public class MetricsService {
...
@@ -74,6 +75,7 @@ public class MetricsService {
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@GraphTransaction
public
AtlasMetrics
getMetrics
()
{
public
AtlasMetrics
getMetrics
()
{
Collection
<
String
>
entityDefNames
=
typeRegistry
.
getAllEntityDefNames
();
Collection
<
String
>
entityDefNames
=
typeRegistry
.
getAllEntityDefNames
();
Collection
<
String
>
classificationDefNames
=
typeRegistry
.
getAllClassificationDefNames
();
Collection
<
String
>
classificationDefNames
=
typeRegistry
.
getAllClassificationDefNames
();
...
...
repository/src/main/java/org/apache/atlas/util/AtlasMetricsUtil.java
View file @
2bd6f469
...
@@ -165,10 +165,15 @@ public class AtlasMetricsUtil {
...
@@ -165,10 +165,15 @@ public class AtlasMetricsUtil {
@Override
@Override
public
void
run
()
{
public
void
run
()
{
graph
.
query
().
has
(
TYPE_NAME_PROPERTY_KEY
,
TYPE_NAME_INTERNAL
).
vertices
(
1
);
graph
.
query
().
has
(
TYPE_NAME_PROPERTY_KEY
,
TYPE_NAME_INTERNAL
).
vertices
(
1
);
graphCommit
();
}
}
},
10
,
TimeUnit
.
SECONDS
);
},
10
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
getMessage
());
LOG
.
error
(
e
.
getMessage
());
graphRollback
();
return
false
;
return
false
;
}
}
...
@@ -183,10 +188,15 @@ public class AtlasMetricsUtil {
...
@@ -183,10 +188,15 @@ public class AtlasMetricsUtil {
@Override
@Override
public
void
run
()
{
public
void
run
()
{
graph
.
indexQuery
(
Constants
.
VERTEX_INDEX
,
query
).
vertices
(
0
,
1
);
graph
.
indexQuery
(
Constants
.
VERTEX_INDEX
,
query
).
vertices
(
0
,
1
);
graphCommit
();
}
}
},
10
,
TimeUnit
.
SECONDS
);
},
10
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
getMessage
());
LOG
.
error
(
e
.
getMessage
());
graphRollback
();
return
false
;
return
false
;
}
}
...
@@ -228,6 +238,24 @@ public class AtlasMetricsUtil {
...
@@ -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
)
{
private
String
millisToTimeDiff
(
long
msDiff
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
...
...
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