| 128 | } |
| 129 | |
| 130 | void CleanThread::CleanLock(const int paxos_group_id, const uint64_t now, |
| 131 | int &nr_group_key, int &nr_group_clean_key) { |
| 132 | if (!impl_->lock->GetNode()->IsIMMaster(paxos_group_id)) |
| 133 | return; |
| 134 | |
| 135 | auto &¤t_map(impl_->lock->GetLockMgr()->map(paxos_group_id)); |
| 136 | int i{0}; |
| 137 | while (current_map.GetSize() > i && |
| 138 | impl_->lock->GetLockOption()->max_clean_lock_num > i) { |
| 139 | ++i; |
| 140 | |
| 141 | // 1. make args |
| 142 | proto::LockPaxosArgs args; |
| 143 | |
| 144 | // begin mutex |
| 145 | { |
| 146 | |
| 147 | // ensure not acquiring lock or geting lock info |
| 148 | comm::utils::MutexGuard guard(current_map.mutex()); |
| 149 | |
| 150 | string current_clean_key; |
| 151 | current_map.CleanForward(current_clean_key); |
| 152 | proto::LocalLockInfo local_lock_info; |
| 153 | comm::RetCode ret{current_map.Get(current_clean_key, local_lock_info)}; |
| 154 | if (comm::RetCode::RET_ERR_IGNORE == ret) { |
| 155 | QLInfo("paxos_group_id %d lock_key \"%s\" Get ignore", |
| 156 | paxos_group_id, current_clean_key.c_str()); |
| 157 | |
| 158 | continue; |
| 159 | } |
| 160 | |
| 161 | ++nr_group_key; |
| 162 | |
| 163 | if (comm::RetCode::RET_OK != ret) { |
| 164 | QLErr("paxos_group_id %d lock_key \"%s\" Get err %d", |
| 165 | paxos_group_id, current_clean_key.c_str(), ret); |
| 166 | |
| 167 | continue; |
| 168 | } |
| 169 | |
| 170 | // add expired lock key |
| 171 | if (now > local_lock_info.expire_time_ms()) { |
| 172 | // TODO: use move? |
| 173 | auto &&lock_info(args.mutable_acquire_lock_req()->mutable_lock_info()); |
| 174 | lock_info->set_lock_key(current_clean_key); |
| 175 | lock_info->set_version(local_lock_info.version()); |
| 176 | lock_info->set_client_id(CLIENT_ID_CLEAN_THREAD); |
| 177 | lock_info->set_lease_time_ms(0); |
| 178 | } |
| 179 | } |
| 180 | // end mutex |
| 181 | |
| 182 | // 2. serialize args to paxos value |
| 183 | string buf; |
| 184 | args.SerializeToString(&buf); |
| 185 | |
| 186 | // 3. send to paxos |
| 187 | LockContext lc; |
nothing calls this directly
no test coverage detected