diff --git a/servers/src/main/java/tachyon/worker/block/meta/BlockMeta.java b/servers/src/main/java/tachyon/worker/block/meta/BlockMeta.java index 2908e8c7671a..5b443796e709 100644 --- a/servers/src/main/java/tachyon/worker/block/meta/BlockMeta.java +++ b/servers/src/main/java/tachyon/worker/block/meta/BlockMeta.java @@ -4,9 +4,9 @@ * 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 @@ -15,54 +15,23 @@ package tachyon.worker.block.meta; -import com.google.common.base.Preconditions; - import tachyon.util.CommonUtils; /** * Represents the metadata of a block in Tachyon managed storage. */ -public class BlockMeta { - private final long mBlockId; - private long mBlockSize; - private StorageDir mDir; - private boolean mCommitted = false; +public class BlockMeta extends BlockMetaBase { public BlockMeta(long blockId, long blockSize, StorageDir dir) { - mBlockId = blockId; - mBlockSize = blockSize; - mDir = Preconditions.checkNotNull(dir); - } - - public long getBlockId() { - return mBlockId; + super(blockId, blockSize, dir); } - public long getBlockSize() { - return mBlockSize; + public BlockMeta(TempBlockMeta tempBlock) { + super(tempBlock.getBlockId(), tempBlock.getBlockSize(), tempBlock.getParentDir(); } + @Override public String getPath() { return CommonUtils.concatPath(mDir.getDirPath(), mBlockId); } - - public String getTmpPath(long userId) { - return CommonUtils.concatPath(mDir.getDirPath(), userId, mBlockId); - } - - public StorageDir getParentDir() { - return mDir; - } - - public boolean commit() { - if (mCommitted) { - return false; - } - mCommitted = true; - } - - public boolean isCommitted() { - return mCommitted; - } - } diff --git a/servers/src/main/java/tachyon/worker/block/meta/BlockMetaBase.java b/servers/src/main/java/tachyon/worker/block/meta/BlockMetaBase.java new file mode 100644 index 000000000000..00b1320f05d5 --- /dev/null +++ b/servers/src/main/java/tachyon/worker/block/meta/BlockMetaBase.java @@ -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(); +} diff --git a/servers/src/main/java/tachyon/worker/block/meta/TempBlockMeta.java b/servers/src/main/java/tachyon/worker/block/meta/TempBlockMeta.java index 035f292de577..075574e1c946 100644 --- a/servers/src/main/java/tachyon/worker/block/meta/TempBlockMeta.java +++ b/servers/src/main/java/tachyon/worker/block/meta/TempBlockMeta.java @@ -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; + } }