【OpenHarmony】分布式文件服务模块架构

分布式文件服务模块架构

1. 模块概述

源码:https://gitee.com/openharmony/filemanagement_dfs_service

1.1 功能与目标

主要功能:

分布式文件服务模块(DFS Service)是OpenHarmony系统中提供跨设备文件访问能力的核心模块,基于分布式软总线动态组网,为网络上各个设备节点提供统一的、逻辑的、树形的文件系统层次结构。

该模块的主要功能包括:

  • 分布式文件系统:提供符合POSIX规范的跨设备文件访问能力
  • 云同步服务:提供云端文件同步、下载、上传等云存储能力
  • 云盘服务:提供云盘文件管理和同步功能
  • 设备管理:管理分布式设备的上线、下线、连接状态
  • 文件传输:提供跨设备的文件传输和共享能力
  • 数据同步:提供应用数据的云端同步能力
  • 版本管理:提供文件版本管理和历史版本恢复功能
  • 冲突处理:处理文件同步过程中的冲突问题
  • 存储优化:提供存储空间优化和清理功能

使用场景:

  • 跨设备文件访问和共享
  • 云端文件同步和备份
  • 分布式应用数据同步
  • 多设备协作办公
  • 文件版本管理和恢复
  • 存储空间优化管理

1.2 系统位置

系统架构位置:

分布式文件服务模块位于OpenHarmony系统的foundation/filemanagement子系统下,是文件管理框架的重要组成部分。

模块关系:

  • 上层对接:为应用层提供分布式文件访问和云同步API
  • 下层对接:对接分布式软总线、设备管理、存储服务等底层模块
  • 横向协作:与用户文件服务、应用文件服务、存储服务等模块协作
  • 系统集成:集成到系统能力管理器中,提供分布式文件管理能力

核心模块地位:

该模块是文件管理子系统的核心模块之一,承担着跨设备文件访问和云同步的重要职责,是实现分布式文件系统的关键基础设施。

1.3 设计思路与模式

设计思路:

  • 分层架构设计:采用daemon、service、kit三层架构
  • 分布式设计:基于分布式软总线实现跨设备通信
  • 云原生设计:支持云端存储和同步能力
  • 统一接口设计:通过统一的API接口屏蔽底层差异
  • 异步处理机制:采用异步处理模式,提高系统响应性能
  • 多用户支持:支持多用户环境下的文件隔离和管理

设计模式:

  • 单例模式:CloudSyncManager、CloudDaemonManager等核心组件采用单例模式
  • 代理模式:Service层作为代理,管理Daemon连接和请求转发
  • 观察者模式:文件变化通知和状态变化回调机制
  • 工厂模式:CloudFileKit等对象的创建和管理
  • 策略模式:不同同步策略和传输策略的处理

1.4 系统框图

外部依赖 分布式文件系统 云盘服务 云同步服务 分布式文件服务模块 应用层 分布式软总线 设备管理 存储服务 网络管理 云存储 HMDFS DeviceManager NetworkManager ChannelManager CloudDiskService SyncFolderManager FileSyncManager ConflictResolver CloudSyncService DataSyncManager CloudDatabase CloudAssetsDownloader CloudSyncManager CloudDaemonManager CloudFileKit DistributedFileDaemon 文件管理器 媒体应用 办公应用 系统服务

2. 模块结构

2.1 源文件与头文件

核心服务文件:

云同步服务:

  • interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h - 云同步管理器
  • interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_callback.h - 云同步回调接口
  • interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_common.h - 云同步通用定义
  • services/cloudsyncservice/ICloudSyncService.idl - 云同步服务接口

云盘服务:

  • interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_manager.h - 云盘服务管理器
  • services/clouddiskservice/ICloudDiskService.idl - 云盘服务接口
  • services/clouddiskservice/include/cloud_disk_service_syncfolder.h - 同步文件夹管理

云文件服务:

  • interfaces/inner_api/native/cloud_file_kit_inner/cloud_file_kit.h - 云文件工具包
  • interfaces/inner_api/native/cloud_file_kit_inner/data_sync_manager.h - 数据同步管理器
  • interfaces/inner_api/native/cloud_file_kit_inner/cloud_database.h - 云数据库

