Updating Couchbase client from old version

Hello Couch community.

I have a pretty old Couchbase client - 1.3.5 - and I would appreciate some help in updating to the new 2.1.0+ SDK.
Basically, we use Couchbase only as a distributed cache for storing and retrieving serializable objects.
After updating the library the API has completely changed and I was wondering if there are some best practices in using the client as we did with the new API.

That was our base usage:

Retrieval:

var result = (T) couchbaseClient.Get(key);

Storage:

couchbaseClient.Store(StoreMode.Set, key, obj, expiryTime);

I cannot find any of those methods in the new API.

Also the type CouchbaseClinet is gone. We have all the obsolete (I think) thread safe code logic to instantiate the client and I am wondering if anyone here has some advice or code snippets on how to properly bootstrap the connection.

Can some one point me some articles how to use properly Couchbase SDK with the new API?

Thanks in advance

Yeah, the 2.0 SDK includes a lot of major changes compared to 1.0. I very recently completed the upgrade for one of my projects.

Here are the key points that can you you started.

  1. The format of the .config file has changed, so you’ll have to rearrange it. The definitions for server URLs are now separate from the definition for buckets. More information: http://developer.couchbase.com/documentation/server/4.0/sdks/dotnet-2.1/configuring-the-client.html

  2. Configuration is not automatically loaded, you’ll need to initialize with configuration during application startup. Do this by calling ClusterHelper.Initialize. The simplest use case is normally ClusterHelper.Initialize(“couchbase”), where “couchbase” agrees with your configuration section name.

  3. CouchbaseClient is no longer a class, you’ll want to use the Couchbase.Core.IBucket interfaces instead. Just call ClusterHelper.GetBucket(“bucketName”) to get an IBucket interface for the bucket you want. Be sure that you don’t call Dispose on this when you’re done, it’s being shared between all uses. Also, you don’t need to do instance management anymore, ClusterHelper is making sure that there is only one instance per application for you.

  4. To get a document, use IBucket.Get(T) or IBucket.GetDocument(T). Note that these do not directly return the document, but instead return it wrapped inside a result object. You can then check the Status to see if the request was successful, and for things like missing keys.

  5. The equivalent of Store with StoreMode.Set is IBucket.Upsert(T). StoreMode.Replace is IBucket.Replace(T), and StoreMode.Add is IBucket.Insert(T).

  6. Note that these methods are really meant for JSON documents. If you need backwards compatibility with other document types you might have to mess with creating a custom ITypeSerializer. The default still uses Newtonsoft.Json. However, I noticed what seemed like some differences with I was reading basic literals like strings that we’re not JSON documents. They were in cache only, so I just flushed the cache, so I’m not 100% certain what the differences might have been.

  7. Also note that IBucket has Async versions of all the read/write methods. You can use this to help improve application performance if you’re using the async/await model for your application.

I hope this helps you get started. Let me know if you have any more specific questions.

Brant

2 Likes

Brant, thank you for the response.
I’m gonna check them one by one thank you.

Edit:
Almost :slight_smile: Managed to bootstrap the whole thing.
ClusterHelper seems very elegant solution.
My last (hope so) problem is this error during bootstrap:

 " is this a Memcached bucket?"

We’re using SDK 2.1.4.0 and the Couchbase Server 2.5.1 enterprise edition (build-1083)

Thanks in advance.

Is this error actually interfering with operations? When I use a memcached bucket, I get the same message in my log file. But everything continues to work fine anyway. I believe it’s more of an informational message.

This is an example of what my log file looks like when I init the cluster:

