repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
etcd-io/etcd
clientv3/client.go
WithRequireLeader
func WithRequireLeader(ctx context.Context) context.Context { md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader) return metadata.NewOutgoingContext(ctx, md) }
go
func WithRequireLeader(ctx context.Context) context.Context { md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader) return metadata.NewOutgoingContext(ctx, md) }
[ "func", "WithRequireLeader", "(", "ctx", "context", ".", "Context", ")", "context", ".", "Context", "{", "md", ":=", "metadata", ".", "Pairs", "(", "rpctypes", ".", "MetadataRequireLeaderKey", ",", "rpctypes", ".", "MetadataHasLeader", ")", "\n", "return", "me...
// WithRequireLeader requires client requests to only succeed // when the cluster has a leader.
[ "WithRequireLeader", "requires", "client", "requests", "to", "only", "succeed", "when", "the", "cluster", "has", "a", "leader", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/client.go#L419-L422
test
etcd-io/etcd
clientv3/client.go
roundRobinQuorumBackoff
func (c *Client) roundRobinQuorumBackoff(waitBetween time.Duration, jitterFraction float64) backoffFunc { return func(attempt uint) time.Duration { // after each round robin across quorum, backoff for our wait between duration n := uint(len(c.Endpoints())) quorum := (n/2 + 1) if attempt%quorum == 0 { c.lg.D...
go
func (c *Client) roundRobinQuorumBackoff(waitBetween time.Duration, jitterFraction float64) backoffFunc { return func(attempt uint) time.Duration { // after each round robin across quorum, backoff for our wait between duration n := uint(len(c.Endpoints())) quorum := (n/2 + 1) if attempt%quorum == 0 { c.lg.D...
[ "func", "(", "c", "*", "Client", ")", "roundRobinQuorumBackoff", "(", "waitBetween", "time", ".", "Duration", ",", "jitterFraction", "float64", ")", "backoffFunc", "{", "return", "func", "(", "attempt", "uint", ")", "time", ".", "Duration", "{", "n", ":=", ...
// roundRobinQuorumBackoff retries against quorum between each backoff. // This is intended for use with a round robin load balancer.
[ "roundRobinQuorumBackoff", "retries", "against", "quorum", "between", "each", "backoff", ".", "This", "is", "intended", "for", "use", "with", "a", "round", "robin", "load", "balancer", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/client.go#L529-L541
test
etcd-io/etcd
clientv3/client.go
isHaltErr
func isHaltErr(ctx context.Context, err error) bool { if ctx != nil && ctx.Err() != nil { return true } if err == nil { return false } ev, _ := status.FromError(err) // Unavailable codes mean the system will be right back. // (e.g., can't connect, lost leader) // Treat Internal codes as if something failed,...
go
func isHaltErr(ctx context.Context, err error) bool { if ctx != nil && ctx.Err() != nil { return true } if err == nil { return false } ev, _ := status.FromError(err) // Unavailable codes mean the system will be right back. // (e.g., can't connect, lost leader) // Treat Internal codes as if something failed,...
[ "func", "isHaltErr", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "bool", "{", "if", "ctx", "!=", "nil", "&&", "ctx", ".", "Err", "(", ")", "!=", "nil", "{", "return", "true", "\n", "}", "\n", "if", "err", "==", "nil", "{", ...
// isHaltErr returns true if the given error and context indicate no forward // progress can be made, even after reconnecting.
[ "isHaltErr", "returns", "true", "if", "the", "given", "error", "and", "context", "indicate", "no", "forward", "progress", "can", "be", "made", "even", "after", "reconnecting", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/client.go#L588-L603
test
etcd-io/etcd
clientv3/namespace/lease.go
NewLease
func NewLease(l clientv3.Lease, prefix string) clientv3.Lease { return &leasePrefix{l, []byte(prefix)} }
go
func NewLease(l clientv3.Lease, prefix string) clientv3.Lease { return &leasePrefix{l, []byte(prefix)} }
[ "func", "NewLease", "(", "l", "clientv3", ".", "Lease", ",", "prefix", "string", ")", "clientv3", ".", "Lease", "{", "return", "&", "leasePrefix", "{", "l", ",", "[", "]", "byte", "(", "prefix", ")", "}", "\n", "}" ]
// NewLease wraps a Lease interface to filter for only keys with a prefix // and remove that prefix when fetching attached keys through TimeToLive.
[ "NewLease", "wraps", "a", "Lease", "interface", "to", "filter", "for", "only", "keys", "with", "a", "prefix", "and", "remove", "that", "prefix", "when", "fetching", "attached", "keys", "through", "TimeToLive", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/namespace/lease.go#L31-L33
test
etcd-io/etcd
clientv3/watch.go
IsCreate
func (e *Event) IsCreate() bool { return e.Type == EventTypePut && e.Kv.CreateRevision == e.Kv.ModRevision }
go
func (e *Event) IsCreate() bool { return e.Type == EventTypePut && e.Kv.CreateRevision == e.Kv.ModRevision }
[ "func", "(", "e", "*", "Event", ")", "IsCreate", "(", ")", "bool", "{", "return", "e", ".", "Type", "==", "EventTypePut", "&&", "e", ".", "Kv", ".", "CreateRevision", "==", "e", ".", "Kv", ".", "ModRevision", "\n", "}" ]
// IsCreate returns true if the event tells that the key is newly created.
[ "IsCreate", "returns", "true", "if", "the", "event", "tells", "that", "the", "key", "is", "newly", "created", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L103-L105
test
etcd-io/etcd
clientv3/watch.go
Err
func (wr *WatchResponse) Err() error { switch { case wr.closeErr != nil: return v3rpc.Error(wr.closeErr) case wr.CompactRevision != 0: return v3rpc.ErrCompacted case wr.Canceled: if len(wr.cancelReason) != 0 { return v3rpc.Error(status.Error(codes.FailedPrecondition, wr.cancelReason)) } return v3rpc.Er...
go
func (wr *WatchResponse) Err() error { switch { case wr.closeErr != nil: return v3rpc.Error(wr.closeErr) case wr.CompactRevision != 0: return v3rpc.ErrCompacted case wr.Canceled: if len(wr.cancelReason) != 0 { return v3rpc.Error(status.Error(codes.FailedPrecondition, wr.cancelReason)) } return v3rpc.Er...
[ "func", "(", "wr", "*", "WatchResponse", ")", "Err", "(", ")", "error", "{", "switch", "{", "case", "wr", ".", "closeErr", "!=", "nil", ":", "return", "v3rpc", ".", "Error", "(", "wr", ".", "closeErr", ")", "\n", "case", "wr", ".", "CompactRevision",...
// Err is the error value if this WatchResponse holds an error.
[ "Err", "is", "the", "error", "value", "if", "this", "WatchResponse", "holds", "an", "error", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L113-L126
test
etcd-io/etcd
clientv3/watch.go
IsProgressNotify
func (wr *WatchResponse) IsProgressNotify() bool { return len(wr.Events) == 0 && !wr.Canceled && !wr.Created && wr.CompactRevision == 0 && wr.Header.Revision != 0 }
go
func (wr *WatchResponse) IsProgressNotify() bool { return len(wr.Events) == 0 && !wr.Canceled && !wr.Created && wr.CompactRevision == 0 && wr.Header.Revision != 0 }
[ "func", "(", "wr", "*", "WatchResponse", ")", "IsProgressNotify", "(", ")", "bool", "{", "return", "len", "(", "wr", ".", "Events", ")", "==", "0", "&&", "!", "wr", ".", "Canceled", "&&", "!", "wr", ".", "Created", "&&", "wr", ".", "CompactRevision",...
// IsProgressNotify returns true if the WatchResponse is progress notification.
[ "IsProgressNotify", "returns", "true", "if", "the", "WatchResponse", "is", "progress", "notification", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L129-L131
test
etcd-io/etcd
clientv3/watch.go
RequestProgress
func (w *watcher) RequestProgress(ctx context.Context) (err error) { ctxKey := streamKeyFromCtx(ctx) w.mu.Lock() if w.streams == nil { return fmt.Errorf("no stream found for context") } wgs := w.streams[ctxKey] if wgs == nil { wgs = w.newWatcherGrpcStream(ctx) w.streams[ctxKey] = wgs } donec := wgs.donec...
go
func (w *watcher) RequestProgress(ctx context.Context) (err error) { ctxKey := streamKeyFromCtx(ctx) w.mu.Lock() if w.streams == nil { return fmt.Errorf("no stream found for context") } wgs := w.streams[ctxKey] if wgs == nil { wgs = w.newWatcherGrpcStream(ctx) w.streams[ctxKey] = wgs } donec := wgs.donec...
[ "func", "(", "w", "*", "watcher", ")", "RequestProgress", "(", "ctx", "context", ".", "Context", ")", "(", "err", "error", ")", "{", "ctxKey", ":=", "streamKeyFromCtx", "(", "ctx", ")", "\n", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "w", ...
// RequestProgress requests a progress notify response be sent in all watch channels.
[ "RequestProgress", "requests", "a", "progress", "notify", "response", "be", "sent", "in", "all", "watch", "channels", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L382-L415
test
etcd-io/etcd
clientv3/watch.go
nextResume
func (w *watchGrpcStream) nextResume() *watcherStream { for len(w.resuming) != 0 { if w.resuming[0] != nil { return w.resuming[0] } w.resuming = w.resuming[1:len(w.resuming)] } return nil }
go
func (w *watchGrpcStream) nextResume() *watcherStream { for len(w.resuming) != 0 { if w.resuming[0] != nil { return w.resuming[0] } w.resuming = w.resuming[1:len(w.resuming)] } return nil }
[ "func", "(", "w", "*", "watchGrpcStream", ")", "nextResume", "(", ")", "*", "watcherStream", "{", "for", "len", "(", "w", ".", "resuming", ")", "!=", "0", "{", "if", "w", ".", "resuming", "[", "0", "]", "!=", "nil", "{", "return", "w", ".", "resu...
// nextResume chooses the next resuming to register with the grpc stream. Abandoned // streams are marked as nil in the queue since the head must wait for its inflight registration.
[ "nextResume", "chooses", "the", "next", "resuming", "to", "register", "with", "the", "grpc", "stream", ".", "Abandoned", "streams", "are", "marked", "as", "nil", "in", "the", "queue", "since", "the", "head", "must", "wait", "for", "its", "inflight", "registr...
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L651-L659
test
etcd-io/etcd
clientv3/watch.go
dispatchEvent
func (w *watchGrpcStream) dispatchEvent(pbresp *pb.WatchResponse) bool { events := make([]*Event, len(pbresp.Events)) for i, ev := range pbresp.Events { events[i] = (*Event)(ev) } // TODO: return watch ID? wr := &WatchResponse{ Header: *pbresp.Header, Events: events, CompactRevision: pbre...
go
func (w *watchGrpcStream) dispatchEvent(pbresp *pb.WatchResponse) bool { events := make([]*Event, len(pbresp.Events)) for i, ev := range pbresp.Events { events[i] = (*Event)(ev) } // TODO: return watch ID? wr := &WatchResponse{ Header: *pbresp.Header, Events: events, CompactRevision: pbre...
[ "func", "(", "w", "*", "watchGrpcStream", ")", "dispatchEvent", "(", "pbresp", "*", "pb", ".", "WatchResponse", ")", "bool", "{", "events", ":=", "make", "(", "[", "]", "*", "Event", ",", "len", "(", "pbresp", ".", "Events", ")", ")", "\n", "for", ...
// dispatchEvent sends a WatchResponse to the appropriate watcher stream
[ "dispatchEvent", "sends", "a", "WatchResponse", "to", "the", "appropriate", "watcher", "stream" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L662-L685
test
etcd-io/etcd
clientv3/watch.go
broadcastResponse
func (w *watchGrpcStream) broadcastResponse(wr *WatchResponse) bool { for _, ws := range w.substreams { select { case ws.recvc <- wr: case <-ws.donec: } } return true }
go
func (w *watchGrpcStream) broadcastResponse(wr *WatchResponse) bool { for _, ws := range w.substreams { select { case ws.recvc <- wr: case <-ws.donec: } } return true }
[ "func", "(", "w", "*", "watchGrpcStream", ")", "broadcastResponse", "(", "wr", "*", "WatchResponse", ")", "bool", "{", "for", "_", ",", "ws", ":=", "range", "w", ".", "substreams", "{", "select", "{", "case", "ws", ".", "recvc", "<-", "wr", ":", "cas...
// broadcastResponse send a watch response to all watch substreams.
[ "broadcastResponse", "send", "a", "watch", "response", "to", "all", "watch", "substreams", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L688-L696
test
etcd-io/etcd
clientv3/watch.go
unicastResponse
func (w *watchGrpcStream) unicastResponse(wr *WatchResponse, watchId int64) bool { ws, ok := w.substreams[watchId] if !ok { return false } select { case ws.recvc <- wr: case <-ws.donec: return false } return true }
go
func (w *watchGrpcStream) unicastResponse(wr *WatchResponse, watchId int64) bool { ws, ok := w.substreams[watchId] if !ok { return false } select { case ws.recvc <- wr: case <-ws.donec: return false } return true }
[ "func", "(", "w", "*", "watchGrpcStream", ")", "unicastResponse", "(", "wr", "*", "WatchResponse", ",", "watchId", "int64", ")", "bool", "{", "ws", ",", "ok", ":=", "w", ".", "substreams", "[", "watchId", "]", "\n", "if", "!", "ok", "{", "return", "f...
// unicastResponse sends a watch response to a specific watch substream.
[ "unicastResponse", "sends", "a", "watch", "response", "to", "a", "specific", "watch", "substream", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L699-L710
test
etcd-io/etcd
clientv3/watch.go
joinSubstreams
func (w *watchGrpcStream) joinSubstreams() { for _, ws := range w.substreams { <-ws.donec } for _, ws := range w.resuming { if ws != nil { <-ws.donec } } }
go
func (w *watchGrpcStream) joinSubstreams() { for _, ws := range w.substreams { <-ws.donec } for _, ws := range w.resuming { if ws != nil { <-ws.donec } } }
[ "func", "(", "w", "*", "watchGrpcStream", ")", "joinSubstreams", "(", ")", "{", "for", "_", ",", "ws", ":=", "range", "w", ".", "substreams", "{", "<-", "ws", ".", "donec", "\n", "}", "\n", "for", "_", ",", "ws", ":=", "range", "w", ".", "resumin...
// joinSubstreams waits for all substream goroutines to complete.
[ "joinSubstreams", "waits", "for", "all", "substream", "goroutines", "to", "complete", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L911-L920
test
etcd-io/etcd
clientv3/watch.go
toPB
func (wr *watchRequest) toPB() *pb.WatchRequest { req := &pb.WatchCreateRequest{ StartRevision: wr.rev, Key: []byte(wr.key), RangeEnd: []byte(wr.end), ProgressNotify: wr.progressNotify, Filters: wr.filters, PrevKv: wr.prevKV, Fragment: wr.fragment, } cr := &pb.Wat...
go
func (wr *watchRequest) toPB() *pb.WatchRequest { req := &pb.WatchCreateRequest{ StartRevision: wr.rev, Key: []byte(wr.key), RangeEnd: []byte(wr.end), ProgressNotify: wr.progressNotify, Filters: wr.filters, PrevKv: wr.prevKV, Fragment: wr.fragment, } cr := &pb.Wat...
[ "func", "(", "wr", "*", "watchRequest", ")", "toPB", "(", ")", "*", "pb", ".", "WatchRequest", "{", "req", ":=", "&", "pb", ".", "WatchCreateRequest", "{", "StartRevision", ":", "wr", ".", "rev", ",", "Key", ":", "[", "]", "byte", "(", "wr", ".", ...
// toPB converts an internal watch request structure to its protobuf WatchRequest structure.
[ "toPB", "converts", "an", "internal", "watch", "request", "structure", "to", "its", "protobuf", "WatchRequest", "structure", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L960-L972
test
etcd-io/etcd
clientv3/watch.go
toPB
func (pr *progressRequest) toPB() *pb.WatchRequest { req := &pb.WatchProgressRequest{} cr := &pb.WatchRequest_ProgressRequest{ProgressRequest: req} return &pb.WatchRequest{RequestUnion: cr} }
go
func (pr *progressRequest) toPB() *pb.WatchRequest { req := &pb.WatchProgressRequest{} cr := &pb.WatchRequest_ProgressRequest{ProgressRequest: req} return &pb.WatchRequest{RequestUnion: cr} }
[ "func", "(", "pr", "*", "progressRequest", ")", "toPB", "(", ")", "*", "pb", ".", "WatchRequest", "{", "req", ":=", "&", "pb", ".", "WatchProgressRequest", "{", "}", "\n", "cr", ":=", "&", "pb", ".", "WatchRequest_ProgressRequest", "{", "ProgressRequest", ...
// toPB converts an internal progress request structure to its protobuf WatchRequest structure.
[ "toPB", "converts", "an", "internal", "progress", "request", "structure", "to", "its", "protobuf", "WatchRequest", "structure", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/watch.go#L975-L979
test
etcd-io/etcd
pkg/types/set.go
Contains
func (us *unsafeSet) Contains(value string) (exists bool) { _, exists = us.d[value] return exists }
go
func (us *unsafeSet) Contains(value string) (exists bool) { _, exists = us.d[value] return exists }
[ "func", "(", "us", "*", "unsafeSet", ")", "Contains", "(", "value", "string", ")", "(", "exists", "bool", ")", "{", "_", ",", "exists", "=", "us", ".", "d", "[", "value", "]", "\n", "return", "exists", "\n", "}" ]
// Contains returns whether the set contains the given value
[ "Contains", "returns", "whether", "the", "set", "contains", "the", "given", "value" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/types/set.go#L62-L65
test
etcd-io/etcd
pkg/types/set.go
ContainsAll
func (us *unsafeSet) ContainsAll(values []string) bool { for _, s := range values { if !us.Contains(s) { return false } } return true }
go
func (us *unsafeSet) ContainsAll(values []string) bool { for _, s := range values { if !us.Contains(s) { return false } } return true }
[ "func", "(", "us", "*", "unsafeSet", ")", "ContainsAll", "(", "values", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "values", "{", "if", "!", "us", ".", "Contains", "(", "s", ")", "{", "return", "false", "\n", "}", ...
// ContainsAll returns whether the set contains all given values
[ "ContainsAll", "returns", "whether", "the", "set", "contains", "all", "given", "values" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/types/set.go#L68-L75
test
etcd-io/etcd
pkg/types/set.go
Equals
func (us *unsafeSet) Equals(other Set) bool { v1 := sort.StringSlice(us.Values()) v2 := sort.StringSlice(other.Values()) v1.Sort() v2.Sort() return reflect.DeepEqual(v1, v2) }
go
func (us *unsafeSet) Equals(other Set) bool { v1 := sort.StringSlice(us.Values()) v2 := sort.StringSlice(other.Values()) v1.Sort() v2.Sort() return reflect.DeepEqual(v1, v2) }
[ "func", "(", "us", "*", "unsafeSet", ")", "Equals", "(", "other", "Set", ")", "bool", "{", "v1", ":=", "sort", ".", "StringSlice", "(", "us", ".", "Values", "(", ")", ")", "\n", "v2", ":=", "sort", ".", "StringSlice", "(", "other", ".", "Values", ...
// Equals returns whether the contents of two sets are identical
[ "Equals", "returns", "whether", "the", "contents", "of", "two", "sets", "are", "identical" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/types/set.go#L78-L84
test
etcd-io/etcd
pkg/types/set.go
Values
func (us *unsafeSet) Values() (values []string) { values = make([]string, 0) for val := range us.d { values = append(values, val) } return values }
go
func (us *unsafeSet) Values() (values []string) { values = make([]string, 0) for val := range us.d { values = append(values, val) } return values }
[ "func", "(", "us", "*", "unsafeSet", ")", "Values", "(", ")", "(", "values", "[", "]", "string", ")", "{", "values", "=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "val", ":=", "range", "us", ".", "d", "{", "values", "=", "...
// Values returns the values of the Set in an unspecified order.
[ "Values", "returns", "the", "values", "of", "the", "Set", "in", "an", "unspecified", "order", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/types/set.go#L92-L98
test
etcd-io/etcd
pkg/types/set.go
Copy
func (us *unsafeSet) Copy() Set { cp := NewUnsafeSet() for val := range us.d { cp.Add(val) } return cp }
go
func (us *unsafeSet) Copy() Set { cp := NewUnsafeSet() for val := range us.d { cp.Add(val) } return cp }
[ "func", "(", "us", "*", "unsafeSet", ")", "Copy", "(", ")", "Set", "{", "cp", ":=", "NewUnsafeSet", "(", ")", "\n", "for", "val", ":=", "range", "us", ".", "d", "{", "cp", ".", "Add", "(", "val", ")", "\n", "}", "\n", "return", "cp", "\n", "}...
// Copy creates a new Set containing the values of the first
[ "Copy", "creates", "a", "new", "Set", "containing", "the", "values", "of", "the", "first" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/types/set.go#L101-L108
test
etcd-io/etcd
pkg/types/set.go
Sub
func (us *unsafeSet) Sub(other Set) Set { oValues := other.Values() result := us.Copy().(*unsafeSet) for _, val := range oValues { if _, ok := result.d[val]; !ok { continue } delete(result.d, val) } return result }
go
func (us *unsafeSet) Sub(other Set) Set { oValues := other.Values() result := us.Copy().(*unsafeSet) for _, val := range oValues { if _, ok := result.d[val]; !ok { continue } delete(result.d, val) } return result }
[ "func", "(", "us", "*", "unsafeSet", ")", "Sub", "(", "other", "Set", ")", "Set", "{", "oValues", ":=", "other", ".", "Values", "(", ")", "\n", "result", ":=", "us", ".", "Copy", "(", ")", ".", "(", "*", "unsafeSet", ")", "\n", "for", "_", ",",...
// Sub removes all elements in other from the set
[ "Sub", "removes", "all", "elements", "in", "other", "from", "the", "set" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/types/set.go#L111-L123
test
etcd-io/etcd
client/members.go
v2MembersURL
func v2MembersURL(ep url.URL) *url.URL { ep.Path = path.Join(ep.Path, defaultV2MembersPrefix) return &ep }
go
func v2MembersURL(ep url.URL) *url.URL { ep.Path = path.Join(ep.Path, defaultV2MembersPrefix) return &ep }
[ "func", "v2MembersURL", "(", "ep", "url", ".", "URL", ")", "*", "url", ".", "URL", "{", "ep", ".", "Path", "=", "path", ".", "Join", "(", "ep", ".", "Path", ",", "defaultV2MembersPrefix", ")", "\n", "return", "&", "ep", "\n", "}" ]
// v2MembersURL add the necessary path to the provided endpoint // to route requests to the default v2 members API.
[ "v2MembersURL", "add", "the", "necessary", "path", "to", "the", "provided", "endpoint", "to", "route", "requests", "to", "the", "default", "v2", "members", "API", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/client/members.go#L291-L294
test
etcd-io/etcd
etcdctl/ctlv3/command/migrate_command.go
NewMigrateCommand
func NewMigrateCommand() *cobra.Command { mc := &cobra.Command{ Use: "migrate", Short: "Migrates keys in a v2 store to a mvcc store", Run: migrateCommandFunc, } mc.Flags().BoolVar(&migrateExcludeTTLKey, "no-ttl", false, "Do not convert TTL keys") mc.Flags().StringVar(&migrateDatadir, "data-dir", "", "Pat...
go
func NewMigrateCommand() *cobra.Command { mc := &cobra.Command{ Use: "migrate", Short: "Migrates keys in a v2 store to a mvcc store", Run: migrateCommandFunc, } mc.Flags().BoolVar(&migrateExcludeTTLKey, "no-ttl", false, "Do not convert TTL keys") mc.Flags().StringVar(&migrateDatadir, "data-dir", "", "Pat...
[ "func", "NewMigrateCommand", "(", ")", "*", "cobra", ".", "Command", "{", "mc", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"migrate\"", ",", "Short", ":", "\"Migrates keys in a v2 store to a mvcc store\"", ",", "Run", ":", "migrateCommandFunc", ",", ...
// NewMigrateCommand returns the cobra command for "migrate".
[ "NewMigrateCommand", "returns", "the", "cobra", "command", "for", "migrate", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/migrate_command.go#L57-L69
test
etcd-io/etcd
contrib/raftexample/raft.go
publishEntries
func (rc *raftNode) publishEntries(ents []raftpb.Entry) bool { for i := range ents { switch ents[i].Type { case raftpb.EntryNormal: if len(ents[i].Data) == 0 { // ignore empty messages break } s := string(ents[i].Data) select { case rc.commitC <- &s: case <-rc.stopc: return false }...
go
func (rc *raftNode) publishEntries(ents []raftpb.Entry) bool { for i := range ents { switch ents[i].Type { case raftpb.EntryNormal: if len(ents[i].Data) == 0 { // ignore empty messages break } s := string(ents[i].Data) select { case rc.commitC <- &s: case <-rc.stopc: return false }...
[ "func", "(", "rc", "*", "raftNode", ")", "publishEntries", "(", "ents", "[", "]", "raftpb", ".", "Entry", ")", "bool", "{", "for", "i", ":=", "range", "ents", "{", "switch", "ents", "[", "i", "]", ".", "Type", "{", "case", "raftpb", ".", "EntryNorm...
// publishEntries writes committed log entries to commit channel and returns // whether all entries could be published.
[ "publishEntries", "writes", "committed", "log", "entries", "to", "commit", "channel", "and", "returns", "whether", "all", "entries", "could", "be", "published", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/contrib/raftexample/raft.go#L143-L189
test
etcd-io/etcd
contrib/raftexample/raft.go
openWAL
func (rc *raftNode) openWAL(snapshot *raftpb.Snapshot) *wal.WAL { if !wal.Exist(rc.waldir) { if err := os.Mkdir(rc.waldir, 0750); err != nil { log.Fatalf("raftexample: cannot create dir for wal (%v)", err) } w, err := wal.Create(zap.NewExample(), rc.waldir, nil) if err != nil { log.Fatalf("raftexample: ...
go
func (rc *raftNode) openWAL(snapshot *raftpb.Snapshot) *wal.WAL { if !wal.Exist(rc.waldir) { if err := os.Mkdir(rc.waldir, 0750); err != nil { log.Fatalf("raftexample: cannot create dir for wal (%v)", err) } w, err := wal.Create(zap.NewExample(), rc.waldir, nil) if err != nil { log.Fatalf("raftexample: ...
[ "func", "(", "rc", "*", "raftNode", ")", "openWAL", "(", "snapshot", "*", "raftpb", ".", "Snapshot", ")", "*", "wal", ".", "WAL", "{", "if", "!", "wal", ".", "Exist", "(", "rc", ".", "waldir", ")", "{", "if", "err", ":=", "os", ".", "Mkdir", "(...
// openWAL returns a WAL ready for reading.
[ "openWAL", "returns", "a", "WAL", "ready", "for", "reading", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/contrib/raftexample/raft.go#L200-L224
test
etcd-io/etcd
contrib/raftexample/raft.go
replayWAL
func (rc *raftNode) replayWAL() *wal.WAL { log.Printf("replaying WAL of member %d", rc.id) snapshot := rc.loadSnapshot() w := rc.openWAL(snapshot) _, st, ents, err := w.ReadAll() if err != nil { log.Fatalf("raftexample: failed to read WAL (%v)", err) } rc.raftStorage = raft.NewMemoryStorage() if snapshot != n...
go
func (rc *raftNode) replayWAL() *wal.WAL { log.Printf("replaying WAL of member %d", rc.id) snapshot := rc.loadSnapshot() w := rc.openWAL(snapshot) _, st, ents, err := w.ReadAll() if err != nil { log.Fatalf("raftexample: failed to read WAL (%v)", err) } rc.raftStorage = raft.NewMemoryStorage() if snapshot != n...
[ "func", "(", "rc", "*", "raftNode", ")", "replayWAL", "(", ")", "*", "wal", ".", "WAL", "{", "log", ".", "Printf", "(", "\"replaying WAL of member %d\"", ",", "rc", ".", "id", ")", "\n", "snapshot", ":=", "rc", ".", "loadSnapshot", "(", ")", "\n", "w...
// replayWAL replays WAL entries into the raft instance.
[ "replayWAL", "replays", "WAL", "entries", "into", "the", "raft", "instance", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/contrib/raftexample/raft.go#L227-L250
test
etcd-io/etcd
contrib/raftexample/raft.go
stop
func (rc *raftNode) stop() { rc.stopHTTP() close(rc.commitC) close(rc.errorC) rc.node.Stop() }
go
func (rc *raftNode) stop() { rc.stopHTTP() close(rc.commitC) close(rc.errorC) rc.node.Stop() }
[ "func", "(", "rc", "*", "raftNode", ")", "stop", "(", ")", "{", "rc", ".", "stopHTTP", "(", ")", "\n", "close", "(", "rc", ".", "commitC", ")", "\n", "close", "(", "rc", ".", "errorC", ")", "\n", "rc", ".", "node", ".", "Stop", "(", ")", "\n"...
// stop closes http, closes all channels, and stops raft.
[ "stop", "closes", "http", "closes", "all", "channels", "and", "stops", "raft", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/contrib/raftexample/raft.go#L318-L323
test
etcd-io/etcd
etcdctl/ctlv3/command/watch_command.go
NewWatchCommand
func NewWatchCommand() *cobra.Command { cmd := &cobra.Command{ Use: "watch [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]", Short: "Watches events stream on keys or prefixes", Run: watchCommandFunc, } cmd.Flags().BoolVarP(&watchInteractive, "interactive", "i", false, "Interactive ...
go
func NewWatchCommand() *cobra.Command { cmd := &cobra.Command{ Use: "watch [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]", Short: "Watches events stream on keys or prefixes", Run: watchCommandFunc, } cmd.Flags().BoolVarP(&watchInteractive, "interactive", "i", false, "Interactive ...
[ "func", "NewWatchCommand", "(", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"watch [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]\"", ",", "Short", ":", "\"Watches events stream on keys or ...
// NewWatchCommand returns the cobra command for "watch".
[ "NewWatchCommand", "returns", "the", "cobra", "command", "for", "watch", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/watch_command.go#L46-L59
test
etcd-io/etcd
raft/storage.go
InitialState
func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) { return ms.hardState, ms.snapshot.Metadata.ConfState, nil }
go
func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) { return ms.hardState, ms.snapshot.Metadata.ConfState, nil }
[ "func", "(", "ms", "*", "MemoryStorage", ")", "InitialState", "(", ")", "(", "pb", ".", "HardState", ",", "pb", ".", "ConfState", ",", "error", ")", "{", "return", "ms", ".", "hardState", ",", "ms", ".", "snapshot", ".", "Metadata", ".", "ConfState", ...
// InitialState implements the Storage interface.
[ "InitialState", "implements", "the", "Storage", "interface", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L95-L97
test
etcd-io/etcd
raft/storage.go
SetHardState
func (ms *MemoryStorage) SetHardState(st pb.HardState) error { ms.Lock() defer ms.Unlock() ms.hardState = st return nil }
go
func (ms *MemoryStorage) SetHardState(st pb.HardState) error { ms.Lock() defer ms.Unlock() ms.hardState = st return nil }
[ "func", "(", "ms", "*", "MemoryStorage", ")", "SetHardState", "(", "st", "pb", ".", "HardState", ")", "error", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "ms", ".", "hardState", "=", "st", "\n", "return", ...
// SetHardState saves the current HardState.
[ "SetHardState", "saves", "the", "current", "HardState", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L100-L105
test
etcd-io/etcd
raft/storage.go
Entries
func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) { ms.Lock() defer ms.Unlock() offset := ms.ents[0].Index if lo <= offset { return nil, ErrCompacted } if hi > ms.lastIndex()+1 { raftLogger.Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) } // only conta...
go
func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) { ms.Lock() defer ms.Unlock() offset := ms.ents[0].Index if lo <= offset { return nil, ErrCompacted } if hi > ms.lastIndex()+1 { raftLogger.Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) } // only conta...
[ "func", "(", "ms", "*", "MemoryStorage", ")", "Entries", "(", "lo", ",", "hi", ",", "maxSize", "uint64", ")", "(", "[", "]", "pb", ".", "Entry", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", ...
// Entries implements the Storage interface.
[ "Entries", "implements", "the", "Storage", "interface", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L108-L125
test
etcd-io/etcd
raft/storage.go
Term
func (ms *MemoryStorage) Term(i uint64) (uint64, error) { ms.Lock() defer ms.Unlock() offset := ms.ents[0].Index if i < offset { return 0, ErrCompacted } if int(i-offset) >= len(ms.ents) { return 0, ErrUnavailable } return ms.ents[i-offset].Term, nil }
go
func (ms *MemoryStorage) Term(i uint64) (uint64, error) { ms.Lock() defer ms.Unlock() offset := ms.ents[0].Index if i < offset { return 0, ErrCompacted } if int(i-offset) >= len(ms.ents) { return 0, ErrUnavailable } return ms.ents[i-offset].Term, nil }
[ "func", "(", "ms", "*", "MemoryStorage", ")", "Term", "(", "i", "uint64", ")", "(", "uint64", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "offset", ":=", "ms", ".", "ents", "[", "0", ...
// Term implements the Storage interface.
[ "Term", "implements", "the", "Storage", "interface", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L128-L139
test
etcd-io/etcd
raft/storage.go
LastIndex
func (ms *MemoryStorage) LastIndex() (uint64, error) { ms.Lock() defer ms.Unlock() return ms.lastIndex(), nil }
go
func (ms *MemoryStorage) LastIndex() (uint64, error) { ms.Lock() defer ms.Unlock() return ms.lastIndex(), nil }
[ "func", "(", "ms", "*", "MemoryStorage", ")", "LastIndex", "(", ")", "(", "uint64", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "return", "ms", ".", "lastIndex", "(", ")", ",", "nil", ...
// LastIndex implements the Storage interface.
[ "LastIndex", "implements", "the", "Storage", "interface", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L142-L146
test
etcd-io/etcd
raft/storage.go
FirstIndex
func (ms *MemoryStorage) FirstIndex() (uint64, error) { ms.Lock() defer ms.Unlock() return ms.firstIndex(), nil }
go
func (ms *MemoryStorage) FirstIndex() (uint64, error) { ms.Lock() defer ms.Unlock() return ms.firstIndex(), nil }
[ "func", "(", "ms", "*", "MemoryStorage", ")", "FirstIndex", "(", ")", "(", "uint64", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "return", "ms", ".", "firstIndex", "(", ")", ",", "nil",...
// FirstIndex implements the Storage interface.
[ "FirstIndex", "implements", "the", "Storage", "interface", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L153-L157
test
etcd-io/etcd
raft/storage.go
Snapshot
func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error) { ms.Lock() defer ms.Unlock() return ms.snapshot, nil }
go
func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error) { ms.Lock() defer ms.Unlock() return ms.snapshot, nil }
[ "func", "(", "ms", "*", "MemoryStorage", ")", "Snapshot", "(", ")", "(", "pb", ".", "Snapshot", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "return", "ms", ".", "snapshot", ",", "nil", ...
// Snapshot implements the Storage interface.
[ "Snapshot", "implements", "the", "Storage", "interface", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L164-L168
test
etcd-io/etcd
raft/storage.go
ApplySnapshot
func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error { ms.Lock() defer ms.Unlock() //handle check for old snapshot being applied msIndex := ms.snapshot.Metadata.Index snapIndex := snap.Metadata.Index if msIndex >= snapIndex { return ErrSnapOutOfDate } ms.snapshot = snap ms.ents = []pb.Entry{{Term...
go
func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error { ms.Lock() defer ms.Unlock() //handle check for old snapshot being applied msIndex := ms.snapshot.Metadata.Index snapIndex := snap.Metadata.Index if msIndex >= snapIndex { return ErrSnapOutOfDate } ms.snapshot = snap ms.ents = []pb.Entry{{Term...
[ "func", "(", "ms", "*", "MemoryStorage", ")", "ApplySnapshot", "(", "snap", "pb", ".", "Snapshot", ")", "error", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "msIndex", ":=", "ms", ".", "snapshot", ".", "Met...
// ApplySnapshot overwrites the contents of this Storage object with // those of the given snapshot.
[ "ApplySnapshot", "overwrites", "the", "contents", "of", "this", "Storage", "object", "with", "those", "of", "the", "given", "snapshot", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L172-L186
test
etcd-io/etcd
raft/storage.go
Compact
func (ms *MemoryStorage) Compact(compactIndex uint64) error { ms.Lock() defer ms.Unlock() offset := ms.ents[0].Index if compactIndex <= offset { return ErrCompacted } if compactIndex > ms.lastIndex() { raftLogger.Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) } i := compac...
go
func (ms *MemoryStorage) Compact(compactIndex uint64) error { ms.Lock() defer ms.Unlock() offset := ms.ents[0].Index if compactIndex <= offset { return ErrCompacted } if compactIndex > ms.lastIndex() { raftLogger.Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) } i := compac...
[ "func", "(", "ms", "*", "MemoryStorage", ")", "Compact", "(", "compactIndex", "uint64", ")", "error", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "offset", ":=", "ms", ".", "ents", "[", "0", "]", ".", "In...
// Compact discards all log entries prior to compactIndex. // It is the application's responsibility to not attempt to compact an index // greater than raftLog.applied.
[ "Compact", "discards", "all", "log", "entries", "prior", "to", "compactIndex", ".", "It", "is", "the", "application", "s", "responsibility", "to", "not", "attempt", "to", "compact", "an", "index", "greater", "than", "raftLog", ".", "applied", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/raft/storage.go#L216-L234
test
etcd-io/etcd
etcdserver/api/rafthttp/urlpick.go
unreachable
func (p *urlPicker) unreachable(u url.URL) { p.mu.Lock() defer p.mu.Unlock() if u == p.urls[p.picked] { p.picked = (p.picked + 1) % len(p.urls) } }
go
func (p *urlPicker) unreachable(u url.URL) { p.mu.Lock() defer p.mu.Unlock() if u == p.urls[p.picked] { p.picked = (p.picked + 1) % len(p.urls) } }
[ "func", "(", "p", "*", "urlPicker", ")", "unreachable", "(", "u", "url", ".", "URL", ")", "{", "p", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "u", "==", "p", ".", "urls", "[", "p",...
// unreachable notices the picker that the given url is unreachable, // and it should use other possible urls.
[ "unreachable", "notices", "the", "picker", "that", "the", "given", "url", "is", "unreachable", "and", "it", "should", "use", "other", "possible", "urls", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/rafthttp/urlpick.go#L51-L57
test
etcd-io/etcd
etcdctl/ctlv3/command/ep_command.go
NewEndpointCommand
func NewEndpointCommand() *cobra.Command { ec := &cobra.Command{ Use: "endpoint <subcommand>", Short: "Endpoint related commands", } ec.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") ec.AddCommand(newEpHealthCommand()) ec.AddCommand(newEpSt...
go
func NewEndpointCommand() *cobra.Command { ec := &cobra.Command{ Use: "endpoint <subcommand>", Short: "Endpoint related commands", } ec.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") ec.AddCommand(newEpHealthCommand()) ec.AddCommand(newEpSt...
[ "func", "NewEndpointCommand", "(", ")", "*", "cobra", ".", "Command", "{", "ec", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"endpoint <subcommand>\"", ",", "Short", ":", "\"Endpoint related commands\"", ",", "}", "\n", "ec", ".", "PersistentFlags",...
// NewEndpointCommand returns the cobra command for "endpoint".
[ "NewEndpointCommand", "returns", "the", "cobra", "command", "for", "endpoint", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/ep_command.go#L34-L46
test
etcd-io/etcd
etcdctl/ctlv3/command/ep_command.go
epHealthCommandFunc
func epHealthCommandFunc(cmd *cobra.Command, args []string) { flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) initDisplayFromCmd(cmd) sec := secureCfgFromCmd(cmd) dt := dialTimeoutFromCmd(cmd) ka := keepAliveTimeFromCmd(cmd) kat := keepAliveTimeoutFromCmd(cmd) auth := authCfgFromCmd(cmd) cfgs := []*v3....
go
func epHealthCommandFunc(cmd *cobra.Command, args []string) { flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) initDisplayFromCmd(cmd) sec := secureCfgFromCmd(cmd) dt := dialTimeoutFromCmd(cmd) ka := keepAliveTimeFromCmd(cmd) kat := keepAliveTimeoutFromCmd(cmd) auth := authCfgFromCmd(cmd) cfgs := []*v3....
[ "func", "epHealthCommandFunc", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "flags", ".", "SetPflagsFromEnv", "(", "\"ETCDCTL\"", ",", "cmd", ".", "InheritedFlags", "(", ")", ")", "\n", "initDisplayFromCmd", "(", "cm...
// epHealthCommandFunc executes the "endpoint-health" command.
[ "epHealthCommandFunc", "executes", "the", "endpoint", "-", "health", "command", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/ep_command.go#L87-L149
test
etcd-io/etcd
etcdctl/ctlv3/command/elect_command.go
NewElectCommand
func NewElectCommand() *cobra.Command { cmd := &cobra.Command{ Use: "elect <election-name> [proposal]", Short: "Observes and participates in leader election", Run: electCommandFunc, } cmd.Flags().BoolVarP(&electListen, "listen", "l", false, "observation mode") return cmd }
go
func NewElectCommand() *cobra.Command { cmd := &cobra.Command{ Use: "elect <election-name> [proposal]", Short: "Observes and participates in leader election", Run: electCommandFunc, } cmd.Flags().BoolVarP(&electListen, "listen", "l", false, "observation mode") return cmd }
[ "func", "NewElectCommand", "(", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"elect <election-name> [proposal]\"", ",", "Short", ":", "\"Observes and participates in leader election\"", ",", "Run", ":", "ele...
// NewElectCommand returns the cobra command for "elect".
[ "NewElectCommand", "returns", "the", "cobra", "command", "for", "elect", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/elect_command.go#L35-L43
test
etcd-io/etcd
etcdctl/ctlv3/command/defrag_command.go
NewDefragCommand
func NewDefragCommand() *cobra.Command { cmd := &cobra.Command{ Use: "defrag", Short: "Defragments the storage of the etcd members with given endpoints", Run: defragCommandFunc, } cmd.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") cmd.Fla...
go
func NewDefragCommand() *cobra.Command { cmd := &cobra.Command{ Use: "defrag", Short: "Defragments the storage of the etcd members with given endpoints", Run: defragCommandFunc, } cmd.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") cmd.Fla...
[ "func", "NewDefragCommand", "(", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"defrag\"", ",", "Short", ":", "\"Defragments the storage of the etcd members with given endpoints\"", ",", "Run", ":", "defragCo...
// NewDefragCommand returns the cobra command for "Defrag".
[ "NewDefragCommand", "returns", "the", "cobra", "command", "for", "Defrag", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/defrag_command.go#L32-L41
test
etcd-io/etcd
clientv3/balancer/balancer.go
RegisterBuilder
func RegisterBuilder(cfg Config) { bb := &builder{cfg} balancer.Register(bb) bb.cfg.Logger.Debug( "registered balancer", zap.String("policy", bb.cfg.Policy.String()), zap.String("name", bb.cfg.Name), ) }
go
func RegisterBuilder(cfg Config) { bb := &builder{cfg} balancer.Register(bb) bb.cfg.Logger.Debug( "registered balancer", zap.String("policy", bb.cfg.Policy.String()), zap.String("name", bb.cfg.Name), ) }
[ "func", "RegisterBuilder", "(", "cfg", "Config", ")", "{", "bb", ":=", "&", "builder", "{", "cfg", "}", "\n", "balancer", ".", "Register", "(", "bb", ")", "\n", "bb", ".", "cfg", ".", "Logger", ".", "Debug", "(", "\"registered balancer\"", ",", "zap", ...
// RegisterBuilder creates and registers a builder. Since this function calls balancer.Register, it // must be invoked at initialization time.
[ "RegisterBuilder", "creates", "and", "registers", "a", "builder", ".", "Since", "this", "function", "calls", "balancer", ".", "Register", "it", "must", "be", "invoked", "at", "initialization", "time", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/balancer/balancer.go#L35-L44
test
etcd-io/etcd
clientv3/balancer/balancer.go
Build
func (b *builder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { bb := &baseBalancer{ id: strconv.FormatInt(time.Now().UnixNano(), 36), policy: b.cfg.Policy, name: b.cfg.Name, lg: b.cfg.Logger, addrToSc: make(map[resolver.Address]balancer.SubConn), scToAddr: make(ma...
go
func (b *builder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { bb := &baseBalancer{ id: strconv.FormatInt(time.Now().UnixNano(), 36), policy: b.cfg.Policy, name: b.cfg.Name, lg: b.cfg.Logger, addrToSc: make(map[resolver.Address]balancer.SubConn), scToAddr: make(ma...
[ "func", "(", "b", "*", "builder", ")", "Build", "(", "cc", "balancer", ".", "ClientConn", ",", "opt", "balancer", ".", "BuildOptions", ")", "balancer", ".", "Balancer", "{", "bb", ":=", "&", "baseBalancer", "{", "id", ":", "strconv", ".", "FormatInt", ...
// Build is called initially when creating "ccBalancerWrapper". // "grpc.Dial" is called to this client connection. // Then, resolved addresses will be handled via "HandleResolvedAddrs".
[ "Build", "is", "called", "initially", "when", "creating", "ccBalancerWrapper", ".", "grpc", ".", "Dial", "is", "called", "to", "this", "client", "connection", ".", "Then", "resolved", "addresses", "will", "be", "handled", "via", "HandleResolvedAddrs", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/balancer/balancer.go#L53-L86
test
etcd-io/etcd
clientv3/balancer/connectivity.go
recordTransition
func (cse *connectivityStateEvaluator) recordTransition(oldState, newState connectivity.State) connectivity.State { // Update counters. for idx, state := range []connectivity.State{oldState, newState} { updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new. switch state { case connectivity.Ready: ...
go
func (cse *connectivityStateEvaluator) recordTransition(oldState, newState connectivity.State) connectivity.State { // Update counters. for idx, state := range []connectivity.State{oldState, newState} { updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new. switch state { case connectivity.Ready: ...
[ "func", "(", "cse", "*", "connectivityStateEvaluator", ")", "recordTransition", "(", "oldState", ",", "newState", "connectivity", ".", "State", ")", "connectivity", ".", "State", "{", "for", "idx", ",", "state", ":=", "range", "[", "]", "connectivity", ".", ...
// recordTransition records state change happening in every subConn and based on // that it evaluates what aggregated state should be. // It can only transition between Ready, Connecting and TransientFailure. Other states, // Idle and Shutdown are transitioned into by ClientConn; in the beginning of the connection // b...
[ "recordTransition", "records", "state", "change", "happening", "in", "every", "subConn", "and", "based", "on", "that", "it", "evaluates", "what", "aggregated", "state", "should", "be", ".", "It", "can", "only", "transition", "between", "Ready", "Connecting", "an...
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/balancer/connectivity.go#L36-L58
test
etcd-io/etcd
etcdserver/v3_server.go
doSerialize
func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) error, get func()) error { ai, err := s.AuthInfoFromCtx(ctx) if err != nil { return err } if ai == nil { // chk expects non-nil AuthInfo; use empty credentials ai = &auth.AuthInfo{} } if err = chk(ai); err != nil { return err ...
go
func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) error, get func()) error { ai, err := s.AuthInfoFromCtx(ctx) if err != nil { return err } if ai == nil { // chk expects non-nil AuthInfo; use empty credentials ai = &auth.AuthInfo{} } if err = chk(ai); err != nil { return err ...
[ "func", "(", "s", "*", "EtcdServer", ")", "doSerialize", "(", "ctx", "context", ".", "Context", ",", "chk", "func", "(", "*", "auth", ".", "AuthInfo", ")", "error", ",", "get", "func", "(", ")", ")", "error", "{", "ai", ",", "err", ":=", "s", "."...
// doSerialize handles the auth logic, with permissions checked by "chk", for a serialized request "get". Returns a non-nil error on authentication failure.
[ "doSerialize", "handles", "the", "auth", "logic", "with", "permissions", "checked", "by", "chk", "for", "a", "serialized", "request", "get", ".", "Returns", "a", "non", "-", "nil", "error", "on", "authentication", "failure", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/v3_server.go#L541-L561
test
etcd-io/etcd
proxy/grpcproxy/watcher.go
send
func (w *watcher) send(wr clientv3.WatchResponse) { if wr.IsProgressNotify() && !w.progress { return } if w.nextrev > wr.Header.Revision && len(wr.Events) > 0 { return } if w.nextrev == 0 { // current watch; expect updates following this revision w.nextrev = wr.Header.Revision + 1 } events := make([]*mv...
go
func (w *watcher) send(wr clientv3.WatchResponse) { if wr.IsProgressNotify() && !w.progress { return } if w.nextrev > wr.Header.Revision && len(wr.Events) > 0 { return } if w.nextrev == 0 { // current watch; expect updates following this revision w.nextrev = wr.Header.Revision + 1 } events := make([]*mv...
[ "func", "(", "w", "*", "watcher", ")", "send", "(", "wr", "clientv3", ".", "WatchResponse", ")", "{", "if", "wr", ".", "IsProgressNotify", "(", ")", "&&", "!", "w", ".", "progress", "{", "return", "\n", "}", "\n", "if", "w", ".", "nextrev", ">", ...
// send filters out repeated events by discarding revisions older // than the last one sent over the watch channel.
[ "send", "filters", "out", "repeated", "events", "by", "discarding", "revisions", "older", "than", "the", "last", "one", "sent", "over", "the", "watch", "channel", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/proxy/grpcproxy/watcher.go#L55-L118
test
etcd-io/etcd
proxy/grpcproxy/watcher.go
post
func (w *watcher) post(wr *pb.WatchResponse) bool { select { case w.wps.watchCh <- wr: case <-time.After(50 * time.Millisecond): w.wps.cancel() return false } return true }
go
func (w *watcher) post(wr *pb.WatchResponse) bool { select { case w.wps.watchCh <- wr: case <-time.After(50 * time.Millisecond): w.wps.cancel() return false } return true }
[ "func", "(", "w", "*", "watcher", ")", "post", "(", "wr", "*", "pb", ".", "WatchResponse", ")", "bool", "{", "select", "{", "case", "w", ".", "wps", ".", "watchCh", "<-", "wr", ":", "case", "<-", "time", ".", "After", "(", "50", "*", "time", "....
// post puts a watch response on the watcher's proxy stream channel
[ "post", "puts", "a", "watch", "response", "on", "the", "watcher", "s", "proxy", "stream", "channel" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/proxy/grpcproxy/watcher.go#L121-L129
test
etcd-io/etcd
etcdserver/server_access_control.go
OriginAllowed
func (ac *AccessController) OriginAllowed(origin string) bool { ac.corsMu.RLock() defer ac.corsMu.RUnlock() if len(ac.CORS) == 0 { // allow all return true } _, ok := ac.CORS["*"] if ok { return true } _, ok = ac.CORS[origin] return ok }
go
func (ac *AccessController) OriginAllowed(origin string) bool { ac.corsMu.RLock() defer ac.corsMu.RUnlock() if len(ac.CORS) == 0 { // allow all return true } _, ok := ac.CORS["*"] if ok { return true } _, ok = ac.CORS[origin] return ok }
[ "func", "(", "ac", "*", "AccessController", ")", "OriginAllowed", "(", "origin", "string", ")", "bool", "{", "ac", ".", "corsMu", ".", "RLock", "(", ")", "\n", "defer", "ac", ".", "corsMu", ".", "RUnlock", "(", ")", "\n", "if", "len", "(", "ac", "....
// OriginAllowed determines whether the server will allow a given CORS origin. // If CORS is empty, allow all.
[ "OriginAllowed", "determines", "whether", "the", "server", "will", "allow", "a", "given", "CORS", "origin", ".", "If", "CORS", "is", "empty", "allow", "all", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/server_access_control.go#L37-L49
test
etcd-io/etcd
etcdserver/server_access_control.go
IsHostWhitelisted
func (ac *AccessController) IsHostWhitelisted(host string) bool { ac.hostWhitelistMu.RLock() defer ac.hostWhitelistMu.RUnlock() if len(ac.HostWhitelist) == 0 { // allow all return true } _, ok := ac.HostWhitelist["*"] if ok { return true } _, ok = ac.HostWhitelist[host] return ok }
go
func (ac *AccessController) IsHostWhitelisted(host string) bool { ac.hostWhitelistMu.RLock() defer ac.hostWhitelistMu.RUnlock() if len(ac.HostWhitelist) == 0 { // allow all return true } _, ok := ac.HostWhitelist["*"] if ok { return true } _, ok = ac.HostWhitelist[host] return ok }
[ "func", "(", "ac", "*", "AccessController", ")", "IsHostWhitelisted", "(", "host", "string", ")", "bool", "{", "ac", ".", "hostWhitelistMu", ".", "RLock", "(", ")", "\n", "defer", "ac", ".", "hostWhitelistMu", ".", "RUnlock", "(", ")", "\n", "if", "len",...
// IsHostWhitelisted returns true if the host is whitelisted. // If whitelist is empty, allow all.
[ "IsHostWhitelisted", "returns", "true", "if", "the", "host", "is", "whitelisted", ".", "If", "whitelist", "is", "empty", "allow", "all", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/server_access_control.go#L53-L65
test
etcd-io/etcd
pkg/flags/selective_string.go
Valids
func (ss *SelectiveStringValue) Valids() []string { s := make([]string, 0, len(ss.valids)) for k := range ss.valids { s = append(s, k) } sort.Strings(s) return s }
go
func (ss *SelectiveStringValue) Valids() []string { s := make([]string, 0, len(ss.valids)) for k := range ss.valids { s = append(s, k) } sort.Strings(s) return s }
[ "func", "(", "ss", "*", "SelectiveStringValue", ")", "Valids", "(", ")", "[", "]", "string", "{", "s", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "ss", ".", "valids", ")", ")", "\n", "for", "k", ":=", "range", "ss", ".", ...
// Valids returns the list of valid strings.
[ "Valids", "returns", "the", "list", "of", "valid", "strings", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/flags/selective_string.go#L46-L53
test
etcd-io/etcd
pkg/flags/selective_string.go
NewSelectiveStringsValue
func NewSelectiveStringsValue(valids ...string) *SelectiveStringsValue { vm := make(map[string]struct{}) for _, v := range valids { vm[v] = struct{}{} } return &SelectiveStringsValue{valids: vm, vs: []string{}} }
go
func NewSelectiveStringsValue(valids ...string) *SelectiveStringsValue { vm := make(map[string]struct{}) for _, v := range valids { vm[v] = struct{}{} } return &SelectiveStringsValue{valids: vm, vs: []string{}} }
[ "func", "NewSelectiveStringsValue", "(", "valids", "...", "string", ")", "*", "SelectiveStringsValue", "{", "vm", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ")", "\n", "for", "_", ",", "v", ":=", "range", "valids", "{", "vm", "["...
// NewSelectiveStringsValue creates a new string slice flag // for which any one of the given strings is a valid value, // and any other value is an error.
[ "NewSelectiveStringsValue", "creates", "a", "new", "string", "slice", "flag", "for", "which", "any", "one", "of", "the", "given", "strings", "is", "a", "valid", "value", "and", "any", "other", "value", "is", "an", "error", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/flags/selective_string.go#L108-L114
test
etcd-io/etcd
clientv3/namespace/kv.go
NewKV
func NewKV(kv clientv3.KV, prefix string) clientv3.KV { return &kvPrefix{kv, prefix} }
go
func NewKV(kv clientv3.KV, prefix string) clientv3.KV { return &kvPrefix{kv, prefix} }
[ "func", "NewKV", "(", "kv", "clientv3", ".", "KV", ",", "prefix", "string", ")", "clientv3", ".", "KV", "{", "return", "&", "kvPrefix", "{", "kv", ",", "prefix", "}", "\n", "}" ]
// NewKV wraps a KV instance so that all requests // are prefixed with a given string.
[ "NewKV", "wraps", "a", "KV", "instance", "so", "that", "all", "requests", "are", "prefixed", "with", "a", "given", "string", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/namespace/kv.go#L32-L34
test
etcd-io/etcd
pkg/flags/urls.go
NewURLsValue
func NewURLsValue(s string) *URLsValue { if s == "" { return &URLsValue{} } v := &URLsValue{} if err := v.Set(s); err != nil { plog.Panicf("new URLsValue should never fail: %v", err) } return v }
go
func NewURLsValue(s string) *URLsValue { if s == "" { return &URLsValue{} } v := &URLsValue{} if err := v.Set(s); err != nil { plog.Panicf("new URLsValue should never fail: %v", err) } return v }
[ "func", "NewURLsValue", "(", "s", "string", ")", "*", "URLsValue", "{", "if", "s", "==", "\"\"", "{", "return", "&", "URLsValue", "{", "}", "\n", "}", "\n", "v", ":=", "&", "URLsValue", "{", "}", "\n", "if", "err", ":=", "v", ".", "Set", "(", "...
// NewURLsValue implements "url.URL" slice as flag.Value interface. // Given value is to be separated by comma.
[ "NewURLsValue", "implements", "url", ".", "URL", "slice", "as", "flag", ".", "Value", "interface", ".", "Given", "value", "is", "to", "be", "separated", "by", "comma", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/flags/urls.go#L51-L60
test
etcd-io/etcd
pkg/flags/urls.go
URLsFromFlag
func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL { return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue)) }
go
func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL { return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue)) }
[ "func", "URLsFromFlag", "(", "fs", "*", "flag", ".", "FlagSet", ",", "urlsFlagName", "string", ")", "[", "]", "url", ".", "URL", "{", "return", "[", "]", "url", ".", "URL", "(", "*", "fs", ".", "Lookup", "(", "urlsFlagName", ")", ".", "Value", ".",...
// URLsFromFlag returns a slices from url got from the flag.
[ "URLsFromFlag", "returns", "a", "slices", "from", "url", "got", "from", "the", "flag", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/flags/urls.go#L63-L65
test
etcd-io/etcd
embed/etcd.go
servePeers
func (e *Etcd) servePeers() (err error) { ph := etcdhttp.NewPeerHandler(e.GetLogger(), e.Server) var peerTLScfg *tls.Config if !e.cfg.PeerTLSInfo.Empty() { if peerTLScfg, err = e.cfg.PeerTLSInfo.ServerConfig(); err != nil { return err } } for _, p := range e.Peers { u := p.Listener.Addr().String() gs :...
go
func (e *Etcd) servePeers() (err error) { ph := etcdhttp.NewPeerHandler(e.GetLogger(), e.Server) var peerTLScfg *tls.Config if !e.cfg.PeerTLSInfo.Empty() { if peerTLScfg, err = e.cfg.PeerTLSInfo.ServerConfig(); err != nil { return err } } for _, p := range e.Peers { u := p.Listener.Addr().String() gs :...
[ "func", "(", "e", "*", "Etcd", ")", "servePeers", "(", ")", "(", "err", "error", ")", "{", "ph", ":=", "etcdhttp", ".", "NewPeerHandler", "(", "e", ".", "GetLogger", "(", ")", ",", "e", ".", "Server", ")", "\n", "var", "peerTLScfg", "*", "tls", "...
// configure peer handlers after rafthttp.Transport started
[ "configure", "peer", "handlers", "after", "rafthttp", ".", "Transport", "started" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/embed/etcd.go#L527-L585
test
etcd-io/etcd
mvcc/kvstore.go
NewStore
func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *store { s := &store{ b: b, ig: ig, kvindex: newTreeIndex(lg), le: le, currentRev: 1, compactMainRev: -1, bytesBuf8: make([]byte, 8), fifoSched: schedule.NewFIFOScheduler(), stopc: make(chan...
go
func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *store { s := &store{ b: b, ig: ig, kvindex: newTreeIndex(lg), le: le, currentRev: 1, compactMainRev: -1, bytesBuf8: make([]byte, 8), fifoSched: schedule.NewFIFOScheduler(), stopc: make(chan...
[ "func", "NewStore", "(", "lg", "*", "zap", ".", "Logger", ",", "b", "backend", ".", "Backend", ",", "le", "lease", ".", "Lessor", ",", "ig", "ConsistentIndexGetter", ")", "*", "store", "{", "s", ":=", "&", "store", "{", "b", ":", "b", ",", "ig", ...
// NewStore returns a new store. It is useful to create a store inside // mvcc pkg. It should only be used for testing externally.
[ "NewStore", "returns", "a", "new", "store", ".", "It", "is", "useful", "to", "create", "a", "store", "inside", "mvcc", "pkg", ".", "It", "should", "only", "be", "used", "for", "testing", "externally", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/mvcc/kvstore.go#L111-L150
test
etcd-io/etcd
mvcc/kvstore.go
appendMarkTombstone
func appendMarkTombstone(lg *zap.Logger, b []byte) []byte { if len(b) != revBytesLen { if lg != nil { lg.Panic( "cannot append tombstone mark to non-normal revision bytes", zap.Int("expected-revision-bytes-size", revBytesLen), zap.Int("given-revision-bytes-size", len(b)), ) } else { plog.Panic...
go
func appendMarkTombstone(lg *zap.Logger, b []byte) []byte { if len(b) != revBytesLen { if lg != nil { lg.Panic( "cannot append tombstone mark to non-normal revision bytes", zap.Int("expected-revision-bytes-size", revBytesLen), zap.Int("given-revision-bytes-size", len(b)), ) } else { plog.Panic...
[ "func", "appendMarkTombstone", "(", "lg", "*", "zap", ".", "Logger", ",", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "if", "len", "(", "b", ")", "!=", "revBytesLen", "{", "if", "lg", "!=", "nil", "{", "lg", ".", "Panic", "(", "\"cannot ap...
// appendMarkTombstone appends tombstone mark to normal revision bytes.
[ "appendMarkTombstone", "appends", "tombstone", "mark", "to", "normal", "revision", "bytes", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/mvcc/kvstore.go#L569-L582
test
etcd-io/etcd
pkg/fileutil/fileutil.go
IsDirWriteable
func IsDirWriteable(dir string) error { f := filepath.Join(dir, ".touch") if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { return err } return os.Remove(f) }
go
func IsDirWriteable(dir string) error { f := filepath.Join(dir, ".touch") if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { return err } return os.Remove(f) }
[ "func", "IsDirWriteable", "(", "dir", "string", ")", "error", "{", "f", ":=", "filepath", ".", "Join", "(", "dir", ",", "\".touch\"", ")", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "f", ",", "[", "]", "byte", "(", "\"\"", ")", ",", ...
// IsDirWriteable checks if dir is writable by writing and removing a file // to dir. It returns nil if dir is writable.
[ "IsDirWriteable", "checks", "if", "dir", "is", "writable", "by", "writing", "and", "removing", "a", "file", "to", "dir", ".", "It", "returns", "nil", "if", "dir", "is", "writable", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/fileutil/fileutil.go#L38-L44
test
etcd-io/etcd
pkg/fileutil/fileutil.go
TouchDirAll
func TouchDirAll(dir string) error { // If path is already a directory, MkdirAll does nothing // and returns nil. err := os.MkdirAll(dir, PrivateDirMode) if err != nil { // if mkdirAll("a/text") and "text" is not // a directory, this will return syscall.ENOTDIR return err } return IsDirWriteable(dir) }
go
func TouchDirAll(dir string) error { // If path is already a directory, MkdirAll does nothing // and returns nil. err := os.MkdirAll(dir, PrivateDirMode) if err != nil { // if mkdirAll("a/text") and "text" is not // a directory, this will return syscall.ENOTDIR return err } return IsDirWriteable(dir) }
[ "func", "TouchDirAll", "(", "dir", "string", ")", "error", "{", "err", ":=", "os", ".", "MkdirAll", "(", "dir", ",", "PrivateDirMode", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "IsDirWriteable", "(", "dir", ...
// TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory // does not exists. TouchDirAll also ensures the given directory is writable.
[ "TouchDirAll", "is", "similar", "to", "os", ".", "MkdirAll", ".", "It", "creates", "directories", "with", "0700", "permission", "if", "any", "directory", "does", "not", "exists", ".", "TouchDirAll", "also", "ensures", "the", "given", "directory", "is", "writab...
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/fileutil/fileutil.go#L48-L58
test
etcd-io/etcd
pkg/fileutil/fileutil.go
CreateDirAll
func CreateDirAll(dir string) error { err := TouchDirAll(dir) if err == nil { var ns []string ns, err = ReadDir(dir) if err != nil { return err } if len(ns) != 0 { err = fmt.Errorf("expected %q to be empty, got %q", dir, ns) } } return err }
go
func CreateDirAll(dir string) error { err := TouchDirAll(dir) if err == nil { var ns []string ns, err = ReadDir(dir) if err != nil { return err } if len(ns) != 0 { err = fmt.Errorf("expected %q to be empty, got %q", dir, ns) } } return err }
[ "func", "CreateDirAll", "(", "dir", "string", ")", "error", "{", "err", ":=", "TouchDirAll", "(", "dir", ")", "\n", "if", "err", "==", "nil", "{", "var", "ns", "[", "]", "string", "\n", "ns", ",", "err", "=", "ReadDir", "(", "dir", ")", "\n", "if...
// CreateDirAll is similar to TouchDirAll but returns error // if the deepest directory was not empty.
[ "CreateDirAll", "is", "similar", "to", "TouchDirAll", "but", "returns", "error", "if", "the", "deepest", "directory", "was", "not", "empty", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/fileutil/fileutil.go#L62-L75
test
etcd-io/etcd
pkg/fileutil/fileutil.go
ZeroToEnd
func ZeroToEnd(f *os.File) error { // TODO: support FALLOC_FL_ZERO_RANGE off, err := f.Seek(0, io.SeekCurrent) if err != nil { return err } lenf, lerr := f.Seek(0, io.SeekEnd) if lerr != nil { return lerr } if err = f.Truncate(off); err != nil { return err } // make sure blocks remain allocated if err ...
go
func ZeroToEnd(f *os.File) error { // TODO: support FALLOC_FL_ZERO_RANGE off, err := f.Seek(0, io.SeekCurrent) if err != nil { return err } lenf, lerr := f.Seek(0, io.SeekEnd) if lerr != nil { return lerr } if err = f.Truncate(off); err != nil { return err } // make sure blocks remain allocated if err ...
[ "func", "ZeroToEnd", "(", "f", "*", "os", ".", "File", ")", "error", "{", "off", ",", "err", ":=", "f", ".", "Seek", "(", "0", ",", "io", ".", "SeekCurrent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "lenf", ...
// ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily // shorten the length of the file.
[ "ZeroToEnd", "zeros", "a", "file", "starting", "from", "SEEK_CUR", "to", "its", "SEEK_END", ".", "May", "temporarily", "shorten", "the", "length", "of", "the", "file", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/fileutil/fileutil.go#L85-L104
test
etcd-io/etcd
wal/file_pipeline.go
Open
func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) { select { case f = <-fp.filec: case err = <-fp.errc: } return f, err }
go
func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) { select { case f = <-fp.filec: case err = <-fp.errc: } return f, err }
[ "func", "(", "fp", "*", "filePipeline", ")", "Open", "(", ")", "(", "f", "*", "fileutil", ".", "LockedFile", ",", "err", "error", ")", "{", "select", "{", "case", "f", "=", "<-", "fp", ".", "filec", ":", "case", "err", "=", "<-", "fp", ".", "er...
// Open returns a fresh file for writing. Rename the file before calling // Open again or there will be file collisions.
[ "Open", "returns", "a", "fresh", "file", "for", "writing", ".", "Rename", "the", "file", "before", "calling", "Open", "again", "or", "there", "will", "be", "file", "collisions", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/wal/file_pipeline.go#L58-L64
test
etcd-io/etcd
pkg/logutil/zap_raft.go
NewRaftLoggerFromZapCore
func NewRaftLoggerFromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) raft.Logger { // "AddCallerSkip" to annotate caller outside of "logutil" lg := zap.New(cr, zap.AddCaller(), zap.AddCallerSkip(1), zap.ErrorOutput(syncer)) return &zapRaftLogger{lg: lg, sugar: lg.Sugar()} }
go
func NewRaftLoggerFromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) raft.Logger { // "AddCallerSkip" to annotate caller outside of "logutil" lg := zap.New(cr, zap.AddCaller(), zap.AddCallerSkip(1), zap.ErrorOutput(syncer)) return &zapRaftLogger{lg: lg, sugar: lg.Sugar()} }
[ "func", "NewRaftLoggerFromZapCore", "(", "cr", "zapcore", ".", "Core", ",", "syncer", "zapcore", ".", "WriteSyncer", ")", "raft", ".", "Logger", "{", "lg", ":=", "zap", ".", "New", "(", "cr", ",", "zap", ".", "AddCaller", "(", ")", ",", "zap", ".", "...
// NewRaftLoggerFromZapCore creates "raft.Logger" from "zap.Core" // and "zapcore.WriteSyncer".
[ "NewRaftLoggerFromZapCore", "creates", "raft", ".", "Logger", "from", "zap", ".", "Core", "and", "zapcore", ".", "WriteSyncer", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/pkg/logutil/zap_raft.go#L40-L44
test
etcd-io/etcd
clientv3/yaml/config.go
NewConfig
func NewConfig(fpath string) (*clientv3.Config, error) { b, err := ioutil.ReadFile(fpath) if err != nil { return nil, err } yc := &yamlConfig{} err = yaml.Unmarshal(b, yc) if err != nil { return nil, err } if yc.InsecureTransport { return &yc.Config, nil } var ( cert *tls.Certificate cp *x509....
go
func NewConfig(fpath string) (*clientv3.Config, error) { b, err := ioutil.ReadFile(fpath) if err != nil { return nil, err } yc := &yamlConfig{} err = yaml.Unmarshal(b, yc) if err != nil { return nil, err } if yc.InsecureTransport { return &yc.Config, nil } var ( cert *tls.Certificate cp *x509....
[ "func", "NewConfig", "(", "fpath", "string", ")", "(", "*", "clientv3", ".", "Config", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "fpath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", ...
// NewConfig creates a new clientv3.Config from a yaml file.
[ "NewConfig", "creates", "a", "new", "clientv3", ".", "Config", "from", "a", "yaml", "file", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/yaml/config.go#L44-L91
test
etcd-io/etcd
etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go
RegisterElectionHandler
func RegisterElectionHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { return RegisterElectionHandlerClient(ctx, mux, v3electionpb.NewElectionClient(conn)) }
go
func RegisterElectionHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { return RegisterElectionHandlerClient(ctx, mux, v3electionpb.NewElectionClient(conn)) }
[ "func", "RegisterElectionHandler", "(", "ctx", "context", ".", "Context", ",", "mux", "*", "runtime", ".", "ServeMux", ",", "conn", "*", "grpc", ".", "ClientConn", ")", "error", "{", "return", "RegisterElectionHandlerClient", "(", "ctx", ",", "mux", ",", "v3...
// RegisterElectionHandler registers the http handlers for service Election to "mux". // The handlers forward requests to the grpc endpoint over "conn".
[ "RegisterElectionHandler", "registers", "the", "http", "handlers", "for", "service", "Election", "to", "mux", ".", "The", "handlers", "forward", "requests", "to", "the", "grpc", "endpoint", "over", "conn", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go#L132-L134
test
etcd-io/etcd
etcdserver/api/capability.go
UpdateCapability
func UpdateCapability(lg *zap.Logger, v *semver.Version) { if v == nil { // if recovered but version was never set by cluster return } enableMapMu.Lock() if curVersion != nil && !curVersion.LessThan(*v) { enableMapMu.Unlock() return } curVersion = v enabledMap = capabilityMaps[curVersion.String()] enabl...
go
func UpdateCapability(lg *zap.Logger, v *semver.Version) { if v == nil { // if recovered but version was never set by cluster return } enableMapMu.Lock() if curVersion != nil && !curVersion.LessThan(*v) { enableMapMu.Unlock() return } curVersion = v enabledMap = capabilityMaps[curVersion.String()] enabl...
[ "func", "UpdateCapability", "(", "lg", "*", "zap", ".", "Logger", ",", "v", "*", "semver", ".", "Version", ")", "{", "if", "v", "==", "nil", "{", "return", "\n", "}", "\n", "enableMapMu", ".", "Lock", "(", ")", "\n", "if", "curVersion", "!=", "nil"...
// UpdateCapability updates the enabledMap when the cluster version increases.
[ "UpdateCapability", "updates", "the", "enabledMap", "when", "the", "cluster", "version", "increases", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/capability.go#L60-L82
test
etcd-io/etcd
etcdctl/ctlv3/command/lock_command.go
NewLockCommand
func NewLockCommand() *cobra.Command { c := &cobra.Command{ Use: "lock <lockname> [exec-command arg1 arg2 ...]", Short: "Acquires a named lock", Run: lockCommandFunc, } c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session") return c }
go
func NewLockCommand() *cobra.Command { c := &cobra.Command{ Use: "lock <lockname> [exec-command arg1 arg2 ...]", Short: "Acquires a named lock", Run: lockCommandFunc, } c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session") return c }
[ "func", "NewLockCommand", "(", ")", "*", "cobra", ".", "Command", "{", "c", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"lock <lockname> [exec-command arg1 arg2 ...]\"", ",", "Short", ":", "\"Acquires a named lock\"", ",", "Run", ":", "lockCommandFunc",...
// NewLockCommand returns the cobra command for "lock".
[ "NewLockCommand", "returns", "the", "cobra", "command", "for", "lock", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/lock_command.go#L35-L43
test
etcd-io/etcd
etcdserver/raft.go
tick
func (r *raftNode) tick() { r.tickMu.Lock() r.Tick() r.tickMu.Unlock() }
go
func (r *raftNode) tick() { r.tickMu.Lock() r.Tick() r.tickMu.Unlock() }
[ "func", "(", "r", "*", "raftNode", ")", "tick", "(", ")", "{", "r", ".", "tickMu", ".", "Lock", "(", ")", "\n", "r", ".", "Tick", "(", ")", "\n", "r", ".", "tickMu", ".", "Unlock", "(", ")", "\n", "}" ]
// raft.Node does not have locks in Raft package
[ "raft", ".", "Node", "does", "not", "have", "locks", "in", "Raft", "package" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/raft.go#L150-L154
test
etcd-io/etcd
etcdserver/raft.go
advanceTicks
func (r *raftNode) advanceTicks(ticks int) { for i := 0; i < ticks; i++ { r.tick() } }
go
func (r *raftNode) advanceTicks(ticks int) { for i := 0; i < ticks; i++ { r.tick() } }
[ "func", "(", "r", "*", "raftNode", ")", "advanceTicks", "(", "ticks", "int", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "ticks", ";", "i", "++", "{", "r", ".", "tick", "(", ")", "\n", "}", "\n", "}" ]
// advanceTicks advances ticks of Raft node. // This can be used for fast-forwarding election // ticks in multi data-center deployments, thus // speeding up election process.
[ "advanceTicks", "advances", "ticks", "of", "Raft", "node", ".", "This", "can", "be", "used", "for", "fast", "-", "forwarding", "election", "ticks", "in", "multi", "data", "-", "center", "deployments", "thus", "speeding", "up", "election", "process", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/raft.go#L415-L419
test
etcd-io/etcd
etcdctl/ctlv3/command/auth_command.go
NewAuthCommand
func NewAuthCommand() *cobra.Command { ac := &cobra.Command{ Use: "auth <enable or disable>", Short: "Enable or disable authentication", } ac.AddCommand(newAuthEnableCommand()) ac.AddCommand(newAuthDisableCommand()) return ac }
go
func NewAuthCommand() *cobra.Command { ac := &cobra.Command{ Use: "auth <enable or disable>", Short: "Enable or disable authentication", } ac.AddCommand(newAuthEnableCommand()) ac.AddCommand(newAuthDisableCommand()) return ac }
[ "func", "NewAuthCommand", "(", ")", "*", "cobra", ".", "Command", "{", "ac", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"auth <enable or disable>\"", ",", "Short", ":", "\"Enable or disable authentication\"", ",", "}", "\n", "ac", ".", "AddCommand"...
// NewAuthCommand returns the cobra command for "auth".
[ "NewAuthCommand", "returns", "the", "cobra", "command", "for", "auth", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/auth_command.go#L25-L35
test
etcd-io/etcd
etcdctl/ctlv3/command/auth_command.go
authEnableCommandFunc
func authEnableCommandFunc(cmd *cobra.Command, args []string) { if len(args) != 0 { ExitWithError(ExitBadArgs, fmt.Errorf("auth enable command does not accept any arguments")) } ctx, cancel := commandCtx(cmd) cli := mustClientFromCmd(cmd) var err error for err == nil { if _, err = cli.AuthEnable(ctx); err ==...
go
func authEnableCommandFunc(cmd *cobra.Command, args []string) { if len(args) != 0 { ExitWithError(ExitBadArgs, fmt.Errorf("auth enable command does not accept any arguments")) } ctx, cancel := commandCtx(cmd) cli := mustClientFromCmd(cmd) var err error for err == nil { if _, err = cli.AuthEnable(ctx); err ==...
[ "func", "authEnableCommandFunc", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "if", "len", "(", "args", ")", "!=", "0", "{", "ExitWithError", "(", "ExitBadArgs", ",", "fmt", ".", "Errorf", "(", "\"auth enable comma...
// authEnableCommandFunc executes the "auth enable" command.
[ "authEnableCommandFunc", "executes", "the", "auth", "enable", "command", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/auth_command.go#L46-L73
test
etcd-io/etcd
etcdctl/ctlv3/command/auth_command.go
authDisableCommandFunc
func authDisableCommandFunc(cmd *cobra.Command, args []string) { if len(args) != 0 { ExitWithError(ExitBadArgs, fmt.Errorf("auth disable command does not accept any arguments")) } ctx, cancel := commandCtx(cmd) _, err := mustClientFromCmd(cmd).Auth.AuthDisable(ctx) cancel() if err != nil { ExitWithError(Exit...
go
func authDisableCommandFunc(cmd *cobra.Command, args []string) { if len(args) != 0 { ExitWithError(ExitBadArgs, fmt.Errorf("auth disable command does not accept any arguments")) } ctx, cancel := commandCtx(cmd) _, err := mustClientFromCmd(cmd).Auth.AuthDisable(ctx) cancel() if err != nil { ExitWithError(Exit...
[ "func", "authDisableCommandFunc", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "if", "len", "(", "args", ")", "!=", "0", "{", "ExitWithError", "(", "ExitBadArgs", ",", "fmt", ".", "Errorf", "(", "\"auth disable com...
// authDisableCommandFunc executes the "auth disable" command.
[ "authDisableCommandFunc", "executes", "the", "auth", "disable", "command", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv3/command/auth_command.go#L84-L97
test
etcd-io/etcd
clientv3/retry.go
RetryKVClient
func RetryKVClient(c *Client) pb.KVClient { return &retryKVClient{ kc: pb.NewKVClient(c.conn), } }
go
func RetryKVClient(c *Client) pb.KVClient { return &retryKVClient{ kc: pb.NewKVClient(c.conn), } }
[ "func", "RetryKVClient", "(", "c", "*", "Client", ")", "pb", ".", "KVClient", "{", "return", "&", "retryKVClient", "{", "kc", ":", "pb", ".", "NewKVClient", "(", "c", ".", "conn", ")", ",", "}", "\n", "}" ]
// RetryKVClient implements a KVClient.
[ "RetryKVClient", "implements", "a", "KVClient", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/retry.go#L103-L107
test
etcd-io/etcd
clientv3/retry.go
RetryLeaseClient
func RetryLeaseClient(c *Client) pb.LeaseClient { return &retryLeaseClient{ lc: pb.NewLeaseClient(c.conn), } }
go
func RetryLeaseClient(c *Client) pb.LeaseClient { return &retryLeaseClient{ lc: pb.NewLeaseClient(c.conn), } }
[ "func", "RetryLeaseClient", "(", "c", "*", "Client", ")", "pb", ".", "LeaseClient", "{", "return", "&", "retryLeaseClient", "{", "lc", ":", "pb", ".", "NewLeaseClient", "(", "c", ".", "conn", ")", ",", "}", "\n", "}" ]
// RetryLeaseClient implements a LeaseClient.
[ "RetryLeaseClient", "implements", "a", "LeaseClient", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/retry.go#L133-L137
test
etcd-io/etcd
clientv3/retry.go
RetryClusterClient
func RetryClusterClient(c *Client) pb.ClusterClient { return &retryClusterClient{ cc: pb.NewClusterClient(c.conn), } }
go
func RetryClusterClient(c *Client) pb.ClusterClient { return &retryClusterClient{ cc: pb.NewClusterClient(c.conn), } }
[ "func", "RetryClusterClient", "(", "c", "*", "Client", ")", "pb", ".", "ClusterClient", "{", "return", "&", "retryClusterClient", "{", "cc", ":", "pb", ".", "NewClusterClient", "(", "c", ".", "conn", ")", ",", "}", "\n", "}" ]
// RetryClusterClient implements a ClusterClient.
[ "RetryClusterClient", "implements", "a", "ClusterClient", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/retry.go#L164-L168
test
etcd-io/etcd
clientv3/retry.go
RetryMaintenanceClient
func RetryMaintenanceClient(c *Client, conn *grpc.ClientConn) pb.MaintenanceClient { return &retryMaintenanceClient{ mc: pb.NewMaintenanceClient(conn), } }
go
func RetryMaintenanceClient(c *Client, conn *grpc.ClientConn) pb.MaintenanceClient { return &retryMaintenanceClient{ mc: pb.NewMaintenanceClient(conn), } }
[ "func", "RetryMaintenanceClient", "(", "c", "*", "Client", ",", "conn", "*", "grpc", ".", "ClientConn", ")", "pb", ".", "MaintenanceClient", "{", "return", "&", "retryMaintenanceClient", "{", "mc", ":", "pb", ".", "NewMaintenanceClient", "(", "conn", ")", ",...
// RetryMaintenanceClient implements a Maintenance.
[ "RetryMaintenanceClient", "implements", "a", "Maintenance", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/retry.go#L191-L195
test
etcd-io/etcd
clientv3/retry.go
RetryAuthClient
func RetryAuthClient(c *Client) pb.AuthClient { return &retryAuthClient{ ac: pb.NewAuthClient(c.conn), } }
go
func RetryAuthClient(c *Client) pb.AuthClient { return &retryAuthClient{ ac: pb.NewAuthClient(c.conn), } }
[ "func", "RetryAuthClient", "(", "c", "*", "Client", ")", "pb", ".", "AuthClient", "{", "return", "&", "retryAuthClient", "{", "ac", ":", "pb", ".", "NewAuthClient", "(", "c", ".", "conn", ")", ",", "}", "\n", "}" ]
// RetryAuthClient implements a AuthClient.
[ "RetryAuthClient", "implements", "a", "AuthClient", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/retry.go#L230-L234
test
etcd-io/etcd
etcdctl/ctlv2/command/set_dir_command.go
NewSetDirCommand
func NewSetDirCommand() cli.Command { return cli.Command{ Name: "setdir", Usage: "create a new directory or update an existing directory TTL", ArgsUsage: "<key>", Flags: []cli.Flag{ cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, }, Action: func(c *cli.Context) error {...
go
func NewSetDirCommand() cli.Command { return cli.Command{ Name: "setdir", Usage: "create a new directory or update an existing directory TTL", ArgsUsage: "<key>", Flags: []cli.Flag{ cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live in seconds"}, }, Action: func(c *cli.Context) error {...
[ "func", "NewSetDirCommand", "(", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"setdir\"", ",", "Usage", ":", "\"create a new directory or update an existing directory TTL\"", ",", "ArgsUsage", ":", "\"<key>\"", ",", "Flags", ...
// NewSetDirCommand returns the CLI command for "setDir".
[ "NewSetDirCommand", "returns", "the", "CLI", "command", "for", "setDir", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdctl/ctlv2/command/set_dir_command.go#L23-L36
test
etcd-io/etcd
contrib/recipes/double_barrier.go
Enter
func (b *DoubleBarrier) Enter() error { client := b.s.Client() ek, err := newUniqueEphemeralKey(b.s, b.key+"/waiters") if err != nil { return err } b.myKey = ek resp, err := client.Get(b.ctx, b.key+"/waiters", clientv3.WithPrefix()) if err != nil { return err } if len(resp.Kvs) > b.count { return ErrTo...
go
func (b *DoubleBarrier) Enter() error { client := b.s.Client() ek, err := newUniqueEphemeralKey(b.s, b.key+"/waiters") if err != nil { return err } b.myKey = ek resp, err := client.Get(b.ctx, b.key+"/waiters", clientv3.WithPrefix()) if err != nil { return err } if len(resp.Kvs) > b.count { return ErrTo...
[ "func", "(", "b", "*", "DoubleBarrier", ")", "Enter", "(", ")", "error", "{", "client", ":=", "b", ".", "s", ".", "Client", "(", ")", "\n", "ek", ",", "err", ":=", "newUniqueEphemeralKey", "(", "b", ".", "s", ",", "b", ".", "key", "+", "\"/waiter...
// Enter waits for "count" processes to enter the barrier then returns
[ "Enter", "waits", "for", "count", "processes", "to", "enter", "the", "barrier", "then", "returns" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/contrib/recipes/double_barrier.go#L46-L75
test
etcd-io/etcd
contrib/recipes/double_barrier.go
Leave
func (b *DoubleBarrier) Leave() error { client := b.s.Client() resp, err := client.Get(b.ctx, b.key+"/waiters", clientv3.WithPrefix()) if err != nil { return err } if len(resp.Kvs) == 0 { return nil } lowest, highest := resp.Kvs[0], resp.Kvs[0] for _, k := range resp.Kvs { if k.ModRevision < lowest.ModRe...
go
func (b *DoubleBarrier) Leave() error { client := b.s.Client() resp, err := client.Get(b.ctx, b.key+"/waiters", clientv3.WithPrefix()) if err != nil { return err } if len(resp.Kvs) == 0 { return nil } lowest, highest := resp.Kvs[0], resp.Kvs[0] for _, k := range resp.Kvs { if k.ModRevision < lowest.ModRe...
[ "func", "(", "b", "*", "DoubleBarrier", ")", "Leave", "(", ")", "error", "{", "client", ":=", "b", ".", "s", ".", "Client", "(", ")", "\n", "resp", ",", "err", ":=", "client", ".", "Get", "(", "b", ".", "ctx", ",", "b", ".", "key", "+", "\"/w...
// Leave waits for "count" processes to leave the barrier then returns
[ "Leave", "waits", "for", "count", "processes", "to", "leave", "the", "barrier", "then", "returns" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/contrib/recipes/double_barrier.go#L78-L138
test
etcd-io/etcd
etcdserver/api/etcdhttp/base.go
HandleBasic
func HandleBasic(mux *http.ServeMux, server etcdserver.ServerPeer) { mux.HandleFunc(varsPath, serveVars) // TODO: deprecate '/config/local/log' in v3.5 mux.HandleFunc(configPath+"/local/log", logHandleFunc) HandleMetricsHealth(mux, server) mux.HandleFunc(versionPath, versionHandler(server.Cluster(), serveVersion...
go
func HandleBasic(mux *http.ServeMux, server etcdserver.ServerPeer) { mux.HandleFunc(varsPath, serveVars) // TODO: deprecate '/config/local/log' in v3.5 mux.HandleFunc(configPath+"/local/log", logHandleFunc) HandleMetricsHealth(mux, server) mux.HandleFunc(versionPath, versionHandler(server.Cluster(), serveVersion...
[ "func", "HandleBasic", "(", "mux", "*", "http", ".", "ServeMux", ",", "server", "etcdserver", ".", "ServerPeer", ")", "{", "mux", ".", "HandleFunc", "(", "varsPath", ",", "serveVars", ")", "\n", "mux", ".", "HandleFunc", "(", "configPath", "+", "\"/local/l...
// HandleBasic adds handlers to a mux for serving JSON etcd client requests // that do not access the v2 store.
[ "HandleBasic", "adds", "handlers", "to", "a", "mux", "for", "serving", "JSON", "etcd", "client", "requests", "that", "do", "not", "access", "the", "v2", "store", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/etcdhttp/base.go#L48-L56
test
etcd-io/etcd
etcdserver/api/etcdhttp/base.go
WriteError
func WriteError(lg *zap.Logger, w http.ResponseWriter, r *http.Request, err error) { if err == nil { return } switch e := err.(type) { case *v2error.Error: e.WriteTo(w) case *httptypes.HTTPError: if et := e.WriteTo(w); et != nil { if lg != nil { lg.Debug( "failed to write v2 HTTP error", za...
go
func WriteError(lg *zap.Logger, w http.ResponseWriter, r *http.Request, err error) { if err == nil { return } switch e := err.(type) { case *v2error.Error: e.WriteTo(w) case *httptypes.HTTPError: if et := e.WriteTo(w); et != nil { if lg != nil { lg.Debug( "failed to write v2 HTTP error", za...
[ "func", "WriteError", "(", "lg", "*", "zap", ".", "Logger", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n", "switch", "e", ":...
// WriteError logs and writes the given Error to the ResponseWriter // If Error is an etcdErr, it is rendered to the ResponseWriter // Otherwise, it is assumed to be a StatusInternalServerError
[ "WriteError", "logs", "and", "writes", "the", "given", "Error", "to", "the", "ResponseWriter", "If", "Error", "is", "an", "etcdErr", "it", "is", "rendered", "to", "the", "ResponseWriter", "Otherwise", "it", "is", "assumed", "to", "be", "a", "StatusInternalServ...
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/etcdhttp/base.go#L141-L203
test
etcd-io/etcd
etcdserver/api/membership/cluster.go
MemberByName
func (c *RaftCluster) MemberByName(name string) *Member { c.Lock() defer c.Unlock() var memb *Member for _, m := range c.members { if m.Name == name { if memb != nil { if c.lg != nil { c.lg.Panic("two member with same name found", zap.String("name", name)) } else { plog.Panicf("two members wi...
go
func (c *RaftCluster) MemberByName(name string) *Member { c.Lock() defer c.Unlock() var memb *Member for _, m := range c.members { if m.Name == name { if memb != nil { if c.lg != nil { c.lg.Panic("two member with same name found", zap.String("name", name)) } else { plog.Panicf("two members wi...
[ "func", "(", "c", "*", "RaftCluster", ")", "MemberByName", "(", "name", "string", ")", "*", "Member", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "var", "memb", "*", "Member", "\n", "for", "_", ",", "m", ...
// MemberByName returns a Member with the given name if exists. // If more than one member has the given name, it will panic.
[ "MemberByName", "returns", "a", "Member", "with", "the", "given", "name", "if", "exists", ".", "If", "more", "than", "one", "member", "has", "the", "given", "name", "it", "will", "panic", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/membership/cluster.go#L117-L134
test
etcd-io/etcd
etcdserver/api/membership/cluster.go
PeerURLs
func (c *RaftCluster) PeerURLs() []string { c.Lock() defer c.Unlock() urls := make([]string, 0) for _, p := range c.members { urls = append(urls, p.PeerURLs...) } sort.Strings(urls) return urls }
go
func (c *RaftCluster) PeerURLs() []string { c.Lock() defer c.Unlock() urls := make([]string, 0) for _, p := range c.members { urls = append(urls, p.PeerURLs...) } sort.Strings(urls) return urls }
[ "func", "(", "c", "*", "RaftCluster", ")", "PeerURLs", "(", ")", "[", "]", "string", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "urls", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for"...
// PeerURLs returns a list of all peer addresses. // The returned list is sorted in ascending lexicographical order.
[ "PeerURLs", "returns", "a", "list", "of", "all", "peer", "addresses", ".", "The", "returned", "list", "is", "sorted", "in", "ascending", "lexicographical", "order", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/membership/cluster.go#L155-L164
test
etcd-io/etcd
etcdserver/api/membership/cluster.go
ValidateConfigurationChange
func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error { members, removed := membersFromStore(c.lg, c.v2store) id := types.ID(cc.NodeID) if removed[id] { return ErrIDRemoved } switch cc.Type { case raftpb.ConfChangeAddNode: if members[id] != nil { return ErrIDExists } urls := mak...
go
func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error { members, removed := membersFromStore(c.lg, c.v2store) id := types.ID(cc.NodeID) if removed[id] { return ErrIDRemoved } switch cc.Type { case raftpb.ConfChangeAddNode: if members[id] != nil { return ErrIDExists } urls := mak...
[ "func", "(", "c", "*", "RaftCluster", ")", "ValidateConfigurationChange", "(", "cc", "raftpb", ".", "ConfChange", ")", "error", "{", "members", ",", "removed", ":=", "membersFromStore", "(", "c", ".", "lg", ",", "c", ".", "v2store", ")", "\n", "id", ":="...
// ValidateConfigurationChange takes a proposed ConfChange and // ensures that it is still valid.
[ "ValidateConfigurationChange", "takes", "a", "proposed", "ConfChange", "and", "ensures", "that", "it", "is", "still", "valid", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/membership/cluster.go#L255-L326
test
etcd-io/etcd
etcdserver/api/membership/cluster.go
AddMember
func (c *RaftCluster) AddMember(m *Member) { c.Lock() defer c.Unlock() if c.v2store != nil { mustSaveMemberToStore(c.v2store, m) } if c.be != nil { mustSaveMemberToBackend(c.be, m) } c.members[m.ID] = m if c.lg != nil { c.lg.Info( "added member", zap.String("cluster-id", c.cid.String()), zap.St...
go
func (c *RaftCluster) AddMember(m *Member) { c.Lock() defer c.Unlock() if c.v2store != nil { mustSaveMemberToStore(c.v2store, m) } if c.be != nil { mustSaveMemberToBackend(c.be, m) } c.members[m.ID] = m if c.lg != nil { c.lg.Info( "added member", zap.String("cluster-id", c.cid.String()), zap.St...
[ "func", "(", "c", "*", "RaftCluster", ")", "AddMember", "(", "m", "*", "Member", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "if", "c", ".", "v2store", "!=", "nil", "{", "mustSaveMemberToStore", "(", "...
// AddMember adds a new Member into the cluster, and saves the given member's // raftAttributes into the store. The given member should have empty attributes. // A Member with a matching id must not exist.
[ "AddMember", "adds", "a", "new", "Member", "into", "the", "cluster", "and", "saves", "the", "given", "member", "s", "raftAttributes", "into", "the", "store", ".", "The", "given", "member", "should", "have", "empty", "attributes", ".", "A", "Member", "with", ...
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/membership/cluster.go#L331-L354
test
etcd-io/etcd
etcdserver/api/membership/cluster.go
RemoveMember
func (c *RaftCluster) RemoveMember(id types.ID) { c.Lock() defer c.Unlock() if c.v2store != nil { mustDeleteMemberFromStore(c.v2store, id) } if c.be != nil { mustDeleteMemberFromBackend(c.be, id) } m, ok := c.members[id] delete(c.members, id) c.removed[id] = true if c.lg != nil { if ok { c.lg.Info(...
go
func (c *RaftCluster) RemoveMember(id types.ID) { c.Lock() defer c.Unlock() if c.v2store != nil { mustDeleteMemberFromStore(c.v2store, id) } if c.be != nil { mustDeleteMemberFromBackend(c.be, id) } m, ok := c.members[id] delete(c.members, id) c.removed[id] = true if c.lg != nil { if ok { c.lg.Info(...
[ "func", "(", "c", "*", "RaftCluster", ")", "RemoveMember", "(", "id", "types", ".", "ID", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "if", "c", ".", "v2store", "!=", "nil", "{", "mustDeleteMemberFromSto...
// RemoveMember removes a member from the store. // The given id MUST exist, or the function panics.
[ "RemoveMember", "removes", "a", "member", "from", "the", "store", ".", "The", "given", "id", "MUST", "exist", "or", "the", "function", "panics", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/membership/cluster.go#L358-L392
test
etcd-io/etcd
etcdserver/api/membership/cluster.go
ValidateClusterAndAssignIDs
func ValidateClusterAndAssignIDs(lg *zap.Logger, local *RaftCluster, existing *RaftCluster) error { ems := existing.Members() lms := local.Members() if len(ems) != len(lms) { return fmt.Errorf("member count is unequal") } sort.Sort(MembersByPeerURLs(ems)) sort.Sort(MembersByPeerURLs(lms)) ctx, cancel := conte...
go
func ValidateClusterAndAssignIDs(lg *zap.Logger, local *RaftCluster, existing *RaftCluster) error { ems := existing.Members() lms := local.Members() if len(ems) != len(lms) { return fmt.Errorf("member count is unequal") } sort.Sort(MembersByPeerURLs(ems)) sort.Sort(MembersByPeerURLs(lms)) ctx, cancel := conte...
[ "func", "ValidateClusterAndAssignIDs", "(", "lg", "*", "zap", ".", "Logger", ",", "local", "*", "RaftCluster", ",", "existing", "*", "RaftCluster", ")", "error", "{", "ems", ":=", "existing", ".", "Members", "(", ")", "\n", "lms", ":=", "local", ".", "Me...
// ValidateClusterAndAssignIDs validates the local cluster by matching the PeerURLs // with the existing cluster. If the validation succeeds, it assigns the IDs // from the existing cluster to the local cluster. // If the validation fails, an error will be returned.
[ "ValidateClusterAndAssignIDs", "validates", "the", "local", "cluster", "by", "matching", "the", "PeerURLs", "with", "the", "existing", "cluster", ".", "If", "the", "validation", "succeeds", "it", "assigns", "the", "IDs", "from", "the", "existing", "cluster", "to",...
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/etcdserver/api/membership/cluster.go#L654-L676
test
etcd-io/etcd
mvcc/index.go
Keep
func (ti *treeIndex) Keep(rev int64) map[revision]struct{} { available := make(map[revision]struct{}) ti.RLock() defer ti.RUnlock() ti.tree.Ascend(func(i btree.Item) bool { keyi := i.(*keyIndex) keyi.keep(rev, available) return true }) return available }
go
func (ti *treeIndex) Keep(rev int64) map[revision]struct{} { available := make(map[revision]struct{}) ti.RLock() defer ti.RUnlock() ti.tree.Ascend(func(i btree.Item) bool { keyi := i.(*keyIndex) keyi.keep(rev, available) return true }) return available }
[ "func", "(", "ti", "*", "treeIndex", ")", "Keep", "(", "rev", "int64", ")", "map", "[", "revision", "]", "struct", "{", "}", "{", "available", ":=", "make", "(", "map", "[", "revision", "]", "struct", "{", "}", ")", "\n", "ti", ".", "RLock", "(",...
// Keep finds all revisions to be kept for a Compaction at the given rev.
[ "Keep", "finds", "all", "revisions", "to", "be", "kept", "for", "a", "Compaction", "at", "the", "given", "rev", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/mvcc/index.go#L221-L231
test
etcd-io/etcd
clientv3/lease.go
closeRequireLeader
func (l *lessor) closeRequireLeader() { l.mu.Lock() defer l.mu.Unlock() for _, ka := range l.keepAlives { reqIdxs := 0 // find all required leader channels, close, mark as nil for i, ctx := range ka.ctxs { md, ok := metadata.FromOutgoingContext(ctx) if !ok { continue } ks := md[rpctypes.Metadat...
go
func (l *lessor) closeRequireLeader() { l.mu.Lock() defer l.mu.Unlock() for _, ka := range l.keepAlives { reqIdxs := 0 // find all required leader channels, close, mark as nil for i, ctx := range ka.ctxs { md, ok := metadata.FromOutgoingContext(ctx) if !ok { continue } ks := md[rpctypes.Metadat...
[ "func", "(", "l", "*", "lessor", ")", "closeRequireLeader", "(", ")", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "ka", ":=", "range", "l", ".", "keepAlives", "{", ...
// closeRequireLeader scans keepAlives for ctxs that have require leader // and closes the associated channels.
[ "closeRequireLeader", "scans", "keepAlives", "for", "ctxs", "that", "have", "require", "leader", "and", "closes", "the", "associated", "channels", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/lease.go#L363-L398
test
etcd-io/etcd
clientv3/lease.go
resetRecv
func (l *lessor) resetRecv() (pb.Lease_LeaseKeepAliveClient, error) { sctx, cancel := context.WithCancel(l.stopCtx) stream, err := l.remote.LeaseKeepAlive(sctx, append(l.callOpts, withMax(0))...) if err != nil { cancel() return nil, err } l.mu.Lock() defer l.mu.Unlock() if l.stream != nil && l.streamCancel ...
go
func (l *lessor) resetRecv() (pb.Lease_LeaseKeepAliveClient, error) { sctx, cancel := context.WithCancel(l.stopCtx) stream, err := l.remote.LeaseKeepAlive(sctx, append(l.callOpts, withMax(0))...) if err != nil { cancel() return nil, err } l.mu.Lock() defer l.mu.Unlock() if l.stream != nil && l.streamCancel ...
[ "func", "(", "l", "*", "lessor", ")", "resetRecv", "(", ")", "(", "pb", ".", "Lease_LeaseKeepAliveClient", ",", "error", ")", "{", "sctx", ",", "cancel", ":=", "context", ".", "WithCancel", "(", "l", ".", "stopCtx", ")", "\n", "stream", ",", "err", "...
// resetRecv opens a new lease stream and starts sending keep alive requests.
[ "resetRecv", "opens", "a", "new", "lease", "stream", "and", "starts", "sending", "keep", "alive", "requests", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/lease.go#L472-L491
test
etcd-io/etcd
clientv3/lease.go
recvKeepAlive
func (l *lessor) recvKeepAlive(resp *pb.LeaseKeepAliveResponse) { karesp := &LeaseKeepAliveResponse{ ResponseHeader: resp.GetHeader(), ID: LeaseID(resp.ID), TTL: resp.TTL, } l.mu.Lock() defer l.mu.Unlock() ka, ok := l.keepAlives[karesp.ID] if !ok { return } if karesp.TTL <= 0 {...
go
func (l *lessor) recvKeepAlive(resp *pb.LeaseKeepAliveResponse) { karesp := &LeaseKeepAliveResponse{ ResponseHeader: resp.GetHeader(), ID: LeaseID(resp.ID), TTL: resp.TTL, } l.mu.Lock() defer l.mu.Unlock() ka, ok := l.keepAlives[karesp.ID] if !ok { return } if karesp.TTL <= 0 {...
[ "func", "(", "l", "*", "lessor", ")", "recvKeepAlive", "(", "resp", "*", "pb", ".", "LeaseKeepAliveResponse", ")", "{", "karesp", ":=", "&", "LeaseKeepAliveResponse", "{", "ResponseHeader", ":", "resp", ".", "GetHeader", "(", ")", ",", "ID", ":", "LeaseID"...
// recvKeepAlive updates a lease based on its LeaseKeepAliveResponse
[ "recvKeepAlive", "updates", "a", "lease", "based", "on", "its", "LeaseKeepAliveResponse" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/lease.go#L494-L533
test
etcd-io/etcd
clientv3/lease.go
deadlineLoop
func (l *lessor) deadlineLoop() { for { select { case <-time.After(time.Second): case <-l.donec: return } now := time.Now() l.mu.Lock() for id, ka := range l.keepAlives { if ka.deadline.Before(now) { // waited too long for response; lease may be expired ka.close() delete(l.keepAlives, i...
go
func (l *lessor) deadlineLoop() { for { select { case <-time.After(time.Second): case <-l.donec: return } now := time.Now() l.mu.Lock() for id, ka := range l.keepAlives { if ka.deadline.Before(now) { // waited too long for response; lease may be expired ka.close() delete(l.keepAlives, i...
[ "func", "(", "l", "*", "lessor", ")", "deadlineLoop", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "time", ".", "After", "(", "time", ".", "Second", ")", ":", "case", "<-", "l", ".", "donec", ":", "return", "\n", "}", "\n", "now", ":...
// deadlineLoop reaps any keep alive channels that have not received a response // within the lease TTL
[ "deadlineLoop", "reaps", "any", "keep", "alive", "channels", "that", "have", "not", "received", "a", "response", "within", "the", "lease", "TTL" ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/lease.go#L537-L555
test
etcd-io/etcd
clientv3/lease.go
sendKeepAliveLoop
func (l *lessor) sendKeepAliveLoop(stream pb.Lease_LeaseKeepAliveClient) { for { var tosend []LeaseID now := time.Now() l.mu.Lock() for id, ka := range l.keepAlives { if ka.nextKeepAlive.Before(now) { tosend = append(tosend, id) } } l.mu.Unlock() for _, id := range tosend { r := &pb.LeaseK...
go
func (l *lessor) sendKeepAliveLoop(stream pb.Lease_LeaseKeepAliveClient) { for { var tosend []LeaseID now := time.Now() l.mu.Lock() for id, ka := range l.keepAlives { if ka.nextKeepAlive.Before(now) { tosend = append(tosend, id) } } l.mu.Unlock() for _, id := range tosend { r := &pb.LeaseK...
[ "func", "(", "l", "*", "lessor", ")", "sendKeepAliveLoop", "(", "stream", "pb", ".", "Lease_LeaseKeepAliveClient", ")", "{", "for", "{", "var", "tosend", "[", "]", "LeaseID", "\n", "now", ":=", "time", ".", "Now", "(", ")", "\n", "l", ".", "mu", ".",...
// sendKeepAliveLoop sends keep alive requests for the lifetime of the given stream.
[ "sendKeepAliveLoop", "sends", "keep", "alive", "requests", "for", "the", "lifetime", "of", "the", "given", "stream", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/lease.go#L558-L589
test
etcd-io/etcd
clientv3/leasing/kv.go
NewKV
func NewKV(cl *v3.Client, pfx string, opts ...concurrency.SessionOption) (v3.KV, func(), error) { cctx, cancel := context.WithCancel(cl.Ctx()) lkv := &leasingKV{ cl: cl, kv: cl.KV, pfx: pfx, leases: leaseCache{revokes: make(map[string]time.Time)}, ctx: cctx, cancel: ...
go
func NewKV(cl *v3.Client, pfx string, opts ...concurrency.SessionOption) (v3.KV, func(), error) { cctx, cancel := context.WithCancel(cl.Ctx()) lkv := &leasingKV{ cl: cl, kv: cl.KV, pfx: pfx, leases: leaseCache{revokes: make(map[string]time.Time)}, ctx: cctx, cancel: ...
[ "func", "NewKV", "(", "cl", "*", "v3", ".", "Client", ",", "pfx", "string", ",", "opts", "...", "concurrency", ".", "SessionOption", ")", "(", "v3", ".", "KV", ",", "func", "(", ")", ",", "error", ")", "{", "cctx", ",", "cancel", ":=", "context", ...
// NewKV wraps a KV instance so that all requests are wired through a leasing protocol.
[ "NewKV", "wraps", "a", "KV", "instance", "so", "that", "all", "requests", "are", "wired", "through", "a", "leasing", "protocol", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/leasing/kv.go#L56-L78
test
etcd-io/etcd
clientv3/leasing/kv.go
rescind
func (lkv *leasingKV) rescind(ctx context.Context, key string, rev int64) { if lkv.leases.Evict(key) > rev { return } cmp := v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev) op := v3.OpDelete(lkv.pfx + key) for ctx.Err() == nil { if _, err := lkv.kv.Txn(ctx).If(cmp).Then(op).Commit(); err == nil { retur...
go
func (lkv *leasingKV) rescind(ctx context.Context, key string, rev int64) { if lkv.leases.Evict(key) > rev { return } cmp := v3.Compare(v3.CreateRevision(lkv.pfx+key), "<", rev) op := v3.OpDelete(lkv.pfx + key) for ctx.Err() == nil { if _, err := lkv.kv.Txn(ctx).If(cmp).Then(op).Commit(); err == nil { retur...
[ "func", "(", "lkv", "*", "leasingKV", ")", "rescind", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "rev", "int64", ")", "{", "if", "lkv", ".", "leases", ".", "Evict", "(", "key", ")", ">", "rev", "{", "return", "\n", "}", "\n...
// rescind releases a lease from this client.
[ "rescind", "releases", "a", "lease", "from", "this", "client", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/leasing/kv.go#L186-L197
test
etcd-io/etcd
clientv3/compare.go
LeaseValue
func LeaseValue(key string) Cmp { return Cmp{Key: []byte(key), Target: pb.Compare_LEASE} }
go
func LeaseValue(key string) Cmp { return Cmp{Key: []byte(key), Target: pb.Compare_LEASE} }
[ "func", "LeaseValue", "(", "key", "string", ")", "Cmp", "{", "return", "Cmp", "{", "Key", ":", "[", "]", "byte", "(", "key", ")", ",", "Target", ":", "pb", ".", "Compare_LEASE", "}", "\n", "}" ]
// LeaseValue compares a key's LeaseID to a value of your choosing. The empty // LeaseID is 0, otherwise known as `NoLease`.
[ "LeaseValue", "compares", "a", "key", "s", "LeaseID", "to", "a", "value", "of", "your", "choosing", ".", "The", "empty", "LeaseID", "is", "0", "otherwise", "known", "as", "NoLease", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/compare.go#L89-L91
test
etcd-io/etcd
clientv3/compare.go
ValueBytes
func (cmp *Cmp) ValueBytes() []byte { if tu, ok := cmp.TargetUnion.(*pb.Compare_Value); ok { return tu.Value } return nil }
go
func (cmp *Cmp) ValueBytes() []byte { if tu, ok := cmp.TargetUnion.(*pb.Compare_Value); ok { return tu.Value } return nil }
[ "func", "(", "cmp", "*", "Cmp", ")", "ValueBytes", "(", ")", "[", "]", "byte", "{", "if", "tu", ",", "ok", ":=", "cmp", ".", "TargetUnion", ".", "(", "*", "pb", ".", "Compare_Value", ")", ";", "ok", "{", "return", "tu", ".", "Value", "\n", "}",...
// ValueBytes returns the byte slice holding the comparison value, if any.
[ "ValueBytes", "returns", "the", "byte", "slice", "holding", "the", "comparison", "value", "if", "any", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/compare.go#L100-L105
test
etcd-io/etcd
clientv3/compare.go
WithRange
func (cmp Cmp) WithRange(end string) Cmp { cmp.RangeEnd = []byte(end) return cmp }
go
func (cmp Cmp) WithRange(end string) Cmp { cmp.RangeEnd = []byte(end) return cmp }
[ "func", "(", "cmp", "Cmp", ")", "WithRange", "(", "end", "string", ")", "Cmp", "{", "cmp", ".", "RangeEnd", "=", "[", "]", "byte", "(", "end", ")", "\n", "return", "cmp", "\n", "}" ]
// WithRange sets the comparison to scan the range [key, end).
[ "WithRange", "sets", "the", "comparison", "to", "scan", "the", "range", "[", "key", "end", ")", "." ]
616592d9ba993e3fe9798eef581316016df98906
https://github.com/etcd-io/etcd/blob/616592d9ba993e3fe9798eef581316016df98906/clientv3/compare.go#L111-L114
test