| 321 | //} |
| 322 | |
| 323 | comm::RetCode LockDb::Put(const string &k, const proto::LocalLockInfo &v, const bool sync) { |
| 324 | if (0 >= k.size()) { |
| 325 | QLErr("key \"%s\" invalid", k.c_str()); |
| 326 | |
| 327 | return comm::RetCode::RET_ERR_KEY; |
| 328 | } |
| 329 | |
| 330 | if (Type::MAP == type_) { |
| 331 | // TODO: emplace? |
| 332 | map_[k] = v; |
| 333 | QLVerb("key \"%s\" ver %llu", k.c_str(), v.version()); |
| 334 | } else if (Type::LEVELDB == type_) { |
| 335 | string vstr; |
| 336 | // TODO: Not copy? |
| 337 | proto::LocalLockInfo v2 = v; |
| 338 | v2.clear_expire_time_ms(); |
| 339 | bool succ{v2.SerializeToString(&vstr)}; |
| 340 | if (!succ) { |
| 341 | QLErr("SerializeToString err"); |
| 342 | |
| 343 | return comm::RetCode::RET_ERR_LOGIC; |
| 344 | } |
| 345 | QLVerb("key \"%s\" ver %llu", k.c_str(), v.version()); |
| 346 | |
| 347 | return Put(k, vstr, sync); |
| 348 | } else { |
| 349 | return comm::RetCode::RET_ERR_NO_IMPL; |
| 350 | } |
| 351 | |
| 352 | return comm::RetCode::RET_OK; |
| 353 | } |
| 354 | |
| 355 | comm::RetCode LockDb::Put(const string &k, const string &vstr, const bool sync) { |
| 356 | if (0 >= k.size()) { |
no test coverage detected