Exemplo n.º 1
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual long Get()
 {
     lock (this)
     {
         try
         {
             currentStat = zkc.Exists(path, false);
             if (currentStat == null)
             {
                 return(0);
             }
             else
             {
                 byte[] bytes = zkc.GetData(path, false, currentStat);
                 BKJournalProtos.MaxTxIdProto.Builder builder = BKJournalProtos.MaxTxIdProto.NewBuilder
                                                                    ();
                 TextFormat.Merge(new string(bytes, Charsets.Utf8), builder);
                 if (!builder.IsInitialized())
                 {
                     throw new IOException("Invalid/Incomplete data in znode");
                 }
                 return(((BKJournalProtos.MaxTxIdProto)builder.Build()).GetTxId());
             }
         }
         catch (KeeperException e)
         {
             throw new IOException("Error reading the max tx id from zk", e);
         }
         catch (Exception ie)
         {
             throw new IOException("Interrupted while reading thr max tx id", ie);
         }
     }
 }
Exemplo n.º 2
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual void Reset(long maxTxId)
 {
     lock (this)
     {
         try
         {
             BKJournalProtos.MaxTxIdProto.Builder builder = BKJournalProtos.MaxTxIdProto.NewBuilder
                                                                ().SetTxId(maxTxId);
             byte[] data = Sharpen.Runtime.GetBytesForString(TextFormat.PrintToString(((BKJournalProtos.MaxTxIdProto
                                                                                        )builder.Build())), Charsets.Utf8);
             if (currentStat != null)
             {
                 currentStat = zkc.SetData(path, data, currentStat.GetVersion());
             }
             else
             {
                 zkc.Create(path, data, ZooDefs.Ids.OpenAclUnsafe, CreateMode.Persistent);
             }
         }
         catch (KeeperException e)
         {
             throw new IOException("Error writing max tx id", e);
         }
         catch (Exception e)
         {
             throw new IOException("Interrupted while writing max tx id", e);
         }
     }
 }