-
Notifications
You must be signed in to change notification settings - Fork 154
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
Showing
10 changed files
with
306 additions
and
104 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
109 changes: 109 additions & 0 deletions
109
client-spark/common/src/main/java/org/apache/spark/shuffle/stage/RssShuffleStatus.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,109 @@ | ||
/* | ||
* 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.spark.shuffle.stage; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* This class is to track the stage attempt status to check whether to trigger the stage retry of | ||
* Spark. | ||
*/ | ||
public class RssShuffleStatus { | ||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); | ||
private final ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); | ||
private final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); | ||
private final int stageId; | ||
private final int shuffleId; | ||
// the retried stage attempt records | ||
private final Set<Integer> stageAttemptRetriedRecords; | ||
|
||
private int stageAttemptNumber; | ||
// the failed task attempt numbers. Attention: these are not task attempt ids! | ||
private Set<Integer> taskAttemptFailureRecords; | ||
|
||
public RssShuffleStatus(int stageId, int shuffleId) { | ||
this.shuffleId = shuffleId; | ||
this.stageId = stageId; | ||
this.stageAttemptRetriedRecords = new HashSet<>(); | ||
this.taskAttemptFailureRecords = new HashSet<>(); | ||
} | ||
|
||
private <T> T withReadLock(Supplier<T> fn) { | ||
readLock.lock(); | ||
try { | ||
return fn.get(); | ||
} finally { | ||
readLock.unlock(); | ||
} | ||
} | ||
|
||
private <T> T withWriteLock(Supplier<T> fn) { | ||
writeLock.lock(); | ||
try { | ||
return fn.get(); | ||
} finally { | ||
writeLock.unlock(); | ||
} | ||
} | ||
|
||
public int getStageRetriedNumber() { | ||
return withReadLock(() -> this.stageAttemptRetriedRecords.size()); | ||
} | ||
|
||
public void markStageAttemptRetried() { | ||
withWriteLock( | ||
() -> { | ||
this.stageAttemptRetriedRecords.add(stageAttemptNumber); | ||
return null; | ||
}); | ||
} | ||
|
||
public int getStageAttempt() { | ||
return withReadLock(() -> this.stageAttemptNumber); | ||
} | ||
|
||
public boolean updateStageAttemptIfNecessary(int stageAttempt) { | ||
return withWriteLock( | ||
() -> { | ||
if (this.stageAttemptNumber < stageAttempt) { | ||
// a new stage attempt is issued. | ||
this.stageAttemptNumber = stageAttempt; | ||
this.taskAttemptFailureRecords = new HashSet<>(); | ||
return true; | ||
} else if (this.stageAttemptNumber > stageAttempt) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
public void incTaskFailure(int taskAttemptNumber) { | ||
withWriteLock( | ||
() -> { | ||
taskAttemptFailureRecords.add(taskAttemptNumber); | ||
return null; | ||
}); | ||
} | ||
|
||
public int getTaskFailureAttemptCount() { | ||
return withReadLock(() -> taskAttemptFailureRecords.size()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...-spark/common/src/main/java/org/apache/spark/shuffle/stage/RssShuffleStatusForReader.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,24 @@ | ||
/* | ||
* 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.spark.shuffle.stage; | ||
|
||
public class RssShuffleStatusForReader extends RssShuffleStatus { | ||
public RssShuffleStatusForReader(int stageId, int shuffleId) { | ||
super(stageId, shuffleId); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...-spark/common/src/main/java/org/apache/spark/shuffle/stage/RssShuffleStatusForWriter.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,24 @@ | ||
/* | ||
* 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.spark.shuffle.stage; | ||
|
||
public class RssShuffleStatusForWriter extends RssShuffleStatus { | ||
public RssShuffleStatusForWriter(int stageId, int shuffleId) { | ||
super(stageId, shuffleId); | ||
} | ||
} |
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.