zoukankan      html  css  js  c++  java
  • DataNode上的block以及meta文件的结构

    package org.apache.hadoop.atest.datanade;

    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;

    import org.apache.hadoop.util.DataChecksum;
    /**

    *程序的主要目的是读取一个block文件和相应的meta文件,然后多相应的data数据进行校验 。

    **/
    public class BlockDataCheckTest {

        /**
         * @param args
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
            //meta文件
            DataInputStream checksumIn= new DataInputStream(new BufferedInputStream(new FileInputStream("D:/hdfs/blk_-8834172473825889857_1040.meta"), 1024));
            //block文件,数据格式:bytesPerChecksum的数据,bytesPerChecksum的数据,bytesPerChecksum的数据,bytesPerChecksum的数据,bytesPerChecksum的数据。。。。。。。。。
            DataInputStream dataIn=new DataInputStream(new BufferedInputStream(new FileInputStream("D:/hdfs/blk_-8834172473825889857"), 1024));
            //meta文件数据:数据version(shot),checkType(byte,0--无校验,1--CRC32校验),bytesPerChecksum(每多少数据做一次校验),bytesPerChecksum个byte数据的校验码,bytesPerChecksum个byte数据的校验码,bytesPerChecksum个byte数据的校验码。。。。。。。
            //其中数据version是一静态变量:FSDataset.METADATA_VERSION = 1;
            short version=checksumIn.readShort();
            byte checkType=checksumIn.readByte();
            int bytesPerChecksum=checksumIn.readInt();
            System.out.println(version+"   "+checkType+"   "+bytesPerChecksum);
            DataChecksum dataChecksum=DataChecksum.newDataChecksum(checkType, bytesPerChecksum);
            byte[]  dataBytes=new byte[bytesPerChecksum];
            byte[]  checkBytes=new byte[dataChecksum.getChecksumSize()];
            while(dataIn.read(dataBytes)>0){
                checksumIn.read(checkBytes);
                dataChecksum.reset();
                dataChecksum.update(dataBytes, 0, dataBytes.length);
                if(dataChecksum.compare(checkBytes, 0)){
                    System.out.println("right !!");
                }else{
                    System.err.println("wrong !!");
                    throw new RuntimeException("-------------------");
                }
            }
            dataIn.close();
            checksumIn.close();
        }
    }

  • 相关阅读:
    mysql小白系列_04 datablock
    mysql小白系列_04 binlog(未完)
    mysql小白系列_03 体系结构-线程池
    mysql小白系列_02 mysql源码安装标准化
    国庆小长假来点不一样的,如何用Python爬取了全国近5000家旅游景点,一起来看
    python爬取p站排行榜并自动发送邮件-这个项目赚了500
    利用Azure backup备份和恢复Azure虚拟机(1)
    定制化Azure站点Java运行环境(5)
    定制化Azure站点Java运行环境(4)
    定制化Azure站点Java运行环境(3)
  • 原文地址:https://www.cnblogs.com/serendipity/p/2396095.html
Copyright © 2011-2022 走看看