From hdfs-issues-return-212236-archive-asf-public=cust-asf.ponee.io@hadoop.apache.org Thu Mar 8 07:25:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id DF3DD180676 for ; Thu, 8 Mar 2018 07:25:04 +0100 (CET) Received: (qmail 27507 invoked by uid 500); 8 Mar 2018 06:25:03 -0000 Mailing-List: contact hdfs-issues-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list hdfs-issues@hadoop.apache.org Received: (qmail 27495 invoked by uid 99); 8 Mar 2018 06:25:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Mar 2018 06:25:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 097FE1A0814 for ; Thu, 8 Mar 2018 06:25:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -102.311 X-Spam-Level: X-Spam-Status: No, score=-102.311 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id z6pmCMxEqP17 for ; Thu, 8 Mar 2018 06:25:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 9C28C5F1E7 for ; Thu, 8 Mar 2018 06:25:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id F288EE0291 for ; Thu, 8 Mar 2018 06:25:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id A62BB25401 for ; Thu, 8 Mar 2018 06:25:00 +0000 (UTC) Date: Thu, 8 Mar 2018 06:25:00 +0000 (UTC) From: "liaoyuxiangqin (JIRA)" To: hdfs-issues@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (HDFS-13246) FileInputStream redundant closes in readReplicasFromCache MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HDFS-13246?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:all-tabpanel ] liaoyuxiangqin updated HDFS-13246: ---------------------------------- Attachment: HDFS-13246.001.patch > FileInputStream redundant closes in readReplicasFromCache=20 > ---------------------------------------------------------- > > Key: HDFS-13246 > URL: https://issues.apache.org/jira/browse/HDFS-13246 > Project: Hadoop HDFS > Issue Type: Improvement > Components: datanode > Affects Versions: 3.2.0 > Reporter: liaoyuxiangqin > Priority: Major > Attachments: HDFS-13246.001.patch > > > When i read the readReplicasFromCache()=C2=A0of=C2=A0BlockPoolSlice=C2=A0= class in datanode, I found the following code closes fileinputstream redund= ant, I think=C2=A0 IOUtils.closeStream(inputStream) in finally=C2=A0code bl= ock could=C2=A0guarantee close=C2=A0the inputStream=C2=A0correctly, So the > inputStream.close() can remove.=C2=A0Thanks. > =C2=A0 > {code:java|title=3DBlockPoolSlice.java|borderStyle=3Dsolid} > FileInputStream inputStream =3D null; > try { > inputStream =3D fileIoProvider.getFileInputStream(volume, replicaFi= le); > BlockListAsLongs blocksList =3D > BlockListAsLongs.readFrom(inputStream, maxDataLength); > if (blocksList =3D=3D null) { > return false; > } > for (BlockReportReplica replica : blocksList) { > switch (replica.getState()) { > case FINALIZED: > addReplicaToReplicasMap(replica, tmpReplicaMap, lazyWriteReplic= aMap, true); > break; > case RUR: > case RBW: > case RWR: > addReplicaToReplicasMap(replica, tmpReplicaMap, lazyWriteReplic= aMap, false); > break; > default: > break; > } > } > inputStream.close(); > // Now it is safe to add the replica into volumeMap > // In case of any exception during parsing this cache file, fall ba= ck > // to scan all the files on disk. > for (Iterator iter =3D > tmpReplicaMap.replicas(bpid).iterator(); iter.hasNext(); ) { > ReplicaInfo info =3D iter.next(); > // We use a lightweight GSet to store replicaInfo, we need to rem= ove > // it from one GSet before adding to another. > iter.remove(); > volumeMap.add(bpid, info); > } > LOG.info("Successfully read replica from cache file : " > + replicaFile.getPath()); > return true; > } catch (Exception e) { > // Any exception we need to revert back to read from disk > // Log the error and return false > LOG.info("Exception occurred while reading the replicas cache file:= " > + replicaFile.getPath(), e ); > return false; > } > finally { > if (!fileIoProvider.delete(volume, replicaFile)) { > LOG.info("Failed to delete replica cache file: " + > replicaFile.getPath()); > } > // close the inputStream > IOUtils.closeStream(inputStream); > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscribe@hadoop.apache.org For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org