2015-09-08 11:40:56,046 [1] INFO Couchbase.Cluster [(null)] <(null)> - Version: 2.1.4.0
2015-09-08 11:40:56,219 [1] INFO Couchbase.Cluster [(null)] <(null)> - Configuration: {“QueryRequestTimeout”:70000,“NodeAvailableCheckInterval”:1000,“EnableTcpKeepAlives”:true,“TcpKeepAliveTime”:7200000,“TcpKeepAliveInterval”:1000,“UseSsl”:false,“SslPort”:11207,“ApiPort”:8092,“MgmtPort”:8091,“DirectPort”:11210,“HttpsMgmtPort”:18091,“HttpsApiPort”:18092,“ObserveTimeout”:500,“ObserveInterval”:2,“MaxViewRetries”:2,“ViewHardTimeout”:30000,“Servers”:[“http://ceserver:8091/pools"],“SerializationSettings”:{“ReferenceLoopHandling”:0,“MissingMemberHandling”:0,“ObjectCreationHandling”:0,“NullValueHandling”:0,“DefaultValueHandling”:0,“Converters”:[],“PreserveReferencesHandling”:0,“TypeNameHandling”:0,“MetadataPropertyHandling”:0,“TypeNameAssemblyFormat”:0,“ConstructorHandling”:0,“ContractResolver”:{“DynamicCodeGeneration”:true,“DefaultMembersSearchFlags”:20,“SerializeCompilerGeneratedMembers”:false,“IgnoreSerializableInterface”:false,“IgnoreSerializableAttribute”:true},“ReferenceResolver”:null,“TraceWriter”:null,“Binder”:null,“Error”:null,“Context”:{“Context”:null,“State”:0},“DateFormatString”:“yyyy’-‘MM’-‘dd’T’HH’:‘mm’:'ss.FFFFFFFK”,“MaxDepth”:null,“Formatting”:0,“DateFormatHandling”:0,“DateTimeZoneHandling”:3,“DateParseHandling”:1,“FloatFormatHandling”:0,“FloatParseHandling”:0,“StringEscapeHandling”:0,“Culture”:"(Default)",“CheckAdditionalContent”:false},“DeserializationSettings”:{“ReferenceLoopHandling”:0,“MissingMemberHandling”:0,“ObjectCreationHandling”:0,“NullValueHandling”:0,“DefaultValueHandling”:0,“Converters”:[],“PreserveReferencesHandling”:0,“TypeNameHandling”:0,“MetadataPropertyHandling”:0,“TypeNameAssemblyFormat”:0,“ConstructorHandling”:0,“ContractResolver”:{“DynamicCodeGeneration”:true,“DefaultMembersSearchFlags”:20,“SerializeCompilerGeneratedMembers”:false,“IgnoreSerializableInterface”:false,“IgnoreSerializableAttribute”:true},“ReferenceResolver”:null,“TraceWriter”:null,“Binder”:null,“Error”:null,“Context”:{“Context”:null,“State”:0},“DateFormatString”:“yyyy’-‘MM’-‘dd’T’HH’:‘mm’:'ss.FFFFFFFK”,“MaxDepth”:null,“Formatting”:0,“DateFormatHandling”:0,“DateTimeZoneHandling”:3,“DateParseHandling”:1,“FloatFormatHandling”:0,“FloatParseHandling”:0,“StringEscapeHandling”:0,“Culture”:"(Default)",“CheckAdditionalContent”:false},“BucketConfigs”:{“default”:{“UseSsl”:false,“Servers”:[“http://ceserver:8091/pools”],“Port”:11210,“BucketName”:“default”,“Password”:"",“Username”:"",“PoolConfiguration”:{“EnableTcpKeepAlives”:true,“TcpKeepAliveTime”:7200000,“TcpKeepAliveInterval”:1000,“MaxSize”:2,“MinSize”:1,“WaitTimeout”:2500,“MaxAcquireIterationCount”:5,“RecieveTimeout”:2500,“ShutdownTimeout”:10000,“OperationTimeout”:2500,“UseSsl”:false,“SendTimeout”:15000,“ConnectTimeout”:10000,“MaxCloseAttempts”:5,“CloseAttemptInterval”:100,“EnableOperationTiming”:false,“BufferSize”:16384,“LockAttributes”:[],“LockAllAttributesExcept”:[],“LockElements”:[],“LockAllElementsExcept”:[],“LockItem”:false,“ElementInformation”:{“Properties”:[],“IsPresent”:false,“IsLocked”:false,“IsCollection”:false,“Source”:null,“LineNumber”:0,“Type”:"Couchbase.Configuration.Client.PoolConfiguration, Couchbase.NetClient, Version=2.1.4.0, Culture=neutral, PublicKeyToken=05e9c6b5a9ec94c2”,“Validator”:{},“Errors”:[]},“CurrentConfiguration”:null},“ObserveTimeout”:500,“ObserveInterval”:2,“DefaultOperationLifespan”:2500},“cart”:{“UseSsl”:false,“Servers”:[“http://ceserver:8091/pools"],“Port”:11210,“BucketName”:“cart”,“Password”:"",“Username”:"",“PoolConfiguration”:{“EnableTcpKeepAlives”:true,“TcpKeepAliveTime”:7200000,“TcpKeepAliveInterval”:1000,“MaxSize”:2,“MinSize”:1,“WaitTimeout”:2500,“MaxAcquireIterationCount”:5,“RecieveTimeout”:2500,“ShutdownTimeout”:10000,“OperationTimeout”:2500,“UseSsl”:false,“SendTimeout”:15000,“ConnectTimeout”:10000,“MaxCloseAttempts”:5,“CloseAttemptInterval”:100,“EnableOperationTiming”:false,“BufferSize”:16384,“LockAttributes”:[],“LockAllAttributesExcept”:[],“LockElements”:[],“LockAllElementsExcept”:[],“LockItem”:false,“ElementInformation”:{“Properties”:[],“IsPresent”:false,“IsLocked”:false,“IsCollection”:false,“Source”:null,“LineNumber”:0,“Type”:"Couchbase.Configuration.Client.PoolConfiguration, Couchbase.NetClient, Version=2.1.4.0, Culture=neutral, PublicKeyToken=05e9c6b5a9ec94c2”,“Validator”:{},“Errors”:[]},“CurrentConfiguration”:null},“ObserveTimeout”:500,“ObserveInterval”:2,“DefaultOperationLifespan”:2500}},“PoolConfiguration”:{“EnableTcpKeepAlives”:true,“TcpKeepAliveTime”:7200000,“TcpKeepAliveInterval”:1000,“MaxSize”:2,“MinSize”:1,“WaitTimeout”:2500,“MaxAcquireIterationCount”:5,“RecieveTimeout”:2500,“ShutdownTimeout”:10000,“OperationTimeout”:2500,“UseSsl”:false,“SendTimeout”:15000,“ConnectTimeout”:10000,“MaxCloseAttempts”:5,“CloseAttemptInterval”:100,“EnableOperationTiming”:false,“BufferSize”:16384,“LockAttributes”:[],“LockAllAttributesExcept”:[],“LockElements”:[],“LockAllElementsExcept”:[],“LockItem”:false,“ElementInformation”:{“Properties”:[],“IsPresent”:false,“IsLocked”:false,“IsCollection”:false,“Source”:null,“LineNumber”:0,“Type”:“Couchbase.Configuration.Client.PoolConfiguration, Couchbase.NetClient, Version=2.1.4.0, Culture=neutral, PublicKeyToken=05e9c6b5a9ec94c2”,“Validator”:{},“Errors”:[]},“CurrentConfiguration”:null},“HeartbeatConfigInterval”:10000.0,“ViewRequestTimeout”:75000,“DefaultConnectionLimit”:2147483647,“MaxServicePointIdleTime”:100000,“Expect100Continue”:false,“EnableConfigHeartBeat”:true,“EnableOperationTiming”:false,“BufferSize”:0,“DefaultOperationLifespan”:2500}
2015-09-08 11:40:56,282 [1] WARN Couchbase.Core.ClusterController [(null)] <(null)> - Couchbase.Configuration.ConfigException: is this a Memcached bucket?
at Couchbase.Configuration.Server.Providers.CarrierPublication.CarrierPublicationProvider.GetConfig(String bucketName, String password)
at Couchbase.Core.ClusterController.CreateBucket(String bucketName, String password)
2015-09-08 11:40:56,288 [1] INFO Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig [(null)] <(null)> - Bootstrapping from http://ceserver:8091/pools
2015-09-08 11:40:56,419 [1] INFO Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig [(null)] <(null)> - Bootstrapped from http://ceserver:8091/pools
2015-09-08 11:40:56,473 [10] INFO Couchbase.Configuration.Server.Providers.Streaming.ConfigThreadState [(null)] <(null)> - Listening to http://10.68.2.6:8091/pools/default/bs/default
2015-09-08 11:40:56,475 [10] INFO Couchbase.Configuration.Server.Providers.Streaming.ConfigThreadState [(null)] <(null)> - configuration changed count: 0
2015-09-08 11:40:56,476 [10] INFO Couchbase.Configuration.Server.Providers.Streaming.ConfigThreadState [(null)] <(null)> - Worker Thread: 10
2015-09-08 11:40:56,477 [10] INFO Couchbase.MemcachedBucket [(null)] <(null)> - Config updated old/new: 0, 5
2015-09-08 11:40:56,478 [1] INFO Couchbase.MemcachedBucket [(null)] <(null)> - Config updated old/new: 5, 5
2015-09-08 11:40:59,238 [11] INFO Couchbase.Configuration.Server.Providers.ConfigProviderBase [(null)] <(null)> - {“name”:“cart”,“bucketType”:null,“authType”:null,“saslPassword”:null,“proxyPort”:0,“replicaIndex”:false,“uri”:"/pools/default/buckets/cart?bucket_uuid=aba639537c1648374d3d3a44acb174d4",“streamingUri”:"/pools/default/bucketsStreaming/cart?bucket_uuid=aba639537c1648374d3d3a44acb174d4",“terseBucketsBase”:null,“terseStreamingBucketsBase”:null,“localRandomKeyUri”:null,“controllers”:null,“nodes”:[{“couchApiBase”:“http://10.68.2.6:8092/cart%2Baba639537c1648374d3d3a44acb174d4",“couchApiBaseHTTPS”:“https://$HOST:18092/default”,“replication”:0.0,“clusterMembership”:null,“status”:null,“thisNode”:false,“hostname”:“10.68.2.6:8091”,“clusterCompatibility”:0,“version”:null,“os”:null,“otpNode”:null,“ports”:{“proxy”:11211,“direct”:11210,“sslDirect”:11207,“httpsCAPI”:18092,“httpsMgmt”:18091}}],“nodesExt”:[{“services”:{“mgmt”:8091,“moxi”:11211,“kv”:11210,“capi”:8092,“kvSSL”:11207,“capiSSL”:18092,“mgmtSSL”:18091,“projector”:0,“indexAdmin”:0,“indexScan”:0,“indexHttp”:0,“indexStreamInit”:0,“indexStreamCatchup”:0,“indexStreamMaint”:0,“n1ql”:0},“hostname”:null}],“stats”:null,“ddocs”:{“uri”:"/pools/default/buckets/cart/ddocs"},“nodeLocator”:“vbucket”,“uuid”:“aba639537c1648374d3d3a44acb174d4”,“vBucketServerMap”:{“hashAlgorithm”:“CRC”,“numReplicas”:0,“serverList”:[“10.68.2.6:11210”],“vBucketMap”:[[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]],“vBucketMapForward”:[]},“replicaNumber”:0,“threadsNumber”:0,“quota”:null,“basicStats”:null,“bucketCapabilitiesVer”:"",“bucketCapabilities”:[“cbhello”,“touch”,“couchapi”,“cccp”,“xdcrCheckpointing”,“nodesExt”],“rev”:5,“UseSsl”:false,“SurrogateHost”:“10.68.2.6”,“Password”:"”}
2015-09-08 11:40:59,246 [11] INFO Couchbase.Configuration.ConfigContextBase [(null)] <(null)> - o2-Creating the Servers list using rev#5
2015-09-08 11:40:59,248 [11] INFO Couchbase.Configuration.ConfigContextBase [(null)] <(null)> - Creating the KeyMapper list using rev#5
2015-09-08 11:40:59,250 [11] INFO Couchbase.Core.Buckets.VBucketKeyMapper [(null)] <(null)> - Creating VBuckets 1024 and FMaps 0 for Rev#5
2015-09-08 11:40:59,251 [11] INFO Couchbase.Core.Buckets.VBucketKeyMapper [(null)] <(null)> - Creating VBucketMapForwards 0
2015-09-08 11:40:59,254 [11] INFO Couchbase.CouchbaseBucket [(null)] <(null)> - Config updated old/new: 0, 5

I’ve managed to bootstrap it finally.
The mistake was that the cluster pooling endpoints in the configuration have changed as well (in the previous version you had to specify the default bucket).

Let’s say that the exception thrown could be more meaningful anyway all seems to work right now.

Thanks for your input!