Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce yield signals to operators
Splits can run for hours even after they have been killed. This is due to expensive functions (e.g., regexp) or cross join. Generally, an operator is not going to stop until it hits the page limit. The stop condition is not subjective to time constraints given time checking is at driver level. This patch adds a yield signal that will be set when the time is up. An operator is actively checking the yield signal and can stop even when the page is not full. The patch adds yield signals to lookup join operators and cursor processors
- Loading branch information
Showing
13 changed files
with
431 additions
and
87 deletions.
There are no files selected for viewing
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
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
95 changes: 95 additions & 0 deletions
95
presto-main/src/main/java/com/facebook/presto/operator/DriverYieldSignal.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,95 @@ | ||
/* | ||
* Licensed 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.facebook.presto.operator; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import javax.annotation.concurrent.GuardedBy; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static com.google.common.base.MoreObjects.toStringHelper; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
|
||
/** | ||
* Methods setWithDelay and reset should be used in pairs; | ||
* usually follow the following idiom: | ||
* <pre> {@code | ||
* DriverYieldSignal signal = ...; | ||
* signal.setWithDelay(duration, executor); | ||
* try { | ||
* // block | ||
* } finally { | ||
* signal.reset(); | ||
* } | ||
* </pre> | ||
*/ | ||
@ThreadSafe | ||
public class DriverYieldSignal | ||
{ | ||
@GuardedBy("this") | ||
private long runningSequence; | ||
|
||
@GuardedBy("this") | ||
private ScheduledFuture<?> yieldFuture; | ||
|
||
private final AtomicBoolean yield = new AtomicBoolean(); | ||
|
||
public synchronized void setWithDelay(long maxRunNanos, ScheduledExecutorService executor) | ||
{ | ||
checkState(yieldFuture == null, "there is an ongoing yield"); | ||
checkState(!isSet(), "yield while driver was not running"); | ||
|
||
this.runningSequence++; | ||
long expectedRunningSequence = this.runningSequence; | ||
yieldFuture = executor.schedule(() -> { | ||
synchronized (this) { | ||
if (expectedRunningSequence == runningSequence && yieldFuture != null) { | ||
yield.set(true); | ||
} | ||
} | ||
}, maxRunNanos, NANOSECONDS); | ||
} | ||
|
||
public synchronized void reset() | ||
{ | ||
checkState(yieldFuture != null, "there is no ongoing yield"); | ||
yield.set(false); | ||
yieldFuture.cancel(true); | ||
yieldFuture = null; | ||
} | ||
|
||
public boolean isSet() | ||
{ | ||
return yield.get(); | ||
} | ||
|
||
public synchronized String toString() | ||
{ | ||
return toStringHelper(this) | ||
.add("yieldScheduled", yieldFuture != null) | ||
.add("yield", yield.get()) | ||
.toString(); | ||
} | ||
|
||
@VisibleForTesting | ||
public synchronized void forceYieldForTesting() | ||
{ | ||
yield.set(true); | ||
} | ||
} |
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
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
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
49 changes: 49 additions & 0 deletions
49
presto-main/src/main/java/com/facebook/presto/operator/project/CursorProcessorOutput.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,49 @@ | ||
/* | ||
* Licensed 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.facebook.presto.operator.project; | ||
|
||
import static com.google.common.base.MoreObjects.toStringHelper; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
public class CursorProcessorOutput | ||
{ | ||
private final int processedRows; | ||
private final boolean finished; | ||
|
||
public CursorProcessorOutput(int processedRows, boolean finished) | ||
{ | ||
checkArgument(processedRows >= 0, "processedRows should be no smaller than 0"); | ||
this.processedRows = processedRows; | ||
this.finished = finished; | ||
} | ||
|
||
public int getProcessedRows() | ||
{ | ||
return processedRows; | ||
} | ||
|
||
public boolean isNoMoreRows() | ||
{ | ||
return finished; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return toStringHelper(this) | ||
.add("processedRows", processedRows) | ||
.add("finished", finished) | ||
.toString(); | ||
} | ||
} |
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.