Skip to content

Commit

Permalink
Clean up a bunch in tachyon.master
Browse files Browse the repository at this point in the history
  • Loading branch information
apc999 committed Apr 14, 2015
1 parent 4f32ceb commit 45a2aa3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 54 deletions.
7 changes: 6 additions & 1 deletion core/src/main/java/tachyon/master/BlockInfo.java
Expand Up @@ -22,6 +22,8 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


import com.google.common.base.Preconditions;

import tachyon.Pair; import tachyon.Pair;
import tachyon.StorageDirId; import tachyon.StorageDirId;
import tachyon.StorageLevelAlias; import tachyon.StorageLevelAlias;
Expand Down Expand Up @@ -75,15 +77,18 @@ public static int computeInodeId(long blockId) {
public final long mOffset; public final long mOffset;
public final long mLength; public final long mLength;


/* Map worker's workerId to its NetAddress */
private final Map<Long, NetAddress> mLocations = new HashMap<Long, NetAddress>(5); private final Map<Long, NetAddress> mLocations = new HashMap<Long, NetAddress>(5);
/* Map worker's NetAddress to storageDirId */
private final Map<NetAddress, Long> mStorageDirIds = new HashMap<NetAddress, Long>(5); private final Map<NetAddress, Long> mStorageDirIds = new HashMap<NetAddress, Long>(5);


/** /**
* @param inodeFile * @param inodeFile
* @param blockIndex * @param blockIndex
* @param length Can not be no bigger than 2^31 - 1 * @param length Can not be larger than 2^31 - 1
*/ */
BlockInfo(InodeFile inodeFile, int blockIndex, long length) { BlockInfo(InodeFile inodeFile, int blockIndex, long length) {
Preconditions.checkArgument(length < (1 << 31), "length can not be larger than 2^31 - 1");
mInodeFile = inodeFile; mInodeFile = inodeFile;
mBlockIndex = blockIndex; mBlockIndex = blockIndex;
mBlockId = computeBlockId(mInodeFile.getId(), mBlockIndex); mBlockId = computeBlockId(mInodeFile.getId(), mBlockIndex);
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/tachyon/master/Inode.java
Expand Up @@ -34,21 +34,23 @@ public abstract class Inode extends ImageWriter implements Comparable<Inode> {
*/ */
private boolean mPinned = false; private boolean mPinned = false;


/**
* The last modification time of this inode, in milliseconds.
*/
private long mLastModificationTimeMs; private long mLastModificationTimeMs;


/** /**
* Create an inode. * Create an inode.
* *
* @param name the name of the inode. * @param name the name of the inode.
* @param id the id of the inode, which is globaly unique. * @param id the id of the inode, which is globally unique.
* @param parentId the parent of the inode. -1 if there is no parent. * @param parentId the id of the parent inode. -1 if there is no parent.
* @param isFolder if the inode presents a folder * @param isFolder if the inode presents a folder
* @param creationTimeMs the creation time of the inode. * @param creationTimeMs the creation time of the inode, in milliseconds.
*/ */
protected Inode(String name, int id, int parentId, boolean isFolder, long creationTimeMs) { protected Inode(String name, int id, int parentId, boolean isFolder, long creationTimeMs) {
mCreationTimeMs = creationTimeMs; mCreationTimeMs = creationTimeMs;
mIsFolder = isFolder; mIsFolder = isFolder;

mId = id; mId = id;
mName = name; mName = name;
mParentId = parentId; mParentId = parentId;
Expand Down
81 changes: 41 additions & 40 deletions core/src/main/java/tachyon/master/InodeFile.java
Expand Up @@ -4,9 +4,9 @@
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a * "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at * copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the License * Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under * or implied. See the License for the specific language governing permissions and limitations under
Expand Down Expand Up @@ -36,7 +36,7 @@
public class InodeFile extends Inode { public class InodeFile extends Inode {
/** /**
* Create a new InodeFile from an image JSON element * Create a new InodeFile from an image JSON element
* *
* @param ele the image JSON element * @param ele the image JSON element
* @return the created inode file. * @return the created inode file.
* @throws IOException * @throws IOException
Expand Down Expand Up @@ -83,10 +83,10 @@ static InodeFile loadImage(ImageElement ele) throws IOException {


/** /**
* Create a new InodeFile. * Create a new InodeFile.
* *
* @param name The name of the file * @param name The name of the file
* @param id The id of the file * @param id The inode id of the file
* @param parentId The id of the parent of the file * @param parentId The inode id of the parent of the file
* @param blockSizeByte The block size of the file, in bytes * @param blockSizeByte The block size of the file, in bytes
* @param creationTimeMs The creation time of the file, in milliseconds * @param creationTimeMs The creation time of the file, in milliseconds
*/ */
Expand All @@ -97,9 +97,9 @@ public InodeFile(String name, int id, int parentId, long blockSizeByte, long cre
} }


/** /**
* Add a block to the file.It will check the legality. Cannot add the block if the file is * Add a block to the file. It will check the legality. Cannot add the block if the file is
* complete or the block's information doesn't match the file's information. * complete or the block's information doesn't match the file's information.
* *
* @param blockInfo The block to be added * @param blockInfo The block to be added
* @throws BlockInfoException * @throws BlockInfoException
*/ */
Expand Down Expand Up @@ -130,7 +130,7 @@ public synchronized void addBlock(BlockInfo blockInfo) throws BlockInfoException


/** /**
* Add a location information of the file. A worker caches a block of the file. * Add a location information of the file. A worker caches a block of the file.
* *
* @param blockIndex The index of the block in the file * @param blockIndex The index of the block in the file
* @param workerId The id of the worker * @param workerId The id of the worker
* @param workerAddress The net address of the worker * @param workerAddress The net address of the worker
Expand Down Expand Up @@ -170,7 +170,7 @@ public ClientFileInfo generateClientFileInfo(String path) {


/** /**
* Get the id of the specified block by the offset of the file. * Get the id of the specified block by the offset of the file.
* *
* @param offset The offset of the file * @param offset The offset of the file
* @return the id of the specified block * @return the id of the specified block
*/ */
Expand All @@ -180,8 +180,8 @@ public long getBlockIdBasedOnOffset(long offset) {
} }


/** /**
* Get all the blocks of the file. It will return a duplication. * Get all the blocks of the file. It will return a duplication of the block list.
* *
* @return a duplication of all the blocks' ids of the file * @return a duplication of all the blocks' ids of the file
*/ */
public synchronized List<Long> getBlockIds() { public synchronized List<Long> getBlockIds() {
Expand All @@ -195,7 +195,7 @@ public synchronized List<Long> getBlockIds() {
/** /**
* The pairs of the blocks and workers. Each pair contains a block's id and the id of the worker * The pairs of the blocks and workers. Each pair contains a block's id and the id of the worker
* who caches it. * who caches it.
* *
* @return all the pairs of the blocks and the workers * @return all the pairs of the blocks and the workers
*/ */
public synchronized List<Pair<Long, Long>> getBlockIdWorkerIdPairs() { public synchronized List<Pair<Long, Long>> getBlockIdWorkerIdPairs() {
Expand All @@ -208,7 +208,7 @@ public synchronized List<Pair<Long, Long>> getBlockIdWorkerIdPairs() {


/** /**
* Get the block list of the file, which is not a duplication. * Get the block list of the file, which is not a duplication.
* *
* @return the block list of the file * @return the block list of the file
*/ */
public List<BlockInfo> getBlockList() { public List<BlockInfo> getBlockList() {
Expand All @@ -217,7 +217,7 @@ public List<BlockInfo> getBlockList() {


/** /**
* Get the locations of the specified block. * Get the locations of the specified block.
* *
* @param blockIndex The index of the block in the file * @param blockIndex The index of the block in the file
* @return a list of the worker's net address who caches the block * @return a list of the worker's net address who caches the block
* @throws BlockInfoException * @throws BlockInfoException
Expand All @@ -233,7 +233,7 @@ public synchronized List<NetAddress> getBlockLocations(int blockIndex, TachyonCo


/** /**
* Get the block size of the file * Get the block size of the file
* *
* @return the block size in bytes * @return the block size in bytes
*/ */
public long getBlockSizeByte() { public long getBlockSizeByte() {
Expand All @@ -242,7 +242,7 @@ public long getBlockSizeByte() {


/** /**
* Get the path of the file in under file system * Get the path of the file in under file system
* *
* @return the path of the file in under file system * @return the path of the file in under file system
*/ */
public synchronized String getUfsPath() { public synchronized String getUfsPath() {
Expand All @@ -251,7 +251,7 @@ public synchronized String getUfsPath() {


/** /**
* Get a ClientBlockInfo of the specified block. * Get a ClientBlockInfo of the specified block.
* *
* @param blockIndex The index of the block in the file * @param blockIndex The index of the block in the file
* @param tachyonConf The {@link tachyon.conf.TachyonConf} instance * @param tachyonConf The {@link tachyon.conf.TachyonConf} instance
* @return the generated ClientBlockInfo * @return the generated ClientBlockInfo
Expand All @@ -268,7 +268,7 @@ public synchronized ClientBlockInfo getClientBlockInfo(int blockIndex, TachyonCo


/** /**
* Get file's all blocks' ClientBlockInfo information. * Get file's all blocks' ClientBlockInfo information.
* *
* @return all blocks ClientBlockInfo * @return all blocks ClientBlockInfo
*/ */
public synchronized List<ClientBlockInfo> getClientBlockInfos(TachyonConf tachyonConf) { public synchronized List<ClientBlockInfo> getClientBlockInfos(TachyonConf tachyonConf) {
Expand All @@ -281,16 +281,17 @@ public synchronized List<ClientBlockInfo> getClientBlockInfos(TachyonConf tachyo


/** /**
* Get the dependency id of the file * Get the dependency id of the file
* *
* @return the dependency id of the file * @return the dependency id of the file
*/ */
public synchronized int getDependencyId() { public synchronized int getDependencyId() {
return mDependencyId; return mDependencyId;
} }


/** /**
* Get the percentage that how many of the file is in memory. * Get the percentage of the file in memory. For a file that has all blocks in memory, it returns
* * 100; for a file that has no block in memory, it returns 0.
*
* @return the in memory percentage * @return the in memory percentage
*/ */
private synchronized int getInMemoryPercentage() { private synchronized int getInMemoryPercentage() {
Expand All @@ -308,17 +309,17 @@ private synchronized int getInMemoryPercentage() {
} }


/** /**
* Get the length of the file * Get the length of the file in bytes.
* *
* @return the length of the file * @return the length of the file in bytes
*/ */
public synchronized long getLength() { public synchronized long getLength() {
return mLength; return mLength;
} }


/** /**
* Get the id of a new block of the file. Also the id of the next block added into the file. * Get the id for a new block of the file. Also the id of the next block added into the file.
* *
* @return the id of a new block of the file * @return the id of a new block of the file
*/ */
public synchronized long getNewBlockId() { public synchronized long getNewBlockId() {
Expand All @@ -327,17 +328,17 @@ public synchronized long getNewBlockId() {


/** /**
* Get the number of the blocks of the file * Get the number of the blocks of the file
* *
* @return the number of the blocks * @return the number of the blocks
*/ */
public synchronized int getNumberOfBlocks() { public synchronized int getNumberOfBlocks() {
return mBlocks.size(); return mBlocks.size();
} }


/** /**
* Return whether the file has checkpointed or not. Note that the file has checkpointed only if * Return whether the file has checkpointed or not. Note that the file has checkpointed only
* the under file system path is not empty. * if the under file system path is not empty.
* *
* @return true if the file has checkpointed, false otherwise * @return true if the file has checkpointed, false otherwise
*/ */
public synchronized boolean hasCheckpointed() { public synchronized boolean hasCheckpointed() {
Expand All @@ -346,7 +347,7 @@ public synchronized boolean hasCheckpointed() {


/** /**
* Return whether the file is cacheable or not. * Return whether the file is cacheable or not.
* *
* @return true if the file is cacheable, false otherwise * @return true if the file is cacheable, false otherwise
*/ */
public synchronized boolean isCache() { public synchronized boolean isCache() {
Expand All @@ -355,7 +356,7 @@ public synchronized boolean isCache() {


/** /**
* Return whether the file is complete or not. * Return whether the file is complete or not.
* *
* @return true if the file is complete, false otherwise * @return true if the file is complete, false otherwise
*/ */
public synchronized boolean isComplete() { public synchronized boolean isComplete() {
Expand All @@ -365,7 +366,7 @@ public synchronized boolean isComplete() {
/** /**
* Return whether the file is fully in memory or not. The file is fully in memory only if all the * Return whether the file is fully in memory or not. The file is fully in memory only if all the
* blocks of the file are in memory, in other words, the in memory percentage is 100. * blocks of the file are in memory, in other words, the in memory percentage is 100.
* *
* @return true if the file is fully in memory, false otherwise * @return true if the file is fully in memory, false otherwise
*/ */
public synchronized boolean isFullyInMemory() { public synchronized boolean isFullyInMemory() {
Expand All @@ -374,7 +375,7 @@ public synchronized boolean isFullyInMemory() {


/** /**
* Remove a location of a block. * Remove a location of a block.
* *
* @param blockIndex The index of the block in the file * @param blockIndex The index of the block in the file
* @param workerId The id of the removed location worker * @param workerId The id of the removed location worker
* @throws BlockInfoException * @throws BlockInfoException
Expand All @@ -388,7 +389,7 @@ public synchronized void removeLocation(int blockIndex, long workerId) throws Bl


/** /**
* Set whether the file is cacheable or not. * Set whether the file is cacheable or not.
* *
* @param cache If true, the file is cacheable * @param cache If true, the file is cacheable
*/ */
public synchronized void setCache(boolean cache) { public synchronized void setCache(boolean cache) {
Expand All @@ -398,7 +399,7 @@ public synchronized void setCache(boolean cache) {


/** /**
* Set the path of the file in under file system. * Set the path of the file in under file system.
* *
* @param ufsPath The new path of the file in under file system * @param ufsPath The new path of the file in under file system
*/ */
public synchronized void setUfsPath(String ufsPath) { public synchronized void setUfsPath(String ufsPath) {
Expand All @@ -414,7 +415,7 @@ public synchronized void setComplete() {


/** /**
* Set the complete flag of the file * Set the complete flag of the file
* *
* @param complete If true, the file is complete * @param complete If true, the file is complete
*/ */
public synchronized void setComplete(boolean complete) { public synchronized void setComplete(boolean complete) {
Expand All @@ -423,7 +424,7 @@ public synchronized void setComplete(boolean complete) {


/** /**
* Set the dependency id of the file * Set the dependency id of the file
* *
* @param dependencyId The new dependency id of the file * @param dependencyId The new dependency id of the file
*/ */
public synchronized void setDependencyId(int dependencyId) { public synchronized void setDependencyId(int dependencyId) {
Expand All @@ -433,7 +434,7 @@ public synchronized void setDependencyId(int dependencyId) {
/** /**
* Set the length of the file. Cannot set the length if the file is complete or the length is * Set the length of the file. Cannot set the length if the file is complete or the length is
* negative. * negative.
* *
* @param length The new length of the file, cannot be negative * @param length The new length of the file, cannot be negative
* @throws SuspectedFileSizeException * @throws SuspectedFileSizeException
* @throws BlockInfoException * @throws BlockInfoException
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/tachyon/master/InodeFolder.java
Expand Up @@ -4,9 +4,9 @@
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a * "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at * copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the License * Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under * or implied. See the License for the specific language governing permissions and limitations under
Expand Down Expand Up @@ -94,8 +94,8 @@ static InodeFolder loadImage(JsonParser parser, ImageElement ele) throws IOExcep
* Create a new InodeFolder. * Create a new InodeFolder.
* *
* @param name The name of the folder * @param name The name of the folder
* @param id The id of the folder * @param id The inode id of the folder
* @param parentId The id of the parent of the folder * @param parentId The inode id of the parent of the folder
* @param creationTimeMs The creation time of the folder, in milliseconds * @param creationTimeMs The creation time of the folder, in milliseconds
*/ */
public InodeFolder(String name, int id, int parentId, long creationTimeMs) { public InodeFolder(String name, int id, int parentId, long creationTimeMs) {
Expand Down Expand Up @@ -152,13 +152,13 @@ public ClientFileInfo generateClientFileInfo(String path) {
} }


/** /**
* Returns the child with the given id. * Returns the child with the given inode id.
* *
* @param fid The id of the child * @param id The inode id of the child
* @return the inode with the given id, or null if there is no child with that id * @return the inode with the given id, or null if there is no child with that id
*/ */
public synchronized Inode getChild(int fid) { public synchronized Inode getChild(int id) {
return mChildrenIds.get(fid); return mChildrenIds.get(id);
} }


/** /**
Expand Down Expand Up @@ -210,7 +210,7 @@ public synchronized boolean removeChild(Inode child) {
} }


/** /**
* Removes the given child from the folder. * Removes the given child by its name from the folder.
* *
* @param name The name of the Inode to remove. * @param name The name of the Inode to remove.
* @return true if the inode was removed, false otherwise. * @return true if the inode was removed, false otherwise.
Expand Down

0 comments on commit 45a2aa3

Please sign in to comment.