HDFS-13808: [SPS]: Remove unwanted FSNamesystem #isFileOpenedForWrite() and #getFileInfo() function. Contributed by Rakesh R.

This commit is contained in:
Uma Maheswara Rao Gangumalla 2018-08-11 23:22:59 -07:00
parent 39ed3a66db
commit 3ac07b720b
18 changed files with 39 additions and 240 deletions

View File

@ -187,6 +187,7 @@ public boolean isRollingUpgrade() throws IOException {
@Override
public Long getNextSPSPath() throws IOException {
rpcServer.checkOperation(OperationCategory.READ, false);
// not supported
return null;
}

View File

@ -4299,21 +4299,6 @@ private void updateNeededReconstructions(final BlockInfo block,
}
}
/**
* Check file has low redundancy blocks.
*/
public boolean hasLowRedundancyBlocks(BlockCollection bc) {
boolean result = false;
for (BlockInfo block : bc.getBlocks()) {
short expected = getExpectedRedundancyNum(block);
final NumberReplicas n = countNodes(block);
if (expected > n.liveReplicas()) {
result = true;
}
}
return result;
}
/**
* Check sufficient redundancy of the blocks in the collection. If any block
* is needed reconstruction, insert it into the reconstruction queue.
@ -5010,25 +4995,6 @@ public ProvidedStorageMap getProvidedStorageMap() {
return providedStorageMap;
}
/**
* Check whether file id has low redundancy blocks.
*
* @param inodeID
* - inode id
*/
public boolean hasLowRedundancyBlocks(long inodeID) {
namesystem.readLock();
try {
BlockCollection bc = namesystem.getBlockCollection(inodeID);
if (bc == null) {
return false;
}
return hasLowRedundancyBlocks(bc);
} finally {
namesystem.readUnlock();
}
}
/**
* Create SPS manager instance. It manages the user invoked sps paths and does
* the movement.

View File

@ -793,7 +793,7 @@ public int getBlocksScheduled() {
}
/** Increment the number of blocks scheduled. */
public void incrementBlocksScheduled(StorageType t) {
void incrementBlocksScheduled(StorageType t) {
currApproxBlocksScheduled.add(t, 1);
}

View File

@ -1988,22 +1988,5 @@ public DatanodeStorageReport[] getDatanodeStorageReport(
}
return reports;
}
public boolean verifyTargetDatanodeHasSpaceForScheduling(DatanodeInfo dn,
StorageType type, long estimatedSize) {
namesystem.readLock();
try {
DatanodeDescriptor datanode =
blockManager.getDatanodeManager().getDatanode(dn.getDatanodeUuid());
if (datanode == null) {
LOG.debug("Target datanode: " + dn + " doesn't exists");
return false;
}
return null != datanode.chooseStorage4Block(type, estimatedSize);
} finally {
namesystem.readUnlock();
}
}
}

View File

