Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Szabo 8 posts 109 karma points
    Mar 14, 2019 @ 14:48
    Peter Szabo
    0

    Disabling NuCache under Umbraco 8

    Hi,

    we are trying to move away from our previous CMS system to Umbraco.

    For this we have created an UmbracoApiController that recreates the old content under Umbraco. We call this one from the old CMS to send over the old content and this services just adds it to Umbraco. Note that we call this from multiple threads to speed it up, calling it one by one would take forever.

    This was all working fine with Umbraco 7, but now we have changed to Umbraco 8 and half of the contents are not created as it throws an exception because of NuCache (see below).

    My question would be, how to disable NuCache. (at least for the time of the import)

    Is there a tag that we could add to the Contoller or a config key or maybe a service setup?

    I have found a service called PublishedSnapshotService and that one has three bools: FullCacheWhenPreviewing, CachePublishedContentChildren and CacheContentCacheRoots. Would these disable the cache? Also I am not sure how to reach this service as it is not public it is not accessible from our controller.

    Thanks for your help in advance. Peter

    "Message":"An error has occurred.","ExceptionMessage":
    "An error occurred when trying to create a controller of type 'ContentController'. Make sure that the controller has a parameterless public constructor.",
    "ExceptionType":"System.InvalidOperationException",
    "StackTrace":"   
    at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
       at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
       at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()",
    "InnerException":{"Message":"An error has occurred.",
    "ExceptionMessage":"panic","ExceptionType":"System.Exception","StackTrace":"
       at Umbraco.Web.PublishedCache.NuCache.ContentStore.CreateSnapshot()
       at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.GetElements(Boolean previewDefault)
       at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshot.get_Elements()
       at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshot.get_Members()
       at Umbraco.Web.Runtime.WebRuntimeComposer.<>c.<Compose>b__0_2(IFactory factory)
       at Umbraco.Core.Composing.LightInject.LightInjectContainer.<>c__DisplayClass20_0`1.<Register>b__0(IServiceFactory f)
       at DynamicMethod(Object[] )
       at LightInject.ServiceContainer.<>c__DisplayClass150_0.<WrapAsFuncDelegate>b__0() in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 3798
       at LightInject.PerRequestLifeTime.GetInstance(Func`1 createInstance, Scope scope) in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 6207
       at DynamicMethod(Object[] )
       at LightInject.ServiceContainer.GetInstance(Type serviceType) in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 3442
       at Umbraco.Core.Composing.LightInject.LightInjectContainer.GetInstance(Type type)
       at Umbraco.Core.FactoryExtensions.GetInstance[T](IFactory factory)
       at Umbraco.Web.Runtime.WebRuntimeComposer.<>c.<Compose>b__0_6(IFactory factory)
       at Umbraco.Core.Composing.LightInject.LightInjectContainer.<>c__DisplayClass20_0`1.<Register>b__0(IServiceFactory f)
       at DynamicMethod(Object[] )
       at LightInject.ServiceContainer.GetInstance(Type serviceType) in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 3442
       at Umbraco.Core.Composing.LightInject.LightInjectContainer.GetInstance(Type type)
       at Umbraco.Core.FactoryExtensions.GetInstance[T](IFactory factory)
       at Umbraco.Web.WebApi.UmbracoApiControllerBase..ctor()
       at Umbraco.Web.WebApi.UmbracoApiController..ctor()
       at cmdportal.com.Controllers.ContentController..ctor()
       at DynamicMethod(Object[] )
       at LightInject.ServiceContainer.<>c__DisplayClass150_0.<WrapAsFuncDelegate>b__0() in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 3798
       at LightInject.PerRequestLifeTime.GetInstance(Func`1 createInstance, Scope scope) in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 6207
       at DynamicMethod(Object[] )
       at LightInject.ServiceContainer.TryGetInstance(Type serviceType) in C:\\projects\\lightinject\\src\\LightInject\\LightInject.cs:line 3498
       at LightInject.WebApi.LightInjectWebApiDependencyScope.GetService(Type serviceType) in C:\\projects\\lightinject-webapi\\build\\tmp\\Net46\\Binary\\LightInject.WebApi\\LightInject.WebApi.cs:line 187
       at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)
       at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"}}
    
  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Mar 14, 2019 @ 15:10
    Sebastiaan Janssen
    0

    Maybe I'm missing something here but the error indicates that cmdportal.com.Controllers.ContentController which doesn't have a parameterless constructor and has nothing to do with NuCache. How does this error lead back to the cache you think?

    FYI: you're unable to disable NuCache.

  • Peter Szabo 8 posts 109 karma points
    Mar 14, 2019 @ 15:28
    Peter Szabo
    0

    Hi Sebastiaan,

    The ContentController is inherited from UmbracoApiController and that one has a parameterless constructor as I remember.

    Also this controller works fine when we call it manually or one by one, it is just that the cache starts to throw errors at some point.

    In my understanding it tries to do a snapshot but something goes wrong, probably because of the multiple threads.

    ...
    at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.GetElements(Boolean previewDefault)
    at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshot.get_Elements()
    at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshot.get_Members()
    ...
    

    As it is working half of the time, I think the issue is not with the missing constructor.

    Half of the times the call does not reach the controllers method, the client just gets the error message.

    We also receive errors under Umbraco when we try to access the back office while the migration is running that also relates to NuCache. Unfortunately I don't have that error message. As I remember it has a weird "panic" message.

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Mar 14, 2019 @ 15:32
    Sebastiaan Janssen
    0

    Right.

    I think it might just have worked by fluke in v7, and I bet you had some weird caching errors there.

    I think we'll need some sample code to see what you're trying to do.

  • Peter Szabo 8 posts 109 karma points
    Mar 14, 2019 @ 15:46
    Peter Szabo
    0

    I have copied the article import code below. (stripped out some irrelevant lines to make it short...)

       [RoutePrefix("umbraco/api/content")]
       [BasicAuthentication]
       public class ContentController : UmbracoApiController
       {
    
        [HttpPost]
        public IHttpActionResult ImportArticle([FromBody]object objarticle)
        {
            try
            {
                CommonClass.BlogArticle article = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonClass.BlogArticle>(objarticle.ToString());
    
                IContentService cs = Services.ContentService;
    
                var content = cs.CreateAndSave(article.title, this.folderID, "article", 0);
    
                content.CreateDate = article.datecreated;
                content.UpdateDate = article.lastEdited;
    
                //content tab
                if (sharedData.pathchanges != null)
                {
                    article.maincontent = ReplacePathsinmainContent(article.maincontent);
                }
    
                content.SetValue("main", article.maincontent);
                content.SetValue("publishName", article.publishName);
                content.SetValue("priority", (int)0);
    
                var result = cs.SaveAndPublish(content);
    
                if (!result.Success)
                {
                    Logger.Warn(this.GetType(), "Failed to add article " + content.Name);
                }
                else
                {
                    Logger.Debug(this.GetType(), "Added the article " + content.Name);
                }
    
                return Ok();
            }
            catch (Exception exc)
            {
                Logger.Error(this.GetType(), exc, "ImportArticles");
                return this.InternalServerError(exc);
            }
        }
       }
    

    At the moment we are working on to replace the CreateAndSave with CreateContent, could that help?

  • Stephen 767 posts 2273 karma points c-trib
    Mar 14, 2019 @ 15:48
    Stephen
    1

    Things to note:

    The error "An error occurred when trying to create a controller of type 'ContentController'. Make sure that the controller has a parameterless public constructor." does not indicate that the controller does not have a parameterless, public constructor, but that something went wrong when constructing the controller. Here: getting a snapshot from NuCache fails.

    Then, although NuCache has been tested under severe load... it may be that you are triggering an issue that only occurs under heavy, multithreaded load. You write: "As I remember it has a weird 'panic' message." and well, these 'panic' messages happen in NuCache when a situation that just is impossible... happened nevertheless.

    So... there definitively is an issue behind all this. I am interested in anything you can give me - stacktraces, details about the panic messages, description of how your import process works, etc - that would help me better understand the problem + create a proper issue on our tracker.

    Stephan

  • Stephen 767 posts 2273 karma points c-trib
    Mar 14, 2019 @ 15:55
    Stephen
    0

    Looked deeper into the exception that you posted and hey, look, the panic error is there:

        "Message":"An error has occurred.",
        "ExceptionMessage":"panic",
        "ExceptionType":"System.Exception",
        "StackTrace":"   at Umbraco.Web.PublishedCache.NuCache.ContentStore.CreateSnapshot()
            at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.GetElements(Boolean previewDefault)
            at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshot.get_Elements()
            at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshot.get_Members()
            at Umbraco.Web.Runtime.WebRuntimeComposer.<>c.<Compose>b__0_2(IFactory factory)
    

    There is only one place where a 'panic' can occure in the CreateSnapshot method. And... we have already seen one case where this exception occured. So, this confirms that we do have a multi-threading issue with NuCache.

    Going to link to the GitHub issue here in a few.

  • Stephen 767 posts 2273 karma points c-trib
    Mar 14, 2019 @ 15:58
    Stephen
    0

    Side note: your code is OK and there is no "magic" (replacing CreateAndSave with CreateContent etc) that I am aware of that would work around the situation.

  • Peter Szabo 8 posts 109 karma points
    Mar 14, 2019 @ 16:01
    Peter Szabo
    0

    Hi Stephen,

    happy to help :)

    See my sample code above. We are calling it from another website with RestSharp. There are more than 30,000 contents to create (in v7 it took around 8 hours). To speed it up we are creating multiple Tasks and do it in batches. At the moment we use 500, the same number of tasks as with v7. Then wait for them to finish and then start another 500.

    Let me know what else could I provide and I will try my best.

    At the moment we are working on to replace the CreateAndSave with CreateContent and check if that helps.

    We were looking at that because we noticed in the cache table the draft is saved into it and also the published saved into it too.

  • Stephen 767 posts 2273 karma points c-trib
    Mar 14, 2019 @ 16:11
    Stephen
    100

    Your code sample is quite OK.

    Going to track the issue there: https://github.com/umbraco/Umbraco-CMS/issues/4992

Please Sign in or register to post replies

Write your reply to:

Draft