// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.IO;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
namespace FASTER.core
{
///
/// Factory to create FASTER objects
///
public static class Devices
{
///
/// This value is supplied for capacity when the device does not have a specified limit.
///
public const long CAPACITY_UNSPECIFIED = -1;
private const string EMULATED_STORAGE_STRING = "UseDevelopmentStorage=true;";
private const string TEST_CONTAINER = "test";
///
/// Create a storage device for the log
///
/// Path to file that will store the log (empty for null device)
/// Whether we try to preallocate the file on creation
/// Delete files on close
/// The maximal number of bytes this storage device can accommondate, or CAPACITY_UNSPECIFIED if there is no such limit
/// Whether to recover device metadata from existing files
/// Device instance
public static IDevice CreateLogDevice(string logPath, bool preallocateFile = true, bool deleteOnClose = false, long capacity = CAPACITY_UNSPECIFIED, bool recoverDevice = false)
{
if (string.IsNullOrWhiteSpace(logPath))
return new NullDevice();
IDevice logDevice;
#if DOTNETCORE
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
logDevice = new ManagedLocalStorageDevice(logPath, preallocateFile, deleteOnClose, capacity, recoverDevice);
}
else
#endif
{
logDevice = new LocalStorageDevice(logPath, preallocateFile, deleteOnClose, true, capacity, recoverDevice);
}
return logDevice;
}
}
}