Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table names for multi-part inserts #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/scala/shark/execution/MemoryStoreSinkOperator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,22 @@ class MemoryStoreSinkOperator extends TerminalOperator {
if (useUnionRDD) {
// If this is an insert, find the existing RDD and create a union of the two, and then
// put the union into the meta data tracker.


val nextPartNum = SharkEnv.memoryMetadataManager.getNextPartNum(tableName)
if (nextPartNum == 1) {
// reset rdd name for existing rdd
SharkEnv.memoryMetadataManager.get(tableName).get.asInstanceOf[RDD[TablePartition]]
.setName(tableName + ".part0")
}
rdd.setName(tableName + ".part" + nextPartNum)

rdd = rdd.union(
SharkEnv.memoryMetadataManager.get(tableName).get.asInstanceOf[RDD[TablePartition]])
} else {
rdd.setName(tableName)
}
SharkEnv.memoryMetadataManager.put(tableName, rdd)
rdd.setName(tableName)

// Run a job on the original RDD to force it to go into cache.
origRdd.context.runJob(origRdd, (iter: Iterator[TablePartition]) => iter.foreach(_ => Unit))
Expand Down
19 changes: 19 additions & 0 deletions src/main/scala/shark/memstore2/MemoryMetadataManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class MemoryMetadataManager {
private val _keyToRdd: ConcurrentMap[String, RDD[_]] =
new ConcurrentHashMap[String, RDD[_]]()

// Tracks number of parts inserted into cached table
private val _keyToNextPart: ConcurrentMap[String, Int] =
new ConcurrentHashMap[String, Int]()

private val _keyToStats: ConcurrentMap[String, collection.Map[Int, TablePartitionStats]] =
new ConcurrentHashMap[String, collection.Map[Int, TablePartitionStats]]

Expand All @@ -52,6 +56,20 @@ class MemoryMetadataManager {
_keyToStats.get(key.toLowerCase)
}

def getNextPartNum(key: String): Int = {
val currentPartNum = _keyToNextPart.get(key.toLowerCase)
currentPartNum match {
case Some(partNum) => {
_keyToNextPart.put(key, partNum + 1)
partNum + 1
}
case None => {
_keyToNextPart.put(key, 1)
1
}
}
}

def rename(oldKey: String, newKey: String) {
if (contains(oldKey)) {
val oldKeyToLowerCase = oldKey.toLowerCase
Expand Down Expand Up @@ -97,6 +115,7 @@ class MemoryMetadataManager {
// corresponding to the argument for 'key'.
val rddValue = _keyToRdd.remove(key.toLowerCase())
_keyToStats.remove(key)
_keyToNextPart.remove(key)
// Unpersist the RDD using the nested helper fn above.
rddValue match {
case Some(rdd) => unpersistRDD(rdd)
Expand Down