地方エンジニアの学習日記

興味ある技術の雑なメモだったりを書いてくブログ。たまに日記とガジェット紹介。

【Aurora】Auroraのレプリカ遅延とは何か

AuroraはWrite/Readのインスタンスのそれぞれが共有のディスクを使っている。なのにレプリカラグがあると言うのは何故だろうと言うので調べた。

Given that the database is aware of all outstanding reads, it can compute at any time the Minimum Read Point LSN on a per-PG basis. If there are read replicas the writer gossips with them toestablish the per-PG Minimum Read Point LSN across all nodes. This value is called the Protection Group Min Read Point LSN (PGMRPL) and represents the “low water mark” below which all the log records of the PG are unnecessary. In other words, astorage node segment is guaranteed that there will be no read page requests with a read-point that is lower than the PGMRPL. Each storage node is aware of the PGMRPL from the database and can, therefore, advance the materialized pages on disk by coalescing the older log records and then safely garbage collecting them.

https://assets.amazon.science/dc/2b/4ef2b89649f9a393d37d3e042f4e/amazon-aurora-design-considerations-for-high-throughput-cloud-native-relational-databases.pdf

論文の4.2.3あたりに書いてある。Writeはストレージ上で永続化されているので常に最新のものが読める。一方でReaderインスタンスにはcacheがある。そのキャッシュをクリアする必要があるのでそのクリアまでの時間がレプリカラグとして遅延されていそうと言う感じに読める。

4.2.4 Replicas
Otherwise it simply discards the log record. Note that the replicas consume log records asynchronously from the perspective of the writer, which acknowledges user commits independent of the replica.

Writerからのログの書き込みは非同期とのことIn practice, each replica typically lags behind the writer by a short interval (20 ms or less).とも書いてあるので書き込みは複数のディスクに書き込まれた時点でクライアントにcommitを返す。