Repository: incubator-atlas Updated Branches: refs/heads/master 60ebe8bea -> 64bda5a41
ATLAS-471 Atlas Server could run out of memory due to Scala memory leak(yhemanth via sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/64bda5a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/64bda5a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/64bda5a4 Branch: refs/heads/master Commit: 64bda5a419cf43c2cdac08d54eee24610b8ad002 Parents: 60ebe8b Author: Suma Shivaprasad <[email protected]> Authored: Wed Feb 17 17:22:14 2016 -0800 Committer: Suma Shivaprasad <[email protected]> Committed: Wed Feb 17 17:22:14 2016 -0800 ---------------------------------------------------------------------- .../graph/GraphBackedDiscoveryService.java | 3 +- .../org/apache/atlas/query/QueryParser.scala | 4 +- .../org/apache/atlas/query/GremlinTest.scala | 10 ++--- .../org/apache/atlas/query/GremlinTest2.scala | 4 +- .../org/apache/atlas/query/LexerTest.scala | 9 ++-- .../org/apache/atlas/query/ParserTest.scala | 43 +++++++------------- 6 files changed, 29 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/64bda5a4/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java index 5e84644..f97b83d 100755 --- a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java @@ -128,8 +128,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { public GremlinQueryResult evaluate(String dslQuery) throws DiscoveryException { LOG.info("Executing dsl query={}", dslQuery); try { - QueryParser queryParser = new QueryParser(); - Either<Parsers.NoSuccess, Expressions.Expression> either = queryParser.apply(dslQuery); + Either<Parsers.NoSuccess, Expressions.Expression> either = QueryParser.apply(dslQuery); if (either.isRight()) { Expressions.Expression expression = either.right().get(); return evaluate(expression); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/64bda5a4/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala ---------------------------------------------------------------------- diff --git a/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala b/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala index 8583371..b6bbbd3 100755 --- a/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala +++ b/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala @@ -107,7 +107,7 @@ trait ExpressionUtils { } } -class QueryParser extends StandardTokenParsers with QueryKeywords with ExpressionUtils with PackratParsers { +object QueryParser extends StandardTokenParsers with QueryKeywords with ExpressionUtils with PackratParsers { import scala.language.higherKinds @@ -119,7 +119,7 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio override val lexical = new QueryLexer(queryreservedWords, querydelims) - def apply(input: String): Either[NoSuccess, Expression] = { + def apply(input: String): Either[NoSuccess, Expression] = synchronized { phrase(queryWithPath)(new lexical.Scanner(input)) match { case Success(r, x) => Right(r) case f@Failure(m, x) => Left(f) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/64bda5a4/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala b/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala index 0b57df3..0068364 100755 --- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala +++ b/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala @@ -899,7 +899,7 @@ class GremlinTest extends BaseGremlinTest { } @Test def testArrayComparision { - val p = new QueryParser + val p = QueryParser val e = p("Partition as p where values = ['2015-01-01']," + " table where name = 'sales_fact_daily_mv'," + " db where name = 'Reporting' and clusterName = 'test' select p").right.get @@ -937,7 +937,7 @@ class GremlinTest extends BaseGremlinTest { } @Test def testArrayComparisionWithSelectOnArray { - val p = new QueryParser + val p = QueryParser val e = p("Partition as p where values = ['2015-01-01']," + " table where name = 'sales_fact_daily_mv'," + " db where name = 'Reporting' and clusterName = 'test' select p.values").right.get @@ -976,7 +976,7 @@ class GremlinTest extends BaseGremlinTest { } @Test def testArrayInWhereClause { - val p = new QueryParser + val p = QueryParser val e = p("Partition as p where values = ['2015-01-01']").right.get val r = QueryProcessor.evaluate(e, g, gp) validateJson(r, """{ @@ -1045,13 +1045,13 @@ class GremlinTest extends BaseGremlinTest { @Test(expectedExceptions = Array(classOf[ExpressionException])) def testNegativeInvalidType { - val p = new QueryParser + val p = QueryParser val e = p("from blah").right.get QueryProcessor.evaluate(e, g, gp) } @Test def testJoinAndSelect5 { - val p = new QueryParser + val p = QueryParser val e = p("Table as t where name = 'sales_fact' db where name = 'Sales' and owner = 'John ETL' select t").right.get val r = QueryProcessor.evaluate(e, g, gp) validateJson(r) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/64bda5a4/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala b/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala index b6c1455..79ebfae 100755 --- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala +++ b/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala @@ -89,7 +89,7 @@ class GremlinTest2 extends BaseGremlinTest { } @Test def testLineageAllSelectWithPathFromParser { - val p = new QueryParser + val p = QueryParser val e = p("Table as src loop (LoadProcess outputTable) as dest " + "select src.name as srcTable, dest.name as destTable withPath").right.get //Table as src loop (LoadProcess where LoadProcess.outputTable) as dest select src.name as srcTable, dest.name as destTable withPath @@ -98,7 +98,7 @@ class GremlinTest2 extends BaseGremlinTest { } @Test def testLineageAllSelectWithPathFromParser2 { - val p = new QueryParser + val p = QueryParser val e = p("Table as src loop (`LoadProcess->outputTable` inputTables) as dest " + "select src.name as srcTable, dest.name as destTable withPath").right.get http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/64bda5a4/repository/src/test/scala/org/apache/atlas/query/LexerTest.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/LexerTest.scala b/repository/src/test/scala/org/apache/atlas/query/LexerTest.scala index 10e966e..8d9cdaf 100755 --- a/repository/src/test/scala/org/apache/atlas/query/LexerTest.scala +++ b/repository/src/test/scala/org/apache/atlas/query/LexerTest.scala @@ -25,8 +25,8 @@ import scala.util.parsing.input.CharArrayReader class LexerTest { - def scan(p: QueryParser, str: String): p.lexical.ParseResult[_] = { - val l = p.lexical + def scan(str: String): QueryParser.lexical.ParseResult[_] = { + val l = QueryParser.lexical var s: l.Input = new CharArrayReader(str.toCharArray) var r = (l.whitespace.? ~ l.token)(s) s = r.next @@ -37,12 +37,11 @@ class LexerTest { r = (l.whitespace.? ~ l.token)(s) } } - r.asInstanceOf[p.lexical.ParseResult[_]] + r.asInstanceOf[QueryParser.lexical.ParseResult[_]] } @Test def testSimple { - val p = new QueryParser - val r = scan(p, """DB where db1.name""") + val r = scan("""DB where db1.name""") Assert.assertTrue(r.successful) } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/64bda5a4/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala b/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala index 1655607..8f277fc 100755 --- a/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala +++ b/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala @@ -31,74 +31,61 @@ class ParserTest extends BaseTest { } @Test def testFrom: Unit = { - val p = new QueryParser - println(p("from DB").right.get.toString) + println(QueryParser.apply("from DB").right.get.toString) } @Test def testFrom2: Unit = { - val p = new QueryParser - println(p("DB").right.get.toString) + println(QueryParser.apply("DB").right.get.toString) } @Test def testJoin1: Unit = { - val p = new QueryParser - println(p("DB, Table").right.get.toString) + println(QueryParser.apply("DB, Table").right.get.toString) } @Test def testWhere1: Unit = { - val p = new QueryParser - println(p("DB as db1 Table where db1.name ").right.get.toString) + println(QueryParser.apply("DB as db1 Table where db1.name ").right.get.toString) } @Test def testWhere2: Unit = { - val p = new QueryParser - println(p("DB name = \"Reporting\"").right.get.toString) + println(QueryParser.apply("DB name = \"Reporting\"").right.get.toString) } @Test def testIsTrait: Unit = { - val p = new QueryParser - println(p("Table isa Dimension").right.get.toString) - println(p("Table is Dimension").right.get.toString) + println(QueryParser.apply("Table isa Dimension").right.get.toString) + println(QueryParser.apply("Table is Dimension").right.get.toString) } @Test def test4: Unit = { - val p = new QueryParser - println(p("DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1").right.get.toString) + println(QueryParser.apply("DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1").right.get.toString) } @Test def testJoin2: Unit = { - val p = new QueryParser - println(p("DB as db1 where (createTime + 1) > 0 and (db1.name = \"Reporting\") or DB has owner Table as tab " + + println(QueryParser.apply("DB as db1 where (createTime + 1) > 0 and (db1.name = \"Reporting\") or DB has owner Table as tab " + " select db1.name as dbName, tab.name as tabName").right.get.toString) } @Test def testLoop: Unit = { - val p = new QueryParser - println(p("Table loop (LoadProcess outputTable)").right.get.toString) + println(QueryParser.apply("Table loop (LoadProcess outputTable)").right.get.toString) } @Test def testNegInvalidateType: Unit = { - val p = new QueryParser - val x = p("from blah") - println(p("from blah").left) + val x = QueryParser.apply("from blah") + println(QueryParser.apply("from blah").left) } @Test def testPath1: Unit = { - val p = new QueryParser - println(p("Table loop (LoadProcess outputTable) withPath").right.get.toString) + println(QueryParser.apply("Table loop (LoadProcess outputTable) withPath").right.get.toString) } @Test def testPath2: Unit = { - val p = new QueryParser - println(p( + println(QueryParser.apply( "Table as src loop (LoadProcess outputTable) as dest " + "select src.name as srcTable, dest.name as destTable withPath").right.get.toString ) } @Test def testList: Unit = { - val p = new QueryParser - println(p( + println(QueryParser.apply( "Partition as p where values = ['2015-01-01']," + " table where name = 'tableoq8ty'," + " db where name = 'default' and clusterName = 'test'").right.get.toString
