引言
juicefs是一款面向云原生设计的高性能分布式文件系统,其有如下特点:
数据存储和元数据存储分离,可以适配多种数据和元数据存储引擎。
后端存储可以直接对接各种对象存储,使用起来更方便,更加适配云服务趋势。
相关技术架构可直接参考:https://juicefs.com/docs/zh/community/architecture
format流程
format是使用juicefs对接具体文件业务前的初始化阶段,其包括初始化数据和元数据引擎,可以根据format参数进行适配,流程如下
接收客户端执行的mount命令
根据指定的元数据服务,并初始化元数据服务对象
创建和初始化对象存储服务,构建format结构体对象,包含对象存储服务信息,block size等信息
持久化format信息到元数据服务中
核心函数及调用栈如下:
// 接收format命令
func format(c *cli.Context) error
// 解析命令参数,根据url相关信息创建元数据client对象
func NewClient(uri string, conf *Config) Meta
...
// 校验参数
...
// 创建后端存储对象
func createStorage(format meta.Format) (object.ObjectStorage, error)
// 初始化object对象,即object_storage.go中的全局变量
// 创建后端对象存储,即bucket,ak/sk,token
func CreateStorage(name, endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
// 配置数据编码
func NewDataEncryptor(keyEncryptor Encryptor, algo string) (Encryptor, error)
...
// 元数据服务初始化
func (m *dbMeta) Init(format *Format, force bool) error
mount流程
mount就是将自定义的文件系统挂载到指定目录下,可供符合POSIX的接口进行调用,由mount中开启的server服务进行文件操作请求接收并处理,其主要流程包括:
创建元数据服务连接client
根据format信息创建对象存储服务连接实例storage,创建store对象,store对象是对对象存储数据进行管理,store对象属性里包含了storage对象和对cache的管理
初始化vfs对象,vfs是一层虚拟文件系统对象,它包含了对meta和storage的管理,创建了读写对象和文件句柄管理
mount文件系统,并启动fuse server,用于处理客户端请求
核心函数及调用栈如下:
// mount命令执行
func mount(c *cli.Context) error
// 获取meta config,并创建元数据client
func getMetaConf(c *cli.Context, mp string, readOnly bool) *meta.Config
func NewClient(uri string, conf *Config) Meta
...
// 获取chunk配置,并初始化cachestore
func getChunkConf(c *cli.Context, format *meta.Format) *chunk.Config
func NewCachedStore(storage object.ObjectStorage, config Config, reg prometheus.Registerer) ChunkStore
...
// 获取vfs配置
func getVfsConf(c *cli.Context, metaConf *meta.Config, format *meta.Format, chunkConf *chunk.Config) *vfs.Config
...
// 检查mount点
func prepareMp(newCfg *vfs.Config, mp string) (ignore bool)
func checkMountpoint(name, mp, logPath string, background bool)
...
// 创建本次挂载session,并保存
func (m *baseMeta) NewSession() error
// 保存session到元数据引擎
func (m *dbMeta) doNewSession(sinfo []byte) error
...
// 创建vfs对象,包含了对meta和storage的管理,创建了读写对象和文件句柄管理
func NewVFS(conf *Config, m meta.Meta, store chunk.ChunkStore, registerer prometheus.Registerer, registry *prometheus.Registry) *VFS
...
// mount文件系统
func mount_main(v *vfs.VFS, c *cli.Context)
// 创建fuse server,用来接收fuse文件系统操作
func Serve(v *vfs.VFS, options string, xattrs, ioctl bool) error
// 创建rawfilesystem
func newFileSystem(conf *vfs.Config, v *vfs.VFS) *fileSystem
// 创建fuse server
func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions)
// 启动fuse server
func (ms *Server) Serve()
// 监听处理请求
func (ms *Server) loop(exitIdle bool)