[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-24 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475711430



##
File path: 
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala
##
@@ -1214,8 +1214,8 @@ private[history] class FsHistoryProvider(conf: SparkConf, 
clock: Clock)
 // Use InMemoryStore to rebuild app store
 while (hybridStore == null) {
   // A RuntimeException will be thrown if the heap memory is not sufficient
-  memoryManager.lease(appId, attempt.info.attemptId, reader.totalSize,

Review comment:
   Make sense, I've reverted the changes on lease().





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-23 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475325934



##
File path: 
core/src/test/scala/org/apache/spark/deploy/history/HybridStoreSuite.scala
##
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.deploy.history
+
+import java.io.File
+import java.util.NoSuchElementException
+import java.util.concurrent.LinkedBlockingQueue
+
+import org.apache.commons.io.FileUtils
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.status.KVUtils._
+import org.apache.spark.util.kvstore._
+
+class HybridStoreSuite extends SparkFunSuite with BeforeAndAfter {
+
+  private var db: LevelDB = _
+  private var dbpath: File = _
+
+  before {
+dbpath = File.createTempFile("test.", ".ldb")
+dbpath.delete()
+db = new LevelDB(dbpath, new KVStoreScalaSerializer())
+  }
+
+  after {
+if (db != null) {
+  db.close()
+}
+if (dbpath != null) {
+  FileUtils.deleteQuietly(dbpath)
+}
+  }
+
+  test("test multiple objects write read delete") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+val t2 = createCustomType1(2)
+
+intercept[NoSuchElementException] {
+  store.read(t1.getClass(), t1.key)
+}
+
+store.write(t1)
+store.write(t2)
+store.delete(t2.getClass(), t2.key)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  intercept[NoSuchElementException] {
+   store.read(t2.getClass(), t2.key)
+  }
+  assert(store.read(t1.getClass(), t1.key) === t1)
+  assert(store.count(t1.getClass()) === 1L)
+}
+  }
+
+  test("test metadata") {
+val store = createHybridStore()
+assert(store.getMetadata(classOf[CustomType1]) === null)
+
+val t1 = createCustomType1(1)
+store.setMetadata(t1)
+assert(store.getMetadata(classOf[CustomType1]) === t1)
+
+// Switch to LevelDB and set a new metadata
+switchHybridStore(store)
+
+val t2 = createCustomType1(2)
+store.setMetadata(t2)
+assert(store.getMetadata(classOf[CustomType1]) === t2)
+  }
+
+  test("test update") {
+val store = createHybridStore()
+val t = createCustomType1(1)
+
+store.write(t)
+t.name = "name2"
+store.write(t)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  assert(store.count(t.getClass()) === 1L)
+  assert(store.read(t.getClass(), t.key) === t)
+}
+  }
+
+  test("test basic iteration") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+store.write(t1)
+val t2 = createCustomType1(2)
+store.write(t2)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  assert(store.view(t1.getClass()).iterator().next().id === t1.id)
+  assert(store.view(t1.getClass()).skip(1).iterator().next().id === t2.id)
+  assert(store.view(t1.getClass()).skip(1).max(1).iterator().next().id === 
t2.id)
+  
assert(store.view(t1.getClass()).first(t1.key).max(1).iterator().next().id === 
t1.id)
+  
assert(store.view(t1.getClass()).first(t2.key).max(1).iterator().next().id === 
t2.id)
+}
+  }
+
+  test("test delete after switch") {
+val store = createHybridStore()
+val t = createCustomType1(1)
+store.write(t)
+switchHybridStore(store)
+intercept[IllegalStateException] {
+ store.delete(t.getClass(), t.key)
+}
+  }
+
+  test("test klassMap") {
+val store = createHybridStore()
+val t1 = createCustomType1(1)
+store.write(t1)
+assert(store.klassMap.size === 1)
+val t2 = new CustomType2("key2")
+store.write(t2)
+assert(store.klassMap.size === 2)
+
+switchHybridStore(store)
+val t3 = new CustomType3("key3")
+store.write(t3)
+// Cannot put new klass to klassMap after the switching starts
+assert(store.klassMap.size === 2)
+  }
+
+  private def createHybridStore(): HybridStore = {
+val store = new HybridStore()
+store.setLevelDB(db)
+store
+  }
+
+  private def createCustomType1(i: Int): CustomType1 = {
+new CustomType1("key" + i, "id" + i, 

[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-23 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475325165



##
File path: 
core/src/test/scala/org/apache/spark/deploy/history/HybridStoreSuite.scala
##
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.deploy.history
+
+import java.io.File
+import java.util.NoSuchElementException
+import java.util.concurrent.LinkedBlockingQueue
+
+import org.apache.commons.io.FileUtils
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.status.KVUtils._
+import org.apache.spark.util.kvstore._
+
+class HybridStoreSuite extends SparkFunSuite with BeforeAndAfter {
+
+  private var db: LevelDB = _
+  private var dbpath: File = _
+
+  before {
+dbpath = File.createTempFile("test.", ".ldb")
+dbpath.delete()
+db = new LevelDB(dbpath, new KVStoreScalaSerializer())
+  }
+
+  after {
+if (db != null) {
+  db.close()
+}
+if (dbpath != null) {
+  FileUtils.deleteQuietly(dbpath)
+}
+  }
+
+  test("test multiple objects write read delete") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+val t2 = createCustomType1(2)
+
+intercept[NoSuchElementException] {
+  store.read(t1.getClass(), t1.key)
+}
+
+store.write(t1)
+store.write(t2)
+store.delete(t2.getClass(), t2.key)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  intercept[NoSuchElementException] {
+   store.read(t2.getClass(), t2.key)
+  }
+  assert(store.read(t1.getClass(), t1.key) === t1)
+  assert(store.count(t1.getClass()) === 1L)
+}
+  }
+
+  test("test metadata") {
+val store = createHybridStore()
+assert(store.getMetadata(classOf[CustomType1]) === null)
+
+val t1 = createCustomType1(1)
+store.setMetadata(t1)
+assert(store.getMetadata(classOf[CustomType1]) === t1)
+
+// Switch to LevelDB and set a new metadata
+switchHybridStore(store)
+
+val t2 = createCustomType1(2)
+store.setMetadata(t2)
+assert(store.getMetadata(classOf[CustomType1]) === t2)
+  }
+
+  test("test update") {
+val store = createHybridStore()
+val t = createCustomType1(1)
+
+store.write(t)
+t.name = "name2"
+store.write(t)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  assert(store.count(t.getClass()) === 1L)
+  assert(store.read(t.getClass(), t.key) === t)
+}
+  }
+
+  test("test basic iteration") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+store.write(t1)
+val t2 = createCustomType1(2)
+store.write(t2)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  assert(store.view(t1.getClass()).iterator().next().id === t1.id)
+  assert(store.view(t1.getClass()).skip(1).iterator().next().id === t2.id)
+  assert(store.view(t1.getClass()).skip(1).max(1).iterator().next().id === 
t2.id)
+  
assert(store.view(t1.getClass()).first(t1.key).max(1).iterator().next().id === 
t1.id)
+  
assert(store.view(t1.getClass()).first(t2.key).max(1).iterator().next().id === 
t2.id)
+}
+  }
+
+  test("test delete after switch") {
+val store = createHybridStore()
+val t = createCustomType1(1)
+store.write(t)
+switchHybridStore(store)
+intercept[IllegalStateException] {
+ store.delete(t.getClass(), t.key)
+}
+  }
+
+  test("test klassMap") {
+val store = createHybridStore()
+val t1 = createCustomType1(1)
+store.write(t1)
+assert(store.klassMap.size === 1)
+val t2 = new CustomType2("key2")
+store.write(t2)
+assert(store.klassMap.size === 2)
+
+switchHybridStore(store)
+val t3 = new CustomType3("key3")
+store.write(t3)
+// Cannot put new klass to klassMap after the switching starts
+assert(store.klassMap.size === 2)
+  }
+
+  private def createHybridStore(): HybridStore = {
+val store = new HybridStore()
+store.setLevelDB(db)
+store
+  }
+
+  private def createCustomType1(i: Int): CustomType1 = {
+new CustomType1("key" + i, "id" + i, 

[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-23 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475325041



##
File path: 
core/src/test/scala/org/apache/spark/deploy/history/HybridStoreSuite.scala
##
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.deploy.history
+
+import java.io.File
+import java.util.NoSuchElementException
+import java.util.concurrent.LinkedBlockingQueue
+
+import org.apache.commons.io.FileUtils
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.status.KVUtils._
+import org.apache.spark.util.kvstore._
+
+class HybridStoreSuite extends SparkFunSuite with BeforeAndAfter {
+
+  private var db: LevelDB = _
+  private var dbpath: File = _
+
+  before {
+dbpath = File.createTempFile("test.", ".ldb")
+dbpath.delete()
+db = new LevelDB(dbpath, new KVStoreScalaSerializer())
+  }
+
+  after {
+if (db != null) {
+  db.close()
+}
+if (dbpath != null) {
+  FileUtils.deleteQuietly(dbpath)
+}
+  }
+
+  test("test multiple objects write read delete") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+val t2 = createCustomType1(2)
+
+intercept[NoSuchElementException] {
+  store.read(t1.getClass(), t1.key)
+}
+
+store.write(t1)
+store.write(t2)
+store.delete(t2.getClass(), t2.key)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  intercept[NoSuchElementException] {
+   store.read(t2.getClass(), t2.key)

Review comment:
   Fixed





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-23 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475325096



##
File path: 
core/src/test/scala/org/apache/spark/deploy/history/HybridStoreSuite.scala
##
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.deploy.history
+
+import java.io.File
+import java.util.NoSuchElementException
+import java.util.concurrent.LinkedBlockingQueue
+
+import org.apache.commons.io.FileUtils
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.status.KVUtils._
+import org.apache.spark.util.kvstore._
+
+class HybridStoreSuite extends SparkFunSuite with BeforeAndAfter {
+
+  private var db: LevelDB = _
+  private var dbpath: File = _
+
+  before {
+dbpath = File.createTempFile("test.", ".ldb")
+dbpath.delete()
+db = new LevelDB(dbpath, new KVStoreScalaSerializer())
+  }
+
+  after {
+if (db != null) {
+  db.close()
+}
+if (dbpath != null) {
+  FileUtils.deleteQuietly(dbpath)
+}
+  }
+
+  test("test multiple objects write read delete") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+val t2 = createCustomType1(2)
+
+intercept[NoSuchElementException] {
+  store.read(t1.getClass(), t1.key)
+}
+
+store.write(t1)
+store.write(t2)
+store.delete(t2.getClass(), t2.key)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  intercept[NoSuchElementException] {
+   store.read(t2.getClass(), t2.key)
+  }
+  assert(store.read(t1.getClass(), t1.key) === t1)
+  assert(store.count(t1.getClass()) === 1L)
+}
+  }
+
+  test("test metadata") {
+val store = createHybridStore()
+assert(store.getMetadata(classOf[CustomType1]) === null)
+
+val t1 = createCustomType1(1)
+store.setMetadata(t1)
+assert(store.getMetadata(classOf[CustomType1]) === t1)
+
+// Switch to LevelDB and set a new metadata
+switchHybridStore(store)
+
+val t2 = createCustomType1(2)
+store.setMetadata(t2)
+assert(store.getMetadata(classOf[CustomType1]) === t2)
+  }
+
+  test("test update") {
+val store = createHybridStore()
+val t = createCustomType1(1)
+
+store.write(t)
+t.name = "name2"
+store.write(t)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  assert(store.count(t.getClass()) === 1L)
+  assert(store.read(t.getClass(), t.key) === t)
+}
+  }
+
+  test("test basic iteration") {
+val store = createHybridStore()
+
+val t1 = createCustomType1(1)
+store.write(t1)
+val t2 = createCustomType1(2)
+store.write(t2)
+
+Seq(false, true).foreach { switch =>
+  if (switch) switchHybridStore(store)
+
+  assert(store.view(t1.getClass()).iterator().next().id === t1.id)
+  assert(store.view(t1.getClass()).skip(1).iterator().next().id === t2.id)
+  assert(store.view(t1.getClass()).skip(1).max(1).iterator().next().id === 
t2.id)
+  
assert(store.view(t1.getClass()).first(t1.key).max(1).iterator().next().id === 
t1.id)
+  
assert(store.view(t1.getClass()).first(t2.key).max(1).iterator().next().id === 
t2.id)
+}
+  }
+
+  test("test delete after switch") {
+val store = createHybridStore()
+val t = createCustomType1(1)
+store.write(t)
+switchHybridStore(store)
+intercept[IllegalStateException] {
+ store.delete(t.getClass(), t.key)
+}
+  }
+
+  test("test klassMap") {
+val store = createHybridStore()
+val t1 = createCustomType1(1)
+store.write(t1)
+assert(store.klassMap.size === 1)
+val t2 = new CustomType2("key2")
+store.write(t2)
+assert(store.klassMap.size === 2)
+
+switchHybridStore(store)
+val t3 = new CustomType3("key3")
+store.write(t3)
+// Cannot put new klass to klassMap after the switching starts
+assert(store.klassMap.size === 2)
+  }
+
+  private def createHybridStore(): HybridStore = {
+val store = new HybridStore()
+store.setLevelDB(db)
+store
+  }
+
+  private def createCustomType1(i: Int): CustomType1 = {
+new CustomType1("key" + i, "id" + i, 

[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-23 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475325018



##
File path: 
core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala
##
@@ -1509,13 +1513,18 @@ class FsHistoryProviderSuite extends SparkFunSuite with 
Matchers with Logging {
 new FileOutputStream(file).close()
   }
 
-  private def createTestConf(inMemory: Boolean = false): SparkConf = {
+  private def createTestConf(
+  inMemory: Boolean = false,
+  useHybridStore: Boolean = false): SparkConf = {
 val conf = new SparkConf()
   .set(HISTORY_LOG_DIR, testDir.getAbsolutePath())
   .set(FAST_IN_PROGRESS_PARSING, true)
 
 if (!inMemory) {
   conf.set(LOCAL_STORE_DIR, Utils.createTempDir().getAbsolutePath())
+  if (useHybridStore) {

Review comment:
   Fixed





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] baohe-zhang commented on a change in pull request #29509: [SPARK-31608][CORE][WEBUI][TEST] Add test suites for HybridStore and HistoryServerMemoryManager

2020-08-23 Thread GitBox


baohe-zhang commented on a change in pull request #29509:
URL: https://github.com/apache/spark/pull/29509#discussion_r475320679



##
File path: 
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala
##
@@ -1214,8 +1214,8 @@ private[history] class FsHistoryProvider(conf: SparkConf, 
clock: Clock)
 // Use InMemoryStore to rebuild app store
 while (hybridStore == null) {
   // A RuntimeException will be thrown if the heap memory is not sufficient
-  memoryManager.lease(appId, attempt.info.attemptId, reader.totalSize,

Review comment:
   It's related to the test code, but my original thought is that passing 
the actual amount of memory, instead of filesize to memoryManager.lease() would 
make more sense. Although exposing inner details to fsHistoryProvider is not 
ideal. What's your opinion? Should I revert this change?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org