-
Notifications
You must be signed in to change notification settings - Fork 440
TEZ-4349. DAGClient gets stuck with invalid cached DAGStatus #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
104 changes: 104 additions & 0 deletions
104
tez-api/src/main/java/org/apache/tez/common/CachedEntity.java
This file contains hidden or 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,104 @@ | ||
| /** | ||
| * 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.tez.common; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.apache.hadoop.yarn.util.Clock; | ||
| import org.apache.hadoop.yarn.util.MonotonicClock; | ||
|
|
||
| /** | ||
| * A thread safe implementation used as a container for cacheable entries with Expiration times. | ||
| * It supports custom {@link Clock} to control the elapsed time calculation. | ||
| * @param <T> the data object type. | ||
| */ | ||
| public class CachedEntity<T> { | ||
| private final AtomicReference<T> entryDataRef; | ||
| private final Clock cacheClock; | ||
| private final long expiryDurationMS; | ||
| private volatile long entryTimeStamp; | ||
|
|
||
| public CachedEntity(TimeUnit expiryTimeUnit, long expiryLength, Clock clock) { | ||
| entryDataRef = new AtomicReference<>(null); | ||
| cacheClock = clock; | ||
| expiryDurationMS = TimeUnit.MILLISECONDS.convert(expiryLength, expiryTimeUnit); | ||
| entryTimeStamp = 0; | ||
| } | ||
|
|
||
| public CachedEntity(TimeUnit expiryTimeUnit, long expiryLength) { | ||
| this(expiryTimeUnit, expiryLength, new MonotonicClock()); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @return true if expiration timestamp is 0, or the elapsed time since last update is | ||
| * greater than {@link #expiryDurationMS} | ||
| */ | ||
| public boolean isExpired() { | ||
| return (entryTimeStamp == 0) | ||
| || ((cacheClock.getTime() - entryTimeStamp) > expiryDurationMS); | ||
| } | ||
|
|
||
| /** | ||
| * If the entry has expired, it reset the cache reference through {@link #clearExpiredEntry()}. | ||
| * @return cached data if the timestamp is valid. Null, if the timestamp has expired. | ||
| */ | ||
| public T getValue() { | ||
| if (isExpired()) { // quick check for expiration | ||
| if (clearExpiredEntry()) { // remove reference to the expired entry | ||
| return null; | ||
| } | ||
| } | ||
| return entryDataRef.get(); | ||
| } | ||
|
|
||
| /** | ||
| * Safely sets the cached data. | ||
| * @param newEntry | ||
| */ | ||
| public void setValue(T newEntry) { | ||
| T currentEntry = entryDataRef.get(); | ||
| while (!entryDataRef.compareAndSet(currentEntry, newEntry)) { | ||
| currentEntry = entryDataRef.get(); | ||
| } | ||
| entryTimeStamp = cacheClock.getTime(); | ||
| } | ||
|
|
||
| /** | ||
| * Enforces the expiration of the cached entry. | ||
| */ | ||
| public void enforceExpiration() { | ||
| entryTimeStamp = 0; | ||
| } | ||
|
|
||
| /** | ||
| * Safely deletes the reference to the data if it was not null. | ||
| * @return true if the reference is set to Null. False indicates that another thread | ||
| * updated the cache. | ||
| */ | ||
| private boolean clearExpiredEntry() { | ||
| T currentEntry = entryDataRef.get(); | ||
| if (currentEntry == null) { | ||
| return true; | ||
| } | ||
| // the current value is not null: try to reset it. | ||
| // if the CAS is successful, then we won't override a recent update to the cache. | ||
| return (entryDataRef.compareAndSet(currentEntry, null)); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
am I right to assume this is the codepath where the original issue happened? could you please clarify how can we indefinitely stuck here?
I mean, we can only hit this part if getDAGStatusViaAM returns null but dagCompleted is not true, so when we hit this again and again in getDAGStatusViaAM :
also getApplicationReportInternal keeps returning null in checkAndSetDagCompletionStatus
was it the case for you?
if so, does it make sense to put at least debug level log messages to the silent catch branches?
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.
Thanks for the feedback.
Yes, considering the implementation of TezJob.run()-Line222 in Pig:
Pig polls on the DAGStatus inside an infinite loop:
Let's assume the following scenario on Tez Side:
getDAGStatusViaAM()which successfully pulls the DAGStatus and updates the cachedDAGStatus to running.getDAGStatusViaAM()which encountersTezExceptionorIOException. The call would return the last cachedDAGStatus (which is running), instead of null.running, the Pig-thread sleepsgetDAGStatusViaAM()fails, and the last valid DAGStatus is still cached.The problem in this corner case is that the Pig client will keep looping indefinitely as long as it does not receive a null or dagClient.getDAGStatus(null) does not throw an exception.
From a client perspective, it is better to fail early in order to recover faster.