Search in sources :

Example 6 with FinalizedReplica

use of org.apache.hadoop.hdfs.server.datanode.FinalizedReplica in project hadoop by apache.

the class TestReplicaMap method testRemove.

@Test
public void testRemove() {
    // Test 1: null argument throws invalid argument exception
    try {
        map.remove(bpid, null);
        fail("Expected exception not thrown");
    } catch (IllegalArgumentException expected) {
    }
    // Test 2: remove failure - generation stamp mismatch 
    Block b = new Block(block);
    b.setGenerationStamp(0);
    assertNull(map.remove(bpid, b));
    // Test 3: remove failure - blockID mismatch
    b.setGenerationStamp(block.getGenerationStamp());
    b.setBlockId(0);
    assertNull(map.remove(bpid, b));
    // Test 4: remove success
    assertNotNull(map.remove(bpid, block));
    // Test 5: remove failure - invalid blockID
    assertNull(map.remove(bpid, 0));
    // Test 6: remove success
    map.add(bpid, new FinalizedReplica(block, null, null));
    assertNotNull(map.remove(bpid, block.getBlockId()));
}
Also used : Block(org.apache.hadoop.hdfs.protocol.Block) FinalizedReplica(org.apache.hadoop.hdfs.server.datanode.FinalizedReplica) Test(org.junit.Test)

Example 7 with FinalizedReplica

use of org.apache.hadoop.hdfs.server.datanode.FinalizedReplica in project hadoop by apache.

the class FsDatasetImplTestUtils method injectCorruptReplica.

@Override
public void injectCorruptReplica(ExtendedBlock block) throws IOException {
    Preconditions.checkState(!dataset.contains(block), "Block " + block + " already exists on dataset.");
    try (FsVolumeReferences volRef = dataset.getFsVolumeReferences()) {
        FsVolumeImpl volume = (FsVolumeImpl) volRef.get(0);
        FinalizedReplica finalized = new FinalizedReplica(block.getLocalBlock(), volume, volume.getFinalizedDir(block.getBlockPoolId()));
        File blockFile = finalized.getBlockFile();
        if (!blockFile.createNewFile()) {
            throw new FileExistsException("Block file " + blockFile + " already exists.");
        }
        File metaFile = FsDatasetUtil.getMetaFile(blockFile, 1000);
        if (!metaFile.createNewFile()) {
            throw new FileExistsException("Meta file " + metaFile + " already exists.");
        }
        dataset.volumeMap.add(block.getBlockPoolId(), finalized);
    }
}
Also used : FsVolumeReferences(org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi.FsVolumeReferences) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FinalizedReplica(org.apache.hadoop.hdfs.server.datanode.FinalizedReplica) FileExistsException(org.apache.commons.io.FileExistsException)

Example 8 with FinalizedReplica

use of org.apache.hadoop.hdfs.server.datanode.FinalizedReplica in project hadoop by apache.

the class FsDatasetImplTestUtils method createFinalizedReplica.

@Override
public Replica createFinalizedReplica(FsVolumeSpi volume, ExtendedBlock block) throws IOException {
    FsVolumeImpl vol = (FsVolumeImpl) volume;
    FinalizedReplica info = new FinalizedReplica(block.getLocalBlock(), vol, vol.getCurrentDir().getParentFile());
    dataset.volumeMap.add(block.getBlockPoolId(), info);
    info.getBlockFile().createNewFile();
    info.getMetaFile().createNewFile();
    saveMetaFileHeader(info.getMetaFile());
    return info;
}
Also used : FinalizedReplica(org.apache.hadoop.hdfs.server.datanode.FinalizedReplica)

Example 9 with FinalizedReplica

use of org.apache.hadoop.hdfs.server.datanode.FinalizedReplica in project hadoop by apache.

the class FsDatasetImplTestUtils method createReplicaUnderRecovery.

@Override
public Replica createReplicaUnderRecovery(ExtendedBlock block, long recoveryId) throws IOException {
    try (FsVolumeReferences volumes = dataset.getFsVolumeReferences()) {
        FsVolumeImpl volume = (FsVolumeImpl) volumes.get(0);
        ReplicaUnderRecovery rur = new ReplicaUnderRecovery(new FinalizedReplica(block.getLocalBlock(), volume, volume.getCurrentDir().getParentFile()), recoveryId);
        dataset.volumeMap.add(block.getBlockPoolId(), rur);
        return rur;
    }
}
Also used : FsVolumeReferences(org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi.FsVolumeReferences) ReplicaUnderRecovery(org.apache.hadoop.hdfs.server.datanode.ReplicaUnderRecovery) FinalizedReplica(org.apache.hadoop.hdfs.server.datanode.FinalizedReplica)

Example 10 with FinalizedReplica

use of org.apache.hadoop.hdfs.server.datanode.FinalizedReplica in project hadoop by apache.

the class TestBlockListAsLongs method testMix.

@Test
public void testMix() {
    BlockListAsLongs blocks = checkReport(new FinalizedReplica(b1, null, null), new FinalizedReplica(b2, null, null), new ReplicaBeingWritten(b3, null, null, null), new ReplicaWaitingToBeRecovered(b4, null, null));
    assertArrayEquals(new long[] { 2, 2, 1, 11, 111, 2, 22, 222, -1, -1, -1, 3, 33, 333, ReplicaState.RBW.getValue(), 4, 44, 444, ReplicaState.RWR.getValue() }, blocks.getBlockListAsLongs());
}
Also used : ReplicaWaitingToBeRecovered(org.apache.hadoop.hdfs.server.datanode.ReplicaWaitingToBeRecovered) ReplicaBeingWritten(org.apache.hadoop.hdfs.server.datanode.ReplicaBeingWritten) FinalizedReplica(org.apache.hadoop.hdfs.server.datanode.FinalizedReplica) Test(org.junit.Test)

Aggregations

FinalizedReplica (org.apache.hadoop.hdfs.server.datanode.FinalizedReplica)11 Test (org.junit.Test)7 ReplicaBeingWritten (org.apache.hadoop.hdfs.server.datanode.ReplicaBeingWritten)3 File (java.io.File)2 Block (org.apache.hadoop.hdfs.protocol.Block)2 BlockReportReplica (org.apache.hadoop.hdfs.protocol.BlockListAsLongs.BlockReportReplica)2 Replica (org.apache.hadoop.hdfs.server.datanode.Replica)2 ReplicaInfo (org.apache.hadoop.hdfs.server.datanode.ReplicaInfo)2 ReplicaWaitingToBeRecovered (org.apache.hadoop.hdfs.server.datanode.ReplicaWaitingToBeRecovered)2 FsVolumeReferences (org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi.FsVolumeReferences)2 BlockReportContext (org.apache.hadoop.hdfs.server.protocol.BlockReportContext)2 DatanodeRegistration (org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration)2 DatanodeStorage (org.apache.hadoop.hdfs.server.protocol.DatanodeStorage)2 RpcController (com.google.protobuf.RpcController)1 FileInputStream (java.io.FileInputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 FileExistsException (org.apache.commons.io.FileExistsException)1