Skip to content

Commit

Permalink
Add a helper function to derive StorageDirId from BlockLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
apc999 authored and calvinjia committed Jun 27, 2015
1 parent 4c1b9bc commit 77b679a
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions common/src/main/java/tachyon/worker/BlockStoreLocation.java
Expand Up @@ -6,45 +6,54 @@
*/
public class BlockStoreLocation {
private static final int sAnyTier = -1;
private static final int sAnyDir = -2;
private final int mTier;
private final int mDir;
private static final int sAnyDir = -1;
private final int mTierAlias;
private final int mDirIndex;

public static BlockStoreLocation anyTier() {
return new BlockStoreLocation(sAnyTier, sAnyDir);
}

public static BlockStoreLocation anyDirInTier(int tier) {
return new BlockStoreLocation(tier, sAnyDir);
public static BlockStoreLocation anyDirInTier(int tierAlias) {
return new BlockStoreLocation(tierAlias, sAnyDir);
}

public BlockStoreLocation(int tier, int dir) {
mTier = tier;
mDir = dir;
public BlockStoreLocation(int tierAlias, int dirIndex) {
mTierAlias = tierAlias;
mDirIndex = dirIndex;
}

// A helper function to derive StorageDirId from a BlockLocation.
// TODO: remove this method when master also understands BlockLocation
public long getStorageDirId() {
// TODO: double check if mTierAlias is really the level
return (mTierAlias << 24) + (mTierAlias << 16) + mDirIndex;
}


public int tier() {
return mTier;
return mTierAlias;
}

public int dir() {
return mDir;
return mDirIndex;
}

@Override
public String toString() {
String result = "";
if (mDir == sAnyDir) {
if (mDirIndex == sAnyDir) {
result += "any dir";
} else {
result += "dir " + mDir;
result += "dir " + mDirIndex;
}

if (mTier == sAnyTier) {
result += ", any tier"
if (mTierAlias == sAnyTier) {
result += ", any tier";
} else {
result += ", tier " + mTier;
result += ", tier " + mTierAlias;
}
return result;
}

}

0 comments on commit 77b679a

Please sign in to comment.