Problems with initial setup
Hey folks,
we're investigating the use of Membase for a re-architecture of our site, and although I've found the server element to be a doddle to setup, I'm having a nightmare with the client and hopefully someone can help.
The server is pretty much the vanilla install (I had a problem as my machine has multiple IPs, though I just removed the virtual IPs before install and that went fine).
The admin interface reports no issues, and has let me create 2 buckets 'users' and 'sessions'. The test server button works as expected.
I'm using the Enyim client.
I have the following in my App.Config:
[CODE]
[/CODE]
Enyim.Caching + Log4Net are included as references.
A simple:
[CODE]MemcachedClient client = new MemcachedClient();[/CODE]
Throws an 'Object reference not set to an instance of an object' exception.
I've also tried MembaseClient client = new MembaseClient();
I've tried removing the bucket from the app.config.
I'm starting to draw blanks.
Can anyone suggest anything I should be trying? It surely shouldn't be this hard, so I suspect I'm being daft at some point along the line.
Many thanks,
Terry (@terry_brown)
Hi Attila,
Thanks for getting back to me. The exception thrown when attempting to new up a NorthScaleClient() (empty ctor, though app.config lives in the same project) is as follows:
[CODE][NullReferenceException: Object reference not set to an instance of an object.]
NorthScale.Store.NorthScalePool..ctor(INorthScaleClientConfiguration configuration, String bucket) in D:\git\EnyimMemcached\Enyim.Caching\NorthScale.Store\NorthScalePool.cs:30
NorthScale.Store.NorthScaleClient..ctor() in D:\git\EnyimMemcached\Enyim.Caching\NorthScale.Store\NorthScaleClient.cs:13
Tombola.Dal.Caching.MemcachedCache..ctor() in C:\www\Tombola.2010\Tombola.Dal\Caching\MemcachedCache.cs:19
BuildUp_Tombola.Dal.Caching.MemcachedCache(IBuilderContext ) +202
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +191
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +97
[BuildFailedException: The current build operation (build key Build Key[Tombola.Dal.Caching.MemcachedCache, null]) failed: Object reference not set to an instance of an object. (Strategy type BuildPlanStrategy, index 3)]
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +273
Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +59
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +180
[ResolutionFailedException: Resolution of the dependency failed, type = "Tombola.Dal.Interfaces.ITombolaCache", name = "". Exception message is: The current build operation (build key Build Key[Tombola.Dal.Caching.MemcachedCache, null]) failed: Object reference not set to an instance of an object. (Strategy type BuildPlanStrategy, index 3)]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +218
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name) +11
Microsoft.Practices.Unity.UnityContainerBase.Resolve() +64
Tombola.Web.MvcApplication.InitialiseUnityControllerFactory() in C:\www\Tombola.2010\Tombola.Web\Global.asax.cs:175
Tombola.Web.MvcApplication.InitialiseControllerFactory() in C:\www\Tombola.2010\Tombola.Web\Global.asax.cs:138
Tombola.Web.MvcApplication.Application_Start() in C:\www\Tombola.2010\Tombola.Web\Global.asax.cs:24
[HttpException (0x80004005): Resolution of the dependency failed, type = "Tombola.Dal.Interfaces.ITombolaCache", name = "". Exception message is: The current build operation (build key Build Key[Tombola.Dal.Caching.MemcachedCache, null]) failed: Object reference not set to an instance of an object. (Strategy type BuildPlanStrategy, index 3)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9024793
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Resolution of the dependency failed, type = "Tombola.Dal.Interfaces.ITombolaCache", name = "". Exception message is: The current build operation (build key Build Key[Tombola.Dal.Caching.MemcachedCache, null]) failed: Object reference not set to an instance of an object. (Strategy type BuildPlanStrategy, index 3)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
[/CODE]
I'd previously been following that guide you posted, and can't really see what I'm doing differently in there as opposed to your docs?
Hopefully the stack trace reveals something.
Kind regards,
Terry
as a quick update also, I tried ignoring the app.config setup and instead used the following:
[CODE]INorthScaleClientConfiguration config = new NorthScaleClientConfiguration();
config.Urls.Add( new Uri("http://192.168.10.120:8080/pools/default") );[/CODE]
this didn't throw an exception.
Is it possible that the app.config isn't being picked up?
The project is an MVC2 project, and the DAL layer is where this caching lives (separate project) - the config lives in the app.config of the DAL project - I wonder if I need to do anything for it to be seen by the MVC2 project (which calls the cache client)?
Thanks again,
Terry
apologies for the spam :)
ok, moved the configuration from App.Config up to my MVC2 project's web.config. I had to change:
[CODE][/CODE]
to:
[CODE][/CODE]
as I was getting an unknown reference (even after adding enyim.caching and log4net as references to my web project).
I'm happy to go with this as a solution, though I'd be keen to understand if it's good practice to do so or not?
Also, a separate question, but I'm using Unity as an IoC container throughout my project, and (as per the recommendation) am resolving the cache as a singleton on application_start. It seems a shame that once I have an instance, I can't switch buckets? I have to construct a new NorthScaleClient to use a different bucket or have multiple NorthScaleClients (not ideal in my situation). Would be nice if any future implementation of the client added a 'SetBucket' method to the client so that I could use the same singleton instance and just switch, though not sure on the logistics of this?
Kind Regards,
Terry
Oh my, the forum just ate my long reply (and a second one too) :(
In short, you figured it out right, configuration should go into the "web.config" since this is the "app.config" of the application. I'll update the docs to reflect that, since this terminology may not be as well known as I thought.
AS of the bucket changing, there are some technical limitations, which could be worked out or fixed, but
- buckets are separate things, so the client should follow this logic (in my opinion). this waythe users are aware that they are storing stuff in different places.
- a connection to a server (inside the client) is specific to a bucket, so the client could
a) create new connection pools to servers for each bucket (in the end you'd end up having BUCKET_NUM * CONN_POOL_MAX connections of which most users would not be aware of)
b) change bucket ona connection when needed, but this would esssentially cut your cache performance in half (2 operations instead of one every time you need to do something)
In of your specific case, you could
1) make a cache wrapper which holds the clients and selects the required one in a switch...case
2) store everything in one bucket and prefix the keys with a specific string
(i recommend #1, much cleaner)
Hey Atilla - What do you mean when you say the forum ate your replies?
thanks so much for all your help on the forum !!!
james.
slightly OT, but i was logged in, typed for 10 mins, then I posted and the forum asked me to log in again. i did but then i was presented with empty reply form again :) (last time i saved my message with copy&paste, i should have been more careful in the first time)
thanks for the update Attila - I think you're right - a cache wrapper will probably be most elegant and I already have an ICache interface so can build in a method signature into that.
Now all I need to resolve is my other post on the forum (unable to store objects in the cache, only strings) and I'm flying :)
Thanks again,
Terry
Attila, FYI: the session timeout has been increased. We have run into this before and it is annoying. Should be resolved now but may require that you log out to pick up an updated cookie.
MemcachedClient might be faulting because it does not find the defaul "enyim/memcached" section. I'll look into it.
On the other hand your config looks fine and NorthScaleClient should pick it up properly. Do you get any eceptions? If so, please post the stack trace so i can lok into it.
MemCachedClient is used for connecting to normal MC servers. You can use it for NS as well but then you'll lose the bucket handling and dynamic pool updates. (I think i need to clarify this up in the wiki or maybe split the lib into two parts to avoid confusions.)
Additionally, please have a look at [url]http://wiki.github.com/enyim/EnyimMemcached/northscaleclient-usage[/url] and let me know if this helps or i need to add more details.