Skip to content

Commit 18841dd

Browse files
committed
Improve(client/status): added poolset aux info for curvebs volume.
Signed-off-by: Wine93 <[email protected]>
1 parent 18394ff commit 18841dd

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

cli/command/client/map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func NewMapCommand(curveadm *cli.CurveAdm) *cobra.Command {
161161
flags.BoolVar(&options.noExclusive, "no-exclusive", false, "Map volume non exclusive")
162162
flags.StringVar(&options.size, "size", "10GiB", "Specify volume size")
163163
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")
164-
flags.StringVar(&options.poolset, "poolset", "", "Specify the poolset name")
164+
flags.StringVar(&options.poolset, "poolset", "default", "Specify the poolset name")
165165
return cmd
166166
}
167167

internal/errno/errno.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ var (
215215
ERR_GET_CLIENT_BY_ID_FAILED = EC(113002, "execute SQL failed which get client by id")
216216
ERR_GET_ALL_CLIENTS_FAILED = EC(113003, "execute SQL failed which get all clients")
217217
ERR_DELETE_CLIENT_FAILED = EC(113004, "execute SQL failed which delete client")
218+
ERR_SET_CLIENT_AUX_INFO_FAILED = EC(113005, "execute SQL failed which set client aux info")
218219
// 114: database/SQL (execute SQL statement: playground table)
219220
ERR_INSERT_PLAYGROUND_FAILED = EC(114000, "execute SQL failed which insert playground")
220221
ERR_GET_ALL_PLAYGROUND_FAILED = EC(114001, "execute SQL failed which get all playgrounds")

internal/storage/sql.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ var (
205205
// insert client
206206
InsertClient = `INSERT INTO clients(id, kind, host, container_id, aux_info) VALUES(?, ?, ?, ?, ?)`
207207

208+
// set client aux info
209+
SetClientAuxInfo = `UPDATE clients SET aux_info = ? WHERE id = ?`
210+
208211
// select clients
209212
SelectClients = `SELECT * FROM clients`
210213

internal/storage/storage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ func (s *Storage) InsertClient(id, kind, host, containerId, auxInfo string) erro
265265
return s.write(InsertClient, id, kind, host, containerId, auxInfo)
266266
}
267267

268+
func (s *Storage) SetClientAuxInfo(id, auxInfo string) error {
269+
return s.write(SetClientAuxInfo, id, auxInfo)
270+
}
271+
268272
func (s *Storage) getClients(query string, args ...interface{}) ([]Client, error) {
269273
result, err := s.db.Query(query, args...)
270274
if err != nil {

internal/task/task/bs/create_volume.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package bs
2424

2525
import (
26+
"encoding/json"
2627
"fmt"
2728
"strings"
2829

@@ -75,6 +76,28 @@ func checkCreateStatus(out *string) step.LambdaType {
7576
}
7677
}
7778

79+
func setClientAuxInfo(curveadm *cli.CurveAdm, options MapOptions) step.LambdaType {
80+
return func(ctx *context.Context) error {
81+
volumeId := curveadm.GetVolumeId(options.Host, options.User, options.Volume)
82+
83+
auxInfo := &AuxInfo{
84+
User: options.User,
85+
Volume: options.Volume,
86+
Poolset: options.Poolset,
87+
}
88+
bytes, err := json.Marshal(auxInfo)
89+
if err != nil {
90+
return errno.ERR_ENCODE_VOLUME_INFO_TO_JSON_FAILED.E(err)
91+
}
92+
93+
err = curveadm.Storage().SetClientAuxInfo(volumeId, string(bytes))
94+
if err != nil {
95+
return errno.ERR_SET_CLIENT_AUX_INFO_FAILED.E(err)
96+
}
97+
return nil
98+
}
99+
}
100+
78101
func NewCreateVolumeTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) (*task.Task, error) {
79102
options := curveadm.MemStorage().Get(comm.KEY_MAP_OPTIONS).(MapOptions)
80103
hc, err := curveadm.GetHost(options.Host)
@@ -127,6 +150,9 @@ func NewCreateVolumeTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) (*t
127150
t.AddStep(&step.Lambda{
128151
Lambda: checkCreateStatus(&out),
129152
})
153+
t.AddStep(&step.Lambda{
154+
Lambda: setClientAuxInfo(curveadm, options),
155+
})
130156

131157
return t, nil
132158
}

internal/task/task/bs/start_nebd.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ type (
5151
}
5252

5353
AuxInfo struct {
54-
User string `json:"user"`
55-
Volume string `json:"volume,"`
56-
Config string `json:"config,omitempty"` // TODO(P1)
54+
User string `json:"user"`
55+
Volume string `json:"volume"`
56+
Poolset string `json:"poolset"`
57+
Config string `json:"config,omitempty"` // TODO(P1)
5758
}
5859
)
5960

@@ -122,8 +123,9 @@ func (s *step2InsertClient) Execute(ctx *context.Context) error {
122123
volumeId := curveadm.GetVolumeId(options.Host, options.User, options.Volume)
123124

124125
auxInfo := &AuxInfo{
125-
User: options.User,
126-
Volume: options.Volume,
126+
User: options.User,
127+
Volume: options.Volume,
128+
Poolset: options.Poolset,
127129
}
128130
bytes, err := json.Marshal(auxInfo)
129131
if err != nil {

0 commit comments

Comments
 (0)