Skip to content

Commit

Permalink
simplifying logic (removed the ReworkFileName function)
Browse files Browse the repository at this point in the history
  • Loading branch information
visill committed Oct 22, 2024
1 parent f4e6161 commit 2ec8dab
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 49 deletions.
9 changes: 1 addition & 8 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package database

import (
"fmt"
"strings"

"github.com/jackc/pgx"
"github.com/jackc/pgx/pgtype"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (database *DatabaseHandler) GetVirtualExpireIndexes(port uint64) (map[strin
if err := rows2.Scan(&xpath); err != nil {
return nil, nil, fmt.Errorf("unable to parse query output %v", err)
}
p2 := ReworkFileName(xpath)
p2 := xpath
c2[p2] = true
ylogger.Zero.Debug().Str("file", p2).Msg("added")
}
Expand Down Expand Up @@ -170,9 +169,3 @@ func connectToDatabase(port uint64, database string) (*pgx.Conn, error) {
}
return conn, nil
}

func ReworkFileName(str string) string {
p1 := strings.Split(str, "/")
p2 := strings.Join(p1, "_")
return p2
}
2 changes: 1 addition & 1 deletion pkg/proc/delete_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (dh *BasicDeleteHandler) ListGarbageFiles(msg message.DeleteMessage) ([]str

filesToDelete := make([]string, 0)
for i := 0; i < len(objectMetas); i++ {
reworkedName := database.ReworkFileName(objectMetas[i].Path)
reworkedName := objectMetas[i].Path
ylogger.Zero.Debug().Str("reworked name", reworkedName).Msg("lookup chunk")

if vi[reworkedName] {
Expand Down
40 changes: 0 additions & 40 deletions pkg/proc/delete_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,13 @@ import (

"github.com/stretchr/testify/assert"
"github.com/yezzey-gp/yproxy/config"
"github.com/yezzey-gp/yproxy/pkg/database"
"github.com/yezzey-gp/yproxy/pkg/message"
mock "github.com/yezzey-gp/yproxy/pkg/mock"
"github.com/yezzey-gp/yproxy/pkg/object"
"github.com/yezzey-gp/yproxy/pkg/proc"
"go.uber.org/mock/gomock"
)

func TestReworkingName(t *testing.T) {
type TestCase struct {
input string
expected string
}

testCases := []TestCase{
{
input: "/segments_005/seg1/basebackups_005/yezzey/1663_16530_a4c5ad8305b83f07200b020694c36563_17660_1__DY_1_xlog_19649822496",
expected: "1663_16530_a4c5ad8305b83f07200b020694c36563_17660_",
},
{
input: "1663_16530_a4c5ad8305b83f07200b020694c36563_17660_1__DY_1_xlog_19649822496",
expected: "1663_16530_a4c5ad8305b83f07200b020694c36563_17660_",
},
{
input: "seg1/basebackups_005/yezzey/1663_16530_a4c5ad8305b83f07200b020694c36563_17660_1__DY_1_xlog_19649822496",
expected: "1663_16530_a4c5ad8305b83f07200b020694c36563_17660_",
},
{
input: "1663_16530_a4c5ad8305b83f07200b020694c36563",
expected: "1663_16530_a4c5ad8305b83f07200b020694c36563",
},
{
input: "1663___a4c5ad8305b83f07200b020694c36563___",
expected: "1663___a4c5ad8305b83f07200b020694c36563_",
},
{
input: "file",
expected: "file",
},
}

for _, testCase := range testCases {
ans := database.ReworkFileName(testCase.input)
assert.Equal(t, testCase.expected, ans)
}
}

func TestFilesToDeletion(t *testing.T) {
ctrl := gomock.NewController(t)

Expand Down

0 comments on commit 2ec8dab

Please sign in to comment.