Skip to content

Commit

Permalink
Add CLI tools for debugging and analyzing caching issues
Browse files Browse the repository at this point in the history
Add the following CLI tools for debugging and analyzing caching issues:
1. checkCaching. Checks if files under a path have been cached in alluxio.
2. location. Displays the list of hosts storing the specified file.
3. consistentHash. This command is for checking whether the consistent hash ring is changed or not.
			pr-link: #18151
			change-id: cid-c89b98da70a5270070d873bdcfce1aa9b23cf083
  • Loading branch information
JiamingMai authored Sep 17, 2023
1 parent 8bba797 commit 6f35645
Show file tree
Hide file tree
Showing 18 changed files with 1,238 additions and 36 deletions.
67 changes: 67 additions & 0 deletions cli/src/alluxio.org/cli/cmd/fs/check_cached.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 (
"strconv"

"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

func CheckCached(className string) env.Command {
return &CheckCachedCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "check-cached",
JavaClassName: className,
Parameters: []string{"check-cached"},
},
}
}

type CheckCachedCommand struct {
*env.BaseJavaCommand

sample int
limit int
}

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

func (c *CheckCachedCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "check-cached [path]",
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", 1, "Sample ratio, 10 means sample 1 in every 10 files.")
cmd.Flags().IntVar(&c.limit, "limit", 1000, "Limit number of files to check")
return cmd
}

func (c *CheckCachedCommand) Run(args []string) error {
javaArgs := []string{"check-cached"}
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(javaArgs)
}
74 changes: 74 additions & 0 deletions cli/src/alluxio.org/cli/cmd/fs/consistant_hash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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/palantir/stacktrace"
"github.com/spf13/cobra"
)

func ConsistentHash(className string) env.Command {
return &ConsistentHashCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "consistent-hash",
JavaClassName: className,
Parameters: []string{"consistent-hash"},
},
}
}

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: "consistent-hash [--create]|[--compare <1stCheckFilePath> <2ndCheckFilePath>]|[--clean] ",
Short: "This command is for checking whether the consistent hash ring is changed or not",
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
cmd.Flags().BoolVar(&c.createCheckFile, "create", false, "Generate check file.")
cmd.Flags().BoolVar(&c.compareCheckFiles, "compare", false, "Compare check files to see if the hash ring has changed and if data lost.")
cmd.Flags().BoolVar(&c.cleanCheckData, "clean", false, "Clean all check data.")
cmd.MarkFlagsMutuallyExclusive("create", "compare", "clean")
return cmd
}

func (c *ConsistentHashCommand) Run(args []string) error {
javaArgs := []string{}
if c.createCheckFile {
javaArgs = append(javaArgs, "--create")
}
if c.compareCheckFiles {
if len(args) != 2 {
return stacktrace.NewError("expect 2 arguments with --compare-check-files but got %v", len(args))
}
javaArgs = append(javaArgs, "--compare")
}
if c.cleanCheckData {
javaArgs = append(javaArgs, "--clean")
}

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 (
"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,
CheckCached,
ConsistentHash,
} {
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

0 comments on commit 6f35645

Please sign in to comment.