| 3258 | } |
| 3259 | |
| 3260 | void HandleClientSetTTL(const std::vector<std::string>& parts, |
| 3261 | ::fedb::client::TabletClient* client) { |
| 3262 | if (parts.size() < 5) { |
| 3263 | std::cout << "Bad setttl format, eg setttl tid pid type ttl [index_name]" |
| 3264 | << std::endl; |
| 3265 | return; |
| 3266 | } |
| 3267 | std::string index_name; |
| 3268 | try { |
| 3269 | uint64_t abs_ttl = 0; |
| 3270 | uint64_t lat_ttl = 0; |
| 3271 | ::fedb::type::TTLType type = ::fedb::type::kLatestTime; |
| 3272 | if (parts[3] == "absolute") { |
| 3273 | type = ::fedb::type::TTLType::kAbsoluteTime; |
| 3274 | abs_ttl = boost::lexical_cast<uint64_t>(parts[4]); |
| 3275 | if (parts.size() == 6) { |
| 3276 | index_name = parts[5]; |
| 3277 | } else if (parts.size() > 6) { |
| 3278 | std::cout |
| 3279 | << "Bad setttl format, eg setttl tid pid type ttl [index_name]" |
| 3280 | << std::endl; |
| 3281 | return; |
| 3282 | } |
| 3283 | } else if (parts[3] == "absandlat") { |
| 3284 | type = ::fedb::type::TTLType::kAbsAndLat; |
| 3285 | abs_ttl = boost::lexical_cast<uint64_t>(parts[4]); |
| 3286 | lat_ttl = boost::lexical_cast<uint64_t>(parts[5]); |
| 3287 | if (parts.size() == 7) { |
| 3288 | index_name = parts[6]; |
| 3289 | } |
| 3290 | } else if (parts[3] == "absorlat") { |
| 3291 | type = ::fedb::type::TTLType::kAbsOrLat; |
| 3292 | abs_ttl = boost::lexical_cast<uint64_t>(parts[4]); |
| 3293 | lat_ttl = boost::lexical_cast<uint64_t>(parts[5]); |
| 3294 | if (parts.size() == 7) { |
| 3295 | index_name = parts[6]; |
| 3296 | } |
| 3297 | } else if (parts[3] == "latest") { |
| 3298 | lat_ttl = boost::lexical_cast<uint64_t>(parts[4]); |
| 3299 | if (parts.size() == 6) { |
| 3300 | index_name = parts[5]; |
| 3301 | } else if (parts.size() > 6) { |
| 3302 | std::cout |
| 3303 | << "Bad setttl format, eg setttl tid pid type ttl [index_name]" |
| 3304 | << std::endl; |
| 3305 | return; |
| 3306 | } |
| 3307 | } |
| 3308 | bool ok = client->UpdateTTL(boost::lexical_cast<uint32_t>(parts[1]), |
| 3309 | boost::lexical_cast<uint32_t>(parts[2]), |
| 3310 | type, abs_ttl, lat_ttl, index_name); |
| 3311 | if (ok) { |
| 3312 | std::cout << "Set ttl ok !" << std::endl; |
| 3313 | } else { |
| 3314 | std::cout << "Set ttl failed! " << std::endl; |
| 3315 | } |
| 3316 | } catch (std::exception const& e) { |
| 3317 | std::cout << "Invalid args tid and pid should be uint32_t" << std::endl; |
no test coverage detected