首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Delta Lake 学习笔记(四) - 名词解释

文章目录

1 Overview

在了解 Delta Lake 之前,我觉得有必要解释一下经常出现的一些名词,这里收集记录一下。如果跟我一样是菜鸡,可能你也需要看一下…

2 名词解释

2.1 ACID

ACID 就是指数据库事务的四个基本要素,对应的是原子性 Atomicity,一致性 Consistency,隔离性 Isolation 和持久性 Durability。

  1. 原子性: 一个事务要么全部成功,要不全部失败,事务出现错误会被回滚到事务开始时候的状态。
  2. 一致性: 系统始终处于一致的状态,所有操作都应该服务现实中的期望。
  3. 隔离性: 并发事务不会互相干扰,事务之间互相隔离。
  4. 持久性: 事务结束后就一直保存在数据库中,不会被回滚。

2.2 SNAPSHOT

An immutable snapshot of the state of the log at some delta version. Internally this class manages the replay of actions stored in checkpoint or delta files, given an optional starting snapshot.

SNAPSHOT 相当于当前数据的快照。这个快照包括的内容不仅仅只有一个版本号,还会包括当前快找下的数据文件,上一个 SNAPSHOT 的操作,以及时间戳和 DeltaLog 的记录。

2.3 MetaData

Updates the metadata of the table. Only the last update to the [[Metadata]] of a table is kept. It is the responsibility of the writer to ensure that any data already present in the table is still valid after any change.

这里是指 Delta Table 的元数据,包括 id,name,format,创建时间,schema 信息等等。

2.4 事务日志

Used to query the current state of the log as well as modify it by adding new atomic collections of actions. Internally, this class implements an optimistic concurrency control algorithm to handle multiple readers or writers. Any single read is guaranteed to see a consistent snapshot of the table.

事务日志的相关代码主要在 org.apache.spark.sql.delta.DeltaLog 中。后面会专门解释,前面文章也介绍过,这个是 Delta Lake 把对数据/表的操作的记录日志。

2.5 CheckSum

Stats calculated within a snapshot, which we store along individual transactions for verification.

可以说 CheckSum 是一个对象,里面包含了,当前 SNAPSHOT 下的表的物理大小,文件数,MetaData 的数量,协议以及事务的数量。这些信息会转成 Json 格式,存放在 CheckSumFile 中。

那么既然是一种校验的方式,那么他又是如何校验呢?方法很简单了,就是把写好的 CheckSumFile 读取,并对比前后的信息及可以完成校验的过程了。

校验文件是在 SNAPSHOT 的基础上计算的,会和各自的事务生死存亡。

2.6 Protocol

Used to block older clients from reading or writing the log when backwards incompatible changes are made to the protocol. Readers and writers are responsible for checking that the meet the minimum versions before performing any other operations.

Since this action allows us to explicitly block older clients in the case of a breaking change to the protocol, clients should be tolerant of messages and fields that they do not understand.

这个协议是用在 SNAPSHOT 中,比较不同版本的 Version 属性大小的,目的是标识 SNAPSHOT 的读/写版本号,来防止其他客户端读取旧的数据。

3 Summary

本文主要介绍了几个 Delta Lake 里需要知道的一些概念,尽管并不是些什么新概念,但是对于初学者还是很有必要去了解一下的(比如我…),后面会结合源码进行逐一的分析。

举报
领券