Skip to content

Commit d9a468e

Browse files
committed
Debug shim for the GlusterFileSystem. Just replace GlusterFileSystem with GlusterDebugFileSystem in the core-site.xml, and every call to GlusterFileSystem will be logged in /tmp/glusterfs-X.log. See source for details
1 parent 6d4b387 commit d9a468e

File tree

1 file changed

+260
-0
lines changed

1 file changed

+260
-0
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/**
2+
*
3+
* Copyright (c) 2011 Red Hat Inc <http://www.redhat.com>
4+
* This file is part of GlusterFS.
5+
*
6+
* Licensed under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
* implied. See the License for the specific language governing
16+
* permissions and limitations under the License.
17+
*
18+
*/
19+
20+
/**
21+
* Hard-core debugging shim which uses the GlusterFileSystem super class for the heavy lifting, but logs every call
22+
* to /tmp/glusterfs-N.log
23+
*
24+
* This Shim can be interchanged with the GlusterFileSystem to debug calls.
25+
*
26+
* Each JVM instance of GlusterDebugFileSystem will generate a new log, incremented on what's already there.
27+
*
28+
* To use, specify this class as your file system in hadoop:
29+
*
30+
* <property>
31+
* <name>fs.glusterfs.impl</name>
32+
* <value>org.apache.hadoop.fs.glusterfs.GlusterDebugFileSystem</value>
33+
* </property>
34+
*
35+
* Authoer: [email protected]
36+
*
37+
*
38+
*/
39+
40+
package org.apache.hadoop.fs.glusterfs;
41+
42+
import java.io.BufferedWriter;
43+
import java.io.File;
44+
import java.io.FileNotFoundException;
45+
import java.io.FileWriter;
46+
import java.io.IOException;
47+
import java.io.PrintWriter;
48+
import java.net.URI;
49+
import java.text.DateFormat;
50+
import java.text.SimpleDateFormat;
51+
import java.util.Date;
52+
53+
import org.apache.hadoop.conf.Configuration;
54+
import org.apache.hadoop.fs.BlockLocation;
55+
import org.apache.hadoop.fs.FSDataInputStream;
56+
import org.apache.hadoop.fs.FSDataOutputStream;
57+
import org.apache.hadoop.fs.FileStatus;
58+
import org.apache.hadoop.fs.Path;
59+
import org.apache.hadoop.fs.permission.FsPermission;
60+
import org.apache.hadoop.util.Progressable;
61+
62+
public class GlusterDebugFileSystem extends GlusterFileSystem{
63+
64+
private static File logFile=null;
65+
private static final String LOG_PREFIX="/tmp/glusterfs";
66+
67+
public static synchronized void logMachine(String text){
68+
69+
DateFormat dateFormat=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
70+
Date date=new Date();
71+
72+
if(logFile==null){
73+
for(int i=0;i<1000000;i++){
74+
logFile=new File(LOG_PREFIX+"-"+i+".log");
75+
if(!logFile.exists()){
76+
try{
77+
logFile.createNewFile();
78+
break;
79+
}catch (IOException e){
80+
}
81+
}
82+
}
83+
}
84+
85+
try{
86+
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(logFile, true)));
87+
out.write(dateFormat.format(date)+" : "+text+"\n");
88+
out.close();
89+
}catch (FileNotFoundException e){
90+
e.printStackTrace();
91+
}catch (IOException e){
92+
e.printStackTrace();
93+
}
94+
95+
}
96+
public void initialize(URI uri,Configuration conf) throws IOException{
97+
GlusterDebugFileSystem.logMachine("Init of the GlusterDebugFileSystem....");
98+
GlusterDebugFileSystem.logMachine("init(" + uri + "," + conf);
99+
super.initialize(uri,conf);
100+
}
101+
102+
public URI getUri(){
103+
GlusterDebugFileSystem.logMachine("getUri()");
104+
return super.getUri();
105+
}
106+
107+
public String getName(){
108+
GlusterDebugFileSystem.logMachine("getName()");
109+
return super.getName();
110+
}
111+
112+
public Path getWorkingDirectory(){
113+
GlusterDebugFileSystem.logMachine("getWorkingDirectory()");
114+
return super.getWorkingDirectory();
115+
}
116+
117+
public Path getHomeDirectory(){
118+
GlusterDebugFileSystem.logMachine("getHomeDirectory()");
119+
return super.getHomeDirectory();
120+
}
121+
122+
public void setWorkingDirectory(Path dir){
123+
GlusterDebugFileSystem.logMachine("setWorkingDirectory("+dir+")");
124+
super.setWorkingDirectory(dir);
125+
}
126+
127+
public boolean exists(Path path) throws IOException{
128+
GlusterDebugFileSystem.logMachine("exists("+path+")");
129+
return super.exists(path);
130+
}
131+
132+
public boolean mkdirs(Path path,FsPermission permission) throws IOException{
133+
GlusterDebugFileSystem.logMachine("mkdirs("+path+","+permission+")");
134+
return super.mkdirs(path, permission);
135+
}
136+
137+
@Deprecated
138+
public boolean isDirectory(Path path) throws IOException{
139+
GlusterDebugFileSystem.logMachine("isDirectory("+path+")");
140+
return super.isDirectory(path);
141+
}
142+
143+
public boolean isFile(Path path) throws IOException{
144+
GlusterDebugFileSystem.logMachine("isFile("+path+")");
145+
return super.isFile(path);
146+
}
147+
148+
public Path[] listPaths(Path path) throws IOException{
149+
GlusterDebugFileSystem.logMachine("listPaths("+path+")");
150+
return super.listPaths(path);
151+
}
152+
153+
public FileStatus[] listStatus(Path path) throws IOException{
154+
GlusterDebugFileSystem.logMachine("listStatus("+path+")");
155+
return super.listStatus(path);
156+
157+
}
158+
159+
public FileStatus getFileStatusFromFileString(String path) throws IOException{
160+
GlusterDebugFileSystem.logMachine("getFileStatusFromFileString("+path+")");
161+
return super.getFileStatusFromFileString(path);
162+
}
163+
164+
public void setPermission(Path p,FsPermission permission){
165+
GlusterDebugFileSystem.logMachine("setPermission("+p+","+permission+")");
166+
super.setPermission(p, permission);
167+
}
168+
169+
public FileStatus getFileStatus(Path path) throws IOException{
170+
GlusterDebugFileSystem.logMachine("getFileStatus("+path+")");
171+
return super.getFileStatus(path);
172+
}
173+
174+
public FSDataOutputStream create(Path path,FsPermission permission,boolean overwrite,int bufferSize,short replication,long blockSize,Progressable progress) throws IOException{
175+
GlusterDebugFileSystem.logMachine("create("+path+","+permission+","+(overwrite ? "true" : "false")+","+bufferSize+","+replication+","+blockSize+",progress"+"):");
176+
return super.create(path, permission, overwrite, bufferSize, replication, blockSize, progress);
177+
}
178+
179+
public FSDataInputStream open(Path path) throws IOException{
180+
GlusterDebugFileSystem.logMachine("open("+path+")");
181+
return super.open(path);
182+
}
183+
184+
public FSDataInputStream open(Path path,int bufferSize) throws IOException{
185+
GlusterDebugFileSystem.logMachine("open("+path+","+bufferSize+")");
186+
return super.open(path, bufferSize);
187+
}
188+
189+
public FSDataOutputStream append(Path f,int bufferSize,Progressable progress) throws IOException{
190+
GlusterDebugFileSystem.logMachine("append("+f+","+bufferSize+",progress)");
191+
return super.append(f, bufferSize, progress);
192+
}
193+
194+
public boolean rename(Path src,Path dst) throws IOException{
195+
GlusterDebugFileSystem.logMachine("rename("+src+","+dst+")");
196+
return super.rename(src, dst);
197+
}
198+
199+
public boolean delete(Path path) throws IOException{
200+
GlusterDebugFileSystem.logMachine("delete("+path+")");
201+
return super.delete(path);
202+
}
203+
204+
public boolean delete(Path path,boolean recursive) throws IOException{
205+
GlusterDebugFileSystem.logMachine("delete("+path+(recursive ? ",true" : ",false")+"): ");
206+
return super.delete(path, recursive);
207+
}
208+
209+
@Deprecated
210+
public long getLength(Path path) throws IOException{
211+
GlusterDebugFileSystem.logMachine("getLength("+path+") ");
212+
return super.getLength(path);
213+
}
214+
215+
public short getDefaultReplication(Path path) throws IOException{
216+
GlusterDebugFileSystem.logMachine("getDefaultReplication("+path+") ");
217+
return super.getDefaultReplication(path);
218+
}
219+
220+
public long getBlockSize(Path path) throws IOException{
221+
GlusterDebugFileSystem.logMachine("getBlockSize("+path+") ");
222+
return super.getBlockSize(path);
223+
}
224+
225+
public long getDefaultBlockSize(){
226+
GlusterDebugFileSystem.logMachine("getDefaultBlockSize() ");
227+
return super.getDefaultBlockSize();
228+
}
229+
230+
public BlockLocation[] getFileBlockLocations(FileStatus file,long start,long len) throws IOException{
231+
GlusterDebugFileSystem.logMachine("getFileBlockLocations("+file+","+start+","+len+")");
232+
return super.getFileBlockLocations(file, start, len);
233+
}
234+
235+
public void setOwner(Path p,String username,String groupname) throws IOException{
236+
GlusterDebugFileSystem.logMachine("setOwner("+p+","+username+","+groupname+")");
237+
super.setOwner(p, username, groupname);
238+
}
239+
240+
public void copyFromLocalFile(boolean delSrc,Path src,Path dst) throws IOException{
241+
GlusterDebugFileSystem.logMachine("copyFromLocalFile("+delSrc+","+src+","+dst+")");
242+
super.copyFromLocalFile(delSrc, src, dst);
243+
}
244+
245+
public void copyToLocalFile(boolean delSrc,Path src,Path dst) throws IOException{
246+
GlusterDebugFileSystem.logMachine("copyFromLocalFile("+delSrc+","+src+","+dst+")");
247+
super.copyToLocalFile(delSrc, src, dst);
248+
}
249+
250+
public Path startLocalOutput(Path fsOutputFile,Path tmpLocalFile) throws IOException{
251+
GlusterDebugFileSystem.logMachine("startLocalOutput("+fsOutputFile+","+tmpLocalFile+")");
252+
return super.startLocalOutput(fsOutputFile, tmpLocalFile);
253+
}
254+
255+
public void completeLocalOutput(Path fsOutputFile,Path tmpLocalFile) throws IOException{
256+
GlusterDebugFileSystem.logMachine("completeLocalOutput("+fsOutputFile+","+tmpLocalFile+")");
257+
super.completeLocalOutput(fsOutputFile, tmpLocalFile);
258+
}
259+
260+
}

0 commit comments

Comments
 (0)