コード例 #1
0
        /// <summary>
        /// Create a compression instance using the codec specified by
        /// <code>codecClassName</code>
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        internal static Org.Apache.Hadoop.Hdfs.Server.Namenode.FSImageCompression CreateCompression
            (Configuration conf, string codecClassName)
        {
            CompressionCodecFactory factory = new CompressionCodecFactory(conf);
            CompressionCodec        codec   = factory.GetCodecByClassName(codecClassName);

            if (codec == null)
            {
                throw new IOException("Not a supported codec: " + codecClassName);
            }
            return(new Org.Apache.Hadoop.Hdfs.Server.Namenode.FSImageCompression(codec));
        }
コード例 #2
0
        /* (non-Javadoc)
         * @see ImageLoader#processImage(java.io.DataInputStream, ImageVisitor, boolean)
         */
        /// <exception cref="System.IO.IOException"/>
        public override void LoadImage(DataInputStream @in, ImageVisitor v, bool skipBlocks
                                       )
        {
            bool done = false;

            try
            {
                v.Start();
                v.VisitEnclosingElement(ImageVisitor.ImageElement.FsImage);
                imageVersion = @in.ReadInt();
                if (!CanLoadVersion(imageVersion))
                {
                    throw new IOException("Cannot process fslayout version " + imageVersion);
                }
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddLayoutFlags, imageVersion
                                                   ))
                {
                    LayoutFlags.Read(@in);
                }
                v.Visit(ImageVisitor.ImageElement.ImageVersion, imageVersion);
                v.Visit(ImageVisitor.ImageElement.NamespaceId, @in.ReadInt());
                long numInodes = @in.ReadLong();
                v.Visit(ImageVisitor.ImageElement.GenerationStamp, @in.ReadLong());
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.SequentialBlockId, imageVersion
                                                   ))
                {
                    v.Visit(ImageVisitor.ImageElement.GenerationStampV2, @in.ReadLong());
                    v.Visit(ImageVisitor.ImageElement.GenerationStampV1Limit, @in.ReadLong());
                    v.Visit(ImageVisitor.ImageElement.LastAllocatedBlockId, @in.ReadLong());
                }
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.StoredTxids, imageVersion
                                                   ))
                {
                    v.Visit(ImageVisitor.ImageElement.TransactionId, @in.ReadLong());
                }
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddInodeId, imageVersion
                                                   ))
                {
                    v.Visit(ImageVisitor.ImageElement.LastInodeId, @in.ReadLong());
                }
                bool supportSnapshot = NameNodeLayoutVersion.Supports(LayoutVersion.Feature.Snapshot
                                                                      , imageVersion);
                if (supportSnapshot)
                {
                    v.Visit(ImageVisitor.ImageElement.SnapshotCounter, @in.ReadInt());
                    int numSnapshots = @in.ReadInt();
                    v.Visit(ImageVisitor.ImageElement.NumSnapshotsTotal, numSnapshots);
                    for (int i = 0; i < numSnapshots; i++)
                    {
                        ProcessSnapshot(@in, v);
                    }
                }
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.FsimageCompression, imageVersion
                                                   ))
                {
                    bool isCompressed = @in.ReadBoolean();
                    v.Visit(ImageVisitor.ImageElement.IsCompressed, isCompressed.ToString());
                    if (isCompressed)
                    {
                        string codecClassName = Text.ReadString(@in);
                        v.Visit(ImageVisitor.ImageElement.CompressCodec, codecClassName);
                        CompressionCodecFactory codecFac = new CompressionCodecFactory(new Configuration(
                                                                                           ));
                        CompressionCodec codec = codecFac.GetCodecByClassName(codecClassName);
                        if (codec == null)
                        {
                            throw new IOException("Image compression codec not supported: " + codecClassName);
                        }
                        @in = new DataInputStream(codec.CreateInputStream(@in));
                    }
                }
                ProcessINodes(@in, v, numInodes, skipBlocks, supportSnapshot);
                subtreeMap.Clear();
                dirNodeMap.Clear();
                ProcessINodesUC(@in, v, skipBlocks);
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.DelegationToken, imageVersion
                                                   ))
                {
                    ProcessDelegationTokens(@in, v);
                }
                if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.Caching, imageVersion))
                {
                    ProcessCacheManagerState(@in, v);
                }
                v.LeaveEnclosingElement();
                // FSImage
                done = true;
            }
            finally
            {
                if (done)
                {
                    v.Finish();
                }
                else
                {
                    v.FinishAbnormally();
                }
            }
        }