The previous blog post introduced the installation of GO and vscode under windows The installation of go environment and go extension + debugging in vscode under windows
1. Get the source code
git clone https://github.com/juicedata/juicefs.git
First observe the code structure
The picture above is the code I have compiled, which may be somewhat different from the one just downloaded from git.
2. Compile
I am debugging on windows, I need to compile juicefs first. See the documentation for the compilation process.
Document address: Installation | JuiceFS Document Center
For convenience, take a screenshot of the compiled content of the official document under windows.
Note: WinFsp needs to be downloaded and installed. If it is not installed, there will be an error that the header file cannot be found when compiling.
When there is a problem that GCC cannot find the command, you can use the recommended MinGW-w64 and Cygwin. I use MinGW-w64, just download and install it.
3. Debugging
format command
juicefs format
--storage minio
--bucket "https://127.0.0.1:9000/mystor"
--access-key minioadmin
--secret-key minioadmin
tikv://127.0.0.1:2379/mystor
mystor
launch.json parameters as shown in the figure
Program entry: juicefs-->main.go
Press F5 on the juicefs-->main.go page to enter the debugging page.
juicefs-->main.go //Start
cmd-->main.go --> err := app.Run(reorderOptions(app, args))
Among them, the reorderOptions() function judges the input parameters (flag and cmd) (whether they are correct flag and cmd) and sorts them. After returning, directly enter the app.Run() function.
-->app.go c.Run(cCtx) --> command.go c.Action(cCtx)
-->format.go format m:= meta.NewClient()
meta.NewClient() creates a new metadata service client, which mainly checks the information of input metadata related parameters, and invokes specific metadata services according to the incoming parameters.
-->interface.go NewClient()
-->interface.go f(driver, uri[p+3], conf) //jump to meta.newKVMeta here
-->tkv.go newKVMeta() client,err:=newTKVClient(dricer,addr)
-->tkv_tikv.go newTikvClient() client, err := txnkv.NewClient(strings.Split(tUrl.Host, ","))
-->client.go NewClinet() cfg := config.GetGlobalConfig()
-->client.go pdClient, err := tikv.NewPDClient(pdAddrs)
-->kv.go NewPDClient() pd.NewClient()
clinet.go is in github.com\tikv\client-go\[email protected]\txnkv\client.go
-->client.go three functions, the main process is to initialize metadata
uuid := fmt.Sprintf("tikv-%v", pdClient.GetClusterID(context.TODO()))
spkv, err := tikv.NewEtcdSafePointKV(pdAddrs, tlsConfig)
s, err := tikv.NewKVStore(uuid, pdClient, spkv, tikv.NewRPCClient(tikv.WithSecurity(cfg.Security)))
//creates a txn client with pdAddrs.
-->tkv.go newKVMeta() m:=&kvMeta
-->base.go newBaseMeta()
-->format.go format, err := m.Load(false)
-->Base.go --> Load -->m.en.load()
-->Tkv.go --> doLoad() ([]byte, error)
-->Tkv.go --> get(key []byte) ([]byte, error) kvtxn
-->format.go blob, err := createStorage(*format)
Store the url according to the provided object, and create a client for pre-interaction
-->format.go createStorage() //
-->format.go m.Init(format, c.Bool("force")) //Create root directory
-->tkv.go doInit(format *Format, force bool)