Return-Path: X-Original-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3EE87D96C for ; Sat, 27 Oct 2012 16:00:08 +0000 (UTC) Received: (qmail 32984 invoked by uid 500); 27 Oct 2012 16:00:03 -0000 Delivered-To: apmail-hadoop-mapreduce-user-archive@hadoop.apache.org Received: (qmail 32492 invoked by uid 500); 27 Oct 2012 16:00:00 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 32446 invoked by uid 99); 27 Oct 2012 15:59:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Oct 2012 15:59:59 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of liulei412@gmail.com designates 74.125.82.176 as permitted sender) Received: from [74.125.82.176] (HELO mail-we0-f176.google.com) (74.125.82.176) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Oct 2012 15:59:53 +0000 Received: by mail-we0-f176.google.com with SMTP id z53so2097088wey.35 for ; Sat, 27 Oct 2012 08:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=jdmtJarFAz6SRbA132k3u01UYqXu27Xet64WYfNN4RQ=; b=Zu1SUBQhszS0J/inkSvBIkJYM1BAKpN8f6zhT6G3kK7dWTHlhwJkKWNEpakXGHv7/h lRQWjM2U4jYmoTZLVLWVZLWSSRDbwIUjg5MpGUmQzTy1SuUJoM0mflAq5uXs9Gf3y0U9 Fgat0ZfjEqpJXb17qT3psL26sanxlSuOmkowaqk4XBr6ciu7GSx3GZ1Tty1cWAQSWl6x wfT7zTb4Ascy0dRU67kN55WadUC2YBl+42V+9FQTxSL8+BlB+Q/1jUxfbtoVn/YkxC0A SLgEME/V9mqWc1RVgTb4omIl3o2gi5X5peKRZQN/qAgxU9xG0goP3AF+petLkWlXG+9g 1CDA== MIME-Version: 1.0 Received: by 10.180.96.129 with SMTP id ds1mr8991233wib.17.1351353571881; Sat, 27 Oct 2012 08:59:31 -0700 (PDT) Received: by 10.216.106.67 with HTTP; Sat, 27 Oct 2012 08:59:31 -0700 (PDT) In-Reply-To: References: Date: Sat, 27 Oct 2012 23:59:31 +0800 Message-ID: Subject: Re: HDFS HA IO Fencing From: lei liu To: user@hadoop.apache.org Content-Type: multipart/alternative; boundary=f46d044282a09e324c04cd0c8539 X-Virus-Checked: Checked by ClamAV on apache.org --f46d044282a09e324c04cd0c8539 Content-Type: text/plain; charset=ISO-8859-1 I use NFS V4 to test the java FileLock. The 192.168.1.233 machine is NFS Server, the nfs configuration are /home/hdfs.ha/share 192.168.1.221(rw,sync,no_root_squash) /home/hdfs.ha/share 192.168.1.222(rw,sync,no_root_squash) in /etc/exports file. I run below commands to start nfs server: service nfs start service nfslock start The 192.168.1.221 and 192.168.1.222 machines are NFS Client, the nfs configuration is 192.168.1.223:/home/hdfs.ha/share /home/hdfs.ha/share nfs rsize=8192,wsize=8192,timeo=14,intr in /etc/fstab file. I run below commands to start nfs client: service nfs start service nfslock start I write one programm to receive file lock: public class FileLockTest { FileLock lock; public void lock(String path,boolean isShare) throws IOException { this.lock = tryLock(path,isShare); if (lock == null) { String msg = "Cannot lock storage " + path + ". The directory is already locked."; System.out.println(msg); throw new IOException(msg); } } private FileLock tryLock(String path,boolean isShare) throws IOException { boolean deletionHookAdded = false; File lockF = new File(path); if (!lockF.exists()) { lockF.deleteOnExit(); deletionHookAdded = true; } RandomAccessFile file = new RandomAccessFile(lockF, "rws"); FileLock res = null; try { res = file.getChannel().tryLock(0,Long.MAX_VALUE,isShare); } catch (OverlappingFileLockException oe) { file.close(); return null; } catch (IOException e) { e.printStackTrace(); file.close(); throw e; } if (res != null && !deletionHookAdded) { // If the file existed prior to our startup, we didn't // call deleteOnExit above. But since we successfully locked // the dir, we can take care of cleaning it up. lockF.deleteOnExit(); } return res; } public static void main(String[] s) { FileLockTest fileLockTest =new FileLockTest(); try { fileLockTest.lock(s[0], Boolean.valueOf(s[1])); Thread.sleep(1000*60*60*1); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } I do two test cases. 1. The network is OK I run " java -cp ./filelock.jar lock.FileLockTest /home/hdfs.ha/share/test.lock false" command in 192.168.1.221 to hold file lock, and then I run same command to hold same file lock in 192.168.1.222, throw below exception: Cannot lock storage /home/hdfs.ha/share/test.lock. The directory is already locked. java.io.IOException: Cannot lock storage /home/hdfs.ha/share/test.lock. The directory is already locked. at lock.FileLockTest.lock(FileLockTest.java:18) at lock.FileLockTest.main(FileLockTest.java:53) 2. machine which hold file lock is diconnected I run " java -cp ./filelock.jar lock.FileLockTest /home/hdfs.ha/share/test.lock false" command on 192.168.1.221, then 192.168.1.221 machine is disconnected from network . After three minutes , I run the " java -cp ./filelock.jar lock.FileLockTest /home/hdfs.ha/share/test.lock false" command on 192.168.1.222, that can hold the file lock. I use "mount | grep nfs" command to examine the mount nfs directory on 192.168.1.221, the share directory /home/hdfs.ha/share/ is disappear on 192.168.1.221 machine. So I think when the machine is disconnected for a long time, other machine can receive the same file lock. --f46d044282a09e324c04cd0c8539 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I use NFS V4 to test the java =A0FileLock.
=A0
The= 192.168.1.233 machine is NFS Server,=A0 the nfs configuration =A0are
=
/home/hdfs.ha/share=A0 192.168.1.221(rw,sync,no_root_squash)
/home/= hdfs.ha/share=A0 192.168.1.222(rw,sync,no_root_squash)
in /etc/exports file.
=A0
I run below commands to = start nfs server:
service nfs start
service nfslock sta= rt
=A0
The 192.168.1.221 and 192.168.1.222 machines are= NFS Client, the nfs configuration is=A0
192.168.1.223:/home/hdfs.ha/share /home/hdfs.ha/share=A0 nfs rsize=3D8= 192,wsize=3D8192,timeo=3D14,intr in /etc/fstab file.
=A0
I run below commands to start nfs client:
service nfs star= t
service nfslock start
=A0
I write one programm to = receive file lock:
public class FileLockTest {
=A0FileLock loc= k;
=A0
=A0=A0 public void lock(String path,boolean isShare) throws IO= Exception {
=A0=A0=A0=A0=A0=A0 this.lock =3D tryLock(path,isShare);
=A0=A0=A0=A0=A0= =A0 if (lock =3D=3D null) {
=A0=A0=A0=A0=A0=A0=A0=A0 String msg =3D &quo= t;Cannot lock storage " + path
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= + ". The directory is already locked.";
=A0=A0=A0=A0=A0=A0=A0= System.out.println(msg);
=A0=A0=A0=A0=A0=A0=A0=A0 throw new IOException(msg);
=A0=A0=A0=A0=A0=A0 = }
=A0=A0=A0=A0 }
=A0=A0
=A0=A0=A0 private FileLock tryLock(String= path,boolean isShare) throws IOException {
=A0=A0=A0=A0=A0=A0=A0 boolea= n deletionHookAdded =3D false;
=A0=A0=A0=A0=A0=A0=A0 File lockF =3D new = File(path);
=A0=A0=A0=A0=A0=A0=A0 if (!lockF.exists()) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0= lockF.deleteOnExit();
=A0=A0=A0=A0=A0=A0=A0=A0=A0 deletionHookAdded =3D= true;
=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 RandomAccessFile= file =3D new RandomAccessFile(lockF, "rws");
=A0=A0=A0=A0=A0= =A0=A0 FileLock res =3D null;
=A0=A0=A0=A0=A0=A0=A0 try {
=A0=A0=A0=A0=A0=A0=A0=A0=A0 res =3D file.get= Channel().tryLock(0,Long.MAX_VALUE,isShare);
=A0=A0=A0=A0=A0=A0=A0 } cat= ch (OverlappingFileLockException oe) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0 file.= close();
=A0=A0=A0=A0=A0=A0=A0=A0=A0 return null;
=A0=A0=A0=A0=A0=A0= =A0 } catch (IOException e) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0 e.printStackTrace();
=A0=A0=A0=A0=A0=A0=A0= =A0=A0 file.close();
=A0=A0=A0=A0=A0=A0=A0=A0=A0 throw e;
=A0=A0=A0= =A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 if (res !=3D null && !delet= ionHookAdded) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0 // If the file existed prior= to our startup, we didn't
=A0=A0=A0=A0=A0=A0=A0=A0=A0 // call deleteOnExit above. But since we succes= sfully locked
=A0=A0=A0=A0=A0=A0=A0=A0=A0 // the dir, we can take care o= f cleaning it up.
=A0=A0=A0=A0=A0=A0=A0=A0=A0 lockF.deleteOnExit();
= =A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 return res;
=A0=A0=A0= =A0=A0 }
=A0=A0=A0
=A0=A0=A0 public static void main(String[] s) {
=A0=A0=A0=A0 FileLockTes= t fileLockTest =3Dnew FileLockTest();
=A0=A0=A0=A0 try {
=A0=A0=A0=A0= =A0 fileLockTest.lock(s[0], Boolean.valueOf(s[1]));
=A0=A0=A0=A0=A0
= =A0=A0=A0=A0=A0 Thread.sleep(1000*60*60*1);
=A0=A0=A0=A0 } catch (Except= ion e) {
=A0=A0=A0=A0=A0 // TODO Auto-generated catch block
=A0=A0=A0=A0=A0 e.pri= ntStackTrace();
=A0=A0=A0=A0 }
=A0=A0=A0 }
}
=A0
I do two test cases.
=A0
1. The network is OK
<= div>I run "=A0java -cp ./filelock.jar lock.FileLockTest /home/hdfs.ha/= share/test.lock false" command in 192.168.1.221 to hold file lock, and= then I run same command to hold same file lock in 192.168.1.222, throw bel= ow exception:
Cannot lock storage /home/hdfs.ha/share/test.lock. The directory is al= ready locked.
java.io.IOException: Cannot lock storage /home/hdfs.ha/sha= re/test.lock. The directory is already locked.
=A0=A0=A0=A0=A0=A0=A0 at = lock.FileLockTest.lock(FileLockTest.java:18)
=A0=A0=A0=A0=A0=A0=A0 at lock.FileLockTest.main(FileLockTest.java:53)
=
=A0
2. machine which hold file lock=A0is diconnected
<= div>I run " java -cp ./filelock.jar lock.FileLockTest /home/hdfs.ha/sh= are/test.lock false" command=A0on=A0192.168.1.221,=A0=A0then 192.168.1= .221 =A0machine is=A0disconnected from=A0network . After three minutes , I = run the "=A0 java -cp ./filelock.jar lock.FileLockTest /home/hdfs.ha/s= hare/test.lock false" command on 192.168.1.222, that can hold the file= lock.=A0
=A0I use "mount | grep nfs" command to examine the mount nfs= directory on 192.168.1.221, the share directory /home/hdfs.ha/share/ is di= sappear on=A0 192.168.1.221 machine.=A0 So I think when the machine is disc= onnected for a=A0long time, other machine can receive the same file lock.
=A0
=A0
=A0
=A0
=A0
=A0
=A0
=A0
=A0
=A0
=A0
--f46d044282a09e324c04cd0c8539--