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

Use uint64 in delete msg #60

Merged
merged 2 commits into from
Oct 2, 2024
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
8 changes: 4 additions & 4 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var (

offset uint64

segmentPort int
segmentNum int
segmentPort uint64
segmentNum uint64
confirm bool
garbage bool
)
Expand Down Expand Up @@ -367,8 +367,8 @@ func init() {
rootCmd.AddCommand(listCmd)
rootCmd.AddCommand(goolCmd)

deleteCmd.PersistentFlags().IntVarP(&segmentPort, "port", "p", 6000, "port that segment is listening on")
deleteCmd.PersistentFlags().IntVarP(&segmentNum, "segnum", "s", 0, "logical number of a segment")
deleteCmd.PersistentFlags().Uint64VarP(&segmentPort, "port", "p", 6000, "port that segment is listening on")
deleteCmd.PersistentFlags().Uint64VarP(&segmentNum, "segnum", "s", 0, "logical number of a segment")
deleteCmd.PersistentFlags().BoolVarP(&confirm, "confirm", "", false, "confirm deletion")
deleteCmd.PersistentFlags().BoolVarP(&garbage, "garbage", "g", false, "delete garbage")
rootCmd.AddCommand(deleteCmd)
Expand Down
4 changes: 2 additions & 2 deletions pkg/backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type BackupLSN struct {

//go:generate mockgen -destination=pkg/mock/backups.go -package=mock
type BackupInterractor interface {
GetFirstLSN(int) (uint64, error)
GetFirstLSN(seg uint64) (uint64, error)
}

type WalgBackupInterractor struct { //TODO: rewrite to using s3 instead of wal-g cmd
}

// get lsn of the oldest backup
func (b *WalgBackupInterractor) GetFirstLSN(seg int) (uint64, error) {
func (b *WalgBackupInterractor) GetFirstLSN(seg uint64) (uint64, error) {
cmd := exec.Command("/usr/bin/wal-g", "st", "ls", fmt.Sprintf("segments_005/seg%d/basebackups_005/", seg), "--config=/etc/wal-g/wal-g.yaml")
ylogger.Zero.Debug().Any("flags", cmd.Args).Msg("Command args")
var out bytes.Buffer
Expand Down
8 changes: 4 additions & 4 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

//go:generate mockgen -destination=../mock/mock_database_interractor.go -package mock
type DatabaseInterractor interface {
GetVirtualExpireIndexes(int) (map[string]bool, map[string]uint64, error)
GetVirtualExpireIndexes(port uint64) (map[string]bool, map[string]uint64, error)
}

type DatabaseHandler struct {
Expand All @@ -31,7 +31,7 @@ type Ei struct {
fqnmd5 string
}

func (database *DatabaseHandler) GetVirtualExpireIndexes(port int) (map[string]bool, map[string]uint64, error) { //TODO несколько баз
func (database *DatabaseHandler) GetVirtualExpireIndexes(port uint64) (map[string]bool, map[string]uint64, error) { //TODO несколько баз
db, err := getDatabase(port)
if err != nil {
return nil, nil, fmt.Errorf("unable to get ao/aocs tables %v", err) //fix
Expand Down Expand Up @@ -95,7 +95,7 @@ func (database *DatabaseHandler) GetVirtualExpireIndexes(port int) (map[string]b
return c2, c, err
}

func getDatabase(port int) (DB, error) {
func getDatabase(port uint64) (DB, error) {
conn, err := connectToDatabase(port, "postgres")
if err != nil {
return DB{}, err
Expand Down Expand Up @@ -154,7 +154,7 @@ func getDatabase(port int) (DB, error) {
return DB{}, fmt.Errorf("no yezzey schema across databases")
}

func connectToDatabase(port int, database string) (*pgx.Conn, error) {
func connectToDatabase(port uint64, database string) (*pgx.Conn, error) {
config, err := pgx.ParseEnvLibpq()
if err != nil {
return nil, errors.Wrap(err, "Connect: unable to read environment variables")
Expand Down
10 changes: 5 additions & 5 deletions pkg/message/delete_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (

type DeleteMessage struct { //seg port
Name string
Port int
Segnum int
Port uint64
Segnum uint64
Confirm bool
Garbage bool
}

var _ ProtoMessage = &DeleteMessage{}

func NewDeleteMessage(name string, port int, seg int, confirm bool, garbage bool) *DeleteMessage {
func NewDeleteMessage(name string, port uint64, seg uint64, confirm bool, garbage bool) *DeleteMessage {
return &DeleteMessage{
Name: name,
Port: port,
Expand Down Expand Up @@ -65,8 +65,8 @@ func (c *DeleteMessage) Decode(body []byte) {
c.Garbage = true
}
c.Name = c.GetDeleteName(body[4:])
c.Port = int(binary.BigEndian.Uint64(body[len(body)-16 : len(body)-8]))
c.Segnum = int(binary.BigEndian.Uint64(body[len(body)-8:]))
c.Port = binary.BigEndian.Uint64(body[len(body)-16 : len(body)-8])
c.Segnum = binary.BigEndian.Uint64(body[len(body)-8:])
}

func (c *DeleteMessage) GetDeleteName(b []byte) string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ func TestDeleteMsg(t *testing.T) {
msg2.Decode(body[8:])

assert.Equal("myname/mynextname", msg2.Name)
assert.Equal(5432, msg2.Port)
assert.Equal(42, msg2.Segnum)
assert.Equal(uint64(5432), msg2.Port)
assert.Equal(uint64(42), msg2.Segnum)
assert.True(msg2.Confirm)
assert.True(msg2.Garbage)
}
10 changes: 5 additions & 5 deletions pkg/mock/backups.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/mock/database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
BackupInterractor: backupHandler,
}

ylogger.Zero.Debug().Str("Name", msg.Name).Bool("garb", msg.Garbage).Bool("confirm", msg.Confirm).Msg("requested to remove external chunk")

if msg.Garbage {
err = dh.HandleDeleteGarbage(msg)
if err != nil {
Expand All @@ -416,10 +418,17 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
_ = ycl.ReplyError(err, "failed to upload")
return err
}
ylogger.Zero.Info().Msg("Deleted garbage successfully")
if !msg.Confirm {
ylogger.Zero.Warn().Msg("It was a dry-run, nothing was deleted")

if msg.Garbage {
if !msg.Confirm {
ylogger.Zero.Warn().Msg("It was a dry-run, nothing was deleted")
} else {
ylogger.Zero.Info().Msg("Deleted garbage successfully")
}
} else {
ylogger.Zero.Info().Msg("Deleted chunk successfully")
}

case message.MessageTypeGool:
return ProcMotion(s, cr, ycl)

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,6 @@ func (s *S3StorageInteractor) DeleteObject(key string) error {
ylogger.Zero.Err(err).Msg("failed to delete old object")
return err
}
ylogger.Zero.Debug().Msg("deleted object")
ylogger.Zero.Debug().Str("path", key).Msg("deleted object")
return nil
}
Loading