西维蜀黍

【Database】Write-ahead Logging (Redo Logs)

Write-Ahead Logging (WAL)

Write-Ahead Logging (WAL) is a standard method for ensuring data integrity. A detailed description can be found in most (if not all) books about transaction processing. Briefly, WAL’s central concept is that changes to data files (where tables and indexes reside) must be written only after those changes have been logged, that is, after log records describing the changes have been flushed to permanent storage. If we follow this procedure, we do not need to flush data pages to disk on every transaction commit, because we know that in the event of a crash we will be able to recover the database using the log: any changes that have not been applied to the data pages can be redone from the log records. (This is roll-forward recovery, also known as REDO.)

  ...


【Kafka】Transactional Messages

  ...


【Kafka】Exactly Once

  ...


【MySQL】MySQL 中的两阶段提交

Two-phase Commit in MySQL

The two-phase commit in MySQL is not a two-phase commit of a distributed transaction, but a two-phase commit between redo and Binlog after the Binlog is turned on.

Overall, two-phase commit:

  1. prepare phase - call MYSQL_BIN_LOG::prepare
    1. redo log prepare - innobase_xa_prepare, i.e., the transaction is fully recorded in the redo log and syncs the redo log file to disk (as necessary)

  1. commit phase
    1. innodb释放锁,释放回滚段,设置提交状态
    2. write Binlog- call MYSQL_BIN_LOG::commit
    3. redo log commit - innobase_commit
  ...


【Architecture】System Design - Flash Sale(秒杀系统)

热点数据

热点数据 比较好理解,那就是用户的热点请求对应的数据。而热点数据又分为“静态热点数据”和“动态热点数据”。

  • 静态热点数据
    • 所谓“静态热点数据”,就是能够提前预测的热点数据。例如,我们可以通过卖家报名的方式提前筛选出来,通过报名系统对这些热点商品进行打标。另外,我们还可以通过大数据分析来提前发现热点商品,比如我们分析历史成交记录、用户的购物车记录,来发现哪些商品可能更热门、更好卖,这些都是可以提前分析出来的热点。
  • 动态热点数据
    • 所谓“动态热点数据”,就是不能被提前预测到的,系统在运行过程中临时产生的热点。例如,卖家在抖音上做了广告,然后商品一下就火了,导致它在短时间内被大量购买。
  ...