Author: cutting Date: Thu Jun 21 11:09:50 2007 New Revision: 549576 URL: http://svn.apache.org/viewvc?view=rev&rev=549576 Log: HADOOP-1283. Convert most uses of UTF8 in the namenode to be String. Contributed by Konstantin.
Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FileUnderConstruction.java lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/PendingCreates.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Thu Jun 21 11:09:50 2007 @@ -228,6 +228,9 @@ 69. HADOOP-1147. Remove @author tags from Java source files. + 70. HADOOP-1283. Convert most uses of UTF8 in the namenode to be + String. (Konstantin Shvachko via cutting) + Release 0.13.0 - 2007-06-08 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java Thu Jun 21 11:09:50 2007 @@ -17,8 +17,6 @@ */ package org.apache.hadoop.dfs; -import org.apache.hadoop.io.*; - import java.io.*; import java.util.*; @@ -308,8 +306,8 @@ FSNamesystem namesystem = null; INode rootDir = new INode(""); - TreeMap<UTF8, TreeSet<UTF8>> activeLocks = - new TreeMap<UTF8, TreeSet<UTF8>>(); + TreeMap<StringBytesWritable, TreeSet<StringBytesWritable>> activeLocks = + new TreeMap<StringBytesWritable, TreeSet<StringBytesWritable>>(); FSImage fsImage; boolean ready = false; // Metrics record @@ -384,15 +382,14 @@ /** * Add the given filename to the fs. */ - public boolean addFile(UTF8 path, Block[] blocks, short replication) { + public boolean addFile(String path, Block[] blocks, short replication) { waitForReady(); // Always do an implicit mkdirs for parent directory tree - String pathString = path.toString(); - if (!mkdirs(new Path(pathString).getParent().toString())) { + if (!mkdirs(new Path(path).getParent().toString())) { return false; } - INode newNode = new INode(new File(pathString).getName(), blocks, replication); + INode newNode = new INode(new File(path).getName(), blocks, replication); if (!unprotectedAddFile(path, newNode)) { NameNode.stateChangeLog.info("DIR* FSDirectory.addFile: " +"failed to add "+path+" with " @@ -408,10 +405,10 @@ /** */ - boolean unprotectedAddFile(UTF8 path, INode newNode) { + boolean unprotectedAddFile(String path, INode newNode) { synchronized (rootDir) { try { - if (rootDir.addNode(path.toString(), newNode) != null) { + if (rootDir.addNode(path, newNode) != null) { int nrBlocks = (newNode.blocks == null) ? 0 : newNode.blocks.length; // Add file->block mapping for (int i = 0; i < nrBlocks; i++) @@ -426,15 +423,15 @@ } } - boolean unprotectedAddFile(UTF8 path, Block[] blocks, short replication) { + boolean unprotectedAddFile(String path, Block[] blocks, short replication) { return unprotectedAddFile(path, - new INode(path.toString(), blocks, replication)); + new INode(path, blocks, replication)); } /** * Change the filename */ - public boolean renameTo(UTF8 src, UTF8 dst) { + public boolean renameTo(String src, String dst) { NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " +src+" to "+dst); waitForReady(); @@ -446,29 +443,27 @@ /** */ - boolean unprotectedRenameTo(UTF8 src, UTF8 dst) { + boolean unprotectedRenameTo(String src, String dst) { synchronized(rootDir) { - String srcStr = src.toString(); - String dstStr = dst.toString(); - INode renamedNode = rootDir.getNode(srcStr); + INode renamedNode = rootDir.getNode(src); if (renamedNode == null) { NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: " +"failed to rename "+src+" to "+dst+ " because source does not exist"); return false; } if (isDir(dst)) { - dstStr += "/" + new File(srcStr).getName(); + dst += "/" + new File(src).getName(); } - if (rootDir.getNode(dstStr) != null) { + if (rootDir.getNode(dst) != null) { NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: " - +"failed to rename "+src+" to "+dstStr+ " because destination exists"); + +"failed to rename "+src+" to "+dst+ " because destination exists"); return false; } renamedNode.removeNode(); // the renamed node can be reused now try { - if (rootDir.addNode(dstStr, renamedNode) != null) { + if (rootDir.addNode(dst, renamedNode) != null) { NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedRenameTo: " +src+" is renamed to "+dst); return true; @@ -477,7 +472,7 @@ NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: " +"failed to rename "+src+" to "+dst); try { - rootDir.addNode(srcStr, renamedNode); // put it back + rootDir.addNode(src, renamedNode); // put it back }catch(FileNotFoundException e2) { } } @@ -550,7 +545,7 @@ /** * Remove the file from management, return blocks */ - public Block[] delete(UTF8 src) { + public Block[] delete(String src) { NameNode.stateChangeLog.debug("DIR* FSDirectory.delete: " +src); waitForReady(); @@ -562,9 +557,9 @@ /** */ - Block[] unprotectedDelete(UTF8 src) { + Block[] unprotectedDelete(String src) { synchronized (rootDir) { - INode targetNode = rootDir.getNode(src.toString()); + INode targetNode = rootDir.getNode(src); if (targetNode == null) { NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedDelete: " +"failed to remove "+src+" because it does not exist"); @@ -594,28 +589,31 @@ /** */ - public int obtainLock(UTF8 src, UTF8 holder, boolean exclusive) { - TreeSet<UTF8> holders = activeLocks.get(src); + public int obtainLock(String src, String holder, boolean exclusive) throws IOException { + StringBytesWritable srcSBW = new StringBytesWritable(src); + TreeSet<StringBytesWritable> holders = activeLocks.get(srcSBW); if (holders == null) { - holders = new TreeSet<UTF8>(); - activeLocks.put(src, holders); + holders = new TreeSet<StringBytesWritable>(); + activeLocks.put(srcSBW, holders); } if (exclusive && holders.size() > 0) { return STILL_WAITING; } else { - holders.add(holder); + holders.add(new StringBytesWritable(holder)); return COMPLETE_SUCCESS; } } /** */ - public int releaseLock(UTF8 src, UTF8 holder) { - TreeSet holders = (TreeSet) activeLocks.get(src); - if (holders != null && holders.contains(holder)) { - holders.remove(holder); + public int releaseLock(String src, String holder) throws IOException { + StringBytesWritable srcSBW = new StringBytesWritable(src); + StringBytesWritable holderSBW = new StringBytesWritable(holder); + TreeSet<StringBytesWritable> holders = activeLocks.get(srcSBW); + if (holders != null && holders.contains(holderSBW)) { + holders.remove(holderSBW); if (holders.size() == 0) { - activeLocks.remove(src); + activeLocks.remove(srcSBW); } return COMPLETE_SUCCESS; } else { @@ -629,7 +627,7 @@ * This function is admittedly very inefficient right now. We'll * make it better later. */ - public DFSFileInfo[] getListing(UTF8 src) { + public DFSFileInfo[] getListing(String src) { String srcs = normalizePath(src); synchronized (rootDir) { @@ -678,7 +676,7 @@ /** * Check whether the filepath could be created */ - public boolean isValidToCreate(UTF8 src) { + public boolean isValidToCreate(String src) { String srcs = normalizePath(src); synchronized (rootDir) { if (srcs.startsWith("/") && @@ -694,7 +692,7 @@ /** * Check whether the path specifies a directory */ - public boolean isDir(UTF8 src) { + public boolean isDir(String src) { synchronized (rootDir) { INode node = rootDir.getNode(normalizePath(src)); return node != null && node.isDir(); @@ -705,7 +703,7 @@ * Create directory entries for every item */ boolean mkdirs(String src) { - src = normalizePath(new UTF8(src)); + src = normalizePath(src); // Use this to collect all the dirs we need to construct Vector<String> v = new Vector<String>(); @@ -732,7 +730,7 @@ +"created directory "+cur); fsImage.getEditLog().logMkDir(inserted); } else { // otherwise cur exists, verify that it is a directory - if (!isDir(new UTF8(cur))) { + if (!isDir(cur)) { NameNode.stateChangeLog.debug("DIR* FSDirectory.mkdirs: " +"path " + cur + " is not a directory "); return false; @@ -757,11 +755,10 @@ /** */ - String normalizePath(UTF8 src) { - String srcs = src.toString(); - if (srcs.length() > 1 && srcs.endsWith("/")) { - srcs = srcs.substring(0, srcs.length() - 1); + String normalizePath(String src) { + if (src.length() > 1 && src.endsWith("/")) { + src = src.substring(0, src.length() - 1); } - return srcs; + return src; } } Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java Thu Jun 21 11:09:50 2007 @@ -262,7 +262,7 @@ Block blocks[] = new Block[writables.length]; System.arraycopy(writables, 0, blocks, 0, blocks.length); // add to the file tree - fsDir.unprotectedAddFile(name, blocks, replication); + fsDir.unprotectedAddFile(name.toString(), blocks, replication); break; } case OP_SET_REPLICATION: { @@ -281,13 +281,13 @@ UTF8 dst = new UTF8(); src.readFields(in); dst.readFields(in); - fsDir.unprotectedRenameTo(src, dst); + fsDir.unprotectedRenameTo(src.toString(), dst.toString()); break; } case OP_DELETE: { UTF8 src = new UTF8(); src.readFields(in); - fsDir.unprotectedDelete(src); + fsDir.unprotectedDelete(src.toString()); break; } case OP_MKDIR: { @@ -439,8 +439,8 @@ * Add rename record to edit log * TODO: use String parameters until just before writing to disk */ - void logRename(UTF8 src, UTF8 dst) { - logEdit(OP_RENAME, src, dst); + void logRename(String src, String dst) { + logEdit(OP_RENAME, new UTF8(src), new UTF8(dst)); } /** @@ -455,8 +455,8 @@ /** * Add delete file record to edit log */ - void logDelete(UTF8 src) { - logEdit(OP_DELETE, src, null); + void logDelete(String src) { + logEdit(OP_DELETE, new UTF8(src), null); } /** Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java Thu Jun 21 11:09:50 2007 @@ -662,7 +662,7 @@ blocks[j].readFields(in); } } - fsDir.unprotectedAddFile(name, blocks, replication); + fsDir.unprotectedAddFile(name.toString(), blocks, replication); } // load datanode info Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Thu Jun 21 11:09:50 2007 @@ -27,7 +27,11 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.ipc.Server; -import java.io.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import java.util.*; import java.util.Map.Entry; @@ -147,7 +151,7 @@ // Used for handling lock-leases // Mapping: leaseHolder -> Lease // - private Map<UTF8, Lease> leases = new TreeMap<UTF8, Lease>(); + private Map<StringBytesWritable, Lease> leases = new TreeMap<StringBytesWritable, Lease>(); // Set of: Lease private SortedSet<Lease> sortedLeases = new TreeSet<Lease>(); @@ -566,7 +570,7 @@ */ private void verifyReplication(String src, short replication, - UTF8 clientName + String clientName ) throws IOException { String text = "file " + src + ((clientName != null) ? " on client " + clientName : "") @@ -590,15 +594,15 @@ * @return Return an array that consists of the block, plus a set * of machines * @throws IOException if the filename is invalid - * [EMAIL PROTECTED] FSDirectory#isValidToCreate(UTF8)}. + * [EMAIL PROTECTED] FSDirectory#isValidToCreate(String)}. */ - public LocatedBlock startFile(UTF8 src, - UTF8 holder, - UTF8 clientMachine, - boolean overwrite, - short replication, - long blockSize - ) throws IOException { + public synchronized LocatedBlock startFile(String src, + String holder, + String clientMachine, + boolean overwrite, + short replication, + long blockSize + ) throws IOException { // // Create file into pendingCreates and get the first blockId @@ -612,7 +616,7 @@ // try { DatanodeDescriptor clientNode = - host2DataNodeMap.getDatanodeByHost(clientMachine.toString()); + host2DataNodeMap.getDatanodeByHost(clientMachine); DatanodeDescriptor targets[] = replicator.chooseTarget(replication, clientNode, null, blockSize); if (targets.length < this.minReplication) { @@ -639,18 +643,18 @@ } } - public synchronized Block startFileInternal(UTF8 src, - UTF8 holder, - UTF8 clientMachine, - boolean overwrite, - short replication, - long blockSize - ) throws IOException { + public synchronized Block startFileInternal(String src, + String holder, + String clientMachine, + boolean overwrite, + short replication, + long blockSize + ) throws IOException { NameNode.stateChangeLog.debug("DIR* NameSystem.startFile: file " +src+" for "+holder+" at "+clientMachine); if (isInSafeMode()) throw new SafeModeException("Cannot create file" + src, safeMode); - if (!isValidName(src.toString())) { + if (!isValidName(src)) { throw new IOException("Invalid file name: " + src); } try { @@ -660,7 +664,7 @@ // If the file exists in pendingCreate, then it must be in our // leases. Find the appropriate lease record. // - Lease lease = leases.get(holder); + Lease lease = getLease(holder); // // We found the lease for this file. And surprisingly the original // holder is trying to recreate this file. This should never occur. @@ -674,8 +678,7 @@ // // Find the original holder. // - UTF8 oldholder = pendingFile.getClientName(); - lease = leases.get(oldholder); + lease = getLease(pendingFile.getClientName()); if (lease == null) { throw new AlreadyBeingCreatedException( "failed to create file " + src + " for " + holder + @@ -689,13 +692,13 @@ // if (lease.expiredSoftLimit()) { lease.releaseLocks(); - leases.remove(lease.holder); + removeLease(lease.getHolder()); LOG.info("Removing lease " + lease + " "); if (!sortedLeases.remove(lease)) { LOG.error("Unknown failure trying to remove " + lease + " from lease set."); } - } else { + } else { throw new AlreadyBeingCreatedException( "failed to create file " + src + " for " + holder + " on client " + clientMachine + @@ -706,7 +709,7 @@ } try { - verifyReplication(src.toString(), replication, clientMachine); + verifyReplication(src, replication, clientMachine); } catch(IOException e) { throw new IOException("failed to create "+e.getMessage()); } @@ -721,7 +724,7 @@ } DatanodeDescriptor clientNode = - host2DataNodeMap.getDatanodeByHost(clientMachine.toString()); + host2DataNodeMap.getDatanodeByHost(clientMachine); // Reserve space for this pending file pendingCreates.put(src, @@ -733,10 +736,10 @@ NameNode.stateChangeLog.debug("DIR* NameSystem.startFile: " +"add "+src+" to pendingCreates for "+holder); synchronized (leases) { - Lease lease = leases.get(holder); + Lease lease = getLease(holder); if (lease == null) { lease = new Lease(holder); - leases.put(holder, lease); + putLease(holder, lease); sortedLeases.add(lease); } else { sortedLeases.remove(lease); @@ -766,9 +769,9 @@ * are replicated. Will return an empty 2-elt array if we want the * client to "try again later". */ - public LocatedBlock getAdditionalBlock(UTF8 src, - UTF8 clientName - ) throws IOException { + public synchronized LocatedBlock getAdditionalBlock(String src, + String clientName + ) throws IOException { long fileLength, blockSize; int replication; DatanodeDescriptor clientNode = null; @@ -790,9 +793,9 @@ throw new LeaseExpiredException("No lease on " + src); } if (!pendingFile.getClientName().equals(clientName)) { - throw new LeaseExpiredException("Lease mismatch on " + src + - " owned by " + pendingFile.getClientName() + - " and appended by " + clientName); + throw new LeaseExpiredException("Lease mismatch on " + src + " owned by " + + pendingFile.getClientName() + + " and appended by " + clientName); } // @@ -825,7 +828,7 @@ /** * The client would like to let go of the given block */ - public synchronized boolean abandonBlock(Block b, UTF8 src) { + public synchronized boolean abandonBlock(Block b, String src) throws IOException { // // Remove the block from the pending creates list // @@ -843,26 +846,25 @@ /** * Abandon the entire file in progress */ - public synchronized void abandonFileInProgress(UTF8 src, - UTF8 holder + public synchronized void abandonFileInProgress(String src, + String holder ) throws IOException { NameNode.stateChangeLog.debug("DIR* NameSystem.abandonFileInProgress:" + src); synchronized (leases) { // find the lease - Lease lease = leases.get(holder); + Lease lease = getLease(holder); if (lease != null) { // remove the file from the lease if (lease.completedCreate(src)) { // if we found the file in the lease, remove it from pendingCreates internalReleaseCreate(src, holder); } else { - LOG.info("Attempt by " + holder.toString() + - " to release someone else's create lock on " + - src.toString()); + LOG.info("Attempt by " + holder + + " to release someone else's create lock on " + src); } } else { LOG.info("Attempt to release a lock from an unknown lease holder " - + holder.toString() + " for " + src.toString()); + + holder + " for " + src); } } } @@ -873,20 +875,20 @@ * Before we return, we make sure that all the file's blocks have * been reported by datanodes and are replicated correctly. */ - public int completeFile(UTF8 src, UTF8 holder) throws IOException { + public int completeFile(String src, String holder) throws IOException { int status = completeFileInternal(src, holder); getEditLog().logSync(); return status; } - private synchronized int completeFileInternal(UTF8 src, - UTF8 holder) throws IOException { + private synchronized int completeFileInternal(String src, + String holder) throws IOException { NameNode.stateChangeLog.debug("DIR* NameSystem.completeFile: " + src + " for " + holder); if (isInSafeMode()) throw new SafeModeException("Cannot complete file " + src, safeMode); FileUnderConstruction pendingFile = pendingCreates.get(src); - Block[] fileBlocks = dir.getFileBlocks(src.toString()); + Block[] fileBlocks = dir.getFileBlocks(src); if (fileBlocks!= null || pendingFile == null) { NameNode.stateChangeLog.warn("DIR* NameSystem.completeFile: " + "failed to complete " + src @@ -933,11 +935,11 @@ + " is removed from pendingCreates"); synchronized (leases) { - Lease lease = leases.get(holder); + Lease lease = getLease(holder); if (lease != null) { lease.completedCreate(src); if (!lease.hasLocks()) { - leases.remove(holder); + removeLease(holder); sortedLeases.remove(lease); } } @@ -971,7 +973,7 @@ /** * Allocate a block at the given pending filename */ - private Block allocateBlock(UTF8 src) { + synchronized Block allocateBlock(String src) throws IOException { Block b = null; do { b = new Block(FSNamesystem.randBlockId.nextLong(), 0); @@ -1093,7 +1095,7 @@ // are made, edit namespace and return to client. //////////////////////////////////////////////////////////////// - public boolean renameTo(UTF8 src, UTF8 dst) throws IOException { + public boolean renameTo(String src, String dst) throws IOException { boolean status = renameToInternal(src, dst); getEditLog().logSync(); return status; @@ -1102,11 +1104,11 @@ /** * Change the indicated filename. */ - private synchronized boolean renameToInternal(UTF8 src, UTF8 dst) throws IOException { + public synchronized boolean renameToInternal(String src, String dst) throws IOException { NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: " + src + " to " + dst); if (isInSafeMode()) throw new SafeModeException("Cannot rename " + src, safeMode); - if (!isValidName(dst.toString())) { + if (!isValidName(dst)) { throw new IOException("Invalid name: " + dst); } return dir.renameTo(src, dst); @@ -1116,7 +1118,7 @@ * Remove the indicated filename from the namespace. This may * invalidate some blocks that make up the file. */ - public boolean delete(UTF8 src) throws IOException { + public boolean delete(String src) throws IOException { boolean status = deleteInternal(src); getEditLog().logSync(); return status; @@ -1126,7 +1128,7 @@ * Remove the indicated filename from the namespace. This may * invalidate some blocks that make up the file. */ - private synchronized boolean deleteInternal(UTF8 src) throws IOException { + private synchronized boolean deleteInternal(String src) throws IOException { NameNode.stateChangeLog.debug("DIR* NameSystem.delete: " + src); if (isInSafeMode()) throw new SafeModeException("Cannot delete " + src, safeMode); @@ -1152,8 +1154,8 @@ /** * Return whether the given filename exists */ - public boolean exists(UTF8 src) { - if (dir.getFileBlocks(src.toString()) != null || dir.isDir(src)) { + public boolean exists(String src) { + if (dir.getFileBlocks(src) != null || dir.isDir(src)) { return true; } else { return false; @@ -1163,7 +1165,7 @@ /** * Whether the given name is a directory */ - public boolean isDir(UTF8 src) { + public boolean isDir(String src) { return dir.isDir(src); } @@ -1226,13 +1228,13 @@ * expire, all the corresponding locks can be released. *************************************************************/ class Lease implements Comparable<Lease> { - public UTF8 holder; - public long lastUpdate; - private Collection<UTF8> locks = new TreeSet<UTF8>(); - private Collection<UTF8> creates = new TreeSet<UTF8>(); + private StringBytesWritable holder; + private long lastUpdate; + private Collection<StringBytesWritable> locks = new TreeSet<StringBytesWritable>(); + private Collection<StringBytesWritable> creates = new TreeSet<StringBytesWritable>(); - public Lease(UTF8 holder) { - this.holder = holder; + public Lease(String holder) throws IOException { + this.holder = new StringBytesWritable(holder); renew(); } public void renew() { @@ -1256,27 +1258,28 @@ } return false; } - public void obtained(UTF8 src) { - locks.add(src); + public void obtained(String src) throws IOException { + locks.add(new StringBytesWritable(src)); } - public void released(UTF8 src) { - locks.remove(src); + public void released(String src) throws IOException { + locks.remove(new StringBytesWritable(src)); } - public void startedCreate(UTF8 src) { - creates.add(src); + public void startedCreate(String src) throws IOException { + creates.add(new StringBytesWritable(src)); } - public boolean completedCreate(UTF8 src) { - return creates.remove(src); + public boolean completedCreate(String src) throws IOException { + return creates.remove(new StringBytesWritable(src)); } public boolean hasLocks() { return (locks.size() + creates.size()) > 0; } - public void releaseLocks() { - for (Iterator<UTF8> it = locks.iterator(); it.hasNext();) - internalReleaseLock(it.next(), holder); + public void releaseLocks() throws IOException { + String holderStr = holder.getString(); + for (Iterator<StringBytesWritable> it = locks.iterator(); it.hasNext();) + internalReleaseLock(it.next().getString(), holderStr); locks.clear(); - for (Iterator<UTF8> it = creates.iterator(); it.hasNext();) - internalReleaseCreate(it.next(), holder); + for (Iterator<StringBytesWritable> it = creates.iterator(); it.hasNext();) + internalReleaseCreate(it.next().getString(), holderStr); creates.clear(); } @@ -1318,7 +1321,12 @@ public int hashCode() { return holder.hashCode(); } + + String getHolder() throws IOException { + return holder.getString(); + } } + /****************************************************** * LeaseMonitor checks for leases that have expired, * and disposes of them. @@ -1355,6 +1363,18 @@ } } } + + private Lease getLease(String holder) throws IOException { + return leases.get(new StringBytesWritable(holder)); + } + + private void putLease(String holder, Lease lease) throws IOException { + leases.put(new StringBytesWritable(holder), lease); + } + + private void removeLease(String holder) throws IOException { + leases.remove(new StringBytesWritable(holder)); + } /** * Get a lock (perhaps exclusive) on the given file @@ -1366,23 +1386,7 @@ boolean exclusive) throws IOException { if (isInSafeMode()) throw new SafeModeException("Cannot lock file " + src, safeMode); - int result = dir.obtainLock(src, holder, exclusive); - if (result == COMPLETE_SUCCESS) { - synchronized (leases) { - Lease lease = leases.get(holder); - if (lease == null) { - lease = new Lease(holder); - leases.put(holder, lease); - sortedLeases.add(lease); - } else { - sortedLeases.remove(lease); - lease.renew(); - sortedLeases.add(lease); - } - lease.obtained(src); - } - } - return result; + return OPERATION_FAILED; } /** @@ -1391,22 +1395,9 @@ /** @deprecated */ @Deprecated public synchronized int releaseLock(UTF8 src, UTF8 holder) { - int result = internalReleaseLock(src, holder); - if (result == COMPLETE_SUCCESS) { - synchronized (leases) { - Lease lease = leases.get(holder); - if (lease != null) { - lease.released(src); - if (!lease.hasLocks()) { - leases.remove(holder); - sortedLeases.remove(lease); - } - } - } - } - return result; + return OPERATION_FAILED; } - private int internalReleaseLock(UTF8 src, UTF8 holder) { + private int internalReleaseLock(String src, String holder) throws IOException { return dir.releaseLock(src, holder); } @@ -1415,17 +1406,15 @@ * @param src The filename * @param holder The datanode that was creating the file */ - private void internalReleaseCreate(UTF8 src, UTF8 holder) { + private void internalReleaseCreate(String src, String holder) throws IOException { boolean status = pendingCreates.remove(src); if (status) { - NameNode.stateChangeLog.debug("DIR* NameSystem.internalReleaseCreate: " - + src + NameNode.stateChangeLog.debug("DIR* NameSystem.internalReleaseCreate: " + src + " is removed from pendingCreates for " + holder + " (failure)"); } else { NameNode.stateChangeLog.warn("DIR* NameSystem.internalReleaseCreate: " - + "attempt to release a create lock on " - + src.toString() + + "attempt to release a create lock on "+ src + " that was not in pedingCreates"); } } @@ -1433,11 +1422,11 @@ /** * Renew the lease(s) held by the given client */ - public void renewLease(UTF8 holder) throws IOException { + public void renewLease(String holder) throws IOException { synchronized (leases) { if (isInSafeMode()) throw new SafeModeException("Cannot renew lease for " + holder, safeMode); - Lease lease = leases.get(holder); + Lease lease = getLease(holder); if (lease != null) { sortedLeases.remove(lease); lease.renew(); @@ -1450,7 +1439,7 @@ * Get a listing of all files at 'src'. The Object[] array * exists so we can return file attributes (soon to be implemented) */ - public DFSFileInfo[] getListing(UTF8 src) { + public DFSFileInfo[] getListing(String src) { return dir.getListing(src); } @@ -1483,8 +1472,8 @@ * @see DataNode#register() */ public void registerDatanode(DatanodeRegistration nodeReg, - String networkLocation - ) throws IOException { + String networkLocation + ) throws IOException { registerDatanodeInternal(nodeReg, networkLocation); getEditLog().logSync(); } Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FileUnderConstruction.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FileUnderConstruction.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FileUnderConstruction.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FileUnderConstruction.java Thu Jun 21 11:09:50 2007 @@ -17,7 +17,6 @@ */ package org.apache.hadoop.dfs; -import org.apache.hadoop.io.UTF8; import java.io.*; import java.util.*; @@ -33,20 +32,20 @@ private short blockReplication; // file replication private long blockSize; private Collection<Block> blocks; - private UTF8 clientName; // lease holder - private UTF8 clientMachine; + private StringBytesWritable clientName; // lease holder + private StringBytesWritable clientMachine; private DatanodeDescriptor clientNode; // if client is a cluster node too. FileUnderConstruction(short replication, long blockSize, - UTF8 clientName, - UTF8 clientMachine, + String clientName, + String clientMachine, DatanodeDescriptor clientNode) throws IOException { this.blockReplication = replication; this.blockSize = blockSize; this.blocks = new ArrayList<Block>(); - this.clientName = clientName; - this.clientMachine = clientMachine; + this.clientName = new StringBytesWritable(clientName); + this.clientMachine = new StringBytesWritable(clientMachine); this.clientNode = clientNode; } @@ -62,12 +61,12 @@ return blocks; } - public UTF8 getClientName() { - return clientName; + String getClientName() throws IOException { + return clientName.getString(); } - public UTF8 getClientMachine() { - return clientMachine; + String getClientMachine() throws IOException { + return clientMachine.getString(); } public DatanodeDescriptor getClientNode() { Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java Thu Jun 21 11:09:50 2007 @@ -295,9 +295,9 @@ throw new IOException("create: Pathname too long. Limit " + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels."); } - LocatedBlock result = namesystem.startFile(new UTF8(src), - new UTF8(clientName), - new UTF8(clientMachine), + LocatedBlock result = namesystem.startFile(src, + clientName, + clientMachine, overwrite, replication, blockSize); @@ -317,9 +317,7 @@ String clientName) throws IOException { stateChangeLog.debug("*BLOCK* NameNode.addBlock: file " +src+" for "+clientName); - UTF8 src8 = new UTF8(src); - UTF8 client8 = new UTF8(clientName); - return namesystem.getAdditionalBlock(src8, client8); + return namesystem.getAdditionalBlock(src, clientName); } /** @@ -328,7 +326,7 @@ public void abandonBlock(Block b, String src) throws IOException { stateChangeLog.debug("*BLOCK* NameNode.abandonBlock: " +b.getBlockName()+" of file "+src); - if (!namesystem.abandonBlock(b, new UTF8(src))) { + if (!namesystem.abandonBlock(b, src)) { throw new IOException("Cannot abandon block during write to " + src); } } @@ -337,13 +335,13 @@ public void abandonFileInProgress(String src, String holder) throws IOException { stateChangeLog.debug("*DIR* NameNode.abandonFileInProgress:" + src); - namesystem.abandonFileInProgress(new UTF8(src), new UTF8(holder)); + namesystem.abandonFileInProgress(src, holder); } /** */ public boolean complete(String src, String clientName) throws IOException { stateChangeLog.debug("*DIR* NameNode.complete: " + src + " for " + clientName); - int returnCode = namesystem.completeFile(new UTF8(src), new UTF8(clientName)); + int returnCode = namesystem.completeFile(src, clientName); if (returnCode == STILL_WAITING) { return false; } else if (returnCode == COMPLETE_SUCCESS) { @@ -383,7 +381,7 @@ throw new IOException("rename: Pathname too long. Limit " + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels."); } - boolean ret = namesystem.renameTo(new UTF8(src), new UTF8(dst)); + boolean ret = namesystem.renameTo(src, dst); if (ret) { myMetrics.renameFile(); } @@ -394,19 +392,19 @@ */ public boolean delete(String src) throws IOException { stateChangeLog.debug("*DIR* NameNode.delete: " + src); - return namesystem.delete(new UTF8(src)); + return namesystem.delete(src); } /** */ public boolean exists(String src) throws IOException { - return namesystem.exists(new UTF8(src)); + return namesystem.exists(src); } /** */ public boolean isDir(String src) throws IOException { - return namesystem.isDir(new UTF8(src)); + return namesystem.isDir(src); } /** @@ -459,13 +457,13 @@ /** */ public void renewLease(String clientName) throws IOException { - namesystem.renewLease(new UTF8(clientName)); + namesystem.renewLease(clientName); } /** */ public DFSFileInfo[] getListing(String src) throws IOException { - DFSFileInfo[] files = namesystem.getListing(new UTF8(src)); + DFSFileInfo[] files = namesystem.getListing(src); if (files != null) { myMetrics.listFile(files.length); } Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/PendingCreates.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/PendingCreates.java?view=diff&rev=549576&r1=549575&r2=549576 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/PendingCreates.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/PendingCreates.java Thu Jun 21 11:09:50 2007 @@ -17,8 +17,6 @@ */ package org.apache.hadoop.dfs; -import org.apache.commons.logging.*; -import org.apache.hadoop.io.UTF8; import java.io.*; import java.util.*; @@ -33,8 +31,8 @@ * ***************************************************/ class PendingCreates { - private Map<UTF8, FileUnderConstruction> pendingCreates = - new TreeMap<UTF8, FileUnderConstruction>(); + private Map<StringBytesWritable, FileUnderConstruction> pendingCreates = + new TreeMap<StringBytesWritable, FileUnderConstruction>(); // // Keeps track of the blocks that are part of files that are being @@ -46,27 +44,28 @@ // // returns a file if it is being created. Otherwise returns null. // - FileUnderConstruction get(UTF8 filename) { - return pendingCreates.get(filename); + FileUnderConstruction get(String src) throws IOException { + return pendingCreates.get(new StringBytesWritable(src)); } // // inserts a filename into pendingCreates. throws exception if it // already exists // - void put(UTF8 src, FileUnderConstruction file) throws IOException { - FileUnderConstruction oldfile = pendingCreates.put(src, file); + void put(String src, FileUnderConstruction file) throws IOException { + FileUnderConstruction oldfile = pendingCreates.put( + new StringBytesWritable(src), file); if (oldfile != null && oldfile != file) { - throw new IOException("Duplicate entry " + src + - " in pendingCreates."); + throw new IOException("Duplicate entry " + src + " in pendingCreates."); } } // // The specified file is no longer pending. // - boolean remove(UTF8 file) { - FileUnderConstruction v = pendingCreates.remove(file); + boolean remove(String src) throws IOException { + FileUnderConstruction v = pendingCreates.remove( + new StringBytesWritable(src)); if (v != null) { for (Iterator<Block> it2 = v.getBlocks().iterator(); it2.hasNext(); ) { Block b = it2.next(); @@ -81,8 +80,8 @@ // Make this block part of this file. This block // should not already exists in here. // - boolean addBlock(UTF8 file, Block b) { - FileUnderConstruction v = pendingCreates.get(file); + boolean addBlock(String src, Block b) throws IOException { + FileUnderConstruction v = get(src); assert !pendingCreateBlocks.contains(b); v.getBlocks().add(b); pendingCreateBlocks.add(b); @@ -92,8 +91,8 @@ // // Remove this block from a file. // - boolean removeBlock(UTF8 file, Block b) { - FileUnderConstruction v = pendingCreates.get(file); + boolean removeBlock(String src, Block b) throws IOException { + FileUnderConstruction v = get(src); if (v != null) { Collection<Block> pendingVector = v.getBlocks(); for (Iterator<Block> it = pendingVector.iterator(); it.hasNext(); ) {