spark检查点“.bk”和“.crc”文件的作用是什么?

pan*_*ang 2 python java scala crc apache-spark

当我们为 Spark Streaming 应用程序设置检查点目录时,它会生成一个这样的目录:

root@55330815baa7:/usr/local/spark/checkpoint# ll
total 184
drwxr-xr-x  6 root root  4096 May 25 16:35 ./
drwxr-xr-x 18  500  500  4096 May 25 16:19 ../
drwxr-xr-x  2 root root  4096 May 25 16:19 643d19eb-b24b-4664-a865-a263bdd97625/
drwxr-xr-x  2 root root  4096 May 25 16:34 71b2204c-8762-4d75-bb34-f9b1b7a9b530/
drwxr-xr-x  2 root root  4096 May 25 16:19 c946e058-220e-4ae5-8db2-393c00b845d0/
-rw-r--r--  1 root root  9658 May 25 16:35 checkpoint-1464193230000
-rw-r--r--  1 root root    84 May 25 16:35 .checkpoint-1464193230000.bk
-rw-r--r--  1 root root    84 May 25 16:35 .checkpoint-1464193230000.crc
-rw-r--r--  1 root root  9712 May 25 16:35 checkpoint-1464193236000
-rw-r--r--  1 root root    84 May 25 16:35 .checkpoint-1464193236000.bk
-rw-r--r--  1 root root    84 May 25 16:35 .checkpoint-1464193236000.crc
-rw-r--r--  1 root root  9773 May 25 16:35 checkpoint-1464193242000
-rw-r--r--  1 root root  9773 May 25 16:35 checkpoint-1464193242000.bk

-rw-r--r--  1 root root    88 May 25 16:35 .checkpoint-1464193242000.crc
-rw-r--
drwxr-xr-x  2 root root  4096 May 25 16:35 receivedBlockMetadata/
Run Code Online (Sandbox Code Playgroud)

我们可以找到“.bk”文件和“.crc”文件,“.bk”文件是备份文件,但是对于“.crc”文件,有什么作用呢?它是如何工作的?有人对此有想法吗?

Yua*_* JI 6

CRC 代表循环冗余校验。这是一个错误检测代码,用于检测原始数据的意外更改


来自维基百科 CRC 的示例:

我们想用多项式 x^3 + x + 1 用 3 位 CRC 对 14 位消息进行编码

假设我们有这个消息:11010011101100(14 位)
我们使用多项式除数:(1011代表 x^3 + x + 1)

计算是XOR

  1. 首先我们填充零以对应编码消息的位长(14+3=17 位):
    11010011101100 000 <--- input right padded by 3 bits
    1011 <--- divisor (4 bits) = x³ + x + 1
    ------------------
    01100011101100 000 <--- result

  2. 通过在每一步中向右移动除数 1 位(或更多)来迭代计算新结果:
    01100011101100 000 <--- result of step 1
      1011 <--- divisor
    00111011101100 000
       1011
    00010111101100 000
         1011
    00000001101100 000 <--- note that the divisor moves over to align with the next 1 in
                1011 the dividend (since quotient for that step was zero)
    00000000110100 000 (in other words, it doesn't necessarily move one bit per
                  1011 iteration)
    00000000011000 000
                    1011
    00000000001110 000
                      1011
    00000000000101 000
                       101 1
    ------------------
    00000000000000 100 <--- remainder (3 bits). Division algorithm stops here as dividend
                                              is equal to zero.

由于最左边的除数位将它触及的每个输入位都归零,因此当该过程结束时,输入行中唯一可以为非零的位是该行右端的 3 个位。

这 3 位是除法步骤的剩余部分,也将是 CRC 函数的值(除非所选的 CRC 规范要求进行一些后处理)。


接收消息的验证

通过再次执行上述计算,可以很容易地验证接收到的消息的有效性,这次添加校验值而不是零。如果没有可检测的错误,余数应为零。


11010011101100 100 <--- input with check value
1011 <--- divisor
01100011101100 100 <--- result
  1011 <--- divisor ...
00111011101100 100

......

00000000001110 100
                  1011
00000000000101 100
                   101 1
------------------
                             0 <--- remainder