Skip to content

Commit

Permalink
allow bootstrap with multi resources
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Aug 12, 2019
1 parent 3340449 commit fa155df
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion local.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (ls *defaultLocalStore) BootstrapCluster(initResources ...Resource) {
ls.MustPutResource(res)
}

ok, err := ls.pd.GetStore().PutBootstrapped(ls.meta, initResources[0])
ok, err := ls.pd.GetStore().PutBootstrapped(ls.meta, initResources...)
if err != nil {
for _, res := range initResources {
ls.MustRemoveResource(res.ID())
Expand Down
6 changes: 3 additions & 3 deletions meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type codecSerializable interface {

// Peer is the resource peer
type Peer struct {
ID uint64
ContainerID uint64
ID uint64 `json:"id"`
ContainerID uint64 `json:"cid"`
}

// Clone returns a clone value
Expand Down Expand Up @@ -88,7 +88,7 @@ type Container interface {

SetID(id uint64)
ID() uint64
Lables() []Pair
Labels() []Pair
State() State

Clone() Container
Expand Down
2 changes: 1 addition & 1 deletion runtime_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (cr *ContainerRuntime) GetLocationID(keys []string) string {

// GetLabelValue returns label value of key
func (cr *ContainerRuntime) GetLabelValue(key string) string {
for _, label := range cr.meta.Lables() {
for _, label := range cr.meta.Labels() {
if label.Key == key {
return label.Value
}
Expand Down
2 changes: 1 addition & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ type Store interface {
AllocID() (uint64, error)

// PutBootstrapped put cluster is bootstrapped
PutBootstrapped(container Container, res Resource) (bool, error)
PutBootstrapped(container Container, resources ...Resource) (bool, error)
}
14 changes: 8 additions & 6 deletions store_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (s *etcdStore) generate() (uint64, error) {
}

// PutBootstrapped put cluster is bootstrapped
func (s *etcdStore) PutBootstrapped(container Container, res Resource) (bool, error) {
func (s *etcdStore) PutBootstrapped(container Container, resources ...Resource) (bool, error) {
ctx, cancel := context.WithTimeout(s.client.Ctx(), DefaultTimeout)
defer cancel()

Expand All @@ -349,12 +349,14 @@ func (s *etcdStore) PutBootstrapped(container Container, res Resource) (bool, er
}
ops = append(ops, clientv3.OpPut(s.getKey(container.ID(), s.containerPath), string(meta)))

meta, err = res.Marshal()
if err != nil {
return false, err
for _, res := range resources {
meta, err = res.Marshal()
if err != nil {
return false, err
}
ops = append(ops, clientv3.OpPut(s.getKey(res.ID(), s.resourcePath), string(meta)))
ops = append(ops, clientv3.OpPut(s.clusterPath, string(meta)))
}
ops = append(ops, clientv3.OpPut(s.getKey(res.ID(), s.resourcePath), string(meta)))
ops = append(ops, clientv3.OpPut(s.clusterPath, string(meta)))

// txn
resp, err := s.client.Txn(ctx).
Expand Down

0 comments on commit fa155df

Please sign in to comment.