Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memberlist delete op scaffolding #524

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (cfg *Config) RegisterFlagsWithPrefix(flagsPrefix, defaultPrefix string, f

// Client is a high-level client for key-value stores (such as Etcd and
// Consul) that exposes operations such as CAS and Watch which take callbacks.
// It also deals with serialisation by using a Codec and having a instance of
// the the desired type passed in to methods ala json.Unmarshal.
// It also deals with serialisation by using a Codec and having an instance of
// the desired type passed in to methods ala json.Unmarshal.
type Client interface {
// List returns a list of keys under the given prefix. Returned keys will
// include the prefix.
Expand Down
18 changes: 15 additions & 3 deletions kv/memberlist/memberlist_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ func (c *Client) Get(ctx context.Context, key string) (interface{}, error) {
}

// Delete is part of kv.Client interface.
func (c *Client) Delete(_ context.Context, _ string) error {
return errors.New("memberlist does not support Delete")
func (c *Client) Delete(ctx context.Context, key string) error {
// delete item from kv store

err := c.awaitKVRunningOrStopping(ctx)
if err != nil {
return err
}
return c.kv.Delete(ctx, c.codec, key)
}

// CAS is part of kv.Client interface
Expand Down Expand Up @@ -307,7 +313,7 @@ type Message struct {
Changes []string // List of changes in this message (as computed by *this* node).
}

// ValueDesc stores the value along with it's codec and local version.
// ValueDesc stores the value along with its codec and local version.
type ValueDesc struct {
// We store the decoded value here to prevent decoding the entire state for every
// update we receive. Whilst the updates are small and fast to decode,
Expand Down Expand Up @@ -1483,6 +1489,12 @@ func (m *KV) deleteSentReceivedMessages() {
m.receivedMessagesSize = 0
}

func (m *KV) Delete(ctx context.Context, codec codec.Codec, key string) error {
return m.CAS(ctx, key, codec, func(in interface{}) (out interface{}, retry bool, err error) {
return nil, true, nil
})
}

func addMessageToBuffer(msgs []Message, size int, limit int, msg Message) ([]Message, int) {
msgs = append(msgs, msg)
size += msg.Size
Expand Down
2 changes: 1 addition & 1 deletion kv/memberlist/tcp_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (t *TCPTransport) GetAutoBindPort() int {
// FinalAdvertiseAddr is given the user's configured values (which
// might be empty) and returns the desired IP and port to advertise to
// the rest of the cluster.
// (Copied from memberlist' net_transport.go)
// (Copied from memberlist's net_transport.go)
func (t *TCPTransport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error) {
var advertiseAddr net.IP
var advertisePort int
Expand Down