分布式文件守护进程:

  • services/distributedfiledaemon/include/device/device_manager.h - 设备管理器
  • services/distributedfiledaemon/include/network/network_manager.h - 网络管理器
  • services/distributedfiledaemon/include/channel_manager/channel_manager.h - 通道管理器

JS API文件:

  • interfaces/kits/js/cloudsyncmanager/cloud_sync_manager_napi.h - 云同步管理JS接口
  • interfaces/kits/js/cloudfilesync/cloud_sync_napi.h - 云文件同步JS接口
  • interfaces/kits/js/ani/file_cloud_sync/ - 文件云同步JS接口

2.2 类、结构体、函数与方法

核心类定义:

CloudSyncManager类
cpp 复制代码
class CloudSyncManager {
public:
    static CloudSyncManager &GetInstance();
    
    // 回调管理
    virtual int32_t RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback,
                                     const std::string &bundleName = "") = 0;
    virtual int32_t RegisterFileSyncCallback(const std::shared_ptr<CloudSyncCallback> callback,
                                     const std::string &bundleName = "") = 0;
    virtual int32_t UnRegisterCallback(const std::string &bundleName = "") = 0;
    virtual int32_t UnRegisterFileSyncCallback(const std::string &bundleName = "") = 0;
    
    // 同步控制
    virtual int32_t StartSync(const std::string &bundleName = "") = 0;
    virtual int32_t StartFileSync(const std::string &bundleName = "") = 0;
    virtual int32_t StartSync(bool forceFlag, const std::shared_ptr<CloudSyncCallback> callback) = 0;
    virtual int32_t TriggerSync(const std::string &bundleName, const int32_t &userId) = 0;
    virtual int32_t StopSync(const std::string &bundleName = "", bool forceFlag = false) = 0;
    virtual int32_t StopFileSync(const std::string &bundleName = "", bool forceFlag = false) = 0;
    
    // 水位管理
    virtual int32_t ResetCursor(const std::string &bundleName = "") = 0;
    virtual int32_t ResetCursor(bool flag, const std::string &bundleName = "") = 0;
    
    // 应用开关管理
    virtual int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) = 0;
    virtual int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) = 0;
    virtual int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) = 0;
    
    // 云服务管理
    virtual int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) = 0;
    virtual int32_t DisableCloud(const std::string &accoutId) = 0;
    virtual int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) = 0;
    
    // 存储优化
    virtual int32_t OptimizeStorage(const OptimizeSpaceOptions &optimizeOptions,
        const std::shared_ptr<CloudOptimizeCallback> optimizeCallback = nullptr) = 0;
    virtual int32_t StopOptimizeStorage() = 0;
    
    // 文件下载
    virtual int32_t StartDownloadFile(const std::string &uri,
                                      const std::shared_ptr<CloudDownloadCallback> downloadCallback,
                                      int64_t &downloadId) = 0;
    virtual int32_t StartFileCache(const std::vector<std::string> &uriVec,
                                   int64_t &downloadId,
                                   int32_t fieldkey = FieldKey::FIELDKEY_CONTENT,
                                   const std::shared_ptr<CloudDownloadCallback> downloadCallback = nullptr,
                                   int32_t timeout = -1) = 0;
    virtual int32_t StopDownloadFile(int64_t downloadId, bool needClean = false) = 0;
    virtual int32_t StopFileCache(int64_t downloadId, bool needClean = false, int32_t timeout = -1) = 0;
    
    // 降级下载
    virtual int32_t StartDowngrade(const std::string &bundleName,
                                   const std::shared_ptr<DowngradeDlCallback> downloadCallback) = 0;
    virtual int32_t StopDowngrade(const std::string &bundleName) = 0;
    
    // 文件信息查询
    virtual int32_t GetCloudFileInfo(const std::string &bundleName, CloudFileInfo &cloudFileInfo) = 0;
    virtual int32_t GetSyncTime(int64_t &syncTime, const std::string &bundleName = "") = 0;
    
    // 版本管理
    virtual int32_t GetHistoryVersionList(const std::string &uri, const int32_t versionNumLimit,
                                          std::vector<CloudSync::HistoryVersion> &historyVersionList) = 0;
    virtual int32_t DownloadHistoryVersion(const std::string &uri, int64_t &downloadId, const uint64_t versionId,
                                           const std::shared_ptr<CloudDownloadCallback> downloadCallback,
                                           std::string &versionUri) = 0;
    virtual int32_t ReplaceFileWithHistoryVersion(const std::string &uri, const std::string &versionUri) = 0;
    
    // 冲突处理
    virtual int32_t IsFileConflict(const std::string &uri, bool &isConflict) = 0;
    virtual int32_t ClearFileConflict(const std::string &uri) = 0;
    
    // 缓存管理
    virtual int32_t CleanCache(const std::string &uri) = 0;
    virtual int32_t CleanFileCache(const std::string &uri) = 0;
    virtual void CleanGalleryDentryFile() = 0;
    virtual void CleanGalleryDentryFile(const std::string path) = 0;
    virtual int32_t BatchCleanFile(const std::vector<CleanFileInfo> &fileInfo,
        std::vector<std::string> &failCloudId) = 0;
    virtual int32_t BatchDentryFileInsert(const std::vector<DentryFileInfo> &fileInfo,
         std::vector<std::string> &failCloudId) = 0;
};
CloudDaemonManager类
cpp 复制代码
class CloudDaemonManager {
public:
    static CloudDaemonManager &GetInstance();
    
