Created
January 26, 2019 00:45
-
-
Save dotnwat/5bae1e115c5410a66bb0f87f0d0426f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std::string prefix(ZLOG_ENTRY_KEY_PREFIX); | |
std::string start_after; | |
while (true) { | |
std::set<std::string> keys; | |
ret = ioctx_->omap_get_keys(oid, start_after, 1, &keys); | |
if (ret < 0) { | |
return ret; | |
} | |
if (keys.empty()) { | |
break; | |
} | |
start_after = *keys.rbegin(); | |
for (auto it = keys.begin(); it != keys.end();) { | |
auto pos = it->find(prefix); | |
if (pos == std::string::npos) { | |
it = keys.erase(it); | |
continue; | |
} | |
if (pos != 0) { | |
std::cerr << "invalid" << std::endl; | |
return -EIO; | |
} | |
auto spos = it->substr(prefix.length(), std::string::npos); | |
uint64_t ipos; | |
try { | |
ipos = boost::lexical_cast<uint64_t>(spos); | |
} catch (const boost::bad_lexical_cast& e) { | |
return -EIO; | |
} | |
// normally we could skip, but trim_full should imply this property | |
if (ipos > position) { | |
return -EIO; | |
} | |
it++; | |
} | |
if (keys.empty()) { | |
continue; | |
} | |
ret = ioctx_->omap_rm_keys(oid, keys); | |
if (ret) { | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment