Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI tools for debugging and analyzing caching issues #18151

Merged
merged 16 commits into from
Sep 17, 2023
65 changes: 65 additions & 0 deletions cli/src/alluxio.org/cli/cmd/fs/checkcaching.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename file to check-cached.go

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package fs

import (
"alluxio.org/cli/env"
"github.com/spf13/cobra"
"strconv"
)
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved

func CheckCaching(className string) env.Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to

Suggested change
func CheckCaching(className string) env.Command {
func CheckCached(className string) env.Command {

return &CheckCachingCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "checkCaching",
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
JavaClassName: className,
Parameters: []string{"checkCaching"},
},
}
}

type CheckCachingCommand struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to

Suggested change
type CheckCachingCommand struct {
type CheckCachedCommand struct {

*env.BaseJavaCommand

sample int
limit int
}

func (c *CheckCachingCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *CheckCachingCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "checkCaching [path]",
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
Short: "Checks if files under a path have been cached in alluxio.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
cmd.Flags().IntVar(&c.sample, "sample", 0, "Sample ratio, 10 means sample 1 in every 10 files.")
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
cmd.Flags().IntVar(&c.limit, "limit", 0, "limit, default 1000")
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
return cmd
}

func (c *CheckCachingCommand) Run(args []string) error {
javaArgs := []string{"checkCaching"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to you if you want to change the java side names. i only request to change the golang user facing side names

if c.sample != 0 {
javaArgs = append(javaArgs, "--sample", strconv.Itoa(c.sample))
}
if c.limit != 0 {
javaArgs = append(javaArgs, "--limit", strconv.Itoa(c.limit))
}
javaArgs = append(javaArgs, args...)
return c.Base().Run(args)
}
69 changes: 69 additions & 0 deletions cli/src/alluxio.org/cli/cmd/fs/consistanthash.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename file to consistent_hash.go

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package fs

import (
"alluxio.org/cli/env"
"github.com/spf13/cobra"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import (
"alluxio.org/cli/env"
"github.com/spf13/cobra"
)
import (
"github.com/spf13/cobra"
"alluxio.org/cli/env"
)


func ConsistentHash(className string) env.Command {
return &ConsistentHashCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "consistentHash",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CommandName: "consistentHash",
CommandName: "consistent-hash",

JavaClassName: className,
Parameters: []string{"consistentHash"},
},
}
}

type ConsistentHashCommand struct {
*env.BaseJavaCommand

createCheckFile bool
compareCheckFiles bool
cleanCheckData bool
}

func (c *ConsistentHashCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *ConsistentHashCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "consistentHash [--createCheckFile]|[--compareCheckFiles <1stCheckFilePath> <2ndCheckFilePath>]|[--cleanCheckData] ",
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
Short: "This command is for checking whether the consistent hash ring is changed or not. ",
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
cmd.Flags().BoolVarP(&c.createCheckFile, "createCheckFile", "c", false, "Generate check file.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.Flags().BoolVarP(&c.createCheckFile, "createCheckFile", "c", false, "Generate check file.")
cmd.Flags().BoolVar(&c.createCheckFile, "create", false, "Generate check file")

cmd.Flags().BoolVarP(&c.compareCheckFiles, "compareCheckFiles", "C", false, "Compare check files to see if the hash ring has changed and if data lost.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.Flags().BoolVarP(&c.compareCheckFiles, "compareCheckFiles", "C", false, "Compare check files to see if the hash ring has changed and if data lost.")
cmd.Flags().BoolVar(&c.compareCheckFiles, "compare", false, "Compare check files to see if the hash ring has changed and if data lost. Expect two arguments to be provided for the two check file paths")

cmd.Flags().BoolVarP(&c.cleanCheckData, "cleanCheckData", "d", false, "Clean all check data.")
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
return cmd
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *ConsistentHashCommand) Run(args []string) error {
javaArgs := []string{}
if c.createCheckFile {
javaArgs = append(javaArgs, "--createCheckFile")
}
if c.compareCheckFiles {
javaArgs = append(javaArgs, "--compareCheckFiles")
JiamingMai marked this conversation as resolved.
Show resolved Hide resolved
}
if c.cleanCheckData {
javaArgs = append(javaArgs, "--cleanCheckData")
}

javaArgs = append(javaArgs, args...)
return c.Base().Run(javaArgs)
}
55 changes: 29 additions & 26 deletions cli/src/alluxio.org/cli/cmd/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,40 @@
package fs

import (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think golang has strict lint rules... your code won't compile cc @Xenorith

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rule isn't enforced but you could run this command to recursively format the go files: https://golang.cafe/blog/how-to-run-gofmt-recursively.html

i will likely iterate on these new commands and add docs similar to what was done in #1814 so i am not too concerned about doing the cleanup now

"alluxio.org/cli/cmd/names"
"alluxio.org/cli/env"
"alluxio.org/cli/cmd/names"
"alluxio.org/cli/env"
)

var Service = &env.Service{
Name: "fs",
Description: "Operations to interface with the Alluxio filesystem",
Commands: Cmds(names.FileSystemShellJavaClass),
Name: "fs",
Description: "Operations to interface with the Alluxio filesystem",
Commands: Cmds(names.FileSystemShellJavaClass),
}

func Cmds(className string) []env.Command {
var ret []env.Command
for _, c := range []func(string) env.Command{
Cat,
Checksum,
Chgrp,
Chmod,
Chown,
Cp,
Head,
Ls,
Mkdir,
Mv,
Rm,
Stat,
Tail,
Test,
Touch,
} {
ret = append(ret, c(className))
}
var ret []env.Command
for _, c := range []func(string) env.Command{
Cat,
Checksum,
Chgrp,
Chmod,
Chown,
Cp,
Head,
Ls,
Mkdir,
Mv,
Rm,
Stat,
Tail,
Test,
Touch,
Location,
CheckCaching,
ConsistentHash,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cat,
Checksum,
Chgrp,
Chmod,
Chown,
Cp,
Head,
Ls,
Mkdir,
Mv,
Rm,
Stat,
Tail,
Test,
Touch,
Location,
CheckCaching,
ConsistentHash,
Cat,
CheckCached,
Checksum,
Chgrp,
Chmod,
Chown,
ConsistentHash,
Cp,
Head,
Location,
Ls,
Mkdir,
Mv,
Rm,
Stat,
Tail,
Test,
Touch,

} {
ret = append(ret, c(className))
}

return ret
return ret
}
52 changes: 52 additions & 0 deletions cli/src/alluxio.org/cli/cmd/fs/location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package fs

import (
"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

func Location(className string) env.Command {
return &LocationCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "location",
JavaClassName: className,
Parameters: []string{"location"},
},
}
}

type LocationCommand struct {
*env.BaseJavaCommand
}

func (c *LocationCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *LocationCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "location [path]",
Short: "Displays the list of hosts storing the specified file.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
return cmd
}

func (c *LocationCommand) Run(args []string) error {
return c.Base().Run(args)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import alluxio.AlluxioURI;
import alluxio.PositionReader;
import alluxio.client.file.ufs.UfsBaseFileSystem;
import alluxio.conf.AlluxioConfiguration;
import alluxio.exception.AlluxioException;
import alluxio.exception.DirectoryNotEmptyException;
Expand Down Expand Up @@ -50,6 +51,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import javax.annotation.Nullable;

/**
* A wrapper of a FileSystem instance.
Expand Down Expand Up @@ -260,6 +262,18 @@ public void close() throws IOException {
mDelegatedFileSystem.close();
}

@Nullable
@Override
public DoraCacheFileSystem getDoraCacheFileSystem() {
return mDelegatedFileSystem.getDoraCacheFileSystem();
}

@Nullable
@Override
public UfsBaseFileSystem getUfsBaseFileSystem() {
return mDelegatedFileSystem.getUfsBaseFileSystem();
}

/**
* @return the underlying fileSystem
*/
Expand Down
Loading
Loading