Пример #1
0
 /// <exception cref="System.IO.IOException"/>
 public override void Format(NamespaceInfo ns)
 {
     try
     {
         // delete old info
         Stat baseStat   = null;
         Stat ledgerStat = null;
         if ((baseStat = zkc.Exists(basePath, false)) != null)
         {
             if ((ledgerStat = zkc.Exists(ledgerPath, false)) != null)
             {
                 foreach (EditLogLedgerMetadata l in GetLedgerList(true))
                 {
                     try
                     {
                         bkc.DeleteLedger(l.GetLedgerId());
                     }
                     catch (BKException.BKNoSuchLedgerExistsException)
                     {
                         Log.Warn("Ledger " + l.GetLedgerId() + " does not exist;" + " Cannot delete.");
                     }
                 }
             }
             ZKUtil.DeleteRecursive(zkc, basePath);
         }
         // should be clean now.
         zkc.Create(basePath, new byte[] { (byte)('0') }, ZooDefs.Ids.OpenAclUnsafe, CreateMode
                    .Persistent);
         BKJournalProtos.VersionProto.Builder builder = BKJournalProtos.VersionProto.NewBuilder
                                                            ();
         builder.SetNamespaceInfo(PBHelper.Convert(ns)).SetLayoutVersion(BkjmLayoutVersion
                                                                         );
         byte[] data = Sharpen.Runtime.GetBytesForString(TextFormat.PrintToString(((BKJournalProtos.VersionProto
                                                                                    )builder.Build())), Charsets.Utf8);
         zkc.Create(versionPath, data, ZooDefs.Ids.OpenAclUnsafe, CreateMode.Persistent);
         zkc.Create(ledgerPath, new byte[] { (byte)('0') }, ZooDefs.Ids.OpenAclUnsafe, CreateMode
                    .Persistent);
     }
     catch (KeeperException ke)
     {
         Log.Error("Error accessing zookeeper to format", ke);
         throw new IOException("Error accessing zookeeper to format", ke);
     }
     catch (Exception ie)
     {
         Sharpen.Thread.CurrentThread().Interrupt();
         throw new IOException("Interrupted during format", ie);
     }
     catch (BKException bke)
     {
         throw new IOException("Error cleaning up ledgers during format", bke);
     }
 }
Пример #2
0
 public virtual void Setup()
 {
     zkc = ConnectZooKeeper(Hostport);
     try
     {
         ZKUtil.DeleteRecursive(zkc, BkRootPath);
     }
     catch (KeeperException.NoNodeException e)
     {
         Log.Debug("Ignoring no node exception on cleanup", e);
     }
     catch (Exception e)
     {
         Log.Error("Exception when deleting bookie root path in zk", e);
     }
 }