    // FUSE管理
    virtual int32_t StartFuse(int32_t userId, int32_t devFd, const string &path) = 0;
};
CloudFileKit类
cpp 复制代码
class CloudFileKit {
public:
    static CloudFileKit *GetInstance();
    static bool RegisterCloudInstance(CloudFileKit *instance);
    
    virtual ~CloudFileKit() = default;
    
    // 用户信息管理
    virtual int32_t GetCloudUserInfo(const int32_t userId, CloudUserInfo &userInfo);
    virtual int32_t CleanCloudUserInfo(const int32_t userId);
    
    // 空间信息查询
    virtual std::pair<uint64_t, uint64_t> GetSpaceInfo(const int32_t userId, const std::string &bundleName);
    
    // 应用开关状态
    virtual int32_t GetAppSwitchStatus(const std::string &bundleName, const int32_t userId, bool &switchStatus);
    
    // 事件处理
    virtual int32_t ResolveNotificationEvent(const int32_t userId,
                                             const std::string &extraData,
                                             std::string &appBundleName,
                                             std::string &prepareTraceId);
    
    // 配置管理
    virtual int32_t GetAppConfigParams(const int32_t userId,
                                       const std::string &bundleName,
                                       std::map<std::string, std::string> &param);
    
    // 资源上传
    virtual int32_t OnUploadAsset(const int32_t userId, const std::string &request, std::string &result);
    
    // 组件获取
    virtual std::shared_ptr<DataSyncManager> GetDataSyncManager();
    virtual std::shared_ptr<CloudDatabase> GetCloudDatabase(const int32_t userId, const std::string &bundleName);
    virtual std::shared_ptr<CloudAssetsDownloader> GetCloudAssetsDownloader(const int32_t userId,
                                                                            const std::string &bundleName);
    virtual std::shared_ptr<CloudSyncHelper> GetCloudSyncHelper(const int32_t userId, const std::string &bundleName);
    
    // 工具方法
    virtual std::string GetPrepareTraceId(const int32_t userId);
    virtual void Release(int32_t userId);
    
private:
    static inline CloudFileKit *instance_;
};

2.3 继承与多态

继承关系:

  • 各种回调类继承自相应的接口基类
  • 服务类继承自SystemAbility基类
  • 数据类支持序列化接口

多态设计:

  • 通过接口抽象实现不同同步策略的统一管理
  • 回调机制支持多种事件类型的统一处理
  • 策略模式实现不同传输策略的动态切换
  • 工厂模式支持不同组件的创建和管理

2.4 类图

