-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd4a388
commit d7a577d
Showing
12 changed files
with
257 additions
and
20 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
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
68 changes: 68 additions & 0 deletions
68
...main/src/main/java/com/facebook/presto/execution/scheduler/CTEMaterializationTracker.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,68 @@ | ||
/* | ||
* 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.execution.scheduler; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import com.google.common.util.concurrent.SettableFuture; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
/* | ||
* Tracks the completion status of table-finish nodes that write temporary tables for CTE materialization. | ||
* CTEMaterializationTracker manages a map of materialized CTEs and their associated materialization futures. | ||
* When a stage includes a CTE table finish, it marks the corresponding CTE as materialized and completes | ||
* the associated future. This signals the scheduler that some dependency has been resolved, prompting it | ||
* to resume scheduling. The scheduler can call the clearAllFutures() method once it starts scheduling again | ||
*/ | ||
public class CTEMaterializationTracker | ||
{ | ||
private final Map<String, SettableFuture<Void>> materializationFutures = new HashMap<>(); | ||
|
||
private final Map<String, Boolean> materializedCtes = new HashMap<>(); | ||
|
||
public synchronized ListenableFuture<Void> getFutureForCTE(String cteName) | ||
{ | ||
return materializationFutures.compute(cteName, (key, existingFuture) -> { | ||
if (existingFuture == null) { | ||
return SettableFuture.create(); | ||
} | ||
checkArgument(!existingFuture.isCancelled(), "CTE future was found in a cancelled state"); | ||
return existingFuture; | ||
}); | ||
} | ||
|
||
public synchronized void clearAllFutures() | ||
{ | ||
materializationFutures.clear(); | ||
} | ||
|
||
public synchronized void markCTEAsMaterialized(String cteName) | ||
{ | ||
if (materializedCtes.putIfAbsent(cteName, true) == null) { | ||
SettableFuture<Void> future = materializationFutures.get(cteName); | ||
if (future != null) { | ||
checkArgument(!future.isCancelled(), "CTE future was found in a cancelled state"); | ||
future.set(null); // Notify all listeners | ||
} | ||
} | ||
} | ||
|
||
public synchronized boolean hasBeenMaterialized(String cteName) | ||
{ | ||
return materializedCtes.containsKey(cteName); | ||
} | ||
} |
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
Oops, something went wrong.