Skip to content

Commit

Permalink
Storage Class & TableSpace settings for offload. (#53)
Browse files Browse the repository at this point in the history
* Refactor client-server interaction facilities

* Fix for go sum

* Fix unit

* Add put TableSpace and StorageClass settings

* Client-side support to storage class and tablespace settings

* Fix error handling
  • Loading branch information
reshke authored Aug 24, 2024
1 parent ce6d6aa commit 8c492ef
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 172 deletions.
47 changes: 33 additions & 14 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@ import (
"net"
"os"

"github.com/yezzey-gp/yproxy/pkg/storage"

"github.com/spf13/cobra"
"github.com/yezzey-gp/yproxy/config"
"github.com/yezzey-gp/yproxy/pkg/client"
"github.com/yezzey-gp/yproxy/pkg/message"
"github.com/yezzey-gp/yproxy/pkg/object"
"github.com/yezzey-gp/yproxy/pkg/proc"
"github.com/yezzey-gp/yproxy/pkg/tablespace"
"github.com/yezzey-gp/yproxy/pkg/ylogger"
)

var cfgPath string
var oldCfgPath string
var logLevel string
var decrypt bool
var encrypt bool
var offset uint64
var segmentPort int
var segmentNum int
var confirm bool
var garbage bool
var (
cfgPath string
oldCfgPath string
logLevel string

decrypt bool
/* Put command flags */
encrypt bool
storageClass string
tableSpace string

offset uint64

segmentPort int
segmentNum int
confirm bool
garbage bool
)

// TODOV
func Runner(f func(net.Conn, *config.Instance, []string) error) func(*cobra.Command, []string) error {
Expand Down Expand Up @@ -97,7 +105,16 @@ func putFunc(con net.Conn, instanceCnf *config.Instance, args []string) error {
ycl := client.NewYClient(con)
r := proc.NewProtoReader(ycl)

msg := message.NewPutMessage(args[0], encrypt).Encode()
msg := message.NewPutMessageV2(args[0], encrypt, []message.PutSettings{
{
Name: message.StorageClassSetting,
Value: storageClass,
},
{
Name: message.TableSpaceSetting,
Value: tableSpace,
},
}).Encode()
_, err := con.Write(msg)
if err != nil {
return err
Expand Down Expand Up @@ -167,7 +184,7 @@ func listFunc(con net.Conn, instanceCnf *config.Instance, args []string) error {
r := proc.NewProtoReader(ycl)

done := false
res := make([]*storage.ObjectInfo, 0)
res := make([]*object.ObjectInfo, 0)
for {
if done {
break
Expand Down Expand Up @@ -342,6 +359,8 @@ func init() {
rootCmd.AddCommand(copyCmd)

putCmd.PersistentFlags().BoolVarP(&encrypt, "encrypt", "e", false, "encrypt external object before put")
putCmd.PersistentFlags().StringVarP(&storageClass, "storage-class", "s", "STANDARD", "storage class for message upload")
putCmd.PersistentFlags().StringVarP(&tableSpace, "tablespace", "t", tablespace.DefaultTableSpace, "storage class for message upload")
rootCmd.AddCommand(putCmd)

rootCmd.AddCommand(listCmd)
Expand Down
2 changes: 2 additions & 0 deletions config/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Storage struct {
StoragePrefix string `json:"storage_prefix" toml:"storage_prefix" yaml:"storage_prefix"`
StorageBucket string `json:"storage_bucket" toml:"storage_bucket" yaml:"storage_bucket"`

TablespaceMap map[string]string `json:"tablespace_map" toml:"tablespace_map" yaml:"tablespace_map"`

// how many concurrrent connection acquire allowed
StorageConcurrency int64 `json:"storage_concurrency" toml:"storage_concurrency" yaml:"storage_concurrency"`

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
)

require (
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/yezzey-gp/aws-sdk-go v0.1.0 h1:as6ANEva14gKdhWPjZy6qaGR+/WhP0HN4UMzDH
github.com/yezzey-gp/aws-sdk-go v0.1.0/go.mod h1:+gUq+WgyFOP6Eto+AcgJDDeM6tnXmOT4RJmfpuafV3Y=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
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 @@ -81,15 +81,15 @@ func TestPutV2Msg(t *testing.T) {
name string
encrypt bool
err error
settings []message.PutSetting
settings []message.PutSettings
}

for _, tt := range []tcase{
{
"nam1",
true,
nil,
[]message.PutSetting{
[]message.PutSettings{
{
Name: "a",
Value: "b",
Expand Down
10 changes: 5 additions & 5 deletions pkg/message/object_meta_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"bytes"
"encoding/binary"

"github.com/yezzey-gp/yproxy/pkg/storage"
"github.com/yezzey-gp/yproxy/pkg/object"
)

type ObjectInfoMessage struct {
Content []*storage.ObjectInfo
Content []*object.ObjectInfo
}

var _ ProtoMessage = &ObjectInfoMessage{}

func NewObjectMetaMessage(content []*storage.ObjectInfo) *ObjectInfoMessage {
func NewObjectMetaMessage(content []*object.ObjectInfo) *ObjectInfoMessage {
return &ObjectInfoMessage{
Content: content,
}
Expand Down Expand Up @@ -44,12 +44,12 @@ func (c *ObjectInfoMessage) Encode() []byte {

func (c *ObjectInfoMessage) Decode(body []byte) {
body = body[4:]
c.Content = make([]*storage.ObjectInfo, 0)
c.Content = make([]*object.ObjectInfo, 0)
for len(body) > 0 {
name, index := c.GetString(body)
size := int64(binary.BigEndian.Uint64(body[index : index+8]))

c.Content = append(c.Content, &storage.ObjectInfo{
c.Content = append(c.Content, &object.ObjectInfo{
Path: name,
Size: size,
})
Expand Down
11 changes: 7 additions & 4 deletions pkg/message/put_message_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"encoding/binary"
)

type PutSetting struct {
const StorageClassSetting = "StorageClass"
const TableSpaceSetting = "TableSpace"

type PutSettings struct {
Name string
Value string
}
Expand All @@ -14,12 +17,12 @@ type PutMessageV2 struct {
Encrypt bool
Name string

Settings []PutSetting
Settings []PutSettings
}

var _ ProtoMessage = &PutMessageV2{}

func NewPutMessageV2(name string, encrypt bool, settings []PutSetting) *PutMessageV2 {
func NewPutMessageV2(name string, encrypt bool, settings []PutSettings) *PutMessageV2 {
return &PutMessageV2{
Name: name,
Encrypt: encrypt,
Expand Down Expand Up @@ -90,7 +93,7 @@ func (c *PutMessageV2) Decode(body []byte) {

totalOff := 4 + off + 8

c.Settings = make([]PutSetting, settLen)
c.Settings = make([]PutSettings, settLen)

for i := 0; i < int(settLen); i++ {

Expand Down
9 changes: 7 additions & 2 deletions pkg/mock/backups.go

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

9 changes: 7 additions & 2 deletions pkg/mock/database.go

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

11 changes: 8 additions & 3 deletions pkg/mock/proc/yrreader.go

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

Loading

0 comments on commit 8c492ef

Please sign in to comment.