From f6d8059ac129835e28b26e2022cfcdd046a34d6d Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sun, 21 Feb 2016 03:52:15 -0800 Subject: [PATCH 1/2] test: scan for exported godoc violations --- .travis.yml | 5 +++++ test | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.travis.yml b/.travis.yml index 98542bc76..224fbea31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,11 @@ addons: apt: packages: - libpcap-dev + - libaspell-dev + - libhunspell-dev + +before_install: + - go get -v github.com/chzchzchz/goword script: - ./test diff --git a/test b/test index afcf39f69..f54ba08ca 100755 --- a/test +++ b/test @@ -89,6 +89,18 @@ function fmt_tests { fi done + echo "Checking goword..." + # get all go files to process + gofiles=`find $FMT -iname '*.go' 2>/dev/null` + # ignore tests and protobuf files + gofiles=`echo ${gofiles} | sort | uniq | sed "s/ /\n/g" | egrep -v "(\\_test.go|\\.pb\\.go)"` + # only check for broken exported godocs + gowordRes=`goword -use-spell=false ${gofiles} | grep godoc-export | sort` + if [ ! -z "$gowordRes" ]; then + echo -e "goword checking failed:\n${gowordRes}" + exit 255 + fi + echo "Checking for license header..." licRes=$(for file in $(find . -type f -iname '*.go' ! -path './Godeps/*'); do head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e " ${file}" From c5b51946eb1b488045a8629160a183008e6744c9 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sun, 21 Feb 2016 05:05:03 -0800 Subject: [PATCH 2/2] *: exported godoc fixups --- client/keys.go | 3 ++- clientv3/client.go | 2 +- discovery/srv.go | 1 + error/error.go | 2 +- etcdctl/command/rmdir_command.go | 2 +- etcdmain/config.go | 1 + etcdserver/etcdhttp/httptypes/errors.go | 2 +- etcdserver/member.go | 4 ++-- etcdserver/server.go | 3 ++- etcdserver/stats/leader.go | 1 + etcdserver/stats/server.go | 1 + pkg/idutil/id.go | 3 +++ raft/progress.go | 2 ++ raft/raft.go | 2 +- raft/status.go | 1 + raft/storage.go | 2 +- rafthttp/transport.go | 2 +- storage/backend/backend.go | 2 +- storage/backend/batch_tx.go | 6 +++--- storage/watcher.go | 1 + store/node_extern.go | 1 + store/stats.go | 7 +++++++ store/store.go | 4 ++-- 23 files changed, 38 insertions(+), 17 deletions(-) diff --git a/client/keys.go b/client/keys.go index c209cab37..2c5b99dc1 100644 --- a/client/keys.go +++ b/client/keys.go @@ -184,7 +184,7 @@ type SetOptions struct { // a TTL of 0. TTL time.Duration - // When refresh is set to true a TTL value can be updated + // Refresh set to true means a TTL value can be updated // without firing a watch or changing the node value. A // value must not provided when refreshing a key. Refresh bool @@ -311,6 +311,7 @@ func (n *Node) TTLDuration() time.Duration { type Nodes []*Node // interfaces for sorting + func (ns Nodes) Len() int { return len(ns) } func (ns Nodes) Less(i, j int) bool { return ns[i].Key < ns[j].Key } func (ns Nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] } diff --git a/clientv3/client.go b/clientv3/client.go index d90e2e2fa..ae9d8b4df 100644 --- a/clientv3/client.go +++ b/clientv3/client.go @@ -157,7 +157,7 @@ func newClient(cfg *Config) (*Client, error) { }, nil } -// activeConnection returns the current in-use connection +// ActiveConnection returns the current in-use connection func (c *Client) ActiveConnection() *grpc.ClientConn { c.mu.RLock() defer c.mu.RUnlock() diff --git a/discovery/srv.go b/discovery/srv.go index f212c2feb..ed67a41ff 100644 --- a/discovery/srv.go +++ b/discovery/srv.go @@ -28,6 +28,7 @@ var ( resolveTCPAddr = net.ResolveTCPAddr ) +// SRVGetCluster gets the cluster information via DNS discovery. // TODO(barakmich): Currently ignores priority and weight (as they don't make as much sense for a bootstrap) // Also doesn't do any lookups for the token (though it could) // Also sees each entry as a separate instance. diff --git a/error/error.go b/error/error.go index 4b84b3c9a..6304ad851 100644 --- a/error/error.go +++ b/error/error.go @@ -136,7 +136,7 @@ func NewError(errorCode int, cause string, index uint64) *Error { } } -// Only for error interface +// Error is for the error interface func (e Error) Error() string { return e.Message + " (" + e.Cause + ")" } diff --git a/etcdctl/command/rmdir_command.go b/etcdctl/command/rmdir_command.go index 12f34ce80..eb1345055 100644 --- a/etcdctl/command/rmdir_command.go +++ b/etcdctl/command/rmdir_command.go @@ -21,7 +21,7 @@ import ( "github.com/coreos/etcd/client" ) -// NewRemoveCommand returns the CLI command for "rmdir". +// NewRemoveDirCommand returns the CLI command for "rmdir". func NewRemoveDirCommand() cli.Command { return cli.Command{ Name: "rmdir", diff --git a/etcdmain/config.go b/etcdmain/config.go index d466f0103..6e4d03c3c 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -84,6 +84,7 @@ type config struct { maxWalFiles uint name string snapCount uint64 + // TickMs is the number of milliseconds between heartbeat ticks. // TODO: decouple tickMs and heartbeat tick (current heartbeat tick = 1). // make ticks a cluster wide configuration. TickMs uint diff --git a/etcdserver/etcdhttp/httptypes/errors.go b/etcdserver/etcdhttp/httptypes/errors.go index 15d16ff67..4c0cb51be 100644 --- a/etcdserver/etcdhttp/httptypes/errors.go +++ b/etcdserver/etcdhttp/httptypes/errors.go @@ -27,7 +27,7 @@ var ( type HTTPError struct { Message string `json:"message"` - // HTTP return code + // Code is the HTTP status code Code int `json:"-"` } diff --git a/etcdserver/member.go b/etcdserver/member.go index 6e9fe6bc3..0e5ea6a1f 100644 --- a/etcdserver/member.go +++ b/etcdserver/member.go @@ -157,14 +157,14 @@ func nodeToMember(n *store.NodeExtern) (*Member, error) { return m, nil } -// implement sort by ID interface +// MembersByID implements sort by ID interface type MembersByID []*Member func (ms MembersByID) Len() int { return len(ms) } func (ms MembersByID) Less(i, j int) bool { return ms[i].ID < ms[j].ID } func (ms MembersByID) Swap(i, j int) { ms[i], ms[j] = ms[j], ms[i] } -// implement sort by peer urls interface +// MembersByPeerURLs implements sort by peer urls interface type MembersByPeerURLs []*Member func (ms MembersByPeerURLs) Len() int { return len(ms) } diff --git a/etcdserver/server.go b/etcdserver/server.go index 8be2eb45a..cc0a3c6f4 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -814,11 +814,12 @@ func (s *EtcdServer) UpdateMember(ctx context.Context, memb Member) error { } // Implement the RaftTimer interface + func (s *EtcdServer) Index() uint64 { return atomic.LoadUint64(&s.r.index) } func (s *EtcdServer) Term() uint64 { return atomic.LoadUint64(&s.r.term) } -// Only for testing purpose +// Lead is only for testing purposes. // TODO: add Raft server interface to expose raft related info: // Index, Term, Lead, Committed, Applied, LastIndex, etc. func (s *EtcdServer) Lead() uint64 { return atomic.LoadUint64(&s.r.lead) } diff --git a/etcdserver/stats/leader.go b/etcdserver/stats/leader.go index a56c9b327..0dbea6ba3 100644 --- a/etcdserver/stats/leader.go +++ b/etcdserver/stats/leader.go @@ -24,6 +24,7 @@ import ( // LeaderStats is used by the leader in an etcd cluster, and encapsulates // statistics about communication with its followers type LeaderStats struct { + // Leader is the ID of the leader in the etcd cluster. // TODO(jonboulle): clarify that these are IDs, not names Leader string `json:"leader"` Followers map[string]*FollowerStats `json:"followers"` diff --git a/etcdserver/stats/server.go b/etcdserver/stats/server.go index f38cf4660..84065985d 100644 --- a/etcdserver/stats/server.go +++ b/etcdserver/stats/server.go @@ -27,6 +27,7 @@ import ( // communication with other members of the cluster type ServerStats struct { Name string `json:"name"` + // ID is the raft ID of the node. // TODO(jonboulle): use ID instead of name? ID string `json:"id"` State raft.StateType `json:"state"` diff --git a/pkg/idutil/id.go b/pkg/idutil/id.go index 50d80d963..6f1d37911 100644 --- a/pkg/idutil/id.go +++ b/pkg/idutil/id.go @@ -28,6 +28,9 @@ const ( suffixLen = tsLen + cntLen ) +// Generator generates unique identifiers based on counters, timestamps, and +// a node member ID. +// // The initial id is in this format: // High order byte is memberID, next 5 bytes are from timestamp, // and low order 2 bytes are 0s. diff --git a/raft/progress.go b/raft/progress.go index f16fcc082..11f53409d 100644 --- a/raft/progress.go +++ b/raft/progress.go @@ -36,6 +36,8 @@ func (st ProgressStateType) String() string { return prstmap[uint64(st)] } // progresses of all followers, and sends entries to the follower based on its progress. type Progress struct { Match, Next uint64 + // State defines how the leader should interact with the follower. + // // When in ProgressStateProbe, leader sends at most one replication message // per heartbeat interval. It also probes actual progress of the follower. // diff --git a/raft/raft.go b/raft/raft.go index 223046397..42972f2e8 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -103,7 +103,7 @@ type Config struct { // quorum is not active for an electionTimeout. CheckQuorum bool - // logger is the logger used for raft log. For multinode which + // Logger is the logger used for raft log. For multinode which // can host multiple raft group, each raft group can have its // own logger Logger Logger diff --git a/raft/status.go b/raft/status.go index bdf89b6f7..d18a48954 100644 --- a/raft/status.go +++ b/raft/status.go @@ -48,6 +48,7 @@ func getStatus(r *raft) Status { return s } +// MarshalJSON translates the raft status into JSON. // TODO: try to simplify this by introducing ID type into raft func (s Status) MarshalJSON() ([]byte, error) { j := fmt.Sprintf(`{"id":"%x","term":%d,"vote":"%x","commit":%d,"lead":"%x","raftState":%q,"progress":{`, diff --git a/raft/storage.go b/raft/storage.go index b0ab6195b..f3724162c 100644 --- a/raft/storage.go +++ b/raft/storage.go @@ -168,7 +168,7 @@ func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error { return nil } -// Creates a snapshot which can be retrieved with the Snapshot() method and +// CreateSnapshot makes a snapshot which can be retrieved with Snapshot() and // can be used to reconstruct the state at that point. // If any configuration changes have been made since the last compaction, // the result of the last ApplyConfChange must be passed in. diff --git a/rafthttp/transport.go b/rafthttp/transport.go index fd8b41528..26a6b0403 100644 --- a/rafthttp/transport.go +++ b/rafthttp/transport.go @@ -299,12 +299,12 @@ func (t *Transport) SendSnapshot(m snap.Message) { p.sendSnap(m) } +// Pausable is a testing interface for pausing transport traffic. type Pausable interface { Pause() Resume() } -// for testing func (t *Transport) Pause() { for _, p := range t.peers { p.(Pausable).Pause() diff --git a/storage/backend/backend.go b/storage/backend/backend.go index 5a6e7c3ba..bf6f3b35e 100644 --- a/storage/backend/backend.go +++ b/storage/backend/backend.go @@ -107,7 +107,7 @@ func (b *backend) BatchTx() BatchTx { return b.batchTx } -// force commit the current batching tx. +// ForceCommit forces the current batching tx to commit. func (b *backend) ForceCommit() { b.batchTx.Commit() } diff --git a/storage/backend/batch_tx.go b/storage/backend/batch_tx.go index 51eb02f80..d4439a878 100644 --- a/storage/backend/batch_tx.go +++ b/storage/backend/batch_tx.go @@ -55,7 +55,7 @@ func (t *batchTx) UnsafeCreateBucket(name []byte) { t.pending++ } -// before calling unsafePut, the caller MUST hold the lock on tx. +// UnsafePut must be called holding the lock on the tx. func (t *batchTx) UnsafePut(bucketName []byte, key []byte, value []byte) { bucket := t.tx.Bucket(bucketName) if bucket == nil { @@ -67,7 +67,7 @@ func (t *batchTx) UnsafePut(bucketName []byte, key []byte, value []byte) { t.pending++ } -// before calling unsafeRange, the caller MUST hold the lock on tx. +// UnsafeRange must be called holding the lock on the tx. func (t *batchTx) UnsafeRange(bucketName []byte, key, endKey []byte, limit int64) (keys [][]byte, vs [][]byte) { bucket := t.tx.Bucket(bucketName) if bucket == nil { @@ -94,7 +94,7 @@ func (t *batchTx) UnsafeRange(bucketName []byte, key, endKey []byte, limit int64 return keys, vs } -// before calling unsafeDelete, the caller MUST hold the lock on tx. +// UnsafeDelete must be called holding the lock on the tx. func (t *batchTx) UnsafeDelete(bucketName []byte, key []byte) { bucket := t.tx.Bucket(bucketName) if bucket == nil { diff --git a/storage/watcher.go b/storage/watcher.go index a29e36490..b1507fce3 100644 --- a/storage/watcher.go +++ b/storage/watcher.go @@ -85,6 +85,7 @@ type watchStream struct { cancels map[WatchID]cancelFunc } +// Watch creates a new watcher in the stream and returns its WatchID. // TODO: return error if ws is closed? func (ws *watchStream) Watch(key []byte, prefix bool, startRev int64) WatchID { ws.mu.Lock() diff --git a/store/node_extern.go b/store/node_extern.go index e26f857bc..29f5aeda6 100644 --- a/store/node_extern.go +++ b/store/node_extern.go @@ -102,6 +102,7 @@ func (eNode *NodeExtern) Clone() *NodeExtern { type NodeExterns []*NodeExtern // interfaces for sorting + func (ns NodeExterns) Len() int { return len(ns) } diff --git a/store/stats.go b/store/stats.go index 96926d9c0..a3c76796d 100644 --- a/store/stats.go +++ b/store/stats.go @@ -40,30 +40,37 @@ const ( type Stats struct { // Number of get requests + GetSuccess uint64 `json:"getsSuccess"` GetFail uint64 `json:"getsFail"` // Number of sets requests + SetSuccess uint64 `json:"setsSuccess"` SetFail uint64 `json:"setsFail"` // Number of delete requests + DeleteSuccess uint64 `json:"deleteSuccess"` DeleteFail uint64 `json:"deleteFail"` // Number of update requests + UpdateSuccess uint64 `json:"updateSuccess"` UpdateFail uint64 `json:"updateFail"` // Number of create requests + CreateSuccess uint64 `json:"createSuccess"` CreateFail uint64 `json:"createFail"` // Number of testAndSet requests + CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"` CompareAndSwapFail uint64 `json:"compareAndSwapFail"` // Number of compareAndDelete requests + CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"` CompareAndDeleteFail uint64 `json:"compareAndDeleteFail"` diff --git a/store/store.go b/store/store.go index 72d466e01..d959a509d 100644 --- a/store/store.go +++ b/store/store.go @@ -81,7 +81,7 @@ type store struct { readonlySet types.Set } -// The given namespaces will be created as initial directories in the returned store. +// New creates a store where the given namespaces will be created as initial directories. func New(namespaces ...string) Store { s := newStore(namespaces...) s.clock = clockwork.NewRealClock() @@ -107,7 +107,7 @@ func (s *store) Version() int { return s.CurrentVersion } -// Retrieves current of the store +// Index retrieves the current index of the store. func (s *store) Index() uint64 { s.worldLock.RLock() defer s.worldLock.RUnlock()