You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "borismartinovic01 (via GitHub)" <gi...@apache.org> on 2025/01/02 12:03:05 UTC

[PR] Add support for Consul as store engine [kvrocks-controller]

borismartinovic01 opened a new pull request, #240:
URL: https://github.com/apache/kvrocks-controller/pull/240

   This PR introduces `Consul` as a store engine and tries to align the implementation with the implementations of `etcd` and `zookeeper` as much as possible.
   
   ### Constants description:
   
   1. `sessionTTL = 10 seconds` - Minimum required by Consul
   2. `lockDelay = 1 millisecond` - Consul defines a default lock delay of 15 seconds. In the docs it is mentioned that this can be disabled by setting this param to zero value but looking at the source code of Consul's session.go implementation this is not possible, so it is set to the minimum that's bigger than zero value
   3. `defaultElectPath = "kvrocks/controller/leader"` - Removed the backslash from the beginning since Consul requires keys not to start with a backslash.
   
   ### Testing
   
   1. Tested the implementation by running Consul as Docker container locally and running UTs
   
   Tests were kept almost the same as for etcd and zookeeper except the backslash was removed from keys due to limitation mentioned above and wait duration was increased from 15 to 25 seconds in the second test since the sessionTTL is a bit bigger.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2574681527

   @borismartinovic01 I have rerun the CI since it's not related to this PR: #245 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#discussion_r1901474389


