-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix null pointer exception in Dataflow Runner due to unserializable b…
…ackoff
- Loading branch information
Shu Heng
committed
Jan 8, 2020
1 parent
ec6b26b
commit 5778ad0
Showing
9 changed files
with
228 additions
and
166 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
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 |
---|---|---|
@@ -1,38 +1,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2020 The Feast Authors | ||
* | ||
* 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 | ||
* | ||
* https://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 feast.retry; | ||
|
||
import java.io.Serializable; | ||
import org.apache.beam.sdk.util.BackOff; | ||
import org.apache.beam.sdk.util.BackOffUtils; | ||
import org.apache.beam.sdk.util.FluentBackoff; | ||
import org.apache.beam.sdk.util.Sleeper; | ||
import org.joda.time.Duration; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
|
||
public class BackOffExecutor implements Serializable { | ||
|
||
private static FluentBackoff backoff; | ||
private final Integer maxRetries; | ||
private final Duration initialBackOff; | ||
|
||
public BackOffExecutor(Integer maxRetries, Duration initialBackOff) { | ||
backoff = FluentBackoff.DEFAULT | ||
.withMaxRetries(maxRetries) | ||
.withInitialBackoff(initialBackOff); | ||
} | ||
public BackOffExecutor(Integer maxRetries, Duration initialBackOff) { | ||
this.maxRetries = maxRetries; | ||
this.initialBackOff = initialBackOff; | ||
} | ||
|
||
public void execute(Retriable retriable) throws Exception { | ||
FluentBackoff backoff = | ||
FluentBackoff.DEFAULT.withMaxRetries(maxRetries).withInitialBackoff(initialBackOff); | ||
execute(retriable, backoff); | ||
} | ||
|
||
public void execute(Retriable retriable) throws Exception { | ||
Sleeper sleeper = Sleeper.DEFAULT; | ||
BackOff backOff = backoff.backoff(); | ||
while(true) { | ||
try { | ||
retriable.execute(); | ||
break; | ||
} catch (Exception e) { | ||
if(retriable.isExceptionRetriable(e) && BackOffUtils.next(sleeper, backOff)) { | ||
retriable.cleanUpAfterFailure(); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
private void execute(Retriable retriable, FluentBackoff backoff) throws Exception { | ||
Sleeper sleeper = Sleeper.DEFAULT; | ||
BackOff backOff = backoff.backoff(); | ||
while (true) { | ||
try { | ||
retriable.execute(); | ||
break; | ||
} catch (Exception e) { | ||
if (retriable.isExceptionRetriable(e) && BackOffUtils.next(sleeper, backOff)) { | ||
retriable.cleanUpAfterFailure(); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,25 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2020 The Feast Authors | ||
* | ||
* 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 | ||
* | ||
* https://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 feast.retry; | ||
|
||
public interface Retriable { | ||
void execute(); | ||
Boolean isExceptionRetriable(Exception e); | ||
void cleanUpAfterFailure(); | ||
void execute(); | ||
|
||
Boolean isExceptionRetriable(Exception e); | ||
|
||
void cleanUpAfterFailure(); | ||
} |
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.