@ -39,7 +39,6 @@
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.hdfs.client.BlockReportOptions;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.BlockListAsLongs;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
@ -51,7 +50,6 @@
import org.apache.hadoop.hdfs.server.common.IncorrectVersionException;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.protocol.BlockReportContext;
import org.apache.hadoop.hdfs.server.protocol.BlocksStorageMoveAttemptFinished;
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
@ -534,20 +532,6 @@ HeartbeatResponse sendHeartBeat(boolean requestBlockReportLease)
return response;
}
private BlocksStorageMoveAttemptFinished getStorageMoveAttemptFinishedBlocks(
List<Block> finishedBlks) {
if (finishedBlks.isEmpty()) {
return null;
}
// Create BlocksStorageMoveAttemptFinished with currently finished
// blocks
Block[] blockList = new Block[finishedBlks.size()];
finishedBlks.toArray(blockList);
return new BlocksStorageMoveAttemptFinished(blockList);
}
@VisibleForTesting
void sendLifelineForTests() throws IOException {
lifelineSender.sendLifeline();

View File

@ -3133,29 +3133,6 @@ void removeLeasesAndINodes(List<Long> removedUCFiles,
}
}
/**
* Get the file info for a specific file.
*
* @param src The string representation of the path to the file
* @param resolveLink whether to throw UnresolvedLinkException
* if src refers to a symlink
* @param needLocation if blockLocations need to be returned
*
* @throws AccessControlException
* if access is denied
* @throws UnresolvedLinkException
* if a symlink is encountered.
*
* @return object containing information regarding the file or null if file
* not found
* @throws StandbyException
*/
@Override
public HdfsFileStatus getFileInfo(final String src, boolean resolveLink,
boolean needLocation) throws IOException {
return getFileInfo(src, resolveLink, needLocation, false);
}
/**
* Get the file info for a specific file.
*
@ -3603,21 +3580,6 @@ BlockInfo getStoredBlock(Block block) {
return blockManager.getStoredBlock(block);
}
@Override
public boolean isFileOpenedForWrite(String path) {
readLock();
try {
INode inode = dir.getINode(path, FSDirectory.DirOp.READ);
INodeFile iNodeFile = INodeFile.valueOf(inode, path);
LeaseManager.Lease lease = leaseManager.getLease(iNodeFile);
return lease != null;
} catch (IOException e) {
return false;
} finally {
readUnlock();
}
}
@Override
public boolean isInSnapshot(long blockCollectionID) {
assert hasReadLock();

View File

@ -20,7 +20,6 @@
import java.io.IOException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockCollection;
import org.apache.hadoop.hdfs.server.namenode.ha.HAContext;
import org.apache.hadoop.hdfs.util.RwLock;
@ -49,13 +48,6 @@ public interface Namesystem extends RwLock, SafeMode {
*/
boolean inTransitionToActive();
/**
* Check if file is been opened for write purpose.
* @param filePath
* @return true if valid write lease exists, otherwise return false.
*/
boolean isFileOpenedForWrite(String filePath);
/**
* Remove xAttr from the inode.
* @param id
@ -63,18 +55,4 @@ public interface Namesystem extends RwLock, SafeMode {
* @throws IOException
*/
void removeXattr(long id, String xattrName) throws IOException;
/**
* Gets the fileInfo of the given file path.
*
* @param filePath string representation of the path to the file
* @param resolveLink whether to throw UnresolvedLinkException
* if src refers to a symlink
* @param needLocation if blockLocations need to be returned
*
* @return hdfs file status details
* @throws IOException
*/
HdfsFileStatus getFileInfo(String filePath, boolean resolveLink,
boolean needLocation) throws IOException;
}

View File

