This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
[REEF-1978] Adding Checkpoint handler for IMRU master #1429
Open
jwang98052
wants to merge
4
commits into
apache:master
Choose a base branch
from
jwang98052:REEF-1978
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 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
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 |
---|---|---|
|
@@ -20,23 +20,27 @@ | |
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Org.Apache.REEF.Common.Tasks; | ||
using Org.Apache.REEF.IMRU.API; | ||
using Org.Apache.REEF.IMRU.OnREEF.CheckpointHandler; | ||
using Org.Apache.REEF.IMRU.OnREEF.IMRUTasks; | ||
using Org.Apache.REEF.IMRU.OnREEF.Parameters; | ||
using Org.Apache.REEF.IO.TempFileCreation; | ||
using Org.Apache.REEF.Tang.Annotations; | ||
using Org.Apache.REEF.Tang.Implementations.Configuration; | ||
using Org.Apache.REEF.Tang.Implementations.Tang; | ||
using Org.Apache.REEF.Tang.Interface; | ||
using Org.Apache.REEF.Tang.Util; | ||
using Org.Apache.REEF.Utilities.Logging; | ||
using Org.Apache.REEF.Wake.Remote; | ||
|
||
namespace Org.Apache.REEF.IMRU.Examples.PipelinedBroadcastReduce | ||
{ | ||
/// <summary> | ||
/// IMRU program that performs broadcast and reduce with fault tolerance. | ||
/// </summary> | ||
public sealed class PipelinedBroadcastAndReduceWithFaultTolerant : PipelinedBroadcastAndReduce | ||
internal sealed class PipelinedBroadcastAndReduceWithFaultTolerant : PipelinedBroadcastAndReduce | ||
{ | ||
private static readonly Logger Logger = Logger.GetLogger(typeof(PipelinedBroadcastAndReduceWithFaultTolerant)); | ||
|
||
|
@@ -69,6 +73,8 @@ protected override IMRUJobDefinitionBuilder CreateJobDefinitionBuilder(int numbe | |
.SetMapInputPipelineDataConverterConfiguration(MapInputDataConverterConfig(chunkSize)) | ||
.SetMapOutputPipelineDataConverterConfiguration(MapOutputDataConverterConfig(chunkSize)) | ||
.SetPartitionedDatasetConfiguration(PartitionedDatasetConfiguration(numberofMappers)) | ||
.SetResultHandlerConfiguration(BuildResultHandlerConfig()) | ||
.SetCheckpointConfiguration(BuildCheckpointConfig()) | ||
.SetJobName("BroadcastReduce") | ||
.SetNumberOfMappers(numberofMappers) | ||
.SetMapperMemory(mapperMemory) | ||
|
@@ -108,6 +114,19 @@ protected override IConfiguration BuildUpdateFunctionConfig() | |
GenericType<BroadcastSenderReduceReceiverUpdateFunctionFT>.Class).Build(); | ||
} | ||
|
||
/// <summary> | ||
/// Build checkpoint configuration. Subclass can override it. | ||
/// </summary> | ||
protected override IConfiguration BuildCheckpointConfig() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. It is a sample client class, mainly contains driver configurations. I will change the class into internal. |
||
{ | ||
var filePath = TangFactory.GetTang().NewInjector().GetInstance<ITempFileCreator>().CreateTempDirectory("statefiles", string.Empty); | ||
|
||
return CheckpointConfigurationBuilder.ConfigurationModule | ||
.Set(CheckpointConfigurationBuilder.CheckpointFilePath, filePath) | ||
.Set(CheckpointConfigurationBuilder.TaskStateCodec, GenericType<UpdateTaskStateCodec>.Class) | ||
.Build(); | ||
} | ||
|
||
/// <summary> | ||
/// Configuration for Update task state | ||
/// </summary> | ||
|
@@ -290,12 +309,15 @@ internal sealed class BroadcastSenderReduceReceiverUpdateFunctionFT : IUpdateFun | |
private readonly int[] _intArr; | ||
private readonly int _workers; | ||
private readonly UpdateTaskState<int[], int[]> _taskState; | ||
private readonly IIMRUCheckpointHandler _stateHandler; | ||
|
||
[Inject] | ||
private BroadcastSenderReduceReceiverUpdateFunctionFT( | ||
[Parameter(typeof(BroadcastReduceConfiguration.NumberOfIterations))] int maxIters, | ||
[Parameter(typeof(BroadcastReduceConfiguration.Dimensions))] int dim, | ||
[Parameter(typeof(BroadcastReduceConfiguration.NumWorkers))] int numWorkers, | ||
[Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId, | ||
IIMRUCheckpointHandler stateHandler, | ||
ITaskState taskState) | ||
{ | ||
_maxIters = maxIters; | ||
|
@@ -304,6 +326,11 @@ private BroadcastSenderReduceReceiverUpdateFunctionFT( | |
_intArr = new int[_dim]; | ||
_workers = numWorkers; | ||
_taskState = (UpdateTaskState<int[], int[]>)taskState; | ||
|
||
_stateHandler = stateHandler; | ||
|
||
int retryNumber; | ||
int.TryParse(taskId[taskId.Length - 1].ToString(), out retryNumber); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -343,6 +370,8 @@ UpdateResult<int[], int[]> IUpdateFunction<int[], int[], int[]>.Update(int[] inp | |
/// <returns>Map input</returns> | ||
UpdateResult<int[], int[]> IUpdateFunction<int[], int[], int[]>.Initialize() | ||
{ | ||
RestoreState(); | ||
|
||
if (_taskState.Result != null) | ||
{ | ||
Restore(_taskState.Result); | ||
|
@@ -372,7 +401,7 @@ private void SaveState(int[] value) | |
{ | ||
_taskState.Iterations = _iterations; | ||
_taskState.Input = value; | ||
Logger.Log(Level.Info, "State saved: {0}", _taskState.Input[0]); | ||
PersistState(); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -383,7 +412,7 @@ private void SaveResult(int[] value) | |
{ | ||
_taskState.Iterations = _iterations; | ||
_taskState.Result = value; | ||
Logger.Log(Level.Info, "Result saved: {0}", _taskState.Result[0]); | ||
PersistState(); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -397,6 +426,28 @@ private void Restore(int[] d) | |
_intArr[i] = d[i]; | ||
} | ||
} | ||
|
||
private void PersistState() | ||
{ | ||
Logger.Log(Level.Info, "SaveState:currentState: {0}", JsonConvert.SerializeObject(_taskState)); | ||
_stateHandler.Persist(_taskState); | ||
} | ||
|
||
private void RestoreState() | ||
{ | ||
var obj = (UpdateTaskState<int[], int[]>)_stateHandler.Restore(); | ||
|
||
if (obj != null) | ||
{ | ||
Logger.Log(Level.Info, | ||
"RestoreState:DeserializeObject: input: {0}, iteration: {1}, result: {2}.", | ||
obj.Input == null ? string.Empty : string.Join(",", obj.Input), | ||
obj.Iterations, | ||
obj.Result == null ? string.Empty : string.Join(",", obj.Result)); | ||
|
||
_taskState.Update(obj); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
lang/cs/Org.Apache.REEF.IMRU.Examples/PipelinedBroadcastReduce/UpdateTaskStateCodec.cs
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,58 @@ | ||
// 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. | ||
|
||
using Newtonsoft.Json; | ||
using Org.Apache.REEF.IMRU.OnREEF.IMRUTasks; | ||
using Org.Apache.REEF.Tang.Annotations; | ||
using Org.Apache.REEF.Utilities; | ||
using Org.Apache.REEF.Wake.Remote; | ||
|
||
namespace Org.Apache.REEF.IMRU.Examples.PipelinedBroadcastReduce | ||
{ | ||
/// <summary> | ||
/// Codec for Update State | ||
/// </summary> | ||
internal sealed class UpdateTaskStateCodec : ICodec<ITaskState> | ||
{ | ||
[Inject] | ||
private UpdateTaskStateCodec() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Deserialize bytes into ITaskState object. | ||
/// </summary> | ||
/// <param name="data"></param> | ||
/// <returns></returns> | ||
public ITaskState Decode(byte[] data) | ||
{ | ||
var str = ByteUtilities.ByteArraysToString(data); | ||
return JsonConvert.DeserializeObject<UpdateTaskState<int[], int[]>>(str); | ||
} | ||
|
||
/// <summary> | ||
/// Serialize ITaskState in to bytes. | ||
/// </summary> | ||
/// <param name="taskState"></param> | ||
/// <returns></returns> | ||
public byte[] Encode(ITaskState taskState) | ||
{ | ||
var state = JsonConvert.SerializeObject(taskState); | ||
return ByteUtilities.StringToByteArrays(state); | ||
} | ||
} | ||
} |
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.
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.
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.
I'd prefer not to use
public abstract
classes as APIs. Consider re-structuring this using composition instead of inheritance.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.
This is to follow the existing pattern for getting configurations. It was to let client to share the same CreateJobDefinitionBuilder but have its own way to override the configuration. If we really want to change it, it needs to do in different PR as the change must be consistent cross other methods.