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 journal commands to CLI #17569

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions cli/src/alluxio.org/cli/cmd/journal/backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 journal

import (
"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var Backup = &BackupCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "backup",
JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell",
Parameters: []string{"backup"},
},
}

type BackupCommand struct {
*env.BaseJavaCommand

backupPath string
local bool
allowLeader bool
bypassDelegation bool
}

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

func (c *BackupCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: Backup.CommandName,
Short: "Backup the local Alluxio master journal",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(nil)
},
})
cmd.Flags().StringVar(&c.backupPath, "path", "", "Directory to write backup file to")
cmd.MarkFlagRequired("path")
cmd.Flags().BoolVar(&c.local, "local", false, "If true, writes the backup file to the local filesystem instead of root UFS")
cmd.Flags().BoolVar(&c.allowLeader, "allow-leader", false, "If true, allows the leader to take the backup when there are no standby masters")
cmd.Flags().BoolVar(&c.bypassDelegation, "bypass-delegation", false, "If true, takes the backup on the leader even if standby masters are available")
return cmd
}

func (c *BackupCommand) Run(_ []string) error {
javaArgs := []string{c.backupPath}
if c.local {
javaArgs = append(javaArgs, "--local")
}
if c.allowLeader {
javaArgs = append(javaArgs, "--allow-leader")
}
if c.bypassDelegation {
javaArgs = append(javaArgs, "--bypass-delegation")
}
return c.Base().Run(javaArgs)
}
46 changes: 46 additions & 0 deletions cli/src/alluxio.org/cli/cmd/journal/checkpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 journal

import (
"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var Checkpoint = &CheckpointCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "checkpoint",
JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell",
Parameters: []string{"journal", "checkpoint"},
},
}

type CheckpointCommand struct {
*env.BaseJavaCommand
}

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

func (c *CheckpointCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: Checkpoint.CommandName,
Short: "Create a checkpoint in the primary master journal system",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(nil)
},
})
return cmd
}
9 changes: 5 additions & 4 deletions cli/src/alluxio.org/cli/cmd/journal/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (

var Format = &FormatCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "format",
JavaClassName: "alluxio.cli.Format",
Parameters: []string{"master"},
ShellJavaOpts: fmt.Sprintf(env.JavaOptFormat, env.ConfAlluxioLoggerType, "Console"),
CommandName: "format",
JavaClassName: "alluxio.cli.Format",
Parameters: []string{"master"},
UseServerClasspath: true,
ShellJavaOpts: fmt.Sprintf(env.JavaOptFormat, env.ConfAlluxioLoggerType, "Console"),
},
}

Expand Down
3 changes: 3 additions & 0 deletions cli/src/alluxio.org/cli/cmd/journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var Service = &env.Service{
Name: "journal",
Description: "Format, backup, and other journal related operations",
Commands: []env.Command{
Backup,
Checkpoint,
Format,
Read,
},
}
88 changes: 88 additions & 0 deletions cli/src/alluxio.org/cli/cmd/journal/read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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 journal

import (
"fmt"
"strconv"

"github.com/palantir/stacktrace"
"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var Read = &ReadCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "read",
JavaClassName: "alluxio.master.journal.tool.JournalTool",
UseServerClasspath: true,
ShellJavaOpts: fmt.Sprintf(env.JavaOptFormat, env.ConfAlluxioLoggerType, "Console"),
},
}

type ReadCommand struct {
*env.BaseJavaCommand

end int
inputDir string
master string
outputDir string
start int
}

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

func (c *ReadCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: Read.CommandName,
Short: "Read an Alluxio journal file to a human-readable version",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(nil)
},
})
cmd.Flags().IntVar(&c.end, "end", -1, "end log sequence number (exclusive)")
cmd.Flags().StringVar(&c.inputDir, "input-dir", "", "input directory on-disk to read the journal content from")
cmd.Flags().StringVar(&c.master, "master", "FileSystemMaster", "name of the master class")
cmd.Flags().StringVar(&c.outputDir, "output-dir", "", "output directory to write journal content to")
cmd.Flags().IntVar(&c.start, "start", 0, "start log sequence number (inclusive)")
return cmd
}

func (c *ReadCommand) Run(_ []string) error {
var javaArgs []string
if c.start < 0 {
return stacktrace.NewError("start log sequence number must be non-negative but was %v", c.start)
}
if c.end < -1 {
return stacktrace.NewError("end log sequence number must be non-negative but was %v", c.end)
}
if c.end != -1 {
javaArgs = append(javaArgs, "-end", strconv.Itoa(c.end))
}
if c.inputDir != "" {
javaArgs = append(javaArgs, "-inputDir", c.inputDir)
}
if c.master != "FileSystemMaster" {
javaArgs = append(javaArgs, "-master", c.master)
}
if c.outputDir != "" {
javaArgs = append(javaArgs, "-outputDir", c.outputDir)
}
if c.start > 0 {
javaArgs = append(javaArgs, "-start", strconv.Itoa(c.start))
}
return c.Base().Run(javaArgs)
}
12 changes: 9 additions & 3 deletions cli/src/alluxio.org/cli/env/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ type BaseJavaCommand struct {

DebugMode bool

InlineJavaOpts []string // java opts provided by the user as part of the inline command
ShellJavaOpts string // default java opts encoded as part of the specific command
UseServerClasspath bool // defaults to ALLUXIO_CLIENT_CLASSPATH, use ALLUXIO_SERVER_CLASSPATH if true
InlineJavaOpts []string // java opts provided by the user as part of the inline command
ShellJavaOpts string // default java opts encoded as part of the specific command
}

func (c *BaseJavaCommand) InitRunJavaClassCmd(cmd *cobra.Command) *cobra.Command {
Expand All @@ -58,7 +59,12 @@ func (c *BaseJavaCommand) RunJavaClassCmd(args []string) *exec.Cmd {
cmdArgs = append(cmdArgs, strings.Split(opts, " ")...)
}
}
cmdArgs = append(cmdArgs, "-cp", Env.EnvVar.GetString(EnvAlluxioClientClasspath))
classpath := EnvAlluxioClientClasspath
if c.UseServerClasspath {
classpath = EnvAlluxioServerClasspath
}
cmdArgs = append(cmdArgs, "-cp", Env.EnvVar.GetString(classpath))

if opts := Env.EnvVar.GetString(ConfAlluxioUserJavaOpts.EnvVar); opts != "" {
cmdArgs = append(cmdArgs, strings.Split(opts, " ")...)
}
Expand Down