Skip to content

Commit

Permalink
Adding recovery from latest checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunaprasaad Jeganathan committed Jan 18, 2019
1 parent 4096418 commit c93544e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cs/src/core/Index/Common/Contexts.cs
Expand Up @@ -136,13 +136,19 @@ public void CreateHybridLogCheckpointFolder(Guid token)
file.Delete();
}

public string GetIndexCheckpointFolder(Guid token)
public string GetIndexCheckpointFolder(Guid token = default(Guid))
{
return String.Format("{0}\\{1}\\{2}", checkpointDir, index_base_folder, token);
if (token != default(Guid))
return String.Format("{0}\\{1}\\{2}", checkpointDir, index_base_folder, token);
else
return String.Format("{0}\\{1}", checkpointDir, index_base_folder);
}
public string GetHybridLogCheckpointFolder(Guid token)
public string GetHybridLogCheckpointFolder(Guid token = default(Guid))
{
return String.Format("{0}\\{1}\\{2}", checkpointDir, cpr_base_folder, token);
if (token != default(Guid))
return String.Format("{0}\\{1}\\{2}", checkpointDir, cpr_base_folder, token);
else
return String.Format("{0}\\{1}", checkpointDir, cpr_base_folder);
}
public string GetIndexCheckpointMetaFileName(Guid token)
{
Expand Down
8 changes: 8 additions & 0 deletions cs/src/core/Index/FASTER/FASTER.cs
Expand Up @@ -168,6 +168,14 @@ public bool TakeHybridLogCheckpoint(out Guid token)
return success;
}

/// <summary>
/// Recover from the latest checkpoints
/// </summary>
public void Recover()
{
InternalRecoverFromLatestCheckpoints();
}

/// <summary>
/// Recover
/// </summary>
Expand Down
29 changes: 29 additions & 0 deletions cs/src/core/Index/FASTER/Recovery.cs
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Linq;

namespace FASTER.core
{
Expand Down Expand Up @@ -55,6 +56,34 @@ public unsafe partial class FasterKV<Key, Value, Input, Output, Context, Functio
where Value : new()
where Functions : IFunctions<Key, Value, Input, Output, Context>
{

private void InternalRecoverFromLatestCheckpoints()
{
var indexCheckpointDir = new DirectoryInfo(directoryConfiguration.GetIndexCheckpointFolder());
var latestICFolder = indexCheckpointDir.GetDirectories().OrderByDescending(f => f.LastWriteTime).First();
foreach(var dir in indexCheckpointDir.GetDirectories())
{
Console.WriteLine(dir.LastWriteTime);
}
if(latestICFolder == null || !Guid.TryParse(latestICFolder.Name, out Guid indexCheckpointGuid))
{
throw new Exception("No valid index checkpoint to recover from");
}

var hlogCheckpointDir = new DirectoryInfo(directoryConfiguration.GetHybridLogCheckpointFolder());
var latestHLCFolder = hlogCheckpointDir.GetDirectories().OrderByDescending(f => f.LastWriteTime).First();
foreach (var dir in hlogCheckpointDir.GetDirectories())
{
Console.WriteLine(dir.LastWriteTime);
}
if (latestHLCFolder == null || !Guid.TryParse(latestHLCFolder.Name, out Guid hybridLogCheckpointGuid))
{
throw new Exception("No valid hybrid log checkpoint to recover from");
}

InternalRecover(indexCheckpointGuid, hybridLogCheckpointGuid);
}

private void InternalRecover(Guid indexToken, Guid hybridLogToken)
{
_indexCheckpoint.Recover(indexToken, directoryConfiguration);
Expand Down
5 changes: 5 additions & 0 deletions cs/src/core/Index/Interfaces/IFasterKV.cs
Expand Up @@ -132,6 +132,11 @@ public unsafe interface IFasterKV<Key, Value, Input, Output, Context> : IDisposa
/// <returns>Whether checkpoint was initiated</returns>
bool TakeHybridLogCheckpoint(out Guid token);

/// <summary>
/// Recover from last successfuly checkpoints
/// </summary>
void Recover();

/// <summary>
/// Recover using full checkpoint token
/// </summary>
Expand Down

0 comments on commit c93544e

Please sign in to comment.