Here is some C# code to fix Corrupt vBuckets which stop Rebalances

Looking at this topic in the general forum Rolling restart of cluster I found a problem with corrupt vBuckets stopping Rebalances

Here is the C# code to fix it:

 public static void rebalanceFix(bool create = true, string suffix = "")
        {
            string[] bucks = { "buck1", "buck2", "buck3", "default" };

            foreach (string buckname in bucks)
            {

                using (var bucket = CMDMSvc.CouchbaseManager.cluster.OpenBucket(buckname))
                {
                    for (int i = 1; i < 3080; i++)
                    {
                        var key = "rebalance::" + i.ToString() + (!string.IsNullOrWhiteSpace(suffix) ? "::" + suffix : "");
                        if (create)
                        {
                            Couchbase.Document<string> doc = new Couchbase.Document<string>();

                            doc.Id = key;//"rebalance::" + i.ToString();
                            //doc.Expiry = 10 * 60 * 3 * 3 * 1000;// Note I don't use this because I could not figure the time to do a rebalance. So I call this routine again to remove the keys after rebalance
                            doc.Content = "test" + i.ToString();

                            var result = bucket.Upsert<string>(doc);

                            Console.WriteLine(doc.Id + result.Message + result.Success.ToString());
                        }
                        else
                        {
                            var resultdel = bucket.Remove(key);
                            Console.WriteLine(key + resultdel.Message + resultdel.Success.ToString());

                        }
                    }

                }
            }
        }
1 Like

hey @martinesmann this is following up from yesterdays forums posting you were on.

Hi envitraux,
Thanks for the code snippet!

This is the same code as you have posted in the thread you have referenced, correct?

Yes this is definitely the same. I posted in two places because I’m not sure if .net people would see it.

Keith