Skip to content

Commit

Permalink
Implement BlockMeta and TempBlockMeta, which share the common parent …
Browse files Browse the repository at this point in the history
…class BlockMetaBase; Provide getBlockLocation for BlockMetaBase
  • Loading branch information
apc999 authored and calvinjia committed Jun 27, 2015
1 parent 92a44ad commit b085b55
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 40 deletions.
45 changes: 7 additions & 38 deletions servers/src/main/java/tachyon/worker/block/meta/BlockMeta.java
Expand Up @@ -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
Expand All @@ -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;
}

}
56 changes: 56 additions & 0 deletions 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();
}
36 changes: 34 additions & 2 deletions 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;
}
}

0 comments on commit b085b55

Please sign in to comment.