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();
        }
    }

  • 相关阅读:
    (转)ELK Stack 中文指南--性能优化
    (转)如何在CentOS / RHEL 7上安装Elasticsearch,Logstash和Kibana(ELK)
    (转)GlusterFS 01 理论基础,企业实战,故障处理
    (转)CentOS7.4环境下搭建--Gluster分布式集群存储
    (转)DB2性能优化 – 如何通过调整锁参数优化锁升级
    (转)架构师之DNS实战CentOS7VSCentOS6
    PHP:计算文件或数组中单词出现频率
    [获取行数]php读取大文件提供性能的方法,PHP的stream_get_line函数读取大文件获取文件的行数的方...
    Windows下配置环境变量和需不需要重启问题
    CENTOS 下安装APK反编译工具 APKTOOL
  • 原文地址:https://www.cnblogs.com/serendipity/p/2396095.html
Copyright © 2011-2022 走看看