Пример #1
0
        /// <summary>Update the path with prepending version number and hostname</summary>
        /// <param name="path">- to be updated in zookeeper</param>
        /// <exception cref="System.IO.IOException"/>
        internal virtual void Update(string path)
        {
            BKJournalProtos.CurrentInprogressProto.Builder builder = BKJournalProtos.CurrentInprogressProto
                                                                     .NewBuilder();
            builder.SetPath(path).SetHostname(hostName);
            string content = TextFormat.PrintToString(((BKJournalProtos.CurrentInprogressProto
                                                        )builder.Build()));

            try
            {
                zkc.SetData(this.currentInprogressNode, Sharpen.Runtime.GetBytesForString(content
                                                                                          , Charsets.Utf8), this.versionNumberForPermission);
            }
            catch (KeeperException e)
            {
                throw new IOException("Exception when setting the data " + "[" + content + "] to CurrentInprogress. "
                                      , e);
            }
            catch (Exception e)
            {
                throw new IOException("Interrupted while setting the data " + "[" + content + "] to CurrentInprogress"
                                      , e);
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Updated data[" + content + "] to CurrentInprogress");
            }
        }
Пример #2
0
        /// <summary>
        /// Read the CurrentInprogress node data from Zookeeper and also get the znode
        /// version number.
        /// </summary>
        /// <remarks>
        /// Read the CurrentInprogress node data from Zookeeper and also get the znode
        /// version number. Return the 3rd field from the data. i.e saved path with
        /// #update api
        /// </remarks>
        /// <returns>available inprogress node path. returns null if not available.</returns>
        /// <exception cref="System.IO.IOException"/>
        internal virtual string Read()
        {
            Stat stat = new Stat();

            byte[] data = null;
            try
            {
                data = zkc.GetData(this.currentInprogressNode, false, stat);
            }
            catch (KeeperException e)
            {
                throw new IOException("Exception while reading the data from " + currentInprogressNode
                                      , e);
            }
            catch (Exception e)
            {
                throw new IOException("Interrupted while reading data from " + currentInprogressNode
                                      , e);
            }
            this.versionNumberForPermission = stat.GetVersion();
            if (data != null)
            {
                BKJournalProtos.CurrentInprogressProto.Builder builder = BKJournalProtos.CurrentInprogressProto
                                                                         .NewBuilder();
                TextFormat.Merge(new string(data, Charsets.Utf8), builder);
                if (!builder.IsInitialized())
                {
                    throw new IOException("Invalid/Incomplete data in znode");
                }
                return(((BKJournalProtos.CurrentInprogressProto)builder.Build()).GetPath());
            }
            else
            {
                Log.Debug("No data available in CurrentInprogress");
            }
            return(null);
        }