Skip to content

Commit

Permalink
Refactor Tsavorite checkpoint path handling to be OS-aware (#306)
Browse files Browse the repository at this point in the history
* Remove unused DirectoryConfiguration.cs

* Refactor Tsavorite checkpoint path construction

* Use Path.Join() for OS-aware paths.

* Remove LINQ from commit number parsing

* Fix

* Experiment using Path.Join in Tsavorite.tests

* Let's see if this was the issue

* Use OS directory seperator char to split the basePath in Azure storage device

* Or normalize the path to /

* Just testing around, this might be the fix though

* Introduce AzureCheckpointNamingScheme

* Add AzureCheckpointNamingScheme which uses / as the checkpoint path seperator

* Revert unrelated changes

Revert "Experiment using Path.Join in Tsavorite.tests"

This reverts commit d8424d4.

Revert "Use OS directory seperator char to split the basePath in Azure storage device"

This reverts commit b5fd3d8.

Revert "Or normalize the path to /"

This reverts commit c7f399b.

---------

Co-authored-by: Tal Zaccai <talzacc@microsoft.com>
  • Loading branch information
PaulusParssinen and TalZaccai authored Apr 23, 2024
1 parent 4f4891d commit 745db47
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.IO;
using System.Linq;

namespace Tsavorite.core
{
Expand All @@ -12,54 +11,48 @@ namespace Tsavorite.core
/// </summary>
public class DefaultCheckpointNamingScheme : ICheckpointNamingScheme
{
readonly string baseName;
/// <inheritdoc />
public string BaseName { get; }

/// <summary>
/// Create instance of default naming scheme
/// </summary>
/// <param name="baseName">Overall location specifier (e.g., local path or cloud container name)</param>
public DefaultCheckpointNamingScheme(string baseName = "")
{
this.baseName = baseName;
BaseName = baseName;
}

/// <inheritdoc />
public string BaseName() => baseName;

public FileDescriptor LogCheckpointBase(Guid token) => new(Path.Join(LogCheckpointBasePath, token.ToString()), null);
/// <inheritdoc />
public FileDescriptor LogCheckpointBase(Guid token) => new FileDescriptor($"{LogCheckpointBasePath()}/{token}", null);

public FileDescriptor LogCheckpointMetadata(Guid token) => new(Path.Join(LogCheckpointBasePath, token.ToString()), "info.dat");
/// <inheritdoc />
public FileDescriptor LogCheckpointMetadata(Guid token) => new FileDescriptor($"{LogCheckpointBasePath()}/{token}", "info.dat");

public FileDescriptor LogSnapshot(Guid token) => new(Path.Join(LogCheckpointBasePath, token.ToString()), "snapshot.dat");
/// <inheritdoc />
public FileDescriptor LogSnapshot(Guid token) => new FileDescriptor($"{LogCheckpointBasePath()}/{token}", "snapshot.dat");
public FileDescriptor ObjectLogSnapshot(Guid token) => new(Path.Join(LogCheckpointBasePath, token.ToString()), "snapshot.obj.dat");
/// <inheritdoc />
public FileDescriptor ObjectLogSnapshot(Guid token) => new FileDescriptor($"{LogCheckpointBasePath()}/{token}", "snapshot.obj.dat");
/// <inheritdoc />
public FileDescriptor DeltaLog(Guid token) => new FileDescriptor($"{LogCheckpointBasePath()}/{token}", "delta.dat");

public FileDescriptor DeltaLog(Guid token) => new(Path.Join(LogCheckpointBasePath, token.ToString()), "delta.dat");

/// <inheritdoc />
public FileDescriptor IndexCheckpointBase(Guid token) => new FileDescriptor($"{IndexCheckpointBasePath()}/{token}", null);

public FileDescriptor IndexCheckpointBase(Guid token) => new(Path.Join(IndexCheckpointBasePath, token.ToString()), null);
/// <inheritdoc />
public FileDescriptor IndexCheckpointMetadata(Guid token) => new FileDescriptor($"{IndexCheckpointBasePath()}/{token}", "info.dat");
public FileDescriptor IndexCheckpointMetadata(Guid token) => new(Path.Join(IndexCheckpointBasePath, token.ToString()), "info.dat");
/// <inheritdoc />
public FileDescriptor HashTable(Guid token) => new FileDescriptor($"{IndexCheckpointBasePath()}/{token}", "ht.dat");
public FileDescriptor HashTable(Guid token) => new(Path.Join(IndexCheckpointBasePath, token.ToString()), "ht.dat");
/// <inheritdoc />
public FileDescriptor TsavoriteLogCommitMetadata(long commitNumber) => new FileDescriptor($"{TsavoriteLogCommitBasePath()}", $"commit.{commitNumber}");
public FileDescriptor TsavoriteLogCommitMetadata(long commitNumber) => new(TsavoriteLogCommitBasePath, $"commit.{commitNumber}");

/// <inheritdoc />
public Guid Token(FileDescriptor fileDescriptor) => Guid.Parse(new DirectoryInfo(fileDescriptor.directoryName).Name);
/// <inheritdoc />
public long CommitNumber(FileDescriptor fileDescriptor) => long.Parse(fileDescriptor.fileName.Split('.').Reverse().Take(2).Last());
public long CommitNumber(FileDescriptor fileDescriptor) => long.Parse(fileDescriptor.fileName.Split('.')[^2]);

/// <inheritdoc />
public string IndexCheckpointBasePath() => "index-checkpoints";
public string IndexCheckpointBasePath => "index-checkpoints";
/// <inheritdoc />
public string LogCheckpointBasePath() => "cpr-checkpoints";
public string LogCheckpointBasePath => "cpr-checkpoints";
/// <inheritdoc />
public string TsavoriteLogCommitBasePath() => "log-commits";
public string TsavoriteLogCommitBasePath => "log-commits";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DeviceLogCommitCheckpointManager(INamedDeviceFactory deviceFactory, IChec
// // We only keep the latest TsavoriteLog commit
flogCommitHistory = new long[flogCommitCount];
}
deviceFactory.Initialize(checkpointNamingScheme.BaseName());
deviceFactory.Initialize(checkpointNamingScheme.BaseName);
}

/// <inheritdoc />
Expand Down Expand Up @@ -144,7 +144,7 @@ public void Dispose()
/// <inheritdoc />
public IEnumerable<long> ListCommits()
{
return deviceFactory.ListContents(checkpointNamingScheme.TsavoriteLogCommitBasePath()).Select(checkpointNamingScheme.CommitNumber).OrderByDescending(e => e);
return deviceFactory.ListContents(checkpointNamingScheme.TsavoriteLogCommitBasePath).Select(checkpointNamingScheme.CommitNumber).OrderByDescending(e => e);
}

/// <inheritdoc />
Expand Down Expand Up @@ -207,7 +207,7 @@ public unsafe void CommitIndexCheckpoint(Guid indexToken, byte[] commitMetadata)
/// <inheritdoc />
public IEnumerable<Guid> GetIndexCheckpointTokens()
{
return deviceFactory.ListContents(checkpointNamingScheme.IndexCheckpointBasePath()).Select(checkpointNamingScheme.Token);
return deviceFactory.ListContents(checkpointNamingScheme.IndexCheckpointBasePath).Select(checkpointNamingScheme.Token);
}

/// <inheritdoc />
Expand Down Expand Up @@ -276,7 +276,7 @@ public virtual unsafe void CommitLogIncrementalCheckpoint(Guid logToken, long ve
/// <inheritdoc />
public IEnumerable<Guid> GetLogCheckpointTokens()
{
return deviceFactory.ListContents(checkpointNamingScheme.LogCheckpointBasePath()).Select(checkpointNamingScheme.Token);
return deviceFactory.ListContents(checkpointNamingScheme.LogCheckpointBasePath).Select(checkpointNamingScheme.Token);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Tsavorite.core
{

/// <summary>
/// Interface to provide paths and names for all checkpoint-related files
/// </summary>
Expand All @@ -14,103 +13,76 @@ public interface ICheckpointNamingScheme
/// <summary>
/// Base (or container) name for all checkpoint files
/// </summary>
/// <returns></returns>
public string BaseName();
public string BaseName { get; }

/// <summary>
/// Hash table (including overflow buckets)
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor HashTable(Guid token);


/// <summary>
/// Index checkpoint base location (folder)
/// Index checkpoint base location (directory)
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor IndexCheckpointBase(Guid token);

/// <summary>
/// Index checkpoint metadata
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor IndexCheckpointMetadata(Guid token);


/// <summary>
/// Hybrid log checkpoint base location (folder)
/// Hybrid log checkpoint base location (directory)
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor LogCheckpointBase(Guid token);

/// <summary>
/// Hybrid log checkpoint metadata
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor LogCheckpointMetadata(Guid token);

/// <summary>
/// Hybrid log snapshot
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor LogSnapshot(Guid token);

/// <summary>
/// Object log snapshot
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor ObjectLogSnapshot(Guid token);

/// <summary>
/// Delta log
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
FileDescriptor DeltaLog(Guid token);

/// <summary>
/// TsavoriteLog commit metadata
/// </summary>
/// <returns></returns>
FileDescriptor TsavoriteLogCommitMetadata(long commitNumber);

/// <summary>
/// Token associated with given file descriptor
/// </summary>
/// <param name="fileDescriptor"></param>
/// <returns></returns>
Guid Token(FileDescriptor fileDescriptor);

/// <summary>
/// Commit number associated with given file descriptor
/// </summary>
/// <param name="fileDescriptor"></param>
/// <returns></returns>
long CommitNumber(FileDescriptor fileDescriptor);

/// <summary>
/// Get base path holding index checkpoints
/// </summary>
/// <returns></returns>
string IndexCheckpointBasePath();
string IndexCheckpointBasePath { get; }

/// <summary>
/// Get base path holding log checkpoints
/// </summary>
/// <returns></returns>
string LogCheckpointBasePath();
string LogCheckpointBasePath { get; }

/// <summary>
/// Get base path holding TsavoriteLog commits
/// </summary>
/// <returns></returns>
string TsavoriteLogCommitBasePath();
string TsavoriteLogCommitBasePath { get; }
}
}

This file was deleted.

Loading

0 comments on commit 745db47

Please sign in to comment.