Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: single storage client support multiple blob-containers #740

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions libs/server/Servers/GarnetServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,21 @@ public class GarnetServerOptions : ServerOptions
/// </summary>
public int ThreadPoolMaxThreads = 0;

private Func<INamedDeviceFactory> _deviceFactoryCreator;
private Lazy<INamedDeviceFactory> _deviceFactoryLazyCreator;

/// <summary>
/// Creator of device factories
/// </summary>
public Func<INamedDeviceFactory> DeviceFactoryCreator = null;
public Func<INamedDeviceFactory> DeviceFactoryCreator
{
get => _deviceFactoryCreator;
set
{
_deviceFactoryCreator = value;
_deviceFactoryLazyCreator = new Lazy<INamedDeviceFactory>(_deviceFactoryCreator);
}
}

/// <summary>
/// Whether and by how much should we throttle the disk IO for checkpoints (default = 0)
Expand Down Expand Up @@ -640,7 +651,7 @@ public void GetAofSettings(out TsavoriteLogSettings tsavoriteLogSettings)
throw new Exception("AOF Page size cannot be more than the AOF memory size.");
}
tsavoriteLogSettings.LogCommitManager = new DeviceLogCommitCheckpointManager(
MainMemoryReplication ? new NullNamedDeviceFactory() : DeviceFactoryCreator(),
MainMemoryReplication ? new NullNamedDeviceFactory() : GetDeviceFactory(),
new DefaultCheckpointNamingScheme(CheckpointDir + "/AOF"),
removeOutdated: true,
fastCommitThrottleFreq: EnableFastCommit ? FastCommitThrottleFreq : 0);
Expand Down Expand Up @@ -739,6 +750,6 @@ IDevice GetAofDevice()
/// Get device factory
/// </summary>
/// <returns></returns>
public INamedDeviceFactory GetDeviceFactory() => DeviceFactoryCreator();
public INamedDeviceFactory GetDeviceFactory() => _deviceFactoryLazyCreator.Value;
}
}
30 changes: 30 additions & 0 deletions test/Garnet.test/GarnetServerOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using Garnet.server;
using NUnit.Framework;
using Tsavorite.core;

namespace Garnet.test
{
[TestFixture]
public class GarnetServerOptionsTests
{
[Test]
public void TestDeviceFactoryCreator_ReturnSameInstance()
{
// Arrange
var options = new GarnetServerOptions
{
DeviceFactoryCreator = () => new LocalStorageNamedDeviceFactory()
};

// Act
var device1 = options.GetDeviceFactory();
var device2 = options.GetDeviceFactory();

// Assert
Assert.That(device1, Is.SameAs(device2));
}
}
}