##########
go.mod:
##########
@@ -45,6 +46,15 @@ require (
 	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/gogo/protobuf v1.3.2 // indirect
 	github.com/golang/protobuf v1.5.4 // indirect
+	github.com/hashicorp/consul/api v1.31.0 // indirect

Review Comment:
   It shouldn't be "indirect" dependency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "borismartinovic01 (via GitHub)" <gi...@apache.org>.
borismartinovic01 commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2574659680

   Raft tests failed. This is not very clear to me. Do you have any information on why this is happening?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice closed pull request #240: Add support for Consul as store engine
URL: https://github.com/apache/kvrocks-controller/pull/240


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#discussion_r1901474389


##########
go.mod:
##########
@@ -45,6 +46,15 @@ require (
 	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/gogo/protobuf v1.3.2 // indirect
 	github.com/golang/protobuf v1.5.4 // indirect
+	github.com/hashicorp/consul/api v1.31.0 // indirect

Review Comment:
   It shouldn't be an "indirect" dependency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2569719283

   ## [Codecov](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `60.65574%` with `72 lines` in your changes missing coverage. Please review.
   > Project coverage is 46.77%. Comparing base [(`6c56470`)](https://app.codecov.io/gh/apache/kvrocks-controller/commit/6c564700d621ef30a182bad1bfeff0aa13db6ea7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`67e3bd3`)](https://app.codecov.io/gh/apache/kvrocks-controller/commit/67e3bd310b6617fe262d1272b03fe04066d4bfee?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 20 commits behind head on unstable.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [store/engine/consul/consul.go](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?src=pr&el=tree&filepath=store%2Fengine%2Fconsul%2Fconsul.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3RvcmUvZW5naW5lL2NvbnN1bC9jb25zdWwuZ28=) | 61.66% | [57 Missing and 12 partials :warning: ](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [server/server.go](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?src=pr&el=tree&filepath=server%2Fserver.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NlcnZlci5nbw==) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##           unstable     #240      +/-   ##
   ============================================
   + Coverage     43.38%   46.77%   +3.39%     
   ============================================
     Files            37       43       +6     
     Lines          2971     3878     +907     
   ============================================
   + Hits           1289     1814     +525     
   - Misses         1544     1873     +329     
   - Partials        138      191      +53     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [unittests](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `46.77% <60.65%> (+3.39%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/kvrocks-controller/pull/240?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "aleksraiden (via GitHub)" <gi...@apache.org>.
aleksraiden commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2567893039

   Awesome, we use kvrocks at consul+nomad cluster and very need this feature


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2567972279

   Yeah it seems https://github.com/hashicorp/consul is licensed under BSL, which is not an open-source license and not allowed by ASF to be used as a direct dependency of an ASF project.
   
   However, I think there may be several ways to workaround it:
   - Replace `github.com/hashicorp/consul/api` with another project which is under a compatible license. (maybe you need to check the license of other newly-introduced projects, too), or implement a simple client by our own. (I'm not familiar with this project so I don't know how much work it will be. From its docs [here](https://developer.hashicorp.com/consul/api-docs?product_intent=consul), it should not be impossible since it's HTTP-based. Note that we just need the consul client to be license-compatible. )
   - Make this feature **totally** optional, and disable by default. In this way, it might be compliant, from the perspective of the ASF view. Note that, it means that the official release should not include this feature, and all code of these dependencies should not be  compiled into the released binary.
   
   I'm not an expert in this area. See if @tisonkun has any comment.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2567757749

   @borismartinovic01 Thanks for your contribution.
   
   The CI failed due to forgetting to add `github.com/hashicorp/consul/api` into go.mod. You might need to add the `consul` to `scripts/docker/docker-compose.yml` to make the test work.
   
   Another concern is `consul`[1] is licensed under `MPL 2.0` which is a weak copyleft category[2] in ASF. We need to investigate what should be done before introducing it into our release.
   
   [1] https://github.com/hashicorp/consul?tab=License-1-ov-file#readme
   [2] https://www.apache.org/legal/resolved.html#weak-copyleft-licenses


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2567972835

   Sorry for clicking wrong button : )


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2568039166

   Hmm.. I think we can continue to review this PR, and merge it after approving by reviewers. We'll handle further issues if there's any concern from the ASF.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "torwig (via GitHub)" <gi...@apache.org>.
torwig commented on code in PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#discussion_r1904329333


##########
store/engine/consul/consul.go:
##########
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package consul
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"strings"
+	"sync"
+	"sync/atomic"
+	"time"
+
+	"github.com/apache/kvrocks-controller/consts"
+	"github.com/apache/kvrocks-controller/logger"
+	"github.com/apache/kvrocks-controller/store/engine"
+	"github.com/hashicorp/consul/api"
+	"github.com/hashicorp/consul/api/watch"
+	"go.uber.org/zap"
+)
+
+const (
+	sessionTTL = 10 * time.Second
+	lockDelay  = time.Millisecond
+)
+
+const configSchemeWithTLS = "https"

Review Comment:
   These two constant values can be put inside your const-group on lines 41-42.



##########
store/engine/consul/consul.go:
##########
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package consul
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"strings"
+	"sync"
+	"sync/atomic"
+	"time"
+
+	"github.com/apache/kvrocks-controller/consts"
+	"github.com/apache/kvrocks-controller/logger"
+	"github.com/apache/kvrocks-controller/store/engine"
+	"github.com/hashicorp/consul/api"
+	"github.com/hashicorp/consul/api/watch"
+	"go.uber.org/zap"
+)
+
+const (
+	sessionTTL = 10 * time.Second
+	lockDelay  = time.Millisecond
+)
+
+const configSchemeWithTLS = "https"
+const defaultElectPath = "kvrocks/controller/leader"
+
+type Config struct {
+	Addrs []string `yaml:"addrs"`
+	TLS   struct {
+		Enable   bool   `yaml:"enable"`
+		CertFile string `yaml:"cert_file"`
+		KeyFile  string `yaml:"key_file"`
+		CAFile   string `yaml:"ca_file"`
+	} `yaml:"tls"`
+	ElectPath string `yaml:"elect_path"`
+}
+
+type Consul struct {
+	client    *api.Client
+	watchPlan *watch.Plan
+
+	leaderMu  sync.RWMutex
+	leaderID  string
+	myID      string
+	electPath string
+	isReady   atomic.Bool
+
+	leaderChangeCh chan bool
+	electionCh     chan bool
+	lockReleaseCh  chan bool
+	quitCh         chan bool
+	wg             sync.WaitGroup
+}
+
+func New(id string, cfg *Config) (*Consul, error) {
+	if len(id) == 0 {
+		return nil, errors.New("id must NOT be a empty string")
+	}
+
+	clientConfig := &api.Config{
+		Address: cfg.Addrs[0],
+	}
+
+	if cfg.TLS.Enable {
+		clientConfig.Scheme = configSchemeWithTLS
+		tlsConfig := api.TLSConfig{
+			CertFile: cfg.TLS.CertFile,
+			KeyFile:  cfg.TLS.KeyFile,
+			CAFile:   cfg.TLS.CAFile,
+		}
+		clientConfig.TLSConfig = tlsConfig
+	}
+
+	client, err := api.NewClient(clientConfig)
+	if err != nil {
+		return nil, err
+	}
+
+	electPath := defaultElectPath
+	if cfg.ElectPath != "" {
+		electPath = cfg.ElectPath
+	}
+
+	watchPlanParams := map[string]interface{}{
+		"type": "key",
+		"key":  electPath,
+	}
+
+	watchPlan, err := watch.Parse(watchPlanParams)
+	if err != nil {
+		return nil, err
+	}
+
+	c := &Consul{
+		myID:           id,
+		electPath:      electPath,
+		client:         client,
+		watchPlan:      watchPlan,
+		leaderChangeCh: make(chan bool),
+		lockReleaseCh:  make(chan bool),
+		electionCh:     make(chan bool),
+		quitCh:         make(chan bool),
+	}
+	c.watchPlan.Handler = c.watchHandler
+	c.isReady.Store(false)
+	c.wg.Add(2)
+	go c.electLoop()
+	go c.runWatch()
+	return c, nil
+}
+
+func (c *Consul) ID() string {
+	return c.myID
+}
+
+func (c *Consul) Leader() string {
+	c.leaderMu.RLock()
+	defer c.leaderMu.RUnlock()
+	return c.leaderID
+}
+
+func (c *Consul) LeaderChange() <-chan bool {
+	return c.leaderChangeCh
+}
+
+func (c *Consul) IsReady(ctx context.Context) bool {
+	for {
+		select {
+		case <-c.quitCh:
+			return false
+		case <-time.After(100 * time.Millisecond):
+			if c.isReady.Load() {
+				return true
+			}
+		case <-ctx.Done():
+			return c.isReady.Load()
+		}
+	}
+}
+
+func (c *Consul) Get(ctx context.Context, key string) ([]byte, error) {
+	rsp, _, err := c.client.KV().Get(key, nil)
+	if err != nil {
+		return nil, err
+	}
+	if rsp == nil {
+		return nil, consts.ErrNotFound
+	}
+	return rsp.Value, nil
+}
+
+func (c *Consul) Exists(ctx context.Context, key string) (bool, error) {
+	_, err := c.Get(ctx, key)
+	if err != nil {
+		if errors.Is(err, consts.ErrNotFound) {
+			return false, nil
+		}
+		return false, err
+	}
+	return true, nil
+}
+
+func (c *Consul) Set(ctx context.Context, key string, value []byte) error {
+	kvPair := &api.KVPair{
+		Key:   key,
+		Value: value,
+	}
+	_, err := c.client.KV().Put(kvPair, nil)
+	return err
+}
+
+func (c *Consul) Delete(ctx context.Context, key string) error {
+	_, err := c.client.KV().Delete(key, nil)
+	return err
+}
+
+func (c *Consul) List(ctx context.Context, prefix string) ([]engine.Entry, error) {
+	rsp, _, err := c.client.KV().List(prefix, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	prefixLen := len(prefix)
+	entries := make([]engine.Entry, 0)
+	for _, kv := range rsp {
+		if string(kv.Key) == prefix {
+			continue
+		}
+		key := strings.TrimLeft(string(kv.Key[prefixLen+1]), "/")
+		if strings.ContainsRune(key, '/') {
+			continue
+		}
+		entries = append(entries, engine.Entry{
+			Key:   key,
+			Value: kv.Value,
+		})
+	}
+	return entries, nil
+}
+
+func (c *Consul) electLoop() {
+	defer c.wg.Done()
+	for {
+		select {
+		case <-c.quitCh:
+			return
+		default:
+		}
+	reset:
+		sessionID, _, err := c.client.Session().Create(&api.SessionEntry{
+			Name:      c.electPath,
+			Behavior:  "release",
+			TTL:       fmt.Sprintf("%v", sessionTTL),
+			LockDelay: lockDelay,
+		}, nil)
+
+		if err != nil {
+			logger.Get().With(
+				zap.Error(err),
+			).Error("Failed to create session")
+			time.Sleep(sessionTTL / 3)
+			continue
+		}
+
+		kvPair := &api.KVPair{
+			Key:     c.electPath,
+			Value:   []byte(c.myID),
+			Session: sessionID,
+		}
+
+		for {
+			if _, _, err := c.client.KV().Acquire(kvPair, nil); err != nil {
+				logger.Get().With(
+					zap.Error(err),
+				).Error("Failed to acquire the leader campaign")
+				continue
+			}
+
+			select {
+			case <-c.lockReleaseCh:
+				goto reset

Review Comment:
   goto? Can we structure the code to eliminate this instruction?



##########
store/engine/consul/consul.go:
##########
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package consul
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"strings"
+	"sync"
+	"sync/atomic"
+	"time"
+
+	"github.com/apache/kvrocks-controller/consts"
+	"github.com/apache/kvrocks-controller/logger"
+	"github.com/apache/kvrocks-controller/store/engine"
+	"github.com/hashicorp/consul/api"
+	"github.com/hashicorp/consul/api/watch"
+	"go.uber.org/zap"
+)
+
+const (
+	sessionTTL = 10 * time.Second
+	lockDelay  = time.Millisecond
+)
+
+const configSchemeWithTLS = "https"
+const defaultElectPath = "kvrocks/controller/leader"
+
+type Config struct {
+	Addrs []string `yaml:"addrs"`
+	TLS   struct {
+		Enable   bool   `yaml:"enable"`
+		CertFile string `yaml:"cert_file"`
+		KeyFile  string `yaml:"key_file"`
+		CAFile   string `yaml:"ca_file"`
+	} `yaml:"tls"`
+	ElectPath string `yaml:"elect_path"`
+}
+
+type Consul struct {
+	client    *api.Client
+	watchPlan *watch.Plan
+
+	leaderMu  sync.RWMutex
+	leaderID  string
+	myID      string
+	electPath string
+	isReady   atomic.Bool
+
+	leaderChangeCh chan bool
+	electionCh     chan bool
+	lockReleaseCh  chan bool
+	quitCh         chan bool
+	wg             sync.WaitGroup
+}
+
+func New(id string, cfg *Config) (*Consul, error) {
+	if len(id) == 0 {
+		return nil, errors.New("id must NOT be a empty string")
+	}
+
+	clientConfig := &api.Config{
+		Address: cfg.Addrs[0],

Review Comment:
   If `cfg.Addrs` has no elements? Or is this case handled somewhere else?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "borismartinovic01 (via GitHub)" <gi...@apache.org>.
borismartinovic01 commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2567913560

   Okay, I wasn't aware of the license issues.
   I updated PR per comments so it can stay as PoC.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2568006383

   After carefully reading the content of [Category B](https://www.apache.org/legal/resolved.html#weak-copyleft-licenses), it appears that the main restriction is that our source releases should not include MPL source files. As kvrocks-controller is a golang project, we typically do not include these dependent source files in the source release, but instead specify the version and origin of dependencies through `go.mod`/`go.sum`. From this perspective, using these MPL projects as dependencies seems to be compliant. cc @tisonkun 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240#issuecomment-2574876221

   Thank you for your contribution!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support for Consul as store engine [kvrocks-controller]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice merged PR #240:
URL: https://github.com/apache/kvrocks-controller/pull/240


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org