Skip to content

Commit

Permalink
Revert "manager: Implement clean up orphan"
Browse files Browse the repository at this point in the history
This reverts commit b4f7df1.
Ref: longhorn 3682

Signed-off-by: Jack Lin <jack.lin@suse.com>
(cherry picked from commit 4362d55)
  • Loading branch information
ChanYiLin authored and innobead committed Mar 17, 2023
1 parent e9c9224 commit 58ef336
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 245 deletions.
28 changes: 0 additions & 28 deletions app/cmd/backing_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func BackingImageCmd() cli.Command {
ListCmd(),
FetchCmd(),
PrepareDownloadCmd(),
CleanUpOrphanCmd(),
},
}
}
Expand Down Expand Up @@ -268,30 +267,3 @@ func prepareDownload(c *cli.Context) error {
fmt.Println("Download server address:", address)
return nil
}

func CleanUpOrphanCmd() cli.Command {
return cli.Command{
Name: "clean-up-orphan",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name",
Usage: "The name of the backing image",
},
cli.StringFlag{
Name: "uuid",
Usage: "The uuid of the backing image",
},
},
Action: func(c *cli.Context) {
if err := cleanUpOrphan(c); err != nil {
logrus.WithError(err).Fatalf("Error running backing image clean up orphan command")
}
},
}
}

func cleanUpOrphan(c *cli.Context) error {
url := c.GlobalString("url")
bimClient := client.NewBackingImageManagerClient(url)
return bimClient.CleanUpOrphan(c.String("name"), c.String("uuid"))
}
22 changes: 0 additions & 22 deletions pkg/client/manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"golang.org/x/net/context"
"google.golang.org/grpc"

Expand Down Expand Up @@ -198,27 +197,6 @@ func (cli *BackingImageManagerClient) PrepareDownload(name, uuid string) (string
return resp.SrcFilePath, resp.Address, nil
}

func (cli *BackingImageManagerClient) CleanUpOrphan(name, uuid string) error {
if name == "" || uuid == "" {
return fmt.Errorf("failed to clean up orphan: missing required parameter")
}
conn, err := grpc.Dial(cli.Address, grpc.WithInsecure())
if err != nil {
return errors.Wrapf(err, "cannot connect backing image manager service to %v", cli.Address)
}
defer conn.Close()

client := rpc.NewBackingImageManagerServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout)
defer cancel()

_, err = client.CleanUpOrphan(ctx, &rpc.CleanUpOrphanRequest{
Name: name,
Uuid: uuid,
})
return err
}

func (cli *BackingImageManagerClient) VersionGet() (*meta.VersionOutput, error) {
conn, err := grpc.Dial(cli.Address, grpc.WithInsecure())
if err != nil {
Expand Down
24 changes: 0 additions & 24 deletions pkg/manager/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,30 +434,6 @@ func (s *TestSuite) TestBackingImageDownloadToLocal(c *C) {
s.deleteBackingImage(c, s.addr1, s.testDiskPath1, biName, biUUID)
}

func (s *TestSuite) TestCleanUpOrphan(c *C) {
biName := "test-delete-orphan-file"
biUUID := TestBackingImageUUID

cli := client.NewBackingImageManagerClient(s.addr1)

// Create the data source dir
dsFilePath := types.GetDataSourceFilePath(s.testDiskPath1, biName, biUUID)
dsTmpFilePath := fmt.Sprintf("%s%s", dsFilePath, types.TmpFileSuffix)
err := os.MkdirAll(filepath.Dir(dsTmpFilePath), 0777)
c.Assert(err, IsNil)

// Prepare the the data source tmp file as orphan file
err = generateSimpleTestFile(dsTmpFilePath, MockFileSize)
c.Assert(err, IsNil)

// Clean up the orphan file
err = cli.CleanUpOrphan(biName, biUUID)
c.Assert(err, IsNil)

_, err = os.Stat(dsTmpFilePath)
c.Assert(os.IsNotExist(err), Equals, true)
}

func (s *TestSuite) TestDuplicateCalls(c *C) {
biName := "test-duplicate-calls-file"
biUUID := TestBackingImageUUID
Expand Down
23 changes: 0 additions & 23 deletions pkg/manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,29 +509,6 @@ func (m *Manager) PrepareDownload(ctx context.Context, req *rpc.PrepareDownloadR
}, nil
}

func (m *Manager) CleanUpOrphan(ctx context.Context, req *rpc.CleanUpOrphanRequest) (resp *empty.Empty, err error) {
log := m.log.WithFields(logrus.Fields{"biName": req.Name, "biUUID": req.Uuid})
defer func() {
if err != nil {
log.WithError(err).Error("Backing Image Manager: failed to clean up orphan files")
}
}()

if req.Name == "" || req.Uuid == "" {
return nil, status.Errorf(codes.InvalidArgument, "missing required argument")
}

dsFilePath := types.GetDataSourceFilePath(m.diskPath, req.Name, req.Uuid)
orphanTmpFilePath := fmt.Sprintf("%s%s", dsFilePath, types.TmpFileSuffix)

log.Infof("Backing Image Manager: prepare to clean up orphan files %v", orphanTmpFilePath)
if err := os.RemoveAll(orphanTmpFilePath); err != nil {
return nil, err
}
log.Info("Backing Image Manager: orphan files has been cleaned up")
return &empty.Empty{}, nil
}

func (m *Manager) allocatePorts(portCount int32) (int32, int32, error) {
if portCount < 0 {
return 0, 0, fmt.Errorf("invalid port count %v", portCount)
Expand Down
Loading

0 comments on commit 58ef336

Please sign in to comment.