Skip to content

Commit

Permalink
Netstandard/blobstorage (#413)
Browse files Browse the repository at this point in the history
* BlobStorageConfiguration class deleted (obsolete)
* MinimumSizeForFileStreamInBytes config deleted.
* Remove UseFileStream(long fullSize).
* Remove UseFileStream(long fullSize) part#2.
* Remove FileStreamEnabled property.
* Remove unused variable/sqlparam and conditional branch.
* Remove FileStreamData, SenseNetSqlFileStream classes.
* Remove BlobStorageContext.UseFileStream.
* Remove BlobStorageContext.UseFileStream #2.
* Delete unused SQL from code.
* Remove filestream specific members and comments.
* Remove IsFilestreamEnabled() method. Remove "filestream" from comments.
* Add integration test project for the blobs.
* Writing test infrastructure.
* Repository initialization for blob tests.
* Repository start-stop system.
* First green integration test.
* Fault-tolerance in the stored proc: proc_BinaryProperty_WriteStream
* First working tests of BuiltIn provider with a normal and sqlfs database.
* FileStream assertions
* Rewrite mechanism for filestream trigger.
* Split source files by classes.
* Fix test class lifetime problem. Test case: UpdateFile
* Create MsSqlFsBlobProvider project.
* Add files to MsSqlFs project.
* Remove BlobStorage.FileStreamEnabled usage from the SqlFileStreamBlobProvider.
* Remove BlobStorage.FileStreamEnabled condition.
* Create and update file tests.
* Write chunk tests.
* Remove unnecessary classes.
* Use right provider.
* Tests for copy.
* Add FileSystem blob providers.
* Rename test files. Add  a test class for local disk provider with buit-in metaprovider.
* Fix base method of binary cache entity tests.
* Remove unnecessary trace lines.
* Add tests for LocalDiskChunkBlobProvider.
* Tests for delete blobs.
* Migration tests.
* BlobStorage is .NET Standard 2.0
* Remove unused methods and parameters.
* Memorize initialized repository instance.
* Add XML doc. Generate nuget pkg.
* Remove legacy project.
* Cleanup and set assemblyinfo.cs
* Add nuspec and xml doc.
* Move EnableFilestream.sql to MsSqlBlobProvider
* Add more info to the mssqlfs nuspec file and remove blog package creator line from the ps script.
* Remove BlobStorage.IntegrationTests.
* Remove Packaging.IntegrationTests project.
* Remove Search.IntegrationTests.
* The "FILESTREAM" removed from the documentation.
* Raise Tools reference version to 3.0.1 in blob storage project.
* Delete MsSqlFs blob provider source code.
* Make blob metadata provider configurable.
  • Loading branch information
kavics authored and tusmester committed Jul 19, 2018
1 parent da6148a commit d3b82cd
Show file tree
Hide file tree
Showing 47 changed files with 166 additions and 4,437 deletions.
2 changes: 1 addition & 1 deletion docs/blob-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you are working in the context of the sensenet Content Repository, you do not

## Built-in blob provider

The built-in blob provider will always be there as a fallback. Currently it supports storing files in the database either in a regular *varbinary* column or in a *FILESTREAM* column.
The built-in blob provider will always be there as a fallback. Currently it supports storing files in the database in a regular *varbinary* column.

## Custom blob provider

Expand Down
53 changes: 0 additions & 53 deletions src/BlobStorage/BlobStorageConfiguration.cs

This file was deleted.

23 changes: 5 additions & 18 deletions src/BlobStorage/Configuration/BlobStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using SenseNet.ContentRepository.Storage;

// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace
namespace SenseNet.Configuration
{
/// <summary>
Expand Down Expand Up @@ -31,31 +29,20 @@ public class BlobStorage : SnConfig
/// </summary>
public static int BinaryCacheSize { get; internal set; } = GetInt(SectionName, "BinaryCacheSize", 1048576, 102400, 104857600);

/// <summary>
/// Minimum size limit (in bytes) for binary data to be stored in a SQL FileStream column.
/// Files smaller or equal this size will be stored in the database. Bigger files will go
/// to a FileStream column if the feature is enabled in the database.
/// If you set this to 0, all files will go to the filestream column.
/// In case of a huge value everything will remain in the db.
/// </summary>
public static int MinimumSizeForFileStreamInBytes { get; internal set; } = GetInt(SectionName, "MinimumSizeForFileStreamKB", 500) * 1024;

/// <summary>
/// Minimum size limit (in bytes) for binary data to be stored in the external blob storage.
/// Files under this size will be stored in the database. If you set this to 0, all files
/// will go to the external storage. In case of a huge value everything will remain in the db.
/// </summary>
public static int MinimumSizeForBlobProviderInBytes { get; internal set; } = GetInt(SectionName, "MinimumSizeForBlobProviderKB", 500) * 1024;

/// <summary>
/// Whether the FileStream feature is enabled in the system or not.
/// Computed property, not possible to configure.
/// </summary>
public static bool FileStreamEnabled { get; internal set; } = BlobStorageComponents.DataProvider.IsFilestreamEnabled();

/// <summary>
/// Class name of an optional external blob storage provider.
/// </summary>
public static string BlobProviderClassName { get; internal set; } = GetString(SectionName, "BlobProvider");
/// <summary>
/// Class name of an optional external metadata provider for the blob storage.
/// </summary>
public static string MetadataProviderClassName { get; internal set; } = GetString(SectionName, "MetadataProvider");
}
}
27 changes: 10 additions & 17 deletions src/BlobStorage/Data/BlobStorageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected internal static void DeleteBinaryProperty(int versionId, int propertyT
/// <param name="clearStream">Whether the blob provider should clear the stream during assembling the context.</param>
/// <param name="versionId">Content version id.</param>
/// <param name="propertyTypeId">Binary property type id.</param>
protected internal static BlobStorageContext GetBlobStorageContext(int fileId, bool clearStream = false, int versionId = 0, int propertyTypeId = 0)
public static BlobStorageContext GetBlobStorageContext(int fileId, bool clearStream = false, int versionId = 0, int propertyTypeId = 0)
{
return BlobStorageComponents.DataProvider.GetBlobStorageContext(fileId, clearStream, versionId, propertyTypeId);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ protected internal static void WriteChunk(int versionId, string token, byte[] bu
}
catch (Exception ex)
{
throw new DataException("Error during saving binary chunk to filestream.", ex);
throw new DataException("Error during saving binary chunk to stream.", ex);
}
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ protected internal static async Task WriteChunkAsync(int versionId, string token
}
catch (Exception ex)
{
throw new DataException("Error during saving binary chunk to filestream.", ex);
throw new DataException("Error during saving binary chunk to stream.", ex);
}
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ protected internal static void CopyFromStream(int versionId, string token, Strea
{
var context = GetBlobStorageContext(tokenData.FileId, true, versionId, tokenData.PropertyTypeId);

if (context.Provider == BuiltInProvider && !UseFileStream(context.Length))
if (context.Provider == BuiltInProvider)
{
// Our built-in provider does not have a special stream for the case when
// the binary should be saved into a regular SQL varbinary column.
Expand All @@ -240,7 +240,7 @@ protected internal static void CopyFromStream(int versionId, string token, Strea
}
catch (Exception e)
{
throw new DataException("Error during saving binary chunk to filestream.", e);
throw new DataException("Error during saving binary chunk to stream.", e);
}
}
/// <summary>
Expand All @@ -259,7 +259,7 @@ protected internal static async Task CopyFromStreamAsync(int versionId, string t
{
var context = await GetBlobStorageContextAsync(tokenData.FileId, true, versionId, tokenData.PropertyTypeId);

if (context.Provider == BuiltInProvider && !UseFileStream(context.Length))
if (context.Provider == BuiltInProvider)
{
// Our built-in provider does not have a special stream for the case when
// the binary should be saved into a regular SQL varbinary column.
Expand All @@ -277,7 +277,7 @@ protected internal static async Task CopyFromStreamAsync(int versionId, string t
}
catch (Exception e)
{
throw new DataException("Error during saving binary chunk to filestream.", e);
throw new DataException("Error during saving binary chunk to stream.", e);
}
}
private static void CopyFromStreamByChunks(BlobStorageContext context, Stream input)
Expand Down Expand Up @@ -350,7 +350,7 @@ protected internal static bool CleanupFiles()
/// <summary>
/// Gets an instance of the built-in provider.
/// </summary>
protected internal static IBlobProvider BuiltInProvider { get; }
public static IBlobProvider BuiltInProvider { get; }
/// <summary>
/// Gets a list of available blob storage providers in the system.
/// </summary>
Expand All @@ -373,14 +373,14 @@ static BlobStorageBase()
/// Gets a provider based on the binary size and the available blob providers in the system.
/// </summary>
/// <param name="fullSize">Full binary length.</param>
protected internal static IBlobProvider GetProvider(long fullSize)
public static IBlobProvider GetProvider(long fullSize)
{
return BlobStorageComponents.ProviderSelector.GetProvider(fullSize, Providers, BuiltInProvider);
}
/// <summary>
/// Gets the blob provider instance with the specified name. Default is the built-in provider.
/// </summary>
protected internal static IBlobProvider GetProvider(string providerName)
public static IBlobProvider GetProvider(string providerName)
{
if (providerName == null)
return BuiltInProvider;
Expand All @@ -389,12 +389,5 @@ protected internal static IBlobProvider GetProvider(string providerName)
return provider;
throw new InvalidOperationException("BlobProvider not found: '" + providerName + "'.");
}
/// <summary>
/// Decides whether a binary with the provided length should go to a Filestream column or not.
/// </summary>
protected internal static bool UseFileStream(long fullSize)
{
return BlobStorage.FileStreamEnabled && fullSize > BlobStorage.MinimumSizeForFileStreamInBytes;
}
}
}
2 changes: 1 addition & 1 deletion src/BlobStorage/Data/BlobStorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class BlobStorageClient : BlobStorageBase
public static Stream GetStreamForRead(string token)
{
var tokenData = ChunkToken.Parse(token);
var context = BlobStorageBase.GetBlobStorageContext(tokenData.FileId, false, tokenData.VersionId, tokenData.PropertyTypeId);
var context = GetBlobStorageContext(tokenData.FileId, false, tokenData.VersionId, tokenData.PropertyTypeId);

return context.Provider.GetStreamForRead(context);
}
Expand Down
7 changes: 1 addition & 6 deletions src/BlobStorage/Data/BlobStorageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,14 @@ public class BlobStorageContext
/// </summary>
public object BlobProviderData { get; set; }

/// <summary>
/// Gets a value indicating whether this binary value is (or will be) saved into a Filestream column in SQL Server.
/// </summary>
public bool UseFileStream { get; set; }

/// <summary>
/// Creates a new instance of the BlobStorageContext class.
/// </summary>
/// <param name="provider">Blob provider to work with.</param>
/// <param name="providerData">Optional existing provider-specific data in text format.</param>
public BlobStorageContext(IBlobProvider provider, string providerData = null)
{
this.Provider = provider;
Provider = provider;
if (providerData != null)
BlobProviderData = provider.ParseData(providerData);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BlobStorage/Data/ChunkToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class ChunkToken
/// any time. Only the Parse method below can be used to extract the values. The layers above should
/// NOT parse and use the ids compiled into this token.
/// </summary>
internal string GetToken()
public string GetToken()
{
return $"{this.VersionId}|{this.PropertyTypeId}|{this.BinaryPropertyId}|{this.FileId}";
return $"{VersionId}|{PropertyTypeId}|{BinaryPropertyId}|{FileId}";
}

/// <summary>
Expand Down
11 changes: 0 additions & 11 deletions src/BlobStorage/Data/FileStreamData.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/BlobStorage/Data/IBlobStorageMetaDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ namespace SenseNet.ContentRepository.Storage.Data
/// </summary>
public interface IBlobStorageMetaDataProvider
{
/// <summary>
/// Returns whether the FileStream feature is enabled in the blob provider or not.
/// </summary>
bool IsFilestreamEnabled();

/// <summary>
/// Returns a context object that holds provider-specific data for blob storage operations.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BlobStorage/Data/RepositoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class RepositoryStream : Stream
public RepositoryStream(int fileId, long size, byte[] binary = null)
{
Length = size;
this.FileId = fileId;
FileId = fileId;
if (binary != null)
_innerBuffer = binary;
}
Expand Down
Loading

0 comments on commit d3b82cd

Please sign in to comment.