pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.04k stars 5.83k forks source link

Implement the "put-and-verify" lock for external storage. #56523

Open YuJuncen opened 3 days ago

YuJuncen commented 3 days ago

Enhancement

Background

Sometimes, we need to control concurrency access to the same backup archive, like:

But external storage locking isn't trivial. Simply putting a lock file isn't safe enough: because after checking there isn't such a lock file, another one may write it immediately. Object locks provide stronger consistency, but also require extra configuration and permissions.

We can use a "put-and-verify" lock to lock the storage, in detail, a locker need to implement this interface:

type PutAndVerify interface {
    Prefix() string
    Content() io.Reader
    Verify(s ExternalStorage) error
}

Then we lock the storage by:

D3Hunter commented 1 day ago

I'm not that familiar with BR, can you please clearify some description to help me understand

When compacting / restoring, we want to block migrating to a new version.

migrating WHO to a new version? you mean converting a backup stored in S3 to format of another version?

When migrating to a new version, we want to forbid reading.

you mean read/write S3 backup at same time?

When truncating the storage, we don't want another trancating operation join.

the storage is the external storage, such as s3 right?

YuJuncen commented 1 day ago

@D3Hunter The "storage" should be "backup storage", i.e. the set of files generated by log backup. Let me clarify this. "Migration" is an atomic operation that applies to the "stabilized" backup storage (a brief reference here, after applying a "migration", the "stabilized" backup storage goes to a new version.

D3Hunter commented 1 day ago

redefine migration, confusing😓