uses uses uses creates creates creates creates notifies notifies CloudSyncManager +GetInstance() +RegisterCallback() : int32_t +RegisterFileSyncCallback() : int32_t +UnRegisterCallback() : int32_t +UnRegisterFileSyncCallback() : int32_t +StartSync() : int32_t +StartFileSync() : int32_t +StopSync() : int32_t +StopFileSync() : int32_t +TriggerSync() : int32_t +ResetCursor() : int32_t +ChangeAppSwitch() : int32_t +NotifyDataChange() : int32_t +EnableCloud() : int32_t +DisableCloud() : int32_t +Clean() : int32_t +OptimizeStorage() : int32_t +StartDownloadFile() : int32_t +StartFileCache() : int32_t +StopDownloadFile() : int32_t +StopFileCache() : int32_t +StartDowngrade() : int32_t +StopDowngrade() : int32_t +GetCloudFileInfo() : int32_t +GetHistoryVersionList() : int32_t +DownloadHistoryVersion() : int32_t +ReplaceFileWithHistoryVersion() : int32_t +IsFileConflict() : int32_t +ClearFileConflict() : int32_t +CleanCache() : int32_t +CleanFileCache() : int32_t +BatchCleanFile() : int32_t +BatchDentryFileInsert() : int32_t CloudDaemonManager +GetInstance() +StartFuse() : int32_t CloudFileKit -instance_ CloudFileKit +GetInstance() +RegisterCloudInstance() : bool +GetCloudUserInfo() : int32_t +CleanCloudUserInfo() : int32_t +GetSpaceInfo() +GetAppSwitchStatus() : int32_t +ResolveNotificationEvent() : int32_t +GetAppConfigParams() : int32_t +OnUploadAsset() : int32_t +GetDataSyncManager() : shared_ptr<DataSyncManager> +GetCloudDatabase() : shared_ptr<CloudDatabase> +GetCloudAssetsDownloader() : shared_ptr<CloudAssetsDownloader> +GetCloudSyncHelper() : shared_ptr<CloudSyncHelper> +GetPrepareTraceId() : string +Release() : void DataSyncManager +StartSync() : int32_t +StopSync() : int32_t +GetSyncStatus() : int32_t +RegisterCallback() : int32_t +UnregisterCallback() : int32_t CloudDatabase +Open() : int32_t +Close() : int32_t +Insert() : int32_t +Update() : int32_t +Delete() : int32_t +Query() : int32_t CloudAssetsDownloader +StartDownload() : int32_t +StopDownload() : int32_t +GetDownloadProgress() : int32_t +RegisterCallback() : int32_t +UnregisterCallback() : int32_t CloudSyncHelper +SyncFile() : int32_t +SyncDirectory() : int32_t +GetSyncStatus() : int32_t +ResolveConflict() : int32_t <<interface>> CloudSyncCallback +OnSyncStart() : void +OnSyncProgress() : void +OnSyncComplete() : void +OnSyncError() : void <<interface>> CloudDownloadCallback +OnDownloadStart() : void +OnDownloadProgress() : void +OnDownloadComplete() : void +OnDownloadError() : void <<interface>> CloudOptimizeCallback +OnOptimizeStart() : void +OnOptimizeProgress() : void +OnOptimizeComplete() : void +OnOptimizeError() : void

2.5 模块内部依赖框图

数据模型 回调接口 分布式文件系统组件 云盘服务组件 云同步服务组件 分布式文件服务模块内部结构 CloudFileInfo HistoryVersion CleanOptions OptimizeSpaceOptions CloudSyncCallback CloudDownloadCallback CloudOptimizeCallback DowngradeDlCallback HMDFS DeviceManager NetworkManager ChannelManager CloudDiskService SyncFolderManager FileSyncManager ConflictResolver CloudSyncService DataSyncManager CloudDatabase CloudAssetsDownloader CloudSyncHelper CloudSyncManager CloudDaemonManager CloudFileKit DistributedFileDaemon

3. 模块间交互

3.1 交互描述

与系统模块的交互:

  • 分布式软总线:通过dsoftbus模块实现跨设备通信
  • 设备管理:通过device_manager模块管理设备状态和连接
  • 存储服务:通过storage_service模块提供本地存储能力
  • 网络管理:通过netmanager_base模块管理网络连接
  • 用户管理:通过os_account模块管理多用户环境
  • 权限管理:通过access_token模块验证访问权限
  • 应用管理:通过bundle_framework模块管理应用信息

外部库依赖:

  • 系统框架:SAMGR、SAFWK、AAFwk等系统框架
  • 数据库:RelationalStore、Preferences等数据存储
  • 网络库:libfuse、zlib等网络和压缩库
  • 工具库:cJSON、c_utils等基础工具库
  • 事件系统:CommonEvent、EventHandler等事件处理

异步处理机制:

  • 使用IPC机制进行跨进程通信
  • 通过事件循环机制处理文件同步和状态变化
  • 支持多线程并发处理多个同步请求
  • 采用观察者模式处理异步回调

