In class IDiskRemote, all metadata file system operations use os file system api directly.
There is little extendiability if we want store the metadata of HDFS or S3 into distributed file system.
So I suggest change this way by using DiskPtr and will propose a pull request.

In addition, metadata of HDFS or S3 only store local FS which is not sharable.

{
    String revision_str;
    String operation;
    re2::RE2::FullMatch(key, key_regexp, &revision_str, &operation);
    return {(revision_str.empty() ? UNKNOWN_REVISION : static_cast<UInt64>(std::bitset<64>(revision_str).to_ullong())), operation};
}
String DiskS3::shrinkKey(const String & path, const String & key)
{
    if (!key.starts_with(path))
        throw Exception("The key " + key + " prefix mismatch with given " + path, ErrorCodes::LOGICAL_ERROR);
    return key.substr(path.length());
}
String DiskS3::revisionToString(UInt64 revision)
{
    return std::bitset<64>(revision).to_string();
}
String DiskS3::pathToDetached(const String & source_path)
{
    if (source_path.ends_with('/'))
        return fs::path(source_path).parent_path().parent_path() / "detached/";
    return fs::path(source_path).parent_path() / "detached/";
}
void DiskS3::onFreeze(const String & path)
{
    createDirectories(path);
    WriteBufferFromFile revision_file_buf(metadata_path + path + "revision.txt", 32);
    writeIntText(revision_counter.load(), revision_file_buf);
    revision_file_buf.finalize();
}
void DiskS3::applyNewSettings(const Poco::Util::AbstractConfiguration & config, ContextPtr context_, const String &, const DisksMap &)