Repository: incubator-drill Updated Branches: refs/heads/master 70fab8c96 -> 5d7e3d3ab
DRILL-713: Fix resizing of the hash table. Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/1f4276e9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/1f4276e9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/1f4276e9 Branch: refs/heads/master Commit: 1f4276e909e1629f359f7ccaa2c777b6dce0e6d9 Parents: 70fab8c Author: Mehant Baid <[email protected]> Authored: Sun May 18 01:33:53 2014 -0700 Committer: Mehant Baid <[email protected]> Committed: Sun May 18 01:33:53 2014 -0700 ---------------------------------------------------------------------- .../exec/physical/impl/common/HashTableTemplate.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1f4276e9/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/HashTableTemplate.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/HashTableTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/HashTableTemplate.java index 402e395..3a8e609 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/HashTableTemplate.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/HashTableTemplate.java @@ -476,15 +476,20 @@ public abstract class HashTableTemplate implements HashTable { private boolean insertEntry(int incomingRowIdx, int currentIdx, int hashValue, BatchHolder lastEntryBatch, int lastEntryIdx) { - // resize hash table if needed and transfer the metadata - resizeAndRehashIfNeeded(currentIdx); - addBatchIfNeeded(currentIdx); BatchHolder bh = batchHolders.get( (currentIdx >>> 16) & BATCH_MASK); if (bh.insertEntry(incomingRowIdx, currentIdx, hashValue, lastEntryBatch, lastEntryIdx)) { numEntries++ ; + + /* Resize hash table if needed and transfer the metadata + * Resize only after inserting the current entry into the hash table + * Otherwise our calculated lastEntryBatch and lastEntryIdx + * becomes invalid after resize. + */ + resizeAndRehashIfNeeded(); + return true; } @@ -548,7 +553,7 @@ public abstract class HashTableTemplate implements HashTable { // For each entry in the old hash table, re-hash it to the new table and update the metadata // in the new table.. the metadata consists of the startIndices, links and hashValues. // Note that the keys stored in the BatchHolders are not moved around. - private void resizeAndRehashIfNeeded(int currentIdx) { + private void resizeAndRehashIfNeeded() { if (numEntries < threshold) return;
