-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-6806: Moving code for a HashAgg partition into seperate class.
- Loading branch information
Showing
10 changed files
with
774 additions
and
418 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/HashAggBatchAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.drill.exec.physical.impl.aggregate; | ||
|
||
public interface HashAggBatchAllocator { | ||
void allocateOutgoing(int records); | ||
} |
29 changes: 29 additions & 0 deletions
29
...-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/HashAggBatchHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.drill.exec.physical.impl.aggregate; | ||
|
||
public interface HashAggBatchHolder { | ||
void outputValues(); | ||
void clear(); | ||
int getNumPendingOutput(); | ||
void setup(); | ||
int getTargetBatchRowCount(); | ||
void setTargetBatchRowCount(int batchRowCount); | ||
int getCurrentRowCount(); | ||
boolean updateAggrValues(int incomingRowIdx, int idxWithinBatch); | ||
} |
39 changes: 39 additions & 0 deletions
39
.../src/main/java/org/apache/drill/exec/physical/impl/aggregate/HashAggMemoryCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.drill.exec.physical.impl.aggregate; | ||
|
||
/** | ||
* TODO this is an incremental change to move existing code into separate classes. This interface and the corresponding | ||
* Implementation need to be change significantly moving forward. | ||
*/ | ||
public interface HashAggMemoryCalculator { | ||
/** | ||
* Use reserved values memory (if available) to try and preemp an OOM | ||
*/ | ||
void useReservedValuesMemory(); | ||
|
||
/** | ||
* Use reserved outgoing output memory (if available) to try and preemp an OOM | ||
*/ | ||
void useReservedOutgoingMemory(); | ||
|
||
/** | ||
* Restore the reserve memory (both) | ||
*/ | ||
void restoreReservedMemory(); | ||
} |
88 changes: 88 additions & 0 deletions
88
.../main/java/org/apache/drill/exec/physical/impl/aggregate/HashAggMemoryCalculatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.drill.exec.physical.impl.aggregate; | ||
|
||
import org.apache.drill.exec.memory.BufferAllocator; | ||
import org.apache.drill.shaded.guava.com.google.common.base.Preconditions; | ||
|
||
public class HashAggMemoryCalculatorImpl implements HashAggMemoryCalculator { | ||
private boolean initialized = false; | ||
|
||
private final BufferAllocator allocator; | ||
private final long estOutgoingAllocSize; | ||
private final long estValuesBatchSize; | ||
|
||
private long reserveOutgoingMemory; | ||
private long reserveValueBatchMemory; | ||
|
||
public HashAggMemoryCalculatorImpl( | ||
final BufferAllocator allocator, | ||
final long estOutgoingAllocSize, | ||
final long estValuesBatchSize, | ||
final long reserveOutgoingMemory, | ||
final long reserveValueBatchMemory) { | ||
Preconditions.checkState(!initialized); | ||
initialized = true; | ||
|
||
this.allocator = Preconditions.checkNotNull(allocator); | ||
this.estOutgoingAllocSize = estOutgoingAllocSize; | ||
this.estValuesBatchSize = estValuesBatchSize; | ||
this.reserveOutgoingMemory = reserveOutgoingMemory; | ||
this.reserveValueBatchMemory = reserveValueBatchMemory; | ||
} | ||
|
||
@Override | ||
public void useReservedValuesMemory() { | ||
// try to preempt an OOM by using the reserved memory | ||
long reservedMemory = reserveValueBatchMemory; | ||
if ( reservedMemory > 0 ) { allocator.setLimit(allocator.getLimit() + reservedMemory); } | ||
|
||
reserveValueBatchMemory = 0; | ||
} | ||
|
||
@Override | ||
public void useReservedOutgoingMemory() { | ||
Preconditions.checkState(initialized); | ||
|
||
// try to preempt an OOM by using the reserved memory | ||
long reservedMemory = reserveOutgoingMemory; | ||
if ( reservedMemory > 0 ) { allocator.setLimit(allocator.getLimit() + reservedMemory); } | ||
|
||
reserveOutgoingMemory = 0; | ||
} | ||
|
||
@Override | ||
public void restoreReservedMemory() { | ||
Preconditions.checkState(initialized); | ||
|
||
if ( 0 == reserveOutgoingMemory ) { // always restore OutputValues first (needed for spilling) | ||
long memAvail = allocator.getLimit() - allocator.getAllocatedMemory(); | ||
if ( memAvail > estOutgoingAllocSize) { | ||
allocator.setLimit(allocator.getLimit() - estOutgoingAllocSize); | ||
reserveOutgoingMemory = estOutgoingAllocSize; | ||
} | ||
} | ||
if ( 0 == reserveValueBatchMemory ) { | ||
long memAvail = allocator.getLimit() - allocator.getAllocatedMemory(); | ||
if ( memAvail > estValuesBatchSize) { | ||
allocator.setLimit(allocator.getLimit() - estValuesBatchSize); | ||
reserveValueBatchMemory = estValuesBatchSize; | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../main/java/org/apache/drill/exec/physical/impl/aggregate/HashAggMemoryCalculatorNoop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.drill.exec.physical.impl.aggregate; | ||
|
||
public class HashAggMemoryCalculatorNoop implements HashAggMemoryCalculator { | ||
@Override | ||
public void useReservedValuesMemory() { | ||
|
||
} | ||
|
||
@Override | ||
public void useReservedOutgoingMemory() { | ||
|
||
} | ||
|
||
@Override | ||
public void restoreReservedMemory() { | ||
|
||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...va-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/HashAggPartition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.drill.exec.physical.impl.aggregate; | ||
|
||
import org.apache.drill.common.exceptions.RetryAfterSpillException; | ||
import org.apache.drill.exec.exception.SchemaChangeException; | ||
import org.apache.drill.exec.physical.impl.common.HashTable; | ||
import org.apache.drill.exec.physical.impl.common.HashTableStats; | ||
import org.apache.drill.exec.physical.impl.common.IndexPointer; | ||
import org.apache.drill.exec.record.RecordBatch; | ||
|
||
import java.io.IOException; | ||
|
||
public interface HashAggPartition { | ||
void updateBatches(); | ||
void setup(RecordBatch newIncoming) throws SchemaChangeException, IOException; | ||
boolean isSpilled(); | ||
int getBatchHolderCount(); | ||
int getSpilledBatchesCount(); | ||
int getPartitionIndex(); | ||
boolean doneOutputting(); | ||
int outputCurrentBatch(); | ||
void spill(); | ||
HashAggSpilledPartition finishSpilling(int originalPartition); | ||
void addStats(HashTableStats hashTableStats); | ||
void cleanup(); | ||
void reinitPartition(); | ||
boolean hasPendingRows(); | ||
|
||
void addBatchHolder(HashAggBatchHolder batchHolder); | ||
int buildHashcode(int incomingRowIdx) throws SchemaChangeException; | ||
HashAggBatchHolder getBatchHolder(int index); | ||
HashTable.PutStatus put(int incomingRowIdx, IndexPointer htIdxHolder, int hashCode, int batchSize) throws SchemaChangeException, RetryAfterSpillException; | ||
|
||
void resetOutBatchIndex(); | ||
} |
Oops, something went wrong.