Commit fd00f12a authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Add locator for expiration events

parent 14ca1e59
Pipeline #423022 passed with stages
in 33 minutes and 1 second
......@@ -31,11 +31,13 @@
namespace quarkdb {
using KeyBuffer = SmartBuffer<512>;
using ClockValue = uint64_t;
enum class InternalKeyType : char {
kInternal = '_',
kConfiguration = '~',
kDescriptor = '!'
kDescriptor = '!',
kExpirationEvent = '@'
};
class DescriptorLocator {
......@@ -264,6 +266,28 @@ private:
KeyBuffer keyBuffer;
};
class ExpirationEventLocator {
public:
ExpirationEventLocator(ClockValue deadline, const std::string &redisKey) {
reset(deadline, redisKey);
}
void reset(ClockValue deadline, const std::string &redisKey) {
keyBuffer.resize(1 + sizeof(ClockValue) + redisKey.size());
keyBuffer[0] = char(InternalKeyType::kExpirationEvent);
unsignedIntToBinaryString(deadline, keyBuffer.data() + 1);
memcpy(keyBuffer.data()+1+sizeof(ClockValue), redisKey.data(), redisKey.size());
}
rocksdb::Slice toSlice() {
return keyBuffer.toSlice();
}
private:
KeyBuffer keyBuffer;
};
}
#endif
......@@ -881,6 +881,11 @@ TEST(LeaseLocator, BasicSanity) {
ASSERT_EQ(locator2.toSlice().ToString(), "fmy#key");
}
TEST(ExpirationEventLocator, BasicSanity) {
ExpirationEventLocator locator1(ClockValue(123u), "some-key");
ASSERT_EQ(locator1.toSlice().ToString(), SSTR("@" << unsignedIntToBinaryString(123u) << "some-key"));
}
TEST(PatternMatching, BasicSanity) {
ASSERT_EQ(extractPatternPrefix("abc*"), "abc");
ASSERT_EQ(extractPatternPrefix("abc"), "abc");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment