Skip to content

Commit

Permalink
Use uint64 in delete msg
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Oct 2, 2024
1 parent c4f4e25 commit 28b4133
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
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.

0 comments on commit 28b4133

Please sign in to comment.