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

Create shadow file systems in configured LocalTempPath #15637

Merged
merged 1 commit into from Jan 29, 2024

Conversation

ronaldbarendse
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Description

When Umbraco Deploy creates a scope to process a deployment (e.g. content transfers or restores between environments), it enables scoped file systems, so any changes to files are only applied when the scope successfully completes. This is done by creating 'shadow' file systems, which track all changes and stores the files in a temporary directory.

We received some support tickets from customers that got the following exception during these deployments: System.IO.IOException: There is not enough space on the disk. : 'C:\home\site\wwwroot\umbraco\Data\TEMP\ShadowFs\dzpd2b0c\media\[...]. This can happen if they are trying to deploy a large amount and/or very big media files between environments, which exceeds the free/allowed disk space on the server.

I noticed the path was using the persistent storage directory on Umbraco Cloud (Azure App Service), even though Umbraco:CMS:Hosting:LocalTempStorageLocation is set to EnvironmentTemp. This location has limited disk space and is also slower compared to using the local temporary storage. This PR should therefore make deployments faster and at the same time allow for more/larger files to be deployed.

To test the changes, add the following composer and start the debugger. Once the debugger breaks, check whether the test folder/directory is created in the correct ShadowFs directory, in either the environment temp or default location (depending on the configured LocalTempStorageLocation):

using System.Diagnostics;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Infrastructure.Scoping;

internal class ShadowFileSystemComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
        => builder
            .AddNotificationHandler<UmbracoApplicationStartedNotification, ShadowFileSystemApplicationStartedNotificationHandler>()
            .Services.Configure<HostingSettings>(x => x.LocalTempStorageLocation = LocalTempStorage.EnvironmentTemp);

    private class ShadowFileSystemApplicationStartedNotificationHandler : INotificationHandler<UmbracoApplicationStartedNotification>
    {
        private readonly IScopeProvider _scopeProvider;
        private readonly FileSystems _fileSystems;

        public ShadowFileSystemApplicationStartedNotificationHandler(IScopeProvider scopeProvider, FileSystems fileSystems)
        {
            _scopeProvider = scopeProvider;
            _fileSystems = fileSystems;
        }

        public void Handle(UmbracoApplicationStartedNotification notification)
        {
            using (_scopeProvider.CreateScope(scopeFileSystems: true))
            {
                _fileSystems.MvcViewsFileSystem?.CreateFolder("test");

                // Check whether the folder exists in either:
                // Default = umbraco\Data\TEMP\ShadowFs\{Id}\views
                // EnvironmentTemp = %TEMP%\UmbracoData\{ApplicationId}\ShadowFs\{Id}\views
                Debugger.Break();

                _fileSystems.MvcViewsFileSystem?.DeleteDirectory("test");
            }
        }
    }
}

@ronaldbarendse ronaldbarendse added category/performance Fixes for performance (generally cpu or memory) fixes type/feature labels Jan 25, 2024
Copy link
Member

@bergmania bergmania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💪

@bergmania bergmania merged commit 9799c55 into v10/dev Jan 29, 2024
16 checks passed
@bergmania bergmania deleted the v10/feature/shadowfs-localtemppath branch January 29, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants