示例#1
0
        /// <exception cref="System.IO.IOException"/>
        public static InputStream WrapInputStreamForCompression(Configuration conf, string
                                                                codec, InputStream @in)
        {
            if (codec.IsEmpty())
            {
                return(@in);
            }
            FSImageCompression compression = FSImageCompression.CreateCompression(conf, codec
                                                                                  );
            CompressionCodec imageCodec = compression.GetImageCodec();

            return(imageCodec.CreateInputStream(@in));
        }
            /// <exception cref="System.IO.IOException"/>
            private void SaveInternal(FileOutputStream fout, FSImageCompression compression,
                                      string filePath)
            {
                StartupProgress prog     = NameNode.GetStartupProgress();
                MessageDigest   digester = MD5Hash.GetDigester();

                underlyingOutputStream = new DigestOutputStream(new BufferedOutputStream(fout), digester
                                                                );
                underlyingOutputStream.Write(FSImageUtil.MagicHeader);
                fileChannel = fout.GetChannel();
                FsImageProto.FileSummary.Builder b = FsImageProto.FileSummary.NewBuilder().SetOndiskVersion
                                                         (FSImageUtil.FileVersion).SetLayoutVersion(NameNodeLayoutVersion.CurrentLayoutVersion
                                                                                                    );
                codec = compression.GetImageCodec();
                if (codec != null)
                {
                    b.SetCodec(codec.GetType().GetCanonicalName());
                    sectionOutputStream = codec.CreateOutputStream(underlyingOutputStream);
                }
                else
                {
                    sectionOutputStream = underlyingOutputStream;
                }
                SaveNameSystemSection(b);
                // Check for cancellation right after serializing the name system section.
                // Some unit tests, such as TestSaveNamespace#testCancelSaveNameSpace
                // depends on this behavior.
                context.CheckCancelled();
                Step step = new Step(StepType.Inodes, filePath);

                prog.BeginStep(Phase.SavingCheckpoint, step);
                SaveInodes(b);
                SaveSnapshots(b);
                prog.EndStep(Phase.SavingCheckpoint, step);
                step = new Step(StepType.DelegationTokens, filePath);
                prog.BeginStep(Phase.SavingCheckpoint, step);
                SaveSecretManagerSection(b);
                prog.EndStep(Phase.SavingCheckpoint, step);
                step = new Step(StepType.CachePools, filePath);
                prog.BeginStep(Phase.SavingCheckpoint, step);
                SaveCacheManagerSection(b);
                prog.EndStep(Phase.SavingCheckpoint, step);
                SaveStringTableSection(b);
                // We use the underlyingOutputStream to write the header. Therefore flush
                // the buffered stream (which is potentially compressed) first.
                FlushSectionOutputStream();
                FsImageProto.FileSummary summary = ((FsImageProto.FileSummary)b.Build());
                SaveFileSummary(underlyingOutputStream, summary);
                underlyingOutputStream.Close();
                savedDigest = new MD5Hash(digester.Digest());
            }
            /// <exception cref="System.IO.IOException"/>
            internal void Save(FilePath file, FSImageCompression compression)
            {
                FileOutputStream fout = new FileOutputStream(file);

                fileChannel = fout.GetChannel();
                try
                {
                    SaveInternal(fout, compression, file.GetAbsolutePath());
                }
                finally
                {
                    fout.Close();
                }
            }
示例#4
0
        /// <summary>Save the fsimage to a temp file</summary>
        /// <exception cref="System.IO.IOException"/>
        private FilePath SaveFSImageToTempFile()
        {
            SaveNamespaceContext context = new SaveNamespaceContext(fsn, txid, new Canceler()
                                                                    );

            FSImageFormatProtobuf.Saver saver       = new FSImageFormatProtobuf.Saver(context);
            FSImageCompression          compression = FSImageCompression.CreateCompression(conf);
            FilePath imageFile = GetImageFile(testDir, txid);

            fsn.ReadLock();
            try
            {
                saver.Save(imageFile, compression);
            }
            finally
            {
                fsn.ReadUnlock();
            }
            return(imageFile);
        }