/// <exception cref="System.IO.FileNotFoundException"/> /// <exception cref="System.IO.IOException"/> private static void WriteFileToPutRequest(Configuration conf, HttpURLConnection connection , FilePath imageFile, Canceler canceler) { connection.SetRequestProperty(ContentType, "application/octet-stream"); connection.SetRequestProperty(ContentTransferEncoding, "binary"); OutputStream output = connection.GetOutputStream(); FileInputStream input = new FileInputStream(imageFile); try { CopyFileToStream(output, imageFile, input, ImageServlet.GetThrottler(conf), canceler ); } finally { IOUtils.CloseStream(input); IOUtils.CloseStream(output); } }
/// <exception cref="System.Exception"/> public Void Run() { long txid = parsedParams.GetTxId(); NNStorage.NameNodeFile nnf = parsedParams.GetNameNodeFile(); if (!nnImage.AddToCheckpointing(txid)) { response.SendError(HttpServletResponse.ScConflict, "Either current namenode is checkpointing or another" + " checkpointer is already in the process of " + "uploading a checkpoint made at transaction ID " + txid); return(null); } try { if (nnImage.GetStorage().FindImageFile(nnf, txid) != null) { response.SendError(HttpServletResponse.ScConflict, "Either current namenode has checkpointed or " + "another checkpointer already uploaded an " + "checkpoint for txid " + txid); return(null); } InputStream stream = request.GetInputStream(); try { long start = Time.MonotonicNow(); MD5Hash downloadImageDigest = TransferFsImage.HandleUploadImageRequest(request, txid , nnImage.GetStorage(), stream, parsedParams.GetFileSize(), ImageServlet.GetThrottler (conf)); nnImage.SaveDigestAndRenameCheckpointImage(nnf, txid, downloadImageDigest); if (metrics != null) { long elapsed = Time.MonotonicNow() - start; metrics.AddPutImage(elapsed); } nnImage.PurgeOldStorage(nnf); } finally { stream.Close(); } } finally { nnImage.RemoveFromCheckpointing(txid); } return(null); }
/// <exception cref="System.IO.IOException"/> private void ServeFile(FilePath file) { FileInputStream fis = new FileInputStream(file); try { ImageServlet.SetVerificationHeadersForGet(response, file); ImageServlet.SetFileNameHeaders(response, file); if (!file.Exists()) { throw new FileNotFoundException(file.ToString()); } TransferFsImage.CopyFileToStream(response.GetOutputStream(), file, fis, ImageServlet .GetThrottler(conf)); } finally { IOUtils.CloseStream(fis); } }