I was happy using the increment as a ID generator.
Everything was fine, until i started to work with more threads.
I now get repeated ID’s, usually between get 4-8 duplicates / 1K increments.
This isnt good - especially since readdoc&upsert with CAS reduces speed to a crawl ( essentially locks speed down to single thread ping time again )
Increment operations are thread safe already. I can’t explain the repeated IDs. Given that the implementation on the cluster side is so simple, I suspect maybe there’s a bug in the client or application code.
Do you by chance have a test case that shows the duplicates?
Also, what can you tell me about your deployment? Which version of Couchbase and what client SDK? Do you have XDCR in the deployment? Note that atomic counters are at a single cluster level, not across clusters.
Im using Couchbase 3.0.1
.NET 2.00 beta 2
Just made sample code:
ConcurrentBag Results = new ConcurrentBag();
using (var bucket = CBClient.Instance.OpenBucket(“default”))
Parallel.For(0, 1000, (i) =>
var res = bucket.Increment(“test”);// 4.5 seconds
var R = Results.Distinct().ToList();
if (R.Count != Results.Count)
Console.WriteLine(“ERROR: DOUBLES!!!=” + R.Count + " GOT=" + Results.Count);
The same thing happens in a serial for loop, as long as i have multiple instaces running.
CBClient is just a config class and a Cluster instance holder that will live during the application lifetime.
Instance = new Cluster(Cconfig);
I have a 2 server setup, in case that matters.
1 single cluster - nothing fancy
Running the same code posted above with the exception to changing the ConcurrentBag instantiation to: ConcurrentBag Results = new ConcurrentBag() (compiler error, ConcurrenBag requires a T param), I can’t replicate. I tried on a single node 2.5.1 instance and on 2 node 3.0.0 cluster.