MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / CreateCluster

Method CreateCluster

store/store.go:229–251  ·  view source on GitHub ↗
(ctx context.Context, ns string, clusterInfo *Cluster)

Source from the content-addressed store, hash-verified

227}
228
229func (s *ClusterStore) CreateCluster(ctx context.Context, ns string, clusterInfo *Cluster) error {
230 lock := s.getLock(ns, clusterInfo.Name)
231 lock.Lock()
232 defer lock.Unlock()
233
234 if exists, _ := s.existsCluster(ctx, ns, clusterInfo.Name); exists {
235 return fmt.Errorf("cluster: %w", consts.ErrAlreadyExists)
236 }
237 clusterBytes, err := json.Marshal(clusterInfo)
238 if err != nil {
239 return fmt.Errorf("cluster: %w", err)
240 }
241 if err := s.e.Set(ctx, buildClusterKey(ns, clusterInfo.Name), clusterBytes); err != nil {
242 return err
243 }
244 s.EmitEvent(EventPayload{
245 Namespace: ns,
246 Cluster: clusterInfo.Name,
247 Type: EventCluster,
248 Command: CommandCreate,
249 })
250 return nil
251}
252
253func (s *ClusterStore) RemoveCluster(ctx context.Context, ns, cluster string) error {
254 lock := s.getLock(ns, cluster)

Callers 3

TestController_BasicsFunction · 0.95
TestClusterStoreFunction · 0.95
TestClusterMigrateDataFunction · 0.95

Calls 6

getLockMethod · 0.95
existsClusterMethod · 0.95
EmitEventMethod · 0.95
buildClusterKeyFunction · 0.85
ErrorfMethod · 0.80
SetMethod · 0.65

Tested by 3

TestController_BasicsFunction · 0.76
TestClusterStoreFunction · 0.76
TestClusterMigrateDataFunction · 0.76