You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by wa...@apache.org on 2013/09/20 01:42:22 UTC
svn commit: r1524865 [3/5] - in
/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project: hadoop-hdfs-nfs/
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/mount/
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/
hadoop-hdfs-nfs/src/t...
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Thu Sep 19 23:42:10 2013
@@ -36,6 +36,8 @@ import static org.apache.hadoop.hdfs.DFS
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_DEFAULT;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_DEFAULT_AUDIT_LOGGER_NAME;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_DELEGATION_KEY_UPDATE_INTERVAL_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_DELEGATION_KEY_UPDATE_INTERVAL_KEY;
@@ -179,7 +181,6 @@ import org.apache.hadoop.hdfs.server.com
import org.apache.hadoop.hdfs.server.namenode.INode.BlocksMapUpdateInfo;
import org.apache.hadoop.hdfs.server.namenode.JournalSet.JournalAndStream;
import org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease;
-import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress;
@@ -207,6 +208,7 @@ import org.apache.hadoop.hdfs.server.pro
import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo;
+import org.apache.hadoop.hdfs.util.ChunkedArrayList;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.ipc.RetryCache;
@@ -225,6 +227,8 @@ import org.apache.hadoop.security.UserGr
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.security.token.TokenIdentifier;
+import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
import org.apache.hadoop.security.token.delegation.DelegationKey;
import org.apache.hadoop.util.Daemon;
import org.apache.hadoop.util.DataChecksum;
@@ -317,8 +321,14 @@ public class FSNamesystem implements Nam
stat.getGroup(), symlink, path);
}
for (AuditLogger logger : auditLoggers) {
- logger.logAuditEvent(succeeded, ugi.toString(), addr,
- cmd, src, dst, status);
+ if (logger instanceof HdfsAuditLogger) {
+ HdfsAuditLogger hdfsLogger = (HdfsAuditLogger) logger;
+ hdfsLogger.logAuditEvent(succeeded, ugi.toString(), addr, cmd, src, dst,
+ status, ugi, dtSecretManager);
+ } else {
+ logger.logAuditEvent(succeeded, ugi.toString(), addr,
+ cmd, src, dst, status);
+ }
}
}
@@ -375,7 +385,7 @@ public class FSNamesystem implements Nam
final LeaseManager leaseManager = new LeaseManager(this);
- Daemon smmthread = null; // SafeModeMonitor thread
+ volatile Daemon smmthread = null; // SafeModeMonitor thread
Daemon nnrmthread = null; // NamenodeResourceMonitor thread
@@ -2204,10 +2214,15 @@ public class FSNamesystem implements Nam
throw new FileNotFoundException("failed to append to non-existent file "
+ src + " on client " + clientMachine);
}
- final INodeFile myFile = INodeFile.valueOf(inode, src, true);
+ INodeFile myFile = INodeFile.valueOf(inode, src, true);
// Opening an existing file for write - may need to recover lease.
recoverLeaseInternal(myFile, src, holder, clientMachine, false);
-
+
+ // recoverLeaseInternal may create a new InodeFile via
+ // finalizeINodeFileUnderConstruction so we need to refresh
+ // the referenced file.
+ myFile = INodeFile.valueOf(dir.getINode(src), src, true);
+
final DatanodeDescriptor clientNode =
blockManager.getDatanodeManager().getDatanodeByHost(clientMachine);
return prepareFileForWrite(src, myFile, holder, clientMachine, clientNode,
@@ -3177,7 +3192,7 @@ public class FSNamesystem implements Nam
throws AccessControlException, SafeModeException, UnresolvedLinkException,
IOException {
BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo();
- List<INode> removedINodes = new ArrayList<INode>();
+ List<INode> removedINodes = new ChunkedArrayList<INode>();
FSPermissionChecker pc = getPermissionChecker();
checkOperation(OperationCategory.WRITE);
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
@@ -3231,21 +3246,17 @@ public class FSNamesystem implements Nam
* of blocks that need to be removed from blocksMap
*/
void removeBlocks(BlocksMapUpdateInfo blocks) {
- int start = 0;
- int end = 0;
List<Block> toDeleteList = blocks.getToDeleteList();
- while (start < toDeleteList.size()) {
- end = BLOCK_DELETION_INCREMENT + start;
- end = end > toDeleteList.size() ? toDeleteList.size() : end;
+ Iterator<Block> iter = toDeleteList.iterator();
+ while (iter.hasNext()) {
writeLock();
try {
- for (int i = start; i < end; i++) {
- blockManager.removeBlock(toDeleteList.get(i));
+ for (int i = 0; i < BLOCK_DELETION_INCREMENT && iter.hasNext(); i++) {
+ blockManager.removeBlock(iter.next());
}
} finally {
writeUnlock();
}
- start = end;
}
}
@@ -3461,12 +3472,26 @@ public class FSNamesystem implements Nam
return true;
}
- ContentSummary getContentSummary(String src) throws AccessControlException,
- FileNotFoundException, UnresolvedLinkException, StandbyException {
+ /**
+ * Get the content summary for a specific file/dir.
+ *
+ * @param src The string representation of the path to the file
+ *
+ * @throws AccessControlException if access is denied
+ * @throws UnresolvedLinkException if a symlink is encountered.
+ * @throws FileNotFoundException if no file exists
+ * @throws StandbyException
+ * @throws IOException for issues with writing to the audit log
+ *
+ * @return object containing information regarding the file
+ * or null if file not found
+ */
+ ContentSummary getContentSummary(String src) throws IOException {
FSPermissionChecker pc = getPermissionChecker();
checkOperation(OperationCategory.READ);
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
readLock();
+ boolean success = true;
try {
checkOperation(OperationCategory.READ);
src = FSDirectory.resolvePath(src, pathComponents, dir);
@@ -3474,8 +3499,13 @@ public class FSNamesystem implements Nam
checkPermission(pc, src, false, null, null, null, FsAction.READ_EXECUTE);
}
return dir.getContentSummary(src);
+
+ } catch (AccessControlException ace) {
+ success = false;
+ throw ace;
} finally {
readUnlock();
+ logAuditEvent(success, "contentSummary", src);
}
}
@@ -3799,24 +3829,32 @@ public class FSNamesystem implements Nam
// find the DatanodeDescriptor objects
// There should be no locations in the blockManager till now because the
// file is underConstruction
- DatanodeDescriptor[] descriptors = null;
+ List<DatanodeDescriptor> targetList =
+ new ArrayList<DatanodeDescriptor>(newtargets.length);
if (newtargets.length > 0) {
- descriptors = new DatanodeDescriptor[newtargets.length];
- for(int i = 0; i < newtargets.length; i++) {
- descriptors[i] = blockManager.getDatanodeManager().getDatanode(
- newtargets[i]);
+ for (DatanodeID newtarget : newtargets) {
+ // try to get targetNode
+ DatanodeDescriptor targetNode =
+ blockManager.getDatanodeManager().getDatanode(newtarget);
+ if (targetNode != null)
+ targetList.add(targetNode);
+ else if (LOG.isDebugEnabled()) {
+ LOG.debug("DatanodeDescriptor (=" + newtarget + ") not found");
+ }
}
}
- if ((closeFile) && (descriptors != null)) {
+ if ((closeFile) && !targetList.isEmpty()) {
// the file is getting closed. Insert block locations into blockManager.
// Otherwise fsck will report these blocks as MISSING, especially if the
// blocksReceived from Datanodes take a long time to arrive.
- for (int i = 0; i < descriptors.length; i++) {
- descriptors[i].addBlock(storedBlock);
+ for (DatanodeDescriptor targetNode : targetList) {
+ targetNode.addBlock(storedBlock);
}
}
// add pipeline locations into the INodeUnderConstruction
- pendingFile.setLastBlock(storedBlock, descriptors);
+ DatanodeDescriptor[] targetArray =
+ new DatanodeDescriptor[targetList.size()];
+ pendingFile.setLastBlock(storedBlock, targetList.toArray(targetArray));
}
if (closeFile) {
@@ -4575,7 +4613,9 @@ public class FSNamesystem implements Nam
// Have to have write-lock since leaving safemode initializes
// repl queues, which requires write lock
assert hasWriteLock();
- if (needEnter()) {
+ // if smmthread is already running, the block threshold must have been
+ // reached before, there is no need to enter the safe mode again
+ if (smmthread == null && needEnter()) {
enter();
// check if we are ready to initialize replication queues
if (canInitializeReplQueues() && !isPopulatingReplQueues()) {
@@ -4584,7 +4624,7 @@ public class FSNamesystem implements Nam
reportStatus("STATE* Safe mode ON.", false);
return;
}
- // the threshold is reached
+ // the threshold is reached or was reached before
if (!isOn() || // safe mode is off
extension <= 0 || threshold <= 0) { // don't need to wait
this.leave(); // leave safe mode
@@ -4596,9 +4636,11 @@ public class FSNamesystem implements Nam
}
// start monitor
reached = now();
- smmthread = new Daemon(new SafeModeMonitor());
- smmthread.start();
- reportStatus("STATE* Safe mode extension entered.", true);
+ if (smmthread == null) {
+ smmthread = new Daemon(new SafeModeMonitor());
+ smmthread.start();
+ reportStatus("STATE* Safe mode extension entered.", true);
+ }
// check if we are ready to initialize replication queues
if (canInitializeReplQueues() && !isPopulatingReplQueues()) {
@@ -4825,7 +4867,22 @@ public class FSNamesystem implements Nam
*/
@Override
public void run() {
- while (fsRunning && (safeMode != null && !safeMode.canLeave())) {
+ while (fsRunning) {
+ writeLock();
+ try {
+ if (safeMode == null) { // Not in safe mode.
+ break;
+ }
+ if (safeMode.canLeave()) {
+ // Leave safe mode.
+ safeMode.leave();
+ smmthread = null;
+ break;
+ }
+ } finally {
+ writeUnlock();
+ }
+
try {
Thread.sleep(recheckInterval);
} catch (InterruptedException ie) {
@@ -4834,11 +4891,7 @@ public class FSNamesystem implements Nam
}
if (!fsRunning) {
LOG.info("NameNode is being shutdown, exit SafeModeMonitor thread");
- } else {
- // leave safe mode and stop the monitor
- leaveSafeMode();
}
- smmthread = null;
}
}
@@ -5914,7 +5967,10 @@ public class FSNamesystem implements Nam
DFS_NAMENODE_DELEGATION_TOKEN_MAX_LIFETIME_DEFAULT),
conf.getLong(DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_KEY,
DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT),
- DELEGATION_TOKEN_REMOVER_SCAN_INTERVAL, this);
+ DELEGATION_TOKEN_REMOVER_SCAN_INTERVAL,
+ conf.getBoolean(DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_KEY,
+ DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_DEFAULT),
+ this);
}
/**
@@ -6252,6 +6308,7 @@ public class FSNamesystem implements Nam
innerinfo.put("nonDfsUsedSpace", node.getNonDfsUsed());
innerinfo.put("capacity", node.getCapacity());
innerinfo.put("numBlocks", node.numBlocks());
+ innerinfo.put("version", node.getSoftwareVersion());
info.put(node.getHostName(), innerinfo);
}
return JSON.toString(info);
@@ -6415,6 +6472,16 @@ public class FSNamesystem implements Nam
return JSON.toString(jasList);
}
+ @Override // NameNodeMxBean
+ public String getJournalTransactionInfo() {
+ Map<String, String> txnIdMap = new HashMap<String, String>();
+ txnIdMap.put("LastAppliedOrWrittenTxId",
+ Long.toString(this.getFSImage().getLastAppliedOrWrittenTxId()));
+ txnIdMap.put("MostRecentCheckpointTxId",
+ Long.toString(this.getFSImage().getMostRecentCheckpointTxId()));
+ return JSON.toString(txnIdMap);
+ }
+
@Override // NameNodeMXBean
public String getNNStarted() {
return getStartTime().toString();
@@ -6461,6 +6528,22 @@ public class FSNamesystem implements Nam
return JSON.toString(list);
}
+ @Override //NameNodeMXBean
+ public int getDistinctVersionCount() {
+ return blockManager.getDatanodeManager().getDatanodesSoftwareVersions()
+ .size();
+ }
+
+ @Override //NameNodeMXBean
+ public Map<String, Integer> getDistinctVersions() {
+ return blockManager.getDatanodeManager().getDatanodesSoftwareVersions();
+ }
+
+ @Override //NameNodeMXBean
+ public String getSoftwareVersion() {
+ return VersionInfo.getVersion();
+ }
+
/**
* Verifies that the given identifier and password are valid and match.
* @param identifier Token identifier.
@@ -6753,6 +6836,7 @@ public class FSNamesystem implements Nam
return; // Return previous response
}
boolean success = false;
+ checkOperation(OperationCategory.WRITE);
writeLock();
try {
checkOperation(OperationCategory.WRITE);
@@ -6763,7 +6847,7 @@ public class FSNamesystem implements Nam
checkOwner(pc, snapshotRoot);
BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo();
- List<INode> removedINodes = new ArrayList<INode>();
+ List<INode> removedINodes = new ChunkedArrayList<INode>();
dir.writeLock();
try {
snapshotManager.deleteSnapshot(snapshotRoot, snapshotName,
@@ -7015,17 +7099,22 @@ public class FSNamesystem implements Nam
* defined in the config file. It can also be explicitly listed in the
* config file.
*/
- private static class DefaultAuditLogger implements AuditLogger {
+ private static class DefaultAuditLogger extends HdfsAuditLogger {
+
+ private boolean logTokenTrackingId;
@Override
public void initialize(Configuration conf) {
- // Nothing to do.
+ logTokenTrackingId = conf.getBoolean(
+ DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_KEY,
+ DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_DEFAULT);
}
@Override
public void logAuditEvent(boolean succeeded, String userName,
InetAddress addr, String cmd, String src, String dst,
- FileStatus status) {
+ FileStatus status, UserGroupInformation ugi,
+ DelegationTokenSecretManager dtSecretManager) {
if (auditLog.isInfoEnabled()) {
final StringBuilder sb = auditBuffer.get();
sb.setLength(0);
@@ -7043,6 +7132,22 @@ public class FSNamesystem implements Nam
sb.append(status.getGroup()).append(":");
sb.append(status.getPermission());
}
+ if (logTokenTrackingId) {
+ sb.append("\t").append("trackingId=");
+ String trackingId = null;
+ if (ugi != null && dtSecretManager != null
+ && ugi.getAuthenticationMethod() == AuthenticationMethod.TOKEN) {
+ for (TokenIdentifier tid: ugi.getTokenIdentifiers()) {
+ if (tid instanceof DelegationTokenIdentifier) {
+ DelegationTokenIdentifier dtid =
+ (DelegationTokenIdentifier)tid;
+ trackingId = dtSecretManager.getTokenTrackingId(dtid);
+ break;
+ }
+ }
+ }
+ sb.append(trackingId);
+ }
auditLog.info(sb);
}
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java Thu Sep 19 23:42:10 2013
@@ -169,18 +169,26 @@ public class FileJournalManager implemen
* @param fromTxId the txnid which to start looking
* @param forReading whether or not the caller intends to read from the edit
* logs
+ * @param inProgressOk whether or not to include the in-progress edit log
+ * segment
* @return a list of remote edit logs
* @throws IOException if edit logs cannot be listed.
*/
public List<RemoteEditLog> getRemoteEditLogs(long firstTxId,
- boolean forReading) throws IOException {
+ boolean forReading, boolean inProgressOk) throws IOException {
+ // make sure not reading in-progress edit log, i.e., if forReading is true,
+ // we should ignore the in-progress edit log.
+ Preconditions.checkArgument(!(forReading && inProgressOk));
+
File currentDir = sd.getCurrentDir();
List<EditLogFile> allLogFiles = matchEditLogs(currentDir);
List<RemoteEditLog> ret = Lists.newArrayListWithCapacity(
allLogFiles.size());
for (EditLogFile elf : allLogFiles) {
- if (elf.hasCorruptHeader() || elf.isInProgress()) continue;
+ if (elf.hasCorruptHeader() || (!inProgressOk && elf.isInProgress())) {
+ continue;
+ }
if (elf.getFirstTxId() >= firstTxId) {
ret.add(new RemoteEditLog(elf.firstTxId, elf.lastTxId));
} else if (elf.getFirstTxId() < firstTxId && firstTxId <= elf.getLastTxId()) {
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/GetImageServlet.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/GetImageServlet.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/GetImageServlet.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/GetImageServlet.java Thu Sep 19 23:42:10 2013
@@ -310,11 +310,14 @@ public class GetImageServlet extends Htt
static String getParamStringToPutImage(long txid,
InetSocketAddress imageListenAddress, Storage storage) {
-
+ String machine = !imageListenAddress.isUnresolved()
+ && imageListenAddress.getAddress().isAnyLocalAddress() ? null
+ : imageListenAddress.getHostName();
return "putimage=1" +
"&" + TXID_PARAM + "=" + txid +
"&port=" + imageListenAddress.getPort() +
- "&" + STORAGEINFO_PARAM + "=" +
+ (machine != null ? "&machine=" + machine : "")
+ + "&" + STORAGEINFO_PARAM + "=" +
storage.toColonSeparatedString();
}
@@ -341,10 +344,6 @@ public class GetImageServlet extends Htt
Map<String, String[]> pmap = request.getParameterMap();
isGetImage = isGetEdit = isPutImage = fetchLatest = false;
remoteport = 0;
- machineName = request.getRemoteHost();
- if (InetAddresses.isInetAddress(machineName)) {
- machineName = NetUtils.getHostNameOfIP(machineName);
- }
for (Map.Entry<String, String[]> entry : pmap.entrySet()) {
String key = entry.getKey();
@@ -369,11 +368,20 @@ public class GetImageServlet extends Htt
txId = ServletUtil.parseLongParam(request, TXID_PARAM);
} else if (key.equals("port")) {
remoteport = new Integer(val[0]).intValue();
+ } else if (key.equals("machine")) {
+ machineName = val[0];
} else if (key.equals(STORAGEINFO_PARAM)) {
storageInfoString = val[0];
}
}
+ if (machineName == null) {
+ machineName = request.getRemoteHost();
+ if (InetAddresses.isInetAddress(machineName)) {
+ machineName = NetUtils.getHostNameOfIP(machineName);
+ }
+ }
+
int numGets = (isGetImage?1:0) + (isGetEdit?1:0);
if ((numGets > 1) || (numGets == 0) && !isPutImage) {
throw new IOException("Illegal parameters to TransferFsImage");
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java Thu Sep 19 23:42:10 2013
@@ -38,6 +38,7 @@ import org.apache.hadoop.hdfs.server.nam
import org.apache.hadoop.hdfs.server.namenode.snapshot.FileWithSnapshot;
import org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectoryWithSnapshot;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
+import org.apache.hadoop.hdfs.util.ChunkedArrayList;
import org.apache.hadoop.hdfs.util.Diff;
import org.apache.hadoop.util.StringUtils;
@@ -707,7 +708,7 @@ public abstract class INode implements I
}
public BlocksMapUpdateInfo() {
- toDeleteList = new ArrayList<Block>();
+ toDeleteList = new ChunkedArrayList<Block>();
}
/**
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/JournalSet.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/JournalSet.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/JournalSet.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/JournalSet.java Thu Sep 19 23:42:10 2013
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import static org.apache.hadoop.util.ExitUtil.terminate;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -31,14 +33,10 @@ import java.util.concurrent.CopyOnWriteA
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience;
-
-import static org.apache.hadoop.util.ExitUtil.terminate;
-
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLog;
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;
@@ -257,13 +255,12 @@ public class JournalSet implements Journ
". Skipping.", ioe);
}
}
- chainAndMakeRedundantStreams(streams, allStreams, fromTxId, inProgressOk);
+ chainAndMakeRedundantStreams(streams, allStreams, fromTxId);
}
public static void chainAndMakeRedundantStreams(
Collection<EditLogInputStream> outStreams,
- PriorityQueue<EditLogInputStream> allStreams,
- long fromTxId, boolean inProgressOk) {
+ PriorityQueue<EditLogInputStream> allStreams, long fromTxId) {
// We want to group together all the streams that start on the same start
// transaction ID. To do this, we maintain an accumulator (acc) of all
// the streams we've seen at a given start transaction ID. When we see a
@@ -598,7 +595,7 @@ public class JournalSet implements Journ
if (j.getManager() instanceof FileJournalManager) {
FileJournalManager fjm = (FileJournalManager)j.getManager();
try {
- allLogs.addAll(fjm.getRemoteEditLogs(fromTxId, forReading));
+ allLogs.addAll(fjm.getRemoteEditLogs(fromTxId, forReading, false));
} catch (Throwable t) {
LOG.warn("Cannot list edit logs in " + fjm, t);
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Thu Sep 19 23:42:10 2013
@@ -166,12 +166,14 @@ public class NameNode implements NameNod
*/
public static final String[] NAMENODE_SPECIFIC_KEYS = {
DFS_NAMENODE_RPC_ADDRESS_KEY,
+ DFS_NAMENODE_RPC_BIND_HOST_KEY,
DFS_NAMENODE_NAME_DIR_KEY,
DFS_NAMENODE_EDITS_DIR_KEY,
DFS_NAMENODE_SHARED_EDITS_DIR_KEY,
DFS_NAMENODE_CHECKPOINT_DIR_KEY,
DFS_NAMENODE_CHECKPOINT_EDITS_DIR_KEY,
DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY,
+ DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY,
DFS_NAMENODE_HTTP_ADDRESS_KEY,
DFS_NAMENODE_KEYTAB_FILE_KEY,
DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY,
@@ -180,6 +182,7 @@ public class NameNode implements NameNod
DFS_NAMENODE_BACKUP_HTTP_ADDRESS_KEY,
DFS_NAMENODE_BACKUP_SERVICE_RPC_ADDRESS_KEY,
DFS_NAMENODE_USER_NAME_KEY,
+ DFS_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY,
DFS_HA_FENCE_METHODS_KEY,
DFS_HA_ZKFC_PORT_KEY,
DFS_HA_FENCE_METHODS_KEY
@@ -387,6 +390,28 @@ public class NameNode implements NameNod
return getAddress(conf);
}
+ /** Given a configuration get the bind host of the service rpc server
+ * If the bind host is not configured returns null.
+ */
+ protected String getServiceRpcServerBindHost(Configuration conf) {
+ String addr = conf.getTrimmed(DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY);
+ if (addr == null || addr.isEmpty()) {
+ return null;
+ }
+ return addr;
+ }
+
+ /** Given a configuration get the bind host of the client rpc server
+ * If the bind host is not configured returns null.
+ */
+ protected String getRpcServerBindHost(Configuration conf) {
+ String addr = conf.getTrimmed(DFS_NAMENODE_RPC_BIND_HOST_KEY);
+ if (addr == null || addr.isEmpty()) {
+ return null;
+ }
+ return addr;
+ }
+
/**
* Modifies the configuration passed to contain the service rpc address setting
*/
@@ -956,41 +981,49 @@ public class NameNode implements NameNod
FSEditLog sourceEditLog = fsns.getFSImage().editLog;
long fromTxId = fsns.getFSImage().getMostRecentCheckpointTxId();
- Collection<EditLogInputStream> streams = sourceEditLog.selectInputStreams(
- fromTxId+1, 0);
-
- // Set the nextTxid to the CheckpointTxId+1
- newSharedEditLog.setNextTxId(fromTxId + 1);
- // Copy all edits after last CheckpointTxId to shared edits dir
- for (EditLogInputStream stream : streams) {
- LOG.debug("Beginning to copy stream " + stream + " to shared edits");
- FSEditLogOp op;
- boolean segmentOpen = false;
- while ((op = stream.readOp()) != null) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("copying op: " + op);
- }
- if (!segmentOpen) {
- newSharedEditLog.startLogSegment(op.txid, false);
- segmentOpen = true;
+ Collection<EditLogInputStream> streams = null;
+ try {
+ streams = sourceEditLog.selectInputStreams(fromTxId + 1, 0);
+
+ // Set the nextTxid to the CheckpointTxId+1
+ newSharedEditLog.setNextTxId(fromTxId + 1);
+
+ // Copy all edits after last CheckpointTxId to shared edits dir
+ for (EditLogInputStream stream : streams) {
+ LOG.debug("Beginning to copy stream " + stream + " to shared edits");
+ FSEditLogOp op;
+ boolean segmentOpen = false;
+ while ((op = stream.readOp()) != null) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("copying op: " + op);
+ }
+ if (!segmentOpen) {
+ newSharedEditLog.startLogSegment(op.txid, false);
+ segmentOpen = true;
+ }
+
+ newSharedEditLog.logEdit(op);
+
+ if (op.opCode == FSEditLogOpCodes.OP_END_LOG_SEGMENT) {
+ newSharedEditLog.logSync();
+ newSharedEditLog.endCurrentLogSegment(false);
+ LOG.debug("ending log segment because of END_LOG_SEGMENT op in "
+ + stream);
+ segmentOpen = false;
+ }
}
-
- newSharedEditLog.logEdit(op);
- if (op.opCode == FSEditLogOpCodes.OP_END_LOG_SEGMENT) {
+ if (segmentOpen) {
+ LOG.debug("ending log segment because of end of stream in " + stream);
newSharedEditLog.logSync();
newSharedEditLog.endCurrentLogSegment(false);
- LOG.debug("ending log segment because of END_LOG_SEGMENT op in " + stream);
segmentOpen = false;
}
}
-
- if (segmentOpen) {
- LOG.debug("ending log segment because of end of stream in " + stream);
- newSharedEditLog.logSync();
- newSharedEditLog.endCurrentLogSegment(false);
- segmentOpen = false;
+ } finally {
+ if (streams != null) {
+ FSEditLog.closeAllStreams(streams);
}
}
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java Thu Sep 19 23:42:10 2013
@@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_ADMIN;
+
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashMap;
@@ -70,65 +71,30 @@ public class NameNodeHttpServer {
public void start() throws IOException {
final String infoHost = bindAddress.getHostName();
int infoPort = bindAddress.getPort();
-
- httpServer = new HttpServer("hdfs", infoHost, infoPort,
- infoPort == 0, conf,
- new AccessControlList(conf.get(DFS_ADMIN, " "))) {
- {
- // Add SPNEGO support to NameNode
- if (UserGroupInformation.isSecurityEnabled()) {
- initSpnego(conf,
- DFSConfigKeys.DFS_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY,
- DFSUtil.getSpnegoKeytabKey(conf,
- DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY));
- }
- if (WebHdfsFileSystem.isEnabled(conf, LOG)) {
- //add SPNEGO authentication filter for webhdfs
- final String name = "SPNEGO";
- final String classname = AuthFilter.class.getName();
- final String pathSpec = WebHdfsFileSystem.PATH_PREFIX + "/*";
- Map<String, String> params = getAuthFilterParams(conf);
- defineFilter(webAppContext, name, classname, params,
- new String[]{pathSpec});
- LOG.info("Added filter '" + name + "' (class=" + classname + ")");
-
- // add webhdfs packages
- addJerseyResourcePackage(
- NamenodeWebHdfsMethods.class.getPackage().getName()
- + ";" + Param.class.getPackage().getName(), pathSpec);
- }
- }
-
- private Map<String, String> getAuthFilterParams(Configuration conf)
- throws IOException {
- Map<String, String> params = new HashMap<String, String>();
- String principalInConf = conf
- .get(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY);
- if (principalInConf != null && !principalInConf.isEmpty()) {
- params
- .put(
- DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY,
- SecurityUtil.getServerPrincipal(principalInConf,
- bindAddress.getHostName()));
- } else if (UserGroupInformation.isSecurityEnabled()) {
- LOG.error("WebHDFS and security are enabled, but configuration property '" +
- DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY +
- "' is not set.");
- }
- String httpKeytab = conf.get(DFSUtil.getSpnegoKeytabKey(conf,
- DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY));
- if (httpKeytab != null && !httpKeytab.isEmpty()) {
- params.put(
- DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY,
- httpKeytab);
- } else if (UserGroupInformation.isSecurityEnabled()) {
- LOG.error("WebHDFS and security are enabled, but configuration property '" +
- DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY +
- "' is not set.");
- }
- return params;
+ httpServer = new HttpServer.Builder().setName("hdfs")
+ .setBindAddress(infoHost).setPort(infoPort)
+ .setFindPort(infoPort == 0).setConf(conf).setACL(
+ new AccessControlList(conf.get(DFS_ADMIN, " ")))
+ .setSecurityEnabled(UserGroupInformation.isSecurityEnabled())
+ .setUsernameConfKey(
+ DFSConfigKeys.DFS_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY)
+ .setKeytabConfKey(DFSUtil.getSpnegoKeytabKey(conf,
+ DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY)).build();
+ if (WebHdfsFileSystem.isEnabled(conf, HttpServer.LOG)) {
+ //add SPNEGO authentication filter for webhdfs
+ final String name = "SPNEGO";
+ final String classname = AuthFilter.class.getName();
+ final String pathSpec = WebHdfsFileSystem.PATH_PREFIX + "/*";
+ Map<String, String> params = getAuthFilterParams(conf);
+ httpServer.defineFilter(httpServer.getWebAppContext(), name, classname, params,
+ new String[]{pathSpec});
+ HttpServer.LOG.info("Added filter '" + name + "' (class=" + classname + ")");
+
+ // add webhdfs packages
+ httpServer.addJerseyResourcePackage(
+ NamenodeWebHdfsMethods.class.getPackage().getName()
+ + ";" + Param.class.getPackage().getName(), pathSpec);
}
- };
boolean certSSL = conf.getBoolean(DFSConfigKeys.DFS_HTTPS_ENABLE_KEY, false);
if (certSSL) {
@@ -153,6 +119,38 @@ public class NameNodeHttpServer {
httpServer.start();
httpAddress = new InetSocketAddress(bindAddress.getAddress(), httpServer.getPort());
}
+
+ private Map<String, String> getAuthFilterParams(Configuration conf)
+ throws IOException {
+ Map<String, String> params = new HashMap<String, String>();
+ String principalInConf = conf
+ .get(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY);
+ if (principalInConf != null && !principalInConf.isEmpty()) {
+ params
+ .put(
+ DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY,
+ SecurityUtil.getServerPrincipal(principalInConf,
+ bindAddress.getHostName()));
+ } else if (UserGroupInformation.isSecurityEnabled()) {
+ HttpServer.LOG.error(
+ "WebHDFS and security are enabled, but configuration property '" +
+ DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY +
+ "' is not set.");
+ }
+ String httpKeytab = conf.get(DFSUtil.getSpnegoKeytabKey(conf,
+ DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY));
+ if (httpKeytab != null && !httpKeytab.isEmpty()) {
+ params.put(
+ DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY,
+ httpKeytab);
+ } else if (UserGroupInformation.isSecurityEnabled()) {
+ HttpServer.LOG.error(
+ "WebHDFS and security are enabled, but configuration property '" +
+ DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY +
+ "' is not set.");
+ }
+ return params;
+ }
public void stop() throws Exception {
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeMXBean.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeMXBean.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeMXBean.java Thu Sep 19 23:42:10 2013
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import java.util.Map;
+
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
@@ -33,7 +35,13 @@ public interface NameNodeMXBean {
* @return the version
*/
public String getVersion();
-
+
+ /**
+ * Get the version of software running on the Namenode
+ * @return a string representing the version
+ */
+ public String getSoftwareVersion();
+
/**
* Gets the used space by data nodes.
*
@@ -188,6 +196,12 @@ public interface NameNodeMXBean {
* @return the name journal status information, as a JSON string.
*/
public String getNameJournalStatus();
+
+ /**
+ * Get information about the transaction ID, including the last applied
+ * transaction ID and the most recent checkpoint's transaction ID
+ */
+ public String getJournalTransactionInfo();
/**
* Gets the NN start time
@@ -209,4 +223,19 @@ public interface NameNodeMXBean {
* @return the list of corrupt files, as a JSON string.
*/
public String getCorruptFiles();
+
+ /**
+ * Get the number of distinct versions of live datanodes
+ *
+ * @return the number of distinct versions of live datanodes
+ */
+ public int getDistinctVersionCount();
+
+ /**
+ * Get the number of live datanodes for each distinct versions
+ *
+ * @return the number of live datanodes for each distinct versions
+ */
+ public Map<String, Integer> getDistinctVersions();
+
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java Thu Sep 19 23:42:10 2013
@@ -143,6 +143,7 @@ import org.apache.hadoop.util.Fallible;
import org.apache.hadoop.util.VersionInfo;
import org.apache.hadoop.util.VersionUtil;
+import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.BlockingService;
/**
@@ -225,6 +226,13 @@ class NameNodeRpcServer implements Namen
InetSocketAddress serviceRpcAddr = nn.getServiceRpcServerAddress(conf);
if (serviceRpcAddr != null) {
+ String bindHost = nn.getServiceRpcServerBindHost(conf);
+ if (bindHost == null) {
+ bindHost = serviceRpcAddr.getHostName();
+ }
+ LOG.info("Service RPC server is binding to " + bindHost + ":" +
+ serviceRpcAddr.getPort());
+
int serviceHandlerCount =
conf.getInt(DFS_NAMENODE_SERVICE_HANDLER_COUNT_KEY,
DFS_NAMENODE_SERVICE_HANDLER_COUNT_DEFAULT);
@@ -232,7 +240,7 @@ class NameNodeRpcServer implements Namen
.setProtocol(
org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB.class)
.setInstance(clientNNPbService)
- .setBindAddress(serviceRpcAddr.getHostName())
+ .setBindAddress(bindHost)
.setPort(serviceRpcAddr.getPort())
.setNumHandlers(serviceHandlerCount)
.setVerbose(false)
@@ -253,7 +261,10 @@ class NameNodeRpcServer implements Namen
DFSUtil.addPBProtocol(conf, GetUserMappingsProtocolPB.class,
getUserMappingService, serviceRpcServer);
- serviceRPCAddress = serviceRpcServer.getListenerAddress();
+ // Update the address with the correct port
+ InetSocketAddress listenAddr = serviceRpcServer.getListenerAddress();
+ serviceRPCAddress = new InetSocketAddress(
+ serviceRpcAddr.getHostName(), listenAddr.getPort());
nn.setRpcServiceServerAddress(conf, serviceRPCAddress);
} else {
serviceRpcServer = null;
@@ -261,11 +272,17 @@ class NameNodeRpcServer implements Namen
}
InetSocketAddress rpcAddr = nn.getRpcServerAddress(conf);
+ String bindHost = nn.getRpcServerBindHost(conf);
+ if (bindHost == null) {
+ bindHost = rpcAddr.getHostName();
+ }
+ LOG.info("RPC server is binding to " + bindHost + ":" + rpcAddr.getPort());
+
clientRpcServer = new RPC.Builder(conf)
.setProtocol(
org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB.class)
.setInstance(clientNNPbService)
- .setBindAddress(rpcAddr.getHostName())
+ .setBindAddress(bindHost)
.setPort(rpcAddr.getPort())
.setNumHandlers(handlerCount)
.setVerbose(false)
@@ -297,7 +314,9 @@ class NameNodeRpcServer implements Namen
}
// The rpc-server port can be ephemeral... ensure we have the correct info
- clientRpcAddress = clientRpcServer.getListenerAddress();
+ InetSocketAddress listenAddr = clientRpcServer.getListenerAddress();
+ clientRpcAddress = new InetSocketAddress(
+ rpcAddr.getHostName(), listenAddr.getPort());
nn.setRpcServerAddress(conf, clientRpcAddress);
minimumDataNodeVersion = conf.get(
@@ -321,6 +340,12 @@ class NameNodeRpcServer implements Namen
NSQuotaExceededException.class,
DSQuotaExceededException.class);
}
+
+ /** Allow access to the client RPC server for testing */
+ @VisibleForTesting
+ RPC.Server getClientRpcServer() {
+ return clientRpcServer;
+ }
/**
* Start client and service RPC servers.
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java Thu Sep 19 23:42:10 2013
@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -99,6 +100,20 @@ class NamenodeJspHelper {
}
}
+ static String getRollingUpgradeText(FSNamesystem fsn) {
+ DatanodeManager dm = fsn.getBlockManager().getDatanodeManager();
+ Map<String, Integer> list = dm.getDatanodesSoftwareVersions();
+ if(list.size() > 1) {
+ StringBuffer status = new StringBuffer("Rolling upgrades in progress. " +
+ "There are " + list.size() + " versions of datanodes currently live: ");
+ for(Map.Entry<String, Integer> ver: list.entrySet()) {
+ status.append(ver.getKey() + "(" + ver.getValue() + "), ");
+ }
+ return status.substring(0, status.length()-2);
+ }
+ return "";
+ }
+
static String getInodeLimitText(FSNamesystem fsn) {
if (fsn == null) {
return "";
@@ -802,7 +817,9 @@ class NamenodeJspHelper {
+ "<td align=\"right\" class=\"pcbpused\">"
+ percentBpUsed
+ "<td align=\"right\" class=\"volfails\">"
- + d.getVolumeFailures() + "\n");
+ + d.getVolumeFailures()
+ + "<td align=\"right\" class=\"version\">"
+ + d.getSoftwareVersion() + "\n");
}
void generateNodesList(ServletContext context, JspWriter out,
@@ -900,7 +917,9 @@ class NamenodeJspHelper {
+ nodeHeaderStr("pcbpused")
+ "> Block Pool<br>Used (%)" + " <th "
+ nodeHeaderStr("volfails")
- +"> Failed Volumes\n");
+ +"> Failed Volumes <th "
+ + nodeHeaderStr("versionString")
+ +"> Version\n");
JspHelper.sortNodeList(live, sorterField, sorterOrder);
for (int i = 0; i < live.size(); i++) {
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java Thu Sep 19 23:42:10 2013
@@ -256,19 +256,15 @@ public class SecondaryNameNode implement
// initialize the webserver for uploading files.
int tmpInfoPort = infoSocAddr.getPort();
- infoServer = new HttpServer("secondary", infoBindAddress, tmpInfoPort,
- tmpInfoPort == 0, conf,
- new AccessControlList(conf.get(DFS_ADMIN, " "))) {
- {
- if (UserGroupInformation.isSecurityEnabled()) {
- initSpnego(
- conf,
- DFSConfigKeys.DFS_SECONDARY_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY,
- DFSUtil.getSpnegoKeytabKey(conf,
- DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY));
- }
- }
- };
+ infoServer = new HttpServer.Builder().setName("secondary")
+ .setBindAddress(infoBindAddress).setPort(tmpInfoPort)
+ .setFindPort(tmpInfoPort == 0).setConf(conf).setACL(
+ new AccessControlList(conf.get(DFS_ADMIN, " ")))
+ .setSecurityEnabled(UserGroupInformation.isSecurityEnabled())
+ .setUsernameConfKey(
+ DFSConfigKeys.DFS_SECONDARY_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY)
+ .setKeytabConfKey(DFSUtil.getSpnegoKeytabKey(conf,
+ DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY)).build();
infoServer.setAttribute("secondary.name.node", this);
infoServer.setAttribute("name.system.image", checkpointImage);
infoServer.setAttribute(JspHelper.CURRENT_CONF, conf);
@@ -433,10 +429,8 @@ public class SecondaryNameNode implement
dstImage.getStorage().cTime = sig.cTime;
// get fsimage
- boolean downloadImage = true;
if (sig.mostRecentCheckpointTxId ==
dstImage.getStorage().getMostRecentCheckpointTxId()) {
- downloadImage = false;
LOG.info("Image has not changed. Will not download image.");
} else {
LOG.info("Image has changed. Downloading updated image from NN.");
@@ -452,7 +446,9 @@ public class SecondaryNameNode implement
nnHostPort, log, dstImage.getStorage());
}
- return Boolean.valueOf(downloadImage);
+ // true if we haven't loaded all the transactions represented by the
+ // downloaded fsimage.
+ return dstImage.getLastAppliedTxId() < sig.mostRecentCheckpointTxId;
}
});
return b.booleanValue();
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java Thu Sep 19 23:42:10 2013
@@ -226,7 +226,7 @@ public class BootstrapStandby implements
try {
Collection<EditLogInputStream> streams =
image.getEditLog().selectInputStreams(
- firstTxIdInLogs, curTxIdOnOtherNode, null, true);
+ firstTxIdInLogs, curTxIdOnOtherNode, null, true, false);
for (EditLogInputStream stream : streams) {
IOUtils.closeStream(stream);
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java Thu Sep 19 23:42:10 2013
@@ -82,8 +82,10 @@ public class NameNodeMetrics {
@Metric("Cache report") MutableRate cacheReport;
MutableQuantiles[] cacheReportQuantiles;
- @Metric("Duration in SafeMode at startup") MutableGaugeInt safeModeTime;
- @Metric("Time loading FS Image at startup") MutableGaugeInt fsImageLoadTime;
+ @Metric("Duration in SafeMode at startup in msec")
+ MutableGaugeInt safeModeTime;
+ @Metric("Time loading FS Image at startup in msec")
+ MutableGaugeInt fsImageLoadTime;
NameNodeMetrics(String processName, String sessionId, int[] intervals) {
registry.tag(ProcessName, processName).tag(SessionId, sessionId);
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java Thu Sep 19 23:42:10 2013
@@ -119,13 +119,15 @@ public class WebHdfsFileSystem extends F
/** SPNEGO authenticator */
private static final KerberosUgiAuthenticator AUTH = new KerberosUgiAuthenticator();
+ /** Default connection factory may be overriden in tests to use smaller timeout values */
+ URLConnectionFactory connectionFactory = URLConnectionFactory.DEFAULT_CONNECTION_FACTORY;
/** Configures connections for AuthenticatedURL */
- private static final ConnectionConfigurator CONN_CONFIGURATOR =
+ private final ConnectionConfigurator CONN_CONFIGURATOR =
new ConnectionConfigurator() {
@Override
public HttpURLConnection configure(HttpURLConnection conn)
throws IOException {
- URLUtils.setTimeouts(conn);
+ connectionFactory.setTimeouts(conn);
return conn;
}
};
@@ -479,10 +481,9 @@ public class WebHdfsFileSystem extends F
final AuthenticatedURL.Token authToken = new AuthenticatedURL.Token();
conn = new AuthenticatedURL(AUTH, CONN_CONFIGURATOR).openConnection(
url, authToken);
- URLUtils.setTimeouts(conn);
} else {
LOG.debug("open URL connection");
- conn = (HttpURLConnection)URLUtils.openConnection(url);
+ conn = (HttpURLConnection)connectionFactory.openConnection(url);
}
} catch (AuthenticationException e) {
throw new IOException(e);
@@ -577,7 +578,7 @@ public class WebHdfsFileSystem extends F
checkRetry = false;
//Step 2) Submit another Http request with the URL from the Location header with data.
- conn = (HttpURLConnection)URLUtils.openConnection(new URL(redirect));
+ conn = (HttpURLConnection)connectionFactory.openConnection(new URL(redirect));
conn.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
conn.setChunkedStreamingMode(32 << 10); //32kB-chunk
connect();
@@ -600,7 +601,7 @@ public class WebHdfsFileSystem extends F
disconnect();
checkRetry = false;
- conn = (HttpURLConnection)URLUtils.openConnection(new URL(redirect));
+ conn = (HttpURLConnection)connectionFactory.openConnection(new URL(redirect));
connect();
}
Propchange: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/native/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/native:r1514105-1522706
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/DatanodeProtocol.proto
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/DatanodeProtocol.proto?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/DatanodeProtocol.proto (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/DatanodeProtocol.proto Thu Sep 19 23:42:10 2013
@@ -31,6 +31,7 @@ option java_generic_services = true;
option java_generate_equals_and_hash = true;
package hadoop.hdfs;
+import "HAServiceProtocol.proto";
import "hdfs.proto";
/**
@@ -195,11 +196,7 @@ message CacheReportProto {
* txid - Highest transaction ID this NN has seen
*/
message NNHAStatusHeartbeatProto {
- enum State {
- ACTIVE = 0;
- STANDBY = 1;
- }
- required State state = 1;
+ required hadoop.common.HAServiceStateProto state = 1;
required uint64 txid = 2;
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/QJournalProtocol.proto
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/QJournalProtocol.proto?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/QJournalProtocol.proto (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/QJournalProtocol.proto Thu Sep 19 23:42:10 2013
@@ -177,6 +177,7 @@ message GetEditLogManifestRequestProto {
required uint64 sinceTxId = 2; // Transaction ID
// Whether or not the client will be reading from the returned streams.
optional bool forReading = 3 [default = true];
+ optional bool inProgressOk = 4 [default = false];
}
message GetEditLogManifestResponseProto {
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml Thu Sep 19 23:42:10 2013
@@ -52,6 +52,18 @@
</property>
<property>
+ <name>dfs.namenode.rpc-bind-host</name>
+ <value></value>
+ <description>
+ The actual address the server will bind to. If this optional address is
+ set, the RPC server will bind to this address and the port specified in
+ dfs.namenode.rpc-address for the RPC server. It can also be specified
+ per name node or name service for HA/Federation. This is most useful for
+ making name node listen to all interfaces by setting to 0.0.0.0.
+ </description>
+</property>
+
+<property>
<name>dfs.namenode.servicerpc-address</name>
<value></value>
<description>
@@ -65,6 +77,18 @@
</property>
<property>
+ <name>dfs.namenode.servicerpc-bind-host</name>
+ <value></value>
+ <description>
+ The actual address the server will bind to. If this optional address is
+ set, the service RPC server will bind to this address and the port
+ specified in dfs.namenode.servicerpc-address. It can also be specified
+ per name node or name service for HA/Federation. This is most useful for
+ making name node listen to all interfaces by setting to 0.0.0.0.
+ </description>
+</property>
+
+<property>
<name>dfs.namenode.secondary.http-address</name>
<value>0.0.0.0:50090</value>
<description>
Propchange: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode:r1514105-1522706
Propchange: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs:r1514105-1522706
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp Thu Sep 19 23:42:10 2013
@@ -65,6 +65,7 @@
<h3>Cluster Summary</h3>
<b> <%= NamenodeJspHelper.getSecurityModeText()%> </b>
<b> <%= NamenodeJspHelper.getSafeModeText(fsn)%> </b>
+<b> <%= NamenodeJspHelper.getRollingUpgradeText(fsn)%> </b>
<b> <%= NamenodeJspHelper.getInodeLimitText(fsn)%> </b>
<%= NamenodeJspHelper.getCorruptFilesWarning(fsn)%>
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/index.html
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/index.html?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/index.html (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/index.html Thu Sep 19 23:42:10 2013
@@ -1,5 +1,3 @@
-<meta HTTP-EQUIV="REFRESH" content="0;url=dfshealth.jsp"/>
-<html>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,6 +14,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
+<meta HTTP-EQUIV="REFRESH" content="0;url=dfshealth.jsp"/>
+<html>
<head>
<title>Hadoop Administration</title>
</head>
Propchange: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary:r1514105-1522706
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/aop/org/apache/hadoop/fs/TestFiRename.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/aop/org/apache/hadoop/fs/TestFiRename.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/aop/org/apache/hadoop/fs/TestFiRename.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/aop/org/apache/hadoop/fs/TestFiRename.java Thu Sep 19 23:42:10 2013
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.fs;
+import java.io.File;
import java.io.IOException;
import java.util.EnumSet;
@@ -27,6 +28,7 @@ import org.apache.hadoop.fs.Options.Rena
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.test.PathUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -56,8 +58,7 @@ public class TestFiRename {
private static String addChild = "";
private static byte[] data = { 0 };
- private static String TEST_ROOT_DIR =
- System.getProperty("test.build.data", "/tmp") + "/test";
+ private static String TEST_ROOT_DIR = PathUtils.getTestDirName(TestFiRename.class);
private static Configuration CONF = new Configuration();
static {
Propchange: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs:r1514105-1522706
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestGlobPaths.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestGlobPaths.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestGlobPaths.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestGlobPaths.java Thu Sep 19 23:42:10 2013
@@ -20,7 +20,6 @@ package org.apache.hadoop.fs;
import static org.junit.Assert.*;
import java.io.IOException;
-import java.util.Arrays;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
@@ -30,8 +29,6 @@ import org.apache.hadoop.hdfs.HdfsConfig
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.junit.*;
-import com.google.common.base.Joiner;
-
public class TestGlobPaths {
static class RegexPathFilter implements PathFilter {
@@ -50,6 +47,7 @@ public class TestGlobPaths {
static private MiniDFSCluster dfsCluster;
static private FileSystem fs;
+ static private FileContext fc;
static final private int NUM_OF_PATHS = 4;
static private String USER_DIR;
private Path[] path = new Path[NUM_OF_PATHS];
@@ -59,6 +57,7 @@ public class TestGlobPaths {
Configuration conf = new HdfsConfiguration();
dfsCluster = new MiniDFSCluster.Builder(conf).build();
fs = FileSystem.get(conf);
+ fc = FileContext.getFileContext(conf);
USER_DIR = fs.getHomeDirectory().toUri().getPath().toString();
}
@@ -466,6 +465,9 @@ public class TestGlobPaths {
@Test
public void pTestEscape() throws IOException {
+ // Skip the test case on Windows because backslash will be treated as a
+ // path separator instead of an escaping character on Windows.
+ org.junit.Assume.assumeTrue(!Path.WINDOWS);
try {
String [] files = new String[] {USER_DIR+"/ab\\[c.d"};
Path[] matchedPath = prepareTesting(USER_DIR+"/ab\\[c.d", files);
@@ -620,21 +622,7 @@ public class TestGlobPaths {
cleanupDFS();
}
}
-
- @Test
- public void pTestRelativePath() throws IOException {
- try {
- String [] files = new String[] {"a", "abc", "abc.p", "bacd"};
- Path[] matchedPath = prepareTesting("a*", files);
- assertEquals(matchedPath.length, 3);
- assertEquals(matchedPath[0], new Path(USER_DIR, path[0]));
- assertEquals(matchedPath[1], new Path(USER_DIR, path[1]));
- assertEquals(matchedPath[2], new Path(USER_DIR, path[2]));
- } finally {
- cleanupDFS();
- }
- }
-
+
/* Test {xx,yy} */
@Test
public void pTestCurlyBracket() throws IOException {
@@ -800,28 +788,24 @@ public class TestGlobPaths {
/**
* Run a glob test on FileSystem.
*/
- private static void testOnFileSystem(FSTestWrapperGlobTest test) throws Exception {
- Configuration conf = new HdfsConfiguration();
- MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
+ private void testOnFileSystem(FSTestWrapperGlobTest test) throws Exception {
try {
- FileSystem fs = FileSystem.get(conf);
+ fc.mkdir(new Path(USER_DIR), FsPermission.getDefault(), true);
test.run(new FileSystemTestWrapper(fs), fs, null);
} finally {
- cluster.shutdown();
+ fc.delete(new Path(USER_DIR), true);
}
}
/**
* Run a glob test on FileContext.
*/
- private static void testOnFileContext(FSTestWrapperGlobTest test) throws Exception {
- Configuration conf = new HdfsConfiguration();
- MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
+ private void testOnFileContext(FSTestWrapperGlobTest test) throws Exception {
try {
- FileContext fc = FileContext.getFileContext(conf);
+ fs.mkdirs(new Path(USER_DIR));
test.run(new FileContextTestWrapper(fc), null, fc);
} finally {
- cluster.shutdown();
+ cleanupDFS();
}
}
@@ -854,32 +838,33 @@ public class TestGlobPaths {
throws Exception {
// Test that globbing through a symlink to a directory yields a path
// containing that symlink.
- wrap.mkdir(new Path("/alpha"),
- FsPermission.getDirDefault(), false);
- wrap.createSymlink(new Path("/alpha"), new Path("/alphaLink"), false);
- wrap.mkdir(new Path("/alphaLink/beta"),
+ wrap.mkdir(new Path(USER_DIR + "/alpha"), FsPermission.getDirDefault(),
+ false);
+ wrap.createSymlink(new Path(USER_DIR + "/alpha"), new Path(USER_DIR
+ + "/alphaLink"), false);
+ wrap.mkdir(new Path(USER_DIR + "/alphaLink/beta"),
FsPermission.getDirDefault(), false);
// Test simple glob
- FileStatus[] statuses =
- wrap.globStatus(new Path("/alpha/*"), new AcceptAllPathFilter());
+ FileStatus[] statuses = wrap.globStatus(new Path(USER_DIR + "/alpha/*"),
+ new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alpha/beta",
- statuses[0].getPath().toUri().getPath());
+ Assert.assertEquals(USER_DIR + "/alpha/beta", statuses[0].getPath()
+ .toUri().getPath());
// Test glob through symlink
- statuses =
- wrap.globStatus(new Path("/alphaLink/*"), new AcceptAllPathFilter());
+ statuses = wrap.globStatus(new Path(USER_DIR + "/alphaLink/*"),
+ new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alphaLink/beta",
- statuses[0].getPath().toUri().getPath());
+ Assert.assertEquals(USER_DIR + "/alphaLink/beta", statuses[0].getPath()
+ .toUri().getPath());
// If the terminal path component in a globbed path is a symlink,
// we don't dereference that link.
- wrap.createSymlink(new Path("beta"), new Path("/alphaLink/betaLink"),
- false);
- statuses = wrap.globStatus(new Path("/alpha/betaLi*"),
+ wrap.createSymlink(new Path("beta"), new Path(USER_DIR
+ + "/alphaLink/betaLink"), false);
+ statuses = wrap.globStatus(new Path(USER_DIR + "/alpha/betaLi*"),
new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alpha/betaLink",
- statuses[0].getPath().toUri().getPath());
+ Assert.assertEquals(USER_DIR + "/alpha/betaLink", statuses[0].getPath()
+ .toUri().getPath());
// todo: test symlink-to-symlink-to-dir, etc.
}
}
@@ -899,58 +884,64 @@ public class TestGlobPaths {
*
* Also test globbing dangling symlinks. It should NOT throw any exceptions!
*/
- private static class TestGlobWithSymlinksToSymlinks
- implements FSTestWrapperGlobTest {
+ private static class TestGlobWithSymlinksToSymlinks implements
+ FSTestWrapperGlobTest {
public void run(FSTestWrapper wrap, FileSystem fs, FileContext fc)
throws Exception {
// Test that globbing through a symlink to a symlink to a directory
// fully resolves
- wrap.mkdir(new Path("/alpha"), FsPermission.getDirDefault(), false);
- wrap.createSymlink(new Path("/alpha"), new Path("/alphaLink"), false);
- wrap.createSymlink(new Path("/alphaLink"),
- new Path("/alphaLinkLink"), false);
- wrap.mkdir(new Path("/alpha/beta"), FsPermission.getDirDefault(), false);
+ wrap.mkdir(new Path(USER_DIR + "/alpha"), FsPermission.getDirDefault(),
+ false);
+ wrap.createSymlink(new Path(USER_DIR + "/alpha"), new Path(USER_DIR
+ + "/alphaLink"), false);
+ wrap.createSymlink(new Path(USER_DIR + "/alphaLink"), new Path(USER_DIR
+ + "/alphaLinkLink"), false);
+ wrap.mkdir(new Path(USER_DIR + "/alpha/beta"),
+ FsPermission.getDirDefault(), false);
// Test glob through symlink to a symlink to a directory
- FileStatus statuses[] =
- wrap.globStatus(new Path("/alphaLinkLink"), new AcceptAllPathFilter());
+ FileStatus statuses[] = wrap.globStatus(new Path(USER_DIR
+ + "/alphaLinkLink"), new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alphaLinkLink",
- statuses[0].getPath().toUri().getPath());
- statuses =
- wrap.globStatus(new Path("/alphaLinkLink/*"), new AcceptAllPathFilter());
+ Assert.assertEquals(USER_DIR + "/alphaLinkLink", statuses[0].getPath()
+ .toUri().getPath());
+ statuses = wrap.globStatus(new Path(USER_DIR + "/alphaLinkLink/*"),
+ new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alphaLinkLink/beta",
- statuses[0].getPath().toUri().getPath());
+ Assert.assertEquals(USER_DIR + "/alphaLinkLink/beta", statuses[0]
+ .getPath().toUri().getPath());
// Test glob of dangling symlink (theta does not actually exist)
- wrap.createSymlink(new Path("theta"), new Path("/alpha/kappa"), false);
- statuses = wrap.globStatus(new Path("/alpha/kappa/kappa"),
- new AcceptAllPathFilter());
+ wrap.createSymlink(new Path(USER_DIR + "theta"), new Path(USER_DIR
+ + "/alpha/kappa"), false);
+ statuses = wrap.globStatus(new Path(USER_DIR + "/alpha/kappa/kappa"),
+ new AcceptAllPathFilter());
Assert.assertNull(statuses);
// Test glob of symlinks
- wrap.createFile("/alpha/beta/gamma");
- wrap.createSymlink(new Path("gamma"),
- new Path("/alpha/beta/gammaLink"), false);
- wrap.createSymlink(new Path("gammaLink"),
- new Path("/alpha/beta/gammaLinkLink"), false);
- wrap.createSymlink(new Path("gammaLinkLink"),
- new Path("/alpha/beta/gammaLinkLinkLink"), false);
- statuses = wrap.globStatus(new Path("/alpha/*/gammaLinkLinkLink"),
- new AcceptAllPathFilter());
+ wrap.createFile(USER_DIR + "/alpha/beta/gamma");
+ wrap.createSymlink(new Path(USER_DIR + "gamma"), new Path(USER_DIR
+ + "/alpha/beta/gammaLink"), false);
+ wrap.createSymlink(new Path(USER_DIR + "gammaLink"), new Path(USER_DIR
+ + "/alpha/beta/gammaLinkLink"), false);
+ wrap.createSymlink(new Path(USER_DIR + "gammaLinkLink"), new Path(
+ USER_DIR + "/alpha/beta/gammaLinkLinkLink"), false);
+ statuses = wrap.globStatus(new Path(USER_DIR
+ + "/alpha/*/gammaLinkLinkLink"), new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alpha/beta/gammaLinkLinkLink",
+ Assert.assertEquals(USER_DIR + "/alpha/beta/gammaLinkLinkLink",
statuses[0].getPath().toUri().getPath());
- statuses = wrap.globStatus(new Path("/alpha/beta/*"),
- new AcceptAllPathFilter());
- Assert.assertEquals("/alpha/beta/gamma;/alpha/beta/gammaLink;" +
- "/alpha/beta/gammaLinkLink;/alpha/beta/gammaLinkLinkLink",
+ statuses = wrap.globStatus(new Path(USER_DIR + "/alpha/beta/*"),
+ new AcceptAllPathFilter());
+ Assert.assertEquals(USER_DIR + "/alpha/beta/gamma;" + USER_DIR
+ + "/alpha/beta/gammaLink;" + USER_DIR + "/alpha/beta/gammaLinkLink;"
+ + USER_DIR + "/alpha/beta/gammaLinkLinkLink",
TestPath.mergeStatuses(statuses));
// Let's create two symlinks that point to each other, and glob on them.
- wrap.createSymlink(new Path("tweedledee"),
- new Path("/tweedledum"), false);
- wrap.createSymlink(new Path("tweedledum"),
- new Path("/tweedledee"), false);
- statuses = wrap.globStatus(new Path("/tweedledee/unobtainium"),
- new AcceptAllPathFilter());
+ wrap.createSymlink(new Path(USER_DIR + "tweedledee"), new Path(USER_DIR
+ + "/tweedledum"), false);
+ wrap.createSymlink(new Path(USER_DIR + "tweedledum"), new Path(USER_DIR
+ + "/tweedledee"), false);
+ statuses = wrap.globStatus(
+ new Path(USER_DIR + "/tweedledee/unobtainium"),
+ new AcceptAllPathFilter());
Assert.assertNull(statuses);
}
}
@@ -968,34 +959,39 @@ public class TestGlobPaths {
/**
* Test globbing symlinks with a custom PathFilter
*/
- private static class TestGlobSymlinksWithCustomPathFilter
- implements FSTestWrapperGlobTest {
+ private static class TestGlobSymlinksWithCustomPathFilter implements
+ FSTestWrapperGlobTest {
public void run(FSTestWrapper wrap, FileSystem fs, FileContext fc)
throws Exception {
// Test that globbing through a symlink to a symlink to a directory
// fully resolves
- wrap.mkdir(new Path("/alpha"), FsPermission.getDirDefault(), false);
- wrap.createSymlink(new Path("/alpha"), new Path("/alphaLinkz"), false);
- wrap.mkdir(new Path("/alpha/beta"), FsPermission.getDirDefault(), false);
- wrap.mkdir(new Path("/alpha/betaz"), FsPermission.getDirDefault(), false);
- // Test glob through symlink to a symlink to a directory, with a PathFilter
- FileStatus statuses[] =
- wrap.globStatus(new Path("/alpha/beta"), new AcceptPathsEndingInZ());
+ wrap.mkdir(new Path(USER_DIR + "/alpha"), FsPermission.getDirDefault(),
+ false);
+ wrap.createSymlink(new Path(USER_DIR + "/alpha"), new Path(USER_DIR
+ + "/alphaLinkz"), false);
+ wrap.mkdir(new Path(USER_DIR + "/alpha/beta"),
+ FsPermission.getDirDefault(), false);
+ wrap.mkdir(new Path(USER_DIR + "/alpha/betaz"),
+ FsPermission.getDirDefault(), false);
+ // Test glob through symlink to a symlink to a directory, with a
+ // PathFilter
+ FileStatus statuses[] = wrap.globStatus(
+ new Path(USER_DIR + "/alpha/beta"), new AcceptPathsEndingInZ());
Assert.assertNull(statuses);
- statuses =
- wrap.globStatus(new Path("/alphaLinkz/betaz"), new AcceptPathsEndingInZ());
+ statuses = wrap.globStatus(new Path(USER_DIR + "/alphaLinkz/betaz"),
+ new AcceptPathsEndingInZ());
Assert.assertEquals(1, statuses.length);
- Assert.assertEquals("/alphaLinkz/betaz",
- statuses[0].getPath().toUri().getPath());
- statuses =
- wrap.globStatus(new Path("/*/*"), new AcceptPathsEndingInZ());
- Assert.assertEquals("/alpha/betaz;/alphaLinkz/betaz",
- TestPath.mergeStatuses(statuses));
- statuses =
- wrap.globStatus(new Path("/*/*"), new AcceptAllPathFilter());
- Assert.assertEquals("/alpha/beta;/alpha/betaz;" +
- "/alphaLinkz/beta;/alphaLinkz/betaz",
- TestPath.mergeStatuses(statuses));
+ Assert.assertEquals(USER_DIR + "/alphaLinkz/betaz", statuses[0].getPath()
+ .toUri().getPath());
+ statuses = wrap.globStatus(new Path(USER_DIR + "/*/*"),
+ new AcceptPathsEndingInZ());
+ Assert.assertEquals(USER_DIR + "/alpha/betaz;" + USER_DIR
+ + "/alphaLinkz/betaz", TestPath.mergeStatuses(statuses));
+ statuses = wrap.globStatus(new Path(USER_DIR + "/*/*"),
+ new AcceptAllPathFilter());
+ Assert.assertEquals(USER_DIR + "/alpha/beta;" + USER_DIR
+ + "/alpha/betaz;" + USER_DIR + "/alphaLinkz/beta;" + USER_DIR
+ + "/alphaLinkz/betaz", TestPath.mergeStatuses(statuses));
}
}
@@ -1012,24 +1008,25 @@ public class TestGlobPaths {
/**
* Test that globStatus fills in the scheme even when it is not provided.
*/
- private static class TestGlobFillsInScheme
- implements FSTestWrapperGlobTest {
- public void run(FSTestWrapper wrap, FileSystem fs, FileContext fc)
+ private static class TestGlobFillsInScheme implements FSTestWrapperGlobTest {
+ public void run(FSTestWrapper wrap, FileSystem fs, FileContext fc)
throws Exception {
// Verify that the default scheme is hdfs, when we don't supply one.
- wrap.mkdir(new Path("/alpha"), FsPermission.getDirDefault(), false);
- wrap.createSymlink(new Path("/alpha"), new Path("/alphaLink"), false);
- FileStatus statuses[] =
- wrap.globStatus(new Path("/alphaLink"), new AcceptAllPathFilter());
+ wrap.mkdir(new Path(USER_DIR + "/alpha"), FsPermission.getDirDefault(),
+ false);
+ wrap.createSymlink(new Path(USER_DIR + "/alpha"), new Path(USER_DIR
+ + "/alphaLink"), false);
+ FileStatus statuses[] = wrap.globStatus(
+ new Path(USER_DIR + "/alphaLink"), new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
Path path = statuses[0].getPath();
- Assert.assertEquals("/alphaLink", path.toUri().getPath());
+ Assert.assertEquals(USER_DIR + "/alphaLink", path.toUri().getPath());
Assert.assertEquals("hdfs", path.toUri().getScheme());
if (fc != null) {
// If we're using FileContext, then we can list a file:/// URI.
// Since everyone should have the root directory, we list that.
- statuses =
- wrap.globStatus(new Path("file:///"), new AcceptAllPathFilter());
+ statuses = wrap.globStatus(new Path("file:///"),
+ new AcceptAllPathFilter());
Assert.assertEquals(1, statuses.length);
Path filePath = statuses[0].getPath();
Assert.assertEquals("file", filePath.toUri().getScheme());
@@ -1050,4 +1047,43 @@ public class TestGlobPaths {
public void testGlobFillsInSchemeOnFC() throws Exception {
testOnFileContext(new TestGlobFillsInScheme());
}
+
+ /**
+ * Test that globStatus works with relative paths.
+ **/
+ private static class TestRelativePath implements FSTestWrapperGlobTest {
+ public void run(FSTestWrapper wrap, FileSystem fs, FileContext fc)
+ throws Exception {
+ String[] files = new String[] { "a", "abc", "abc.p", "bacd" };
+
+ Path[] path = new Path[files.length];
+ for(int i=0; i < files.length; i++) {
+ path[i] = wrap.makeQualified(new Path(files[i]));
+ wrap.mkdir(path[i], FsPermission.getDirDefault(), true);
+ }
+
+ Path patternPath = new Path("a*");
+ Path[] globResults = FileUtil.stat2Paths(wrap.globStatus(patternPath,
+ new AcceptAllPathFilter()),
+ patternPath);
+
+ for(int i=0; i < globResults.length; i++) {
+ globResults[i] = wrap.makeQualified(globResults[i]);
+ }
+
+ assertEquals(globResults.length, 3);
+ assertEquals(USER_DIR + "/a;" + USER_DIR + "/abc;" + USER_DIR + "/abc.p",
+ TestPath.mergeStatuses(globResults));
+ }
+ }
+
+ @Test
+ public void testRelativePathOnFS() throws Exception {
+ testOnFileSystem(new TestRelativePath());
+ }
+
+ @Test
+ public void testRelativePathOnFC() throws Exception {
+ testOnFileContext(new TestRelativePath());
+ }
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java Thu Sep 19 23:42:10 2013
@@ -18,6 +18,7 @@
package org.apache.hadoop.fs;
+import java.io.File;
import static org.junit.Assert.fail;
import java.io.FileNotFoundException;
@@ -36,6 +37,7 @@ import org.apache.hadoop.hdfs.security.t
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
+import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -48,6 +50,7 @@ import org.junit.Test;
* underlying file system as Hdfs.
*/
public class TestResolveHdfsSymlink {
+ private static File TEST_ROOT_DIR = PathUtils.getTestDir(TestResolveHdfsSymlink.class);
private static MiniDFSCluster cluster = null;
@BeforeClass
@@ -80,12 +83,12 @@ public class TestResolveHdfsSymlink {
.getUri());
Path alphaLocalPath = new Path(fcLocal.getDefaultFileSystem().getUri()
- .toString(), "/tmp/alpha");
+ .toString(), new File(TEST_ROOT_DIR, "alpha").getAbsolutePath());
DFSTestUtil.createFile(FileSystem.getLocal(conf), alphaLocalPath, 16,
(short) 1, 2);
Path linkTarget = new Path(fcLocal.getDefaultFileSystem().getUri()
- .toString(), "/tmp");
+ .toString(), TEST_ROOT_DIR.getAbsolutePath());
Path hdfsLink = new Path(fcHdfs.getDefaultFileSystem().getUri().toString(),
"/tmp/link");
fcHdfs.createSymlink(linkTarget, hdfsLink, true);
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandler.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandler.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandler.java Thu Sep 19 23:42:10 2013
@@ -31,6 +31,7 @@ import java.net.URL;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.test.PathUtils;
import org.junit.Test;
/**
@@ -38,6 +39,8 @@ import org.junit.Test;
*/
public class TestUrlStreamHandler {
+ private static File TEST_ROOT_DIR = PathUtils.getTestDir(TestUrlStreamHandler.class);
+
/**
* Test opening and reading from an InputStream through a hdfs:// URL.
* <p>
@@ -111,13 +114,12 @@ public class TestUrlStreamHandler {
Configuration conf = new HdfsConfiguration();
// Locate the test temporary directory.
- File tmpDir = new File(conf.get("hadoop.tmp.dir"));
- if (!tmpDir.exists()) {
- if (!tmpDir.mkdirs())
- throw new IOException("Cannot create temporary directory: " + tmpDir);
+ if (!TEST_ROOT_DIR.exists()) {
+ if (!TEST_ROOT_DIR.mkdirs())
+ throw new IOException("Cannot create temporary directory: " + TEST_ROOT_DIR);
}
- File tmpFile = new File(tmpDir, "thefile");
+ File tmpFile = new File(TEST_ROOT_DIR, "thefile");
URI uri = tmpFile.toURI();
FileSystem fs = FileSystem.get(uri, conf);