@@ -160,7 +160,7 @@ Status TSDescriptor::Register(const NodeInstancePB& instance,
160160 LocationCache* location_cache) {
161161 // Do basic registration work under the lock.
162162 {
163- std::lock_guard<simple_spinlock > l (lock_);
163+ std::lock_guard<rw_spinlock > l (lock_);
164164 RETURN_NOT_OK (RegisterUnlocked (instance, registration));
165165 }
166166
@@ -181,7 +181,7 @@ Status TSDescriptor::Register(const NodeInstancePB& instance,
181181 // Assign the location under the lock if location resolution succeeds. If
182182 // it fails, log the error.
183183 if (s.ok ()) {
184- std::lock_guard<simple_spinlock > l (lock_);
184+ std::lock_guard<rw_spinlock > l (lock_);
185185 location_.emplace (std::move (location));
186186 } else {
187187 KLOG_EVERY_N_SECS (ERROR, 60 ) << Substitute (
@@ -195,13 +195,13 @@ Status TSDescriptor::Register(const NodeInstancePB& instance,
195195}
196196
197197void TSDescriptor::UpdateHeartbeatTime () {
198- std::lock_guard<simple_spinlock > l (lock_);
198+ std::lock_guard<rw_spinlock > l (lock_);
199199 last_heartbeat_ = MonoTime::Now ();
200200}
201201
202202MonoDelta TSDescriptor::TimeSinceHeartbeat () const {
203203 MonoTime now (MonoTime::Now ());
204- std::lock_guard<simple_spinlock > l (lock_);
204+ shared_lock<rw_spinlock > l (lock_);
205205 return now - last_heartbeat_;
206206}
207207
@@ -210,7 +210,7 @@ bool TSDescriptor::PresumedDead() const {
210210}
211211
212212int64_t TSDescriptor::latest_seqno () const {
213- std::lock_guard<simple_spinlock > l (lock_);
213+ shared_lock<rw_spinlock > l (lock_);
214214 return latest_seqno_;
215215}
216216
@@ -232,33 +232,34 @@ void TSDescriptor::DecayRecentReplicaCreationsUnlocked() {
232232}
233233
234234void TSDescriptor::IncrementRecentReplicaCreations () {
235- std::lock_guard<simple_spinlock > l (lock_);
235+ std::lock_guard<rw_spinlock > l (lock_);
236236 DecayRecentReplicaCreationsUnlocked ();
237237 recent_replica_creations_ += 1 ;
238238}
239239
240240double TSDescriptor::RecentReplicaCreations () {
241- std::lock_guard<simple_spinlock> l (lock_);
241+ // NOTE: not a shared lock because of the "Decay" side effect.
242+ std::lock_guard<rw_spinlock> l (lock_);
242243 DecayRecentReplicaCreationsUnlocked ();
243244 return recent_replica_creations_;
244245}
245246
246247void TSDescriptor::GetRegistration (ServerRegistrationPB* reg) const {
247- std::lock_guard<simple_spinlock > l (lock_);
248+ shared_lock<rw_spinlock > l (lock_);
248249 CHECK (registration_) << " No registration" ;
249250 CHECK_NOTNULL (reg)->CopyFrom (*registration_);
250251}
251252
252253void TSDescriptor::GetNodeInstancePB (NodeInstancePB* instance_pb) const {
253- std::lock_guard<simple_spinlock > l (lock_);
254+ shared_lock<rw_spinlock > l (lock_);
254255 instance_pb->set_permanent_uuid (permanent_uuid_);
255256 instance_pb->set_instance_seqno (latest_seqno_);
256257}
257258
258259Status TSDescriptor::ResolveSockaddr (Sockaddr* addr, string* host) const {
259260 vector<HostPort> hostports;
260261 {
261- std::lock_guard<simple_spinlock > l (lock_);
262+ shared_lock<rw_spinlock > l (lock_);
262263 for (const HostPortPB& addr : registration_->rpc_addresses ()) {
263264 hostports.emplace_back (addr.host (), addr.port ());
264265 }
@@ -293,7 +294,7 @@ Status TSDescriptor::ResolveSockaddr(Sockaddr* addr, string* host) const {
293294Status TSDescriptor::GetTSAdminProxy (const shared_ptr<rpc::Messenger>& messenger,
294295 shared_ptr<tserver::TabletServerAdminServiceProxy>* proxy) {
295296 {
296- std::lock_guard<simple_spinlock > l (lock_);
297+ shared_lock<rw_spinlock > l (lock_);
297298 if (ts_admin_proxy_) {
298299 *proxy = ts_admin_proxy_;
299300 return Status::OK ();
@@ -304,7 +305,7 @@ Status TSDescriptor::GetTSAdminProxy(const shared_ptr<rpc::Messenger>& messenger
304305 string host;
305306 RETURN_NOT_OK (ResolveSockaddr (&addr, &host));
306307
307- std::lock_guard<simple_spinlock > l (lock_);
308+ std::lock_guard<rw_spinlock > l (lock_);
308309 if (!ts_admin_proxy_) {
309310 ts_admin_proxy_.reset (new tserver::TabletServerAdminServiceProxy (
310311 messenger, addr, std::move (host)));
@@ -316,7 +317,7 @@ Status TSDescriptor::GetTSAdminProxy(const shared_ptr<rpc::Messenger>& messenger
316317Status TSDescriptor::GetConsensusProxy (const shared_ptr<rpc::Messenger>& messenger,
317318 shared_ptr<consensus::ConsensusServiceProxy>* proxy) {
318319 {
319- std::lock_guard<simple_spinlock > l (lock_);
320+ shared_lock<rw_spinlock > l (lock_);
320321 if (consensus_proxy_) {
321322 *proxy = consensus_proxy_;
322323 return Status::OK ();
@@ -327,7 +328,7 @@ Status TSDescriptor::GetConsensusProxy(const shared_ptr<rpc::Messenger>& messeng
327328 string host;
328329 RETURN_NOT_OK (ResolveSockaddr (&addr, &host));
329330
330- std::lock_guard<simple_spinlock > l (lock_);
331+ std::lock_guard<rw_spinlock > l (lock_);
331332 if (!consensus_proxy_) {
332333 consensus_proxy_.reset (new consensus::ConsensusServiceProxy (
333334 messenger, addr, std::move (host)));
@@ -337,7 +338,7 @@ Status TSDescriptor::GetConsensusProxy(const shared_ptr<rpc::Messenger>& messeng
337338}
338339
339340string TSDescriptor::ToString () const {
340- std::lock_guard<simple_spinlock > l (lock_);
341+ shared_lock<rw_spinlock > l (lock_);
341342 const auto & addr = registration_->rpc_addresses (0 );
342343 return Substitute (" $0 ($1:$2)" , permanent_uuid_, addr.host (), addr.port ());
343344}
0 commit comments