3.2 事件驱动机制

事件类型:

  • 设备上线/下线事件
  • 文件变化事件
  • 同步状态变化事件
  • 网络状态变化事件
  • 用户登录/退出事件
  • 存储空间变化事件

事件处理流程:

  1. 注册事件监听器
  2. 接收系统或网络事件通知
  3. 解析事件参数
  4. 更新内部状态
  5. 通知相关回调
  6. 执行相应的同步操作

3.3 外部依赖框图

应用层 外部库 系统框架 系统服务 分布式文件服务模块 文件管理器 媒体应用 办公应用 系统服务 libfuse zlib cJSON c_utils RelationalStore Preferences SAMGR SAFWK IPC 事件系统 分布式软总线 设备管理 存储服务 网络管理 用户管理 权限管理 应用管理 CloudSyncManager CloudDaemonManager CloudFileKit DistributedFileDaemon

4. 状态机转换图

4.1 状态机模型

分布式文件服务模块的状态机包含以下主要状态:

服务状态:

  • SERVICE_NOT_START - 服务未启动
  • SERVICE_RUNNING - 服务运行中
  • SERVICE_STOPPING - 服务停止中
  • SERVICE_EXIT - 服务已退出

同步状态:

  • SYNC_IDLE - 同步空闲
  • SYNC_STARTING - 同步启动中
  • SYNC_RUNNING - 同步运行中
  • SYNC_PAUSED - 同步暂停
  • SYNC_COMPLETED - 同步完成
  • SYNC_ERROR - 同步错误

设备状态:

  • DEVICE_UNKNOWN - 设备未知
  • DEVICE_CONNECTING - 设备连接中
  • DEVICE_CONNECTED - 设备已连接
  • DEVICE_DISCONNECTING - 设备断开中
  • DEVICE_DISCONNECTED - 设备已断开
  • DEVICE_ERROR - 设备错误

文件状态:

  • FILE_UNKNOWN - 文件未知
  • FILE_UPLOADING - 文件上传中
  • FILE_DOWNLOADING - 文件下载中
  • FILE_SYNCED - 文件已同步
  • FILE_CONFLICT - 文件冲突
  • FILE_ERROR - 文件错误

4.2 状态切换规则

服务启动流程:

  1. 服务初始状态为SERVICE_NOT_START
  2. 收到启动事件后,进入SERVICE_RUNNING状态
  3. 初始化各个子模块和事件监听器
  4. 注册到系统能力管理器

同步状态转换:

  1. 同步初始状态为SYNC_IDLE
  2. 收到同步请求时,进入SYNC_STARTING状态
  3. 启动完成后,进入SYNC_RUNNING状态
  4. 同步完成时,进入SYNC_COMPLETED状态
  5. 发生错误时,进入SYNC_ERROR状态
  6. 暂停同步时,进入SYNC_PAUSED状态

设备状态转换:

  1. 设备初始状态为DEVICE_UNKNOWN
  2. 检测到设备连接时,进入DEVICE_CONNECTING状态
  3. 连接成功后,进入DEVICE_CONNECTED状态
  4. 设备断开时,进入DEVICE_DISCONNECTING状态
  5. 断开完成后,进入DEVICE_DISCONNECTED状态
  6. 发生错误时,进入DEVICE_ERROR状态

文件状态转换:

  1. 文件初始状态为FILE_UNKNOWN
  2. 开始上传时,进入FILE_UPLOADING状态
  3. 开始下载时,进入FILE_DOWNLOADING状态
  4. 同步完成后,进入FILE_SYNCED状态
  5. 发生冲突时,进入FILE_CONFLICT状态
  6. 发生错误时,进入FILE_ERROR状态

事件触发条件:

  • 服务启动/停止事件
  • 设备连接/断开事件
  • 文件变化事件
  • 同步请求事件
  • 网络状态变化事件
  • 用户操作事件

4.3 状态机转换图

