Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ public int getCapacity() {
/** @return true if there is no datanode storage associated with the block */
abstract boolean hasNoStorage();

/**
* Checks whether this block has a Provided replica.
* @return true if this block has a replica on Provided storage.
*/
abstract boolean isProvided();

/**
* Find specified DatanodeStorageInfo.
* @return DatanodeStorageInfo or null if not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.base.Preconditions;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.BlockType;

Expand Down Expand Up @@ -80,6 +81,19 @@ boolean removeStorage(DatanodeStorageInfo storage) {
return true;
}

@Override
boolean isProvided() {
int len = getCapacity();
for (int idx = 0; idx < len; idx++) {
DatanodeStorageInfo storage = getStorageInfo(idx);
if (storage != null
&& storage.getStorageType().equals(StorageType.PROVIDED)) {
return true;
}
}
return false;
}

@Override
public int numNodes() {
assert this.storages != null : "BlockInfo is not initialized";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ final boolean hasNoStorage() {
return true;
}

/**
* Striped blocks on Provided Storage is not supported. All blocks on
* Provided storage are assumed to be "contiguous".
*/
@Override
boolean isProvided() {
return false;
Comment thread
goiri marked this conversation as resolved.
}

/**
* This class contains datanode storage information and block index in the
* block group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

import static org.apache.hadoop.hdfs.server.namenode.INodeId.INVALID_INODE_ID;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.apache.hadoop.fs.StorageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hdfs.DFSTestUtil;
Expand Down Expand Up @@ -64,6 +67,28 @@ public void testAddStorage() throws Exception {
Assert.assertEquals(storage, blockInfo.getStorageInfo(0));
}

@Test
public void testAddProvidedStorage() throws Exception {
BlockInfo blockInfo = new BlockInfoContiguous((short) 3);

DatanodeStorageInfo storage = mock(DatanodeStorageInfo.class);
when(storage.getStorageType()).thenReturn(StorageType.PROVIDED);
boolean added = blockInfo.addStorage(storage, blockInfo);

Assert.assertTrue(added);
Assert.assertEquals(storage, blockInfo.getStorageInfo(0));
Assert.assertTrue(blockInfo.isProvided());

Comment thread
goiri marked this conversation as resolved.
blockInfo = new BlockInfoContiguous((short) 3);
storage = mock(DatanodeStorageInfo.class);
when(storage.getStorageType()).thenReturn(StorageType.DISK);
added = blockInfo.addStorage(storage, blockInfo);

Assert.assertTrue(added);
Assert.assertEquals(storage, blockInfo.getStorageInfo(0));
Assert.assertFalse(blockInfo.isProvided());
}

@Test
public void testReplaceStorage() throws Exception {

Expand Down