[
https://issues.apache.org/jira/browse/S2GRAPH-148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16110706#comment-16110706
]
ASF GitHub Bot commented on S2GRAPH-148:
----------------------------------------
Github user daewon commented on the issue:
https://github.com/apache/incubator-s2graph/pull/115
@SteamShon I found an error situation during my retest with my colleague.
`rm -rf var storage ; sbt 'project s2core' 'test-only *GlobalIndexTest*'`
In a clean environment, if the test fails with the above command, the first
execution fails and the next execution succeeds.
```scala
def findAll(elementType: String, useCache: Boolean = true)(implicit
session: DBSession = AutoSession): Seq[GlobalIndex] = {
lazy val ls = sql"""select * from global_indices where element_type =
$elementType""".map { rs => GlobalIndex(rs) }.list.apply
if (useCache) {
listCache.withCache(s"findAll:elementType=$elementType") {
putsToCache(ls.map { globalIndex =>
val cacheKey =
s"elementType=${globalIndex.elementType}:indexName=${globalIndex.indexName}"
cacheKey -> globalIndex
})
ls
}
} else {
ls
}
}
```
The above method does not return `ls` in the `useCache` situation (`ls` is
updated in the background thread)
```scala
`rm -rf var storage ; sbt 'project s2core' 'test-only *GlobalIndexTest*'`
클린한 환경에서 위 명령어로 테스트를 실패시 첫 실행은 실패하고 그 다음 실행은 성공을 한다.
```
def findAll(elementType: String, useCache: Boolean = true)(implicit
session: DBSession = AutoSession): Seq[GlobalIndex] = {
lazy val ls = sql"""select * from global_indices where element_type =
$elementType""".map { rs => GlobalIndex(rs) }.list.apply
if (useCache) {
listCache.withCache(s"findAll:elementType=$elementType") {
putsToCache(ls.map { globalIndex =>
val cacheKey =
s"elementType=${globalIndex.elementType}:indexName=${globalIndex.indexName}"
cacheKey -> globalIndex
})
ls
}
} else {
ls
}
}
```
위 메서드에서 보면 `useCache`인 상황에서 ls를 반환하지 않고 있다(ls는 백그라운드에서 업데이트 된다) 이 때문에 위 코드를
아래처럼 수정하면 에러가 발생하지 않는다.
```
def findAll(elementType: String, useCache: Boolean = true)(implicit
session: DBSession = AutoSession): Seq[GlobalIndex] = {
lazy val ls = sql"""select * from global_indices where element_type =
$elementType""".map { rs => GlobalIndex(rs) }.list.apply
if (useCache) {
listCache.withCache(s"findAll:elementType=$elementType") {
putsToCache(ls.map { globalIndex =>
val cacheKey =
s"elementType=${globalIndex.elementType}:indexName=${globalIndex.indexName}"
cacheKey -> globalIndex
})
ls
}
ls
} else {
ls
}
}
```
I changed the code to return `ls` as shown below and confirmed that it
works without problems.
Please review the fixed code.
> Provide Gremlin Plugin
> ----------------------
>
> Key: S2GRAPH-148
> URL: https://issues.apache.org/jira/browse/S2GRAPH-148
> Project: S2Graph
> Issue Type: Sub-task
> Affects Versions: 0.2.0
> Reporter: DOYUNG YOON
> Assignee: DOYUNG YOON
> Labels: features
> Fix For: 0.2.0
>
> Original Estimate: 168h
> Remaining Estimate: 168h
>
> Provide `S2GraphGremlinPlugin` that implement `GremlinPlugin` interface.
> I think by providing such plugin, users can use S2Graph through Gremlin
> Console and Gremlin Server.
> [Reference|http://tinkerpop.apache.org/docs/3.2.4/dev/provider/#gremlin-plugins]
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)