Ejemplo n.º 1
0
        /// <summary>Checks that the edits file has all opCodes</summary>
        /// <param name="filename">edits file</param>
        /// <returns>true is edits (filename) has all opCodes</returns>
        /// <exception cref="System.IO.IOException"/>
        private bool HasAllOpCodes(string inFilename)
        {
            string                 outFilename = inFilename + ".stats";
            FileOutputStream       fout        = new FileOutputStream(outFilename);
            StatisticsEditsVisitor visitor     = new StatisticsEditsVisitor(fout);

            Org.Apache.Hadoop.Hdfs.Tools.OfflineEditsViewer.OfflineEditsViewer oev = new Org.Apache.Hadoop.Hdfs.Tools.OfflineEditsViewer.OfflineEditsViewer
                                                                                         ();
            if (oev.Go(inFilename, outFilename, "stats", new OfflineEditsViewer.Flags(), visitor
                       ) != 0)
            {
                return(false);
            }
            Log.Info("Statistics for " + inFilename + "\n" + visitor.GetStatisticsString());
            bool hasAllOpCodes = true;

            foreach (FSEditLogOpCodes opCode in FSEditLogOpCodes.Values())
            {
                // don't need to test obsolete opCodes
                if (skippedOps.Contains(opCode))
                {
                    continue;
                }
                long count = visitor.GetStatistics()[opCode];
                if ((count == null) || (count == 0))
                {
                    hasAllOpCodes = false;
                    Log.Info("Opcode " + opCode + " not tested in " + inFilename);
                }
            }
            return(hasAllOpCodes);
        }
Ejemplo n.º 2
0
 public override void StartDocument()
 {
     state       = OfflineEditsXmlLoader.ParseState.ExpectEditsTag;
     stanza      = null;
     stanzaStack = new Stack <XMLUtils.Stanza>();
     opCode      = null;
     cbuf        = new StringBuilder();
     nextTxId    = -1;
 }
Ejemplo n.º 3
0
        /// <summary>Increment the op code counter</summary>
        /// <param name="opCode">opCode for which to increment count</param>
        private void IncrementOpCodeCount(FSEditLogOpCodes opCode)
        {
            if (!opCodeCount.Contains(opCode))
            {
                opCodeCount[opCode] = 0L;
            }
            long newValue = opCodeCount[opCode] + 1;

            opCodeCount[opCode] = newValue;
        }
Ejemplo n.º 4
0
        /// <summary>Get the statistics in string format, suitable for printing</summary>
        /// <returns>statistics in in string format, suitable for printing</returns>
        public virtual string GetStatisticsString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("    %-30.30s      : %d%n", "VERSION", version));
            foreach (FSEditLogOpCodes opCode in FSEditLogOpCodes.Values())
            {
                sb.Append(string.Format("    %-30.30s (%3d): %d%n", opCode.ToString(), opCode.GetOpCode
                                            (), opCodeCount[opCode]));
            }
            return(sb.ToString());
        }
 public virtual void TestOpcodeCount()
 {
     NUnit.Framework.Assert.AreEqual(50, FSEditLogOpCodes.Values().Length);
 }
Ejemplo n.º 6
0
        public override void EndElement(string uri, string name, string qName)
        {
            string str = XMLUtils.UnmangleXmlString(cbuf.ToString(), false).Trim();

            cbuf = new StringBuilder();
            switch (state)
            {
            case OfflineEditsXmlLoader.ParseState.ExpectEditsTag:
            {
                throw new XMLUtils.InvalidXmlException("expected <EDITS/>");
            }

            case OfflineEditsXmlLoader.ParseState.ExpectVersion:
            {
                if (!name.Equals("EDITS_VERSION"))
                {
                    throw new XMLUtils.InvalidXmlException("expected </EDITS_VERSION>");
                }
                try
                {
                    int version = System.Convert.ToInt32(str);
                    visitor.Start(version);
                }
                catch (IOException e)
                {
                    // Can't throw IOException from a SAX method, sigh.
                    throw new RuntimeException(e);
                }
                state = OfflineEditsXmlLoader.ParseState.ExpectRecord;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectRecord:
            {
                if (name.Equals("EDITS"))
                {
                    state = OfflineEditsXmlLoader.ParseState.ExpectEnd;
                }
                else
                {
                    if (!name.Equals("RECORD"))
                    {
                        throw new XMLUtils.InvalidXmlException("expected </EDITS> or </RECORD>");
                    }
                }
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectOpcode:
            {
                if (!name.Equals("OPCODE"))
                {
                    throw new XMLUtils.InvalidXmlException("expected </OPCODE>");
                }
                opCode = FSEditLogOpCodes.ValueOf(str);
                state  = OfflineEditsXmlLoader.ParseState.ExpectData;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectData:
            {
                throw new XMLUtils.InvalidXmlException("expected <DATA/>");
            }

            case OfflineEditsXmlLoader.ParseState.HandleData:
            {
                stanza.SetValue(str);
                if (stanzaStack.Empty())
                {
                    if (!name.Equals("DATA"))
                    {
                        throw new XMLUtils.InvalidXmlException("expected </DATA>");
                    }
                    state = OfflineEditsXmlLoader.ParseState.ExpectRecord;
                    FSEditLogOp op = opCache.Get(opCode);
                    opCode = null;
                    try
                    {
                        op.DecodeXml(stanza);
                        stanza = null;
                    }
                    finally
                    {
                        if (stanza != null)
                        {
                            System.Console.Error.WriteLine("fromXml error decoding opcode " + opCode + "\n" +
                                                           stanza.ToString());
                            stanza = null;
                        }
                    }
                    if (fixTxIds)
                    {
                        if (nextTxId <= 0)
                        {
                            nextTxId = op.GetTransactionId();
                            if (nextTxId <= 0)
                            {
                                nextTxId = 1;
                            }
                        }
                        op.SetTransactionId(nextTxId);
                        nextTxId++;
                    }
                    try
                    {
                        visitor.VisitOp(op);
                    }
                    catch (IOException e)
                    {
                        // Can't throw IOException from a SAX method, sigh.
                        throw new RuntimeException(e);
                    }
                    state = OfflineEditsXmlLoader.ParseState.ExpectRecord;
                }
                else
                {
                    stanza = stanzaStack.Pop();
                }
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectEnd:
            {
                throw new XMLUtils.InvalidXmlException("not expecting anything after </EDITS>");
            }
            }
        }