系统启动 OnStart() OnStop() 停止完成 重启服务 初始化同步 StartSync()调用 启动成功 启动失败 同步完成 暂停同步 同步错误 恢复同步 重置状态 错误恢复 初始化设备 设备连接 连接成功 连接失败 设备断开 断开完成 重新检测 错误恢复 初始化文件 开始上传 开始下载 上传完成 上传失败 下载完成 下载失败 检测到冲突 冲突解决 错误恢复 ServiceNotStart ServiceRunning ServiceStopping ServiceExit SyncIdle SyncStarting SyncRunning SyncError SyncCompleted SyncPaused DeviceUnknown DeviceConnecting DeviceConnected DeviceError DeviceDisconnecting DeviceDisconnected FileUnknown FileUploading FileDownloading FileSynced FileError FileConflict 服务运行状态,可以处理
各种分布式文件操作 同步运行状态,可以处理
文件上传下载和同步 设备已连接状态,可以
进行跨设备文件访问 文件已同步状态,表示
文件在云端和本地一致

5. 接口设计

5.1 公共接口

云同步管理接口:

注册同步回调
cpp 复制代码
// IDL接口
void RegisterCallbackInner([in] IRemoteObject remoteObject, [in] String bundleName);
void RegisterFileSyncCallbackInner([in] IRemoteObject remoteObject, [in] String bundleName);
  • 功能:注册云同步回调函数
  • 参数
    • remoteObject - 远程回调对象
    • bundleName - 应用包名
  • 返回值:操作结果码
  • 异常处理:注册失败时返回错误码
启动同步
cpp 复制代码
// IDL接口
void StartSyncInner([in] boolean forceFlag, [in] String bundleName);
void StartFileSyncInner([in] boolean forceFlag, [in] String bundleName);
  • 功能:启动云同步或文件同步
  • 参数
    • forceFlag - 是否强制同步
    • bundleName - 应用包名
  • 返回值:操作结果码
  • 异常处理:启动失败时返回错误码
停止同步
cpp 复制代码
// IDL接口
void StopSyncInner([in] String bundleName, [in] boolean forceFlag);
void StopFileSyncInner([in] String bundleName, [in] boolean forceFlag);
  • 功能:停止云同步或文件同步
  • 参数
    • bundleName - 应用包名
    • forceFlag - 是否强制停止
  • 返回值:操作结果码
  • 异常处理:停止失败时返回错误码

文件下载接口:

开始文件下载
cpp 复制代码
// IDL接口
void StartDownloadFile([in] String uri, [in] IRemoteObject downloadCallback, [out] long downloadId);
void StartFileCache([in] String[] uriVec, [out] long downloadId, [in] int fieldkey,
                    [in] IRemoteObject downloadCallback, [in] int timeout);
  • 功能:开始文件下载或文件缓存
  • 参数
    • uri - 文件URI
    • uriVec - 文件URI数组
    • downloadCallback - 下载回调对象
    • fieldkey - 字段键
    • timeout - 超时时间
    • downloadId - 输出参数,下载ID
  • 返回值:操作结果码
  • 异常处理:下载失败时返回错误码
停止文件下载
cpp 复制代码
// IDL接口
void StopDownloadFile([in] long downloadId, [in] boolean needClean);
void StopFileCache([in] long downloadId, [in] boolean needClean, [in] int timeout);
  • 功能:停止文件下载或文件缓存
  • 参数
    • downloadId - 下载ID
    • needClean - 是否需要清理
    • timeout - 超时时间
  • 返回值:操作结果码
  • 异常处理:停止失败时返回错误码

版本管理接口:

获取历史版本
cpp 复制代码
// IDL接口
void GetHistoryVersionList([in] String uri, [in] int versionNumLimit,
                           [out] HistoryVersion[] historyVersionList);
  • 功能:获取文件的历史版本列表
  • 参数
    • uri - 文件URI
    • versionNumLimit - 版本数量限制
    • historyVersionList - 输出参数,历史版本列表
  • 返回值:操作结果码
  • 异常处理:获取失败时返回错误码
下载历史版本
cpp 复制代码
// IDL接口
void DownloadHistoryVersion([in] String uri, [out] long downloadId, [in] unsigned long versionId,
                            [in] IRemoteObject downloadCallback,
                            [out]String versionUri);
  • 功能:下载指定版本的文件
  • 参数
    • uri - 文件URI
    • downloadId - 输出参数,下载ID
    • versionId - 版本ID
    • downloadCallback - 下载回调对象
    • versionUri - 输出参数,版本文件URI
  • 返回值:操作结果码
  • 异常处理:下载失败时返回错误码

云盘服务接口:

