Ejemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        internal static FSEditLogLoader.EditLogValidation ScanEditLog(FilePath file)
        {
            Org.Apache.Hadoop.Hdfs.Server.Namenode.EditLogFileInputStream @in;
            try
            {
                @in = new Org.Apache.Hadoop.Hdfs.Server.Namenode.EditLogFileInputStream(file);
                // read the header, initialize the inputstream, but do not check the
                // layoutversion
                @in.GetVersion(false);
            }
            catch (EditLogFileInputStream.LogHeaderCorruptException e)
            {
                Log.Warn("Log file " + file + " has no valid header", e);
                return(new FSEditLogLoader.EditLogValidation(0, HdfsConstants.InvalidTxid, true));
            }
            long lastPos  = 0;
            long lastTxId = HdfsConstants.InvalidTxid;
            long numValid = 0;

            try
            {
                while (true)
                {
                    long txid = HdfsConstants.InvalidTxid;
                    lastPos = @in.GetPosition();
                    try
                    {
                        if ((txid = @in.ScanNextOp()) == HdfsConstants.InvalidTxid)
                        {
                            break;
                        }
                    }
                    catch (Exception t)
                    {
                        FSImage.Log.Warn("Caught exception after scanning through " + numValid + " ops from "
                                         + @in + " while determining its valid length. Position was " + lastPos, t);
                        @in.Resync();
                        FSImage.Log.Warn("After resync, position is " + @in.GetPosition());
                        continue;
                    }
                    if (lastTxId == HdfsConstants.InvalidTxid || txid > lastTxId)
                    {
                        lastTxId = txid;
                    }
                    numValid++;
                }
                return(new FSEditLogLoader.EditLogValidation(lastPos, lastTxId, false));
            }
            finally
            {
                IOUtils.CloseStream(@in);
            }
        }
Ejemplo n.º 2
0
 /// <exception cref="System.IO.IOException"/>
 internal static FSEditLogLoader.EditLogValidation ValidateEditLog(FilePath file)
 {
     Org.Apache.Hadoop.Hdfs.Server.Namenode.EditLogFileInputStream @in;
     try
     {
         @in = new Org.Apache.Hadoop.Hdfs.Server.Namenode.EditLogFileInputStream(file);
         @in.GetVersion(true);
     }
     catch (EditLogFileInputStream.LogHeaderCorruptException e)
     {
         // causes us to read the header
         // If the header is malformed or the wrong value, this indicates a corruption
         Log.Warn("Log file " + file + " has no valid header", e);
         return(new FSEditLogLoader.EditLogValidation(0, HdfsConstants.InvalidTxid, true));
     }
     try
     {
         return(FSEditLogLoader.ValidateEditLog(@in));
     }
     finally
     {
         IOUtils.CloseStream(@in);
     }
 }