Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement BlockMeta and TempBlockMeta, which share the common parent …
…class BlockMetaBase; Provide getBlockLocation for BlockMetaBase
- Loading branch information
Showing
3 changed files
with
97 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
servers/src/main/java/tachyon/worker/block/meta/BlockMetaBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the University of California, Berkeley under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional information regarding | ||
* 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 | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package tachyon.worker.block.meta; | ||
|
||
import com.google.common.base.Preconditions; | ||
import tachyon.worker.BlockStoreLocation; | ||
|
||
/** | ||
* A base class of the metadata of blocks in Tachyon managed storage. | ||
*/ | ||
public abstract class BlockMetaBase { | ||
protected final long mBlockId; | ||
protected long mBlockSize; | ||
protected StorageDir mDir; | ||
|
||
public BlockMetaBase(long blockId, long blockSize, StorageDir dir) { | ||
mBlockId = blockId; | ||
mBlockSize = blockSize; | ||
mDir = Preconditions.checkNotNull(dir); | ||
} | ||
|
||
public long getBlockId() { | ||
return mBlockId; | ||
} | ||
|
||
public long getBlockSize() { | ||
return mBlockSize; | ||
} | ||
|
||
/** | ||
* Get the location of a specific block | ||
*/ | ||
public BlockStoreLocation getBlockLocation() { | ||
StorageTier tier = mDir.getParentTier(); | ||
return new BlockStoreLocation(tier.getTierId(), mDir.getDirId()); | ||
} | ||
|
||
public StorageDir getParentDir() { | ||
return mDir; | ||
} | ||
|
||
public abstract String getPath(); | ||
} |
36 changes: 34 additions & 2 deletions
36
servers/src/main/java/tachyon/worker/block/meta/TempBlockMeta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
/* | ||
* Licensed to the University of California, Berkeley under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional information regarding | ||
* 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 | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package tachyon.worker.block.meta; | ||
|
||
import tachyon.util.CommonUtils; | ||
|
||
/** | ||
* Created by binfan on 6/9/15. | ||
* Represents the metadata of an uncommited block in Tachyon managed storage. | ||
*/ | ||
public class TempBlockMeta { | ||
public class TempBlockMeta extends BlockMetaBase { | ||
private final long mUserId; | ||
|
||
public TempBlockMeta(long userId, long blockId, long blockSize, StorageDir dir) { | ||
super(blockId, blockSize, dir); | ||
mUserId = userId; | ||
} | ||
|
||
@Override | ||
public String getPath() { | ||
return CommonUtils.concatPath(mDir.getDirPath(), mUserId, mBlockId); | ||
} | ||
|
||
public void setBlockSize(long newSize) { | ||
mBlockSize = newSize; | ||
} | ||
} |