I’m testing Couchbase 4.0 and 4.1 on seperate servers and noticed for the c# client that open bucket is taking a very long time. One instance is Couchbase 4.0 with 2 nodes on an azure vpn which the web app is connected to. Another is a single node with couchbase 4.1 and running locally.
Is this a known issue? I’m currently using the following for my connections:
web.config:
c# data class:
using (var cluster = new Cluster(“couchbaseClients/couchbase”))
{
IBucket bucket = null;
try
{
bucket = cluster.OpenBucket(bucketName);
string query = String.Format("select id, name, email, department, title, phoneNumber, roles, accessFailedCount from `{0}` where type = \"{1}\";", bucketName, CouchbaseConstants.DocumentType.User);
var queryRequest = new QueryRequest().Statement(query);
var result = bucket.Query<ApplicationUser>(queryRequest);
if (result.Success)
{
companyUsers = result.Rows;
}
else
{
error = result.Message;
}
}
catch (Exception ex)
{
error = String.Format(ServiceConstants.Response.Exception, ex.Message);
}
finally
{
if (bucket != null)
{
cluster.CloseBucket(bucket);
}
}
}
Now I am using ClusterHelper in my global.asx but in my DataLayer I’m just using the following code not sure if this is correct:
using (var cluster = new Cluster("couchbaseClients/couchbase"))
{
IBucket bucket = null;
try
{
bucket = cluster.OpenBucket(bucketName);
string documentID = string.Format(CouchbaseConstants.DocumentID.Company, companyID);
var document = bucket.GetDocument<Company>(documentID);
if (document.Success)
{
company = document.Content;
}
else
{
error = document.Message;
}
}
catch (Exception ex)
{
error = String.Format(ServiceConstants.Response.Exception, ex.Message);
}
finally
{
if (bucket != null)
{
cluster.CloseBucket(bucket);
}
}
}
Also I’m noticing when I do a remove or insert lets say on Company if I’m using multiple buckets 98% of the time it doesn’t show that change unless I do a hard refresh. Is there something on my end I can do to make sure the changes have applied to all the nodes?
When using one node the above Company Insert/Update/Remove doesn’t have any issues.
If you are using ClusterHelper in your global.asax, why wouldn’t you being using it in your data layer? Just make your data layer classes implement a ctor that takes an IBucket reference and using ClusterHelper.GetBucket() to inject the dependency.
The problem with the code you have here is that the Cluster and Bucket will be created every time this code runs; what you want to do is create the Cluster and Bucket when the application starts and close/dispose when it ends. Using ClusterHelper helps here, read this: Couchbase SDKs
I not 100% sure I understand you here…buckets are shared across clusters. When you do write, the document is immediately available from the primary unless you are doing a replica read without durability constraints. That being said, for a N1QL query there is a small amount of time before the documents will be returned in the results because the value may not have yet been indexed. Read this post: N1QL - is there delay like a view query?