This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Add a strategy to fall back to Vanilla Spark shuffle manager #1047
Open
lviiii
wants to merge
15
commits into
oap-project:main
Choose a base branch
from
lviiii:fallback-shuffle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e82c97a
[NSE-913] Add support for Hadoop 3.3.1 (#966)
256b637
[NSE-927][NSE-126] BackPort PR#975 and PR#977 to branch-1.4 (#978)
zhixingheyi-tian 11dcf98
Add the strategy to fallback to Vanilla Spark shuffle manager.
lviiii a43be7f
Merge remote-tracking branch 'origin/branch-1.4' into fallback-shuffle
lviiii b96bc62
Fix the problem "wrong data".
lviiii d4ae565
Merge remote-tracking branch 'gazelle/branch-1.4' into fallback-shuffle
lviiii d371925
Merge branch 'main' into fallback-shuffle
lviiii 7c51696
Update GazellePluginConfig.scala
lviiii ca9e995
Fix the oom issue.
lviiii 732eeab
Remove the exception.
lviiii 4df13d9
Remove the exception.
lviiii 387620f
test.
lviiii 4084905
test.
lviiii 05ff93c
test.
lviiii 5b517c8
test.
lviiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
native-sql-engine/core/src/main/java/com/intel/oap/vectorized/IteratorWrapper.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,43 @@ | ||
/* | ||
* 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 com.intel.oap.vectorized; | ||
|
||
|
||
import scala.collection.convert.Wrappers; | ||
|
||
import java.io.Serializable; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class IteratorWrapper { | ||
|
||
private Iterator<List<Long>> in; | ||
|
||
public IteratorWrapper(Iterator<List<Long>> in) { | ||
this.in = in; | ||
} | ||
|
||
public boolean hasNext() { | ||
return in.hasNext(); | ||
} | ||
|
||
public List<Long> next() { | ||
return in.next(); | ||
} | ||
|
||
} |
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
233 changes: 233 additions & 0 deletions
233
native-sql-engine/core/src/main/java/com/intel/oap/vectorized/SplitIterator.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,233 @@ | ||
/* | ||
* 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 com.intel.oap.vectorized; | ||
|
||
|
||
import com.intel.oap.expression.ConverterUtils; | ||
import org.apache.arrow.memory.ArrowBuf; | ||
import org.apache.arrow.vector.ipc.message.ArrowBuffer; | ||
import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; | ||
import org.apache.spark.sql.vectorized.ColumnarBatch; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.Iterator; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SplitIterator implements Iterator<ColumnarBatch>{ | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(SplitIterator.class); | ||
|
||
public static class IteratorOptions implements Serializable { | ||
private static final long serialVersionUID = -1L; | ||
|
||
private int partitionNum; | ||
|
||
private String name; | ||
|
||
private long offheapPerTask; | ||
|
||
private int bufferSize; | ||
|
||
private String expr; | ||
|
||
public NativePartitioning getNativePartitioning() { | ||
return nativePartitioning; | ||
} | ||
|
||
public void setNativePartitioning(NativePartitioning nativePartitioning) { | ||
this.nativePartitioning = nativePartitioning; | ||
} | ||
|
||
NativePartitioning nativePartitioning; | ||
|
||
public int getPartitionNum() { | ||
return partitionNum; | ||
} | ||
|
||
public void setPartitionNum(int partitionNum) { | ||
this.partitionNum = partitionNum; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public long getOffheapPerTask() { | ||
return offheapPerTask; | ||
} | ||
|
||
public void setOffheapPerTask(long offheapPerTask) { | ||
this.offheapPerTask = offheapPerTask; | ||
} | ||
|
||
public int getBufferSize() { | ||
return bufferSize; | ||
} | ||
|
||
public void setBufferSize(int bufferSize) { | ||
this.bufferSize = bufferSize; | ||
} | ||
|
||
public String getExpr() { | ||
return expr; | ||
} | ||
|
||
public void setExpr(String expr) { | ||
this.expr = expr; | ||
} | ||
|
||
} | ||
|
||
ShuffleSplitterJniWrapper jniWrapper = null; | ||
|
||
private long nativeSplitter = 0; | ||
private final Iterator<ColumnarBatch> iterator; | ||
private final IteratorOptions options; | ||
|
||
private ColumnarBatch cb = null; | ||
|
||
public SplitIterator(Iterator<ColumnarBatch> iterator, IteratorOptions options) { | ||
this.iterator = iterator; | ||
this.options = options; | ||
} | ||
|
||
private void nativeCreateInstance() { | ||
for (int i = 0; i < cb.numCols(); i++) { | ||
ArrowWritableColumnVector vector = (ArrowWritableColumnVector)(cb.column(i)); | ||
vector.getValueVector().setValueCount(cb.numRows()); | ||
} | ||
ArrowRecordBatch recordBatch = ConverterUtils.createArrowRecordBatch(cb); | ||
try { | ||
if (jniWrapper == null) { | ||
jniWrapper = new ShuffleSplitterJniWrapper(); | ||
} | ||
if (nativeSplitter != 0) { | ||
jniWrapper.clear(nativeSplitter); | ||
nativeSplitter = 0; | ||
// throw new Exception("NativeSplitter is not clear."); | ||
} | ||
nativeSplitter = jniWrapper.make( | ||
options.getNativePartitioning(), | ||
options.getOffheapPerTask(), | ||
options.getBufferSize()); | ||
long[] bufAddrs = new long[recordBatch.getBuffers().size()]; | ||
long[] bufSizes = new long[recordBatch.getBuffersLayout().size()]; | ||
int i = 0, j = 0; | ||
for (ArrowBuf buffer: recordBatch.getBuffers()) { | ||
bufAddrs[i++] = buffer.memoryAddress(); | ||
} | ||
for (ArrowBuffer buffer: recordBatch.getBuffersLayout()) { | ||
bufSizes[j++] = buffer.getSize(); | ||
} | ||
if (i != j || i < 1) { | ||
logger.warn("bufAddrs and BuffersLayout have different lengths, and buffer sizes is " + i + " -- " + j); | ||
} | ||
jniWrapper.split(nativeSplitter, cb.numRows(), bufAddrs, bufSizes, false); | ||
jniWrapper.collect(nativeSplitter, cb.numRows()); | ||
} catch (Exception e) { | ||
if (nativeSplitter != 0) { | ||
try { | ||
jniWrapper.clear(nativeSplitter); | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
nativeSplitter = 0; | ||
} | ||
throw new RuntimeException(e); | ||
} finally { | ||
ConverterUtils.releaseArrowRecordBatch(recordBatch); | ||
// cb.close(); | ||
} | ||
|
||
} | ||
|
||
private native boolean nativeHasNext(long instance); | ||
|
||
public boolean hasRecordBatch(){ | ||
while (iterator.hasNext()) { | ||
cb = iterator.next(); | ||
if (cb.numRows() != 0 && cb.numCols() != 0) { | ||
nativeCreateInstance(); | ||
return true; | ||
} | ||
} | ||
if (nativeSplitter != 0) { | ||
try { | ||
jniWrapper.clear(nativeSplitter); | ||
nativeSplitter = 0; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
// jniWrapper.close(nativeSplitter); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
// 1. Init the native splitter | ||
if (nativeSplitter == 0) { | ||
return hasRecordBatch() && nativeHasNext(nativeSplitter); | ||
} | ||
// 2. Call native hasNext | ||
if (nativeHasNext(nativeSplitter)) { | ||
return true; | ||
} else { | ||
return hasRecordBatch() && nativeHasNext(nativeSplitter); | ||
} | ||
} | ||
|
||
private native byte[] nativeNext(long instance); | ||
|
||
@Override | ||
public ColumnarBatch next() { | ||
byte[] serializedRecordBatch = nativeNext(nativeSplitter); | ||
return ConverterUtils.createRecordBatch(serializedRecordBatch, | ||
options.getNativePartitioning().getSchema()); | ||
} | ||
|
||
private native int nativeNextPartitionId(long nativeSplitter); | ||
|
||
public int nextPartitionId() { | ||
return nativeNextPartitionId(nativeSplitter); | ||
} | ||
|
||
@Override | ||
protected void finalize() throws Throwable { | ||
try { | ||
if (nativeSplitter != 0) { | ||
logger.error("NativeSplitter is not clear."); | ||
jniWrapper.clear(nativeSplitter); | ||
nativeSplitter = 0; | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
jniWrapper.close(nativeSplitter); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please also add a short note on how to use this feature? and also make this default to false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added that in the description dialog