Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ case class SortMergeJoinExec(
currentRightMatches = null
currentLeftRow = null
rightMatchesIterator = null
smjScanner.destruct()
return false
}
}
Expand All @@ -188,6 +189,7 @@ case class SortMergeJoinExec(
return true
}
}
smjScanner.destruct()
false
}

Expand Down Expand Up @@ -266,6 +268,7 @@ case class SortMergeJoinExec(
}
}
}
smjScanner.destruct()
false
}

Expand Down Expand Up @@ -306,6 +309,7 @@ case class SortMergeJoinExec(
return true
}
}
smjScanner.destruct()
false
}

Expand Down Expand Up @@ -344,6 +348,7 @@ case class SortMergeJoinExec(
numOutputRows += 1
return true
}
smjScanner.destruct()
false
}

Expand Down Expand Up @@ -604,6 +609,12 @@ case class SortMergeJoinExec(
| }
| if (shouldStop()) return;
|}
|while ($leftInput.hasNext()) {
| $leftInput.next();
|}
while ($rightInput.hasNext()) {
| $rightInput.next();
|}
""".stripMargin
}
}
Expand Down Expand Up @@ -649,6 +660,11 @@ private[joins] class SortMergeJoinScanner(
// Initialization (note: do _not_ want to advance streamed here).
advancedBufferedToRowWithNullFreeJoinKey()

def destruct(): Unit = {
while (streamedIter.advanceNext()) {}
while (bufferedIter.advanceNext()) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain more where is the memory leak? Why we have to exhaust the iterators?

Copy link
Member

@viirya viirya Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we don't advance to next rows, the iterators should not load the rows?** If you exhaust the iterators, it actually spend unnecessary time to pull and process those rows.

** Sort will consume the input iterator first to sort.

Copy link
Contributor Author

@zhzhan zhzhan Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does introduce extra overhead. The other way is to introduce a new interface for RowIterator to destruct itself, which may be more elegant and need more change to core data structure. Memory leak is worse than extra overhead, because it causes more spill and other issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detail is explained below.

}

// --- Public methods ---------------------------------------------------------------------------

def getStreamedRow: InternalRow = streamedRow
Expand Down Expand Up @@ -915,7 +931,11 @@ private abstract class OneSideOuterIterator(

override def advanceNext(): Boolean = {
val r = advanceBufferUntilBoundConditionSatisfied() || advanceStream()
if (r) numOutputRows += 1
if (r) {
numOutputRows += 1
} else {
smjScanner.destruct()
}
r
}

Expand Down Expand Up @@ -947,6 +967,10 @@ private class SortMergeFullOuterJoinScanner(
advancedLeft()
advancedRight()

def destruct(): Unit = {
while (leftIter.advanceNext()) {}
while (rightIter.advanceNext()) {}
}
// --- Private methods --------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -1103,7 +1127,11 @@ private class FullOuterIterator(

override def advanceNext(): Boolean = {
val r = smjScanner.advanceNext()
if (r) numRows += 1
if (r) {
numRows += 1
} else {
smjScanner.destruct();
}
r
}

Expand Down