Return-Path: X-Original-To: apmail-hadoop-hdfs-dev-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2382310B90 for ; Fri, 19 Apr 2013 18:24:51 +0000 (UTC) Received: (qmail 82566 invoked by uid 500); 19 Apr 2013 18:24:50 -0000 Delivered-To: apmail-hadoop-hdfs-dev-archive@hadoop.apache.org Received: (qmail 82472 invoked by uid 500); 19 Apr 2013 18:24:50 -0000 Mailing-List: contact hdfs-dev-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-dev@hadoop.apache.org Received: (qmail 82453 invoked by uid 99); 19 Apr 2013 18:24:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Apr 2013 18:24:50 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of atm@cloudera.com designates 209.85.223.171 as permitted sender) Received: from [209.85.223.171] (HELO mail-ie0-f171.google.com) (209.85.223.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Apr 2013 18:24:43 +0000 Received: by mail-ie0-f171.google.com with SMTP id e11so5053448iej.16 for ; Fri, 19 Apr 2013 11:24:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type:x-gm-message-state; bh=NXHgvmUAjXWgTrL4o5ACk0AFmxxviq1GwEL+Of1buWk=; b=Mt8v8QjEBTo/ND6rFBJCtWnEFXDSkk+dqvI7fQeU/3KQqAnQBXdxrp9pX0wEqa7AsB 28NZs4d2cjbanFPjUDiKnkzCphSncrsj00ugvjdAbSmXB1k/Nv6+tvRHVzoXkiV7LT/C kUC1Qap2/mN2CalyzaM7seNqgpIylMfzc4HF10ftHN4neXUx2gg/bUWL4tfJkohz90+5 qI8XbE8+H0o3lgZSJB5WaCy458I3QzCatTXEDPgL1DkBathxH4LwBP2qbz9/EFbSYRJR zXnpEseSN6gFqGFzMnBPPV1av2z6d1MbH2cts3PCJxosoXtW3puFrSaTeyKs/6Rq9I8V L+Zg== X-Received: by 10.50.79.201 with SMTP id l9mr9463844igx.79.1366395862606; Fri, 19 Apr 2013 11:24:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.70.170 with HTTP; Fri, 19 Apr 2013 11:23:52 -0700 (PDT) In-Reply-To: References: From: "Aaron T. Myers" Date: Sat, 20 Apr 2013 03:23:52 +0900 Message-ID: Subject: Re: Convention question for using DFSConfigKey constants : are zeros magic? To: "hdfs-dev@hadoop.apache.org" Content-Type: multipart/alternative; boundary=089e013cbb8a037a9f04dabad4d0 X-Gm-Message-State: ALoCoQlSGBN8WimYnazRGD/oLl2/Yb8g5vFTdqRJn8bo4mn9/sDlJvJ+dcCvYM/cuYGLzMb7HOdS X-Virus-Checked: Checked by ClamAV on apache.org --089e013cbb8a037a9f04dabad4d0 Content-Type: text/plain; charset=ISO-8859-1 Hi Jay, On Sat, Apr 20, 2013 at 1:10 AM, Jay Vyas wrote: > I recently looked into the HDFS source tree to determine idioms with > respect to a hairy debate about the threshold between what is and is not a > magic number, and found that : And it appears that the number zero is NOT > considered magic - at least not in the HDFS source code. > It's certainly not magic in the Configuration class interpretation of it, though I think if you surveyed the full source code you'd find that there won't be much consistency with regard to ad hoc checks in the code for certain values, like you've identified below. > > I found that that DFSConfigKeys.java defines DEFAULT values of zeros for > some fields, and those defaults result in non-quantitative interpretation > of the field. > > For example: > dfs.image.transfer.bandwidthPerSec > > Is commented like so: > public static final long DFS_IMAGE_TRANSFER_RATE_DEFAULT = 0; //no > throttling > > However in the implementation of these defaults, "magic" zeros are used > without commenting: > if (transferBandwidth > 0) { > throttler = new DataTransferThrottler(transferBandwidth); > } > > -------- > > Seems like the 0 above would be better replaced with > DFS_IMAGE_TRANSFER_RATE_DEFAULT since the "no throttling" behaviour is > defined with the constant in the DFSConfigKeys file, and not defined in the > > hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/GetImageServlet.java. > I don't agree with this. What if we later changed the default to something greater than 0 in DFSConfigKeys? If the code were comparing against the value DFS_IMAGE_TRANSFER_RATE_DEFAULT, the check in the code would then be wrong. The only value for that config that should denote "no throttling" is 0, regardless of what the default is, so the explicit comparison against 0 makes sense to me. > > > -------- > > Trying to get a feel for if there are conventions to enforce in some code > reviews for our hadoop dependent configuration code. We'd like to follow > hadoopy idioms if possible.. > I'd say the main conventions you should concern yourself with for this purpose is config setting naming, e.g. use consistent prefixes within your own code, use lower case separated by dots.and-dashes, etc. > > > -- > Jay Vyas > http://jayunit100.blogspot.com > --089e013cbb8a037a9f04dabad4d0--