@ -19,7 +19,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -79,7 +78,9 @@ public BlockStorageMovementNeeded(Context context) {
* - track info for satisfy the policy
*/
public synchronized void add(ItemInfo trackInfo) {
storageMovementNeeded.add(trackInfo);
if (trackInfo != null) {
storageMovementNeeded.add(trackInfo);
}
}
/**
@ -153,7 +154,6 @@ public synchronized int size() {
}
public synchronized void clearAll() {
ctxt.removeAllSPSPathIds();
storageMovementNeeded.clear();
pendingWorkForDirectory.clear();
}
@ -188,18 +188,6 @@ public synchronized void removeItemTrackInfo(ItemInfo trackInfo,
}
}
public synchronized void clearQueue(long trackId) {
ctxt.removeSPSPathId(trackId);
Iterator<ItemInfo> iterator = storageMovementNeeded.iterator();
while (iterator.hasNext()) {
ItemInfo next = iterator.next();
if (next.getFile() == trackId) {
iterator.remove();
}
}
pendingWorkForDirectory.remove(trackId);
}
/**
* Clean all the movements in spsDirsToBeTraveresed/storageMovementNeeded
* and notify to clean up required resources.

View File

@ -22,8 +22,6 @@
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.fs.ParentNotDirectoryException;
import org.apache.hadoop.fs.UnresolvedLinkException;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
@ -31,7 +29,6 @@
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport;
import org.apache.hadoop.hdfs.server.protocol.BlockStorageMovementCommand.BlockMovingInfo;
import org.apache.hadoop.net.NetworkTopology;
import org.apache.hadoop.security.AccessControlException;
/**
* An interface for the communication between SPS and Namenode module.
@ -50,21 +47,6 @@ public interface Context {
*/
boolean isInSafeMode();
/**
* Returns true if Mover tool is already running, false otherwise.
*/
boolean isMoverRunning();
/**
* Gets the Inode ID number for the given path.
*
* @param path
* - file/dir path
* @return Inode id number
*/
long getFileID(String path) throws UnresolvedLinkException,
AccessControlException, ParentNotDirectoryException;
/**
* Gets the network topology.
*
@ -131,16 +113,6 @@ DatanodeStorageReport[] getLiveDatanodeStorageReport()
*/
Long getNextSPSPath();
/**
* Removes the SPS path id.
*/
void removeSPSPathId(long pathId);
/**
* Removes all SPS path ids.
*/
void removeAllSPSPathIds();
/**
* Do scan and collects the files under that directory and adds to the given
* BlockStorageMovementNeeded.

View File

@ -47,12 +47,9 @@ public interface SPSService {
* Starts the SPS service. Make sure to initialize the helper services before
* invoking this method.
*
* @param reconfigStart
* - to indicate whether the SPS startup requested from
* reconfiguration service
* @param spsMode sps service mode
*/
void start(boolean reconfigStart, StoragePolicySatisfierMode spsMode);
void start(StoragePolicySatisfierMode spsMode);
/**
* Stops the SPS service gracefully. Timed wait to stop storage policy

View File

@ -150,21 +150,14 @@ public void init(final Context context) {
* movements monitor for retry the attempts if needed.
*/
@Override
public synchronized void start(boolean reconfigStart,
StoragePolicySatisfierMode serviceMode) {
public synchronized void start(StoragePolicySatisfierMode serviceMode) {
if (serviceMode == StoragePolicySatisfierMode.NONE) {
LOG.error("Can't start StoragePolicySatisfier for the given mode:{}",
serviceMode);
return;
}
if (reconfigStart) {
LOG.info("Starting {} StoragePolicySatisfier, as admin requested to "
+ "start it.", StringUtils.toLowerCase(serviceMode.toString()));
} else {
LOG.info("Starting {} StoragePolicySatisfier.",
StringUtils.toLowerCase(serviceMode.toString()));
}
LOG.info("Starting {} StoragePolicySatisfier.",
StringUtils.toLowerCase(serviceMode.toString()));
isRunning = true;
storagePolicySatisfierThread = new Daemon(this);
storagePolicySatisfierThread.setName("StoragePolicySatisfier");
@ -229,8 +222,8 @@ public void run() {
}
continue;
}
ItemInfo itemInfo = null;
try {
ItemInfo itemInfo = null;
boolean retryItem = false;
if (!ctxt.isInSafeMode()) {
itemInfo = storageMovementNeeded.get();
@ -324,12 +317,14 @@ public void run() {
blockCount = 0L;
}
if (retryItem) {
// itemInfo.increRetryCount();
this.storageMovementNeeded.add(itemInfo);
}
} catch (IOException e) {
LOG.error("Exception during StoragePolicySatisfier execution - "
+ "will continue next cycle", e);
// Since it could not finish this item in previous iteration due to IOE,
// just try again.
this.storageMovementNeeded.add(itemInfo);
} catch (Throwable t) {
synchronized (this) {
if (isRunning) {

View File

@ -24,10 +24,7 @@
import java.util.List;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.ParentNotDirectoryException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.UnresolvedLinkException;
import org.apache.hadoop.hdfs.DFSUtilClient;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
@ -47,7 +44,6 @@
import org.apache.hadoop.hdfs.server.protocol.BlockStorageMovementCommand.BlockMovingInfo;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport;
import org.apache.hadoop.net.NetworkTopology;
import org.apache.hadoop.security.AccessControlException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -92,35 +88,6 @@ public boolean isInSafeMode() {
}
}
@Override
public boolean isMoverRunning() {
try {
FSDataOutputStream out = nnc.getDistributedFileSystem()
.append(HdfsServerConstants.MOVER_ID_PATH);
out.close();
return false;
} catch (IOException ioe) {
LOG.warn("Exception while checking mover is running..", ioe);
return true;
}
}
@Override
public long getFileID(String path) throws UnresolvedLinkException,
AccessControlException, ParentNotDirectoryException {
HdfsFileStatus fs = null;
try {
fs = (HdfsFileStatus) nnc.getDistributedFileSystem().getFileStatus(
new Path(path));
LOG.info("Fetched the fileID:{} for the path:{}", fs.getFileId(), path);
} catch (IllegalArgumentException | IOException e) {
LOG.warn("Exception while getting file is for the given path:{}.", path,
e);
}
return fs != null ? fs.getFileId() : 0;
}
@Override
public NetworkTopology getNetworkTopology(DatanodeMap datanodeMap) {
// create network topology.
@ -152,8 +119,18 @@ public BlockStoragePolicy getStoragePolicy(byte policyId) {
@Override
public void removeSPSHint(long inodeId) throws IOException {
Path filePath = DFSUtilClient.makePathFromFileId(inodeId);
nnc.getDistributedFileSystem().removeXAttr(filePath,
HdfsServerConstants.XATTR_SATISFY_STORAGE_POLICY);
try {
nnc.getDistributedFileSystem().removeXAttr(filePath,
HdfsServerConstants.XATTR_SATISFY_STORAGE_POLICY);
} catch (IOException e) {
List<String> listXAttrs = nnc.getDistributedFileSystem()
.listXAttrs(filePath);
if (!listXAttrs
.contains(HdfsServerConstants.XATTR_SATISFY_STORAGE_POLICY)) {
LOG.info("SPS hint already removed for the inodeId:{}."
+ " Ignoring exception:{}", inodeId, e.getMessage());
}
}
}
@Override
@ -196,16 +173,6 @@ public Long getNextSPSPath() {
}
}
@Override
public void removeSPSPathId(long pathId) {
// We need not specifically implement for external.
}
@Override
public void removeAllSPSPathIds() {
// We need not specifically implement for external.
}
@Override
public void scanAndCollectFiles(long path)
throws IOException, InterruptedException {

View File

@ -70,7 +70,7 @@ public static void main(String[] args) throws Exception {
ExternalSPSContext context = new ExternalSPSContext(sps, nnc);
sps.init(context);
sps.start(true, StoragePolicySatisfierMode.EXTERNAL);
sps.start(StoragePolicySatisfierMode.EXTERNAL);
if (sps != null) {
sps.join();
}

View File

@ -154,7 +154,7 @@ Note that, when both -p and -f options are omitted, the default path is the root
####Administrator notes:
`StoragePolicySatisfier` and `Mover tool` cannot run simultaneously. If a Mover instance is already triggered and running, SPS will be disabled while starting. In that case, administrator should make sure, Mover execution finished and then enable(internal service inside NN or external service outside NN) SPS again. Similarly when SPS enabled already, Mover cannot be run. If administrator is looking to run Mover tool explicitly, then he/she should make sure to disable SPS first and then run Mover. Please look at the commands section to know how to enable(internal service inside NN or external service outside NN) or disable SPS dynamically.
`StoragePolicySatisfier` and `Mover tool` cannot run simultaneously. If a Mover instance is already triggered and running, SPS will be disabled while starting. In that case, administrator should make sure, Mover execution finished and then enable external SPS service again. Similarly when SPS enabled already, Mover cannot be run. If administrator is looking to run Mover tool explicitly, then he/she should make sure to disable SPS first and then run Mover. Please look at the commands section to know how to enable external service outside NN or disable SPS dynamically.
Storage Policy Commands
-----------------------

View File

@ -113,6 +113,8 @@ private void clusterSetUp(boolean isHAEnabled, Configuration newConf)
// Reduced refresh cycle to update latest datanodes.
conf.setLong(DFSConfigKeys.DFS_SPS_DATANODE_CACHE_REFRESH_INTERVAL_MS,
1000);
conf.setInt(
DFSConfigKeys.DFS_STORAGE_POLICY_SATISFIER_MAX_RETRY_ATTEMPTS_KEY, 20);
final int dnNumber = storageTypes.length;
final short replication = 3;
MiniDFSCluster.Builder clusterBuilder = new MiniDFSCluster.Builder(conf)
@ -136,7 +138,7 @@ private void clusterSetUp(boolean isHAEnabled, Configuration newConf)
ctxt = new ExternalSPSContext(sps, nnc);
sps.init(ctxt);
sps.start(true, StoragePolicySatisfierMode.EXTERNAL);
sps.start(StoragePolicySatisfierMode.EXTERNAL);
createTestFiles(fs, replication);
}
@ -188,6 +190,7 @@ private void clusterShutdown() throws IOException{
*/
@Test(timeout = 300000)
public void testWithCheckpoint() throws Exception {
SecondaryNameNode secondary = null;
try {
clusterSetUp();
fs.setStoragePolicy(testFile, WARM);
@ -196,7 +199,7 @@ public void testWithCheckpoint() throws Exception {
// Start the checkpoint.
conf.set(
DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY, "0.0.0.0:0");
SecondaryNameNode secondary = new SecondaryNameNode(conf);
secondary = new SecondaryNameNode(conf);
secondary.doCheckpoint();
restartCluster();
@ -214,6 +217,9 @@ public void testWithCheckpoint() throws Exception {
childFileName, StorageType.ARCHIVE, 3, timeout, fs);
} finally {
if (secondary != null) {
secondary.shutdown();
}
clusterShutdown();
}
}

View File

@ -510,7 +510,7 @@ private void startSPS() throws IOException {
sps = new StoragePolicySatisfier(conf);
ctxt = new ExternalSPSContext(sps, nnc);
sps.init(ctxt);
sps.start(true, StoragePolicySatisfierMode.EXTERNAL);
sps.start(StoragePolicySatisfierMode.EXTERNAL);
}
private static void initConfWithStripe(Configuration conf,

View File

@ -219,7 +219,7 @@ private MiniDFSCluster startCluster(final Configuration conf,
externalCtxt = new ExternalSPSContext(externalSps, nnc);
externalSps.init(externalCtxt);
externalSps.start(true, StoragePolicySatisfierMode.EXTERNAL);
externalSps.start(StoragePolicySatisfierMode.EXTERNAL);
return cluster;
}
@ -234,7 +234,7 @@ private void restartNamenode() throws IOException{
externalCtxt = new ExternalSPSContext(externalSps, nnc);
externalSps.init(externalCtxt);
externalSps.start(true, StoragePolicySatisfierMode.EXTERNAL);
externalSps.start(StoragePolicySatisfierMode.EXTERNAL);
}
private void initSecureConf(Configuration conf) throws Exception {

View File

@ -71,7 +71,7 @@ public void clusterSetUp() throws IOException, URISyntaxException {
Context externalCtxt = new ExternalSPSContext(externalSps, nnc);
externalSps.init(externalCtxt);
externalSps.start(true, StoragePolicySatisfierMode.EXTERNAL);
externalSps.start(StoragePolicySatisfierMode.EXTERNAL);
}
@After