注册同步文件夹
cpp 复制代码
// IDL接口
void RegisterSyncFolderInner([in] int userId, [in] String bundleName, [in] String path);
void UnregisterSyncFolderInner([in] int userId, [in] String bundleName, [in] String path);
  • 功能:注册或注销同步文件夹
  • 参数
    • userId - 用户ID
    • bundleName - 应用包名
    • path - 文件夹路径
  • 返回值:操作结果码
  • 异常处理:注册失败时返回错误码
获取同步文件夹变化
cpp 复制代码
// IDL接口
ChangesResult GetSyncFolderChangesInner([in] String syncFolder, [in] unsigned long count, [in] unsigned long startUSN);
  • 功能:获取同步文件夹的变化信息
  • 参数
    • syncFolder - 同步文件夹路径
    • count - 变化数量
    • startUSN - 起始USN
  • 返回值:变化结果
  • 异常处理:获取失败时返回错误码

5.2 数据交换接口

IPC接口定义:

  • 使用IDL定义跨进程接口
  • 支持Parcelable对象序列化
  • 提供异步回调机制

数据格式:

  • CloudFileInfo、HistoryVersion等结构体支持序列化
  • 使用MessageParcel进行数据传递
  • 支持大数据量的传输

5.3 接口调用时序图

应用程序 CloudSyncManager CloudSyncService CloudDaemon 云存储 回调函数 RegisterCallback() RegisterCallbackInner() 注册回调 注册成功 返回结果 StartSync() StartSyncInner() 启动同步 连接云存储 连接成功 开始同步 同步启动 返回结果 上传文件 上传进度 OnSyncProgress() 同步进度回调 下载文件 下载完成 OnSyncComplete() 同步完成回调 StopSync() StopSyncInner() 停止同步 断开连接 断开成功 停止成功 返回结果 UnRegisterCallback() UnRegisterCallbackInner() 注销回调 注销成功 返回结果 应用程序 CloudSyncManager CloudSyncService CloudDaemon 云存储 回调函数

6. 总结

分布式文件服务模块是OpenHarmony系统中文件管理框架的重要组成部分,通过分层架构设计为系统和应用提供跨设备文件访问和云同步能力。该模块采用CloudSyncManager、CloudDaemonManager、CloudFileKit等核心组件,实现了分布式文件系统、云同步服务、云盘服务等功能。

主要特点:

  • 分层架构设计,职责清晰
  • 支持跨设备文件访问和共享
  • 完善的云同步和云存储能力
  • 统一的分布式文件管理接口
  • 高效的异步处理能力
  • 支持文件版本管理和冲突处理

技术优势:

  • 基于分布式软总线的跨设备通信机制
  • 完善的错误处理和异常管理
  • 支持多种同步策略和传输方式
  • 灵活的模块化架构设计
  • 高效的云存储集成能力

该模块为OpenHarmony系统的分布式文件管理提供了坚实的基础,支持各种跨设备文件操作需求,是构建分布式应用的重要基础设施。通过分层设计和云原生支持,为开发者提供了灵活、安全、高效的分布式文件管理能力。

相关推荐
無限神樂4 小时前
RabbitMQ概述,Rabbitmq是什么
分布式·rabbitmq
通信小呆呆4 小时前
分布式雷达 vs 多基地雷达:同频共振的“合唱团”和“乐队”
分布式·目标检测·信息与通信·信号处理·计算成像
会跑的葫芦怪4 小时前
RocketMQ 与 RabbitMQ 全面对比:架构、性能与适用场景解析
架构·rabbitmq·rocketmq
北极光SD-WAN组网4 小时前
分布式控制系统(DCS)的智能组网技术解析及解决方案
分布式
2301_768350234 小时前
RabbitMq工作流程
分布式·rabbitmq
kyle~6 小时前
计算机系统---CPU的进程与线程处理
linux·服务器·c语言·c++·操作系统·计算机系统
孟意昶6 小时前
Doris专题17- 数据导入-文件格式
大数据·数据库·分布式·sql·doris
zandy10116 小时前
HENGSHI SENSE异构过滤架构:基于三层执行引擎的跨源联邦查询性能优化实践
性能优化·架构·agentic bi·异构结构
brzhang6 小时前
我用 Flutter 做了个小游戏,结果发现这玩意有点意思
前端·后端·架构