From fad9bdc3e1cd882b38046541ce0549ea9fe3f7ff Mon Sep 17 00:00:00 2001 From: Jared Hulbert Date: Fri, 8 Jul 2016 11:20:47 -0700 Subject: [PATCH] etcdserver: atomic access alignment Most fields accessed with sync/atomic functions are 64bit aligned, but a couple are not. This makes comments out of date and therefore misleading. Affected fields reordered, comments scrubbed and updated. --- etcdserver/server.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/etcdserver/server.go b/etcdserver/server.go index dd232d5ef..d2324e57c 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -154,13 +154,13 @@ type Server interface { // EtcdServer is the production implementation of the Server interface type EtcdServer struct { - // r and inflightSnapshots must be the first elements to keep 64-bit alignment for atomic - // access to fields - - // count the number of inflight snapshots. - // MUST use atomic operation to access this field. - inflightSnapshots int64 - Cfg *ServerConfig + // inflightSnapshots holds count the number of snapshots currently inflight. + inflightSnapshots int64 // must use atomic operations to access; keep 64-bit aligned. + appliedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. + // consistIndex used to hold the offset of current executing entry + // It is initialized to 0 before executing any entry. + consistIndex consistentIndex // must use atomic operations to access; keep 64-bit aligned. + Cfg *ServerConfig readych chan struct{} r raftNode @@ -195,10 +195,6 @@ type EtcdServer struct { // compactor is used to auto-compact the KV. compactor *compactor.Periodic - // consistent index used to hold the offset of current executing entry - // It is initialized to 0 before executing any entry. - consistIndex consistentIndex - // peerRt used to send requests (version, lease) to peers. peerRt http.RoundTripper reqIDGen *idutil.Generator @@ -212,8 +208,6 @@ type EtcdServer struct { // wg is used to wait for the go routines that depends on the server state // to exit when stopping the server. wg sync.WaitGroup - - appliedIndex uint64 } // NewServer creates a new EtcdServer from the supplied configuration. The