Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify expired flow in StringFamily::Set #3643

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/server/generic_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,7 @@ OpResult<uint32_t> OpStick(const OpArgs& op_args, const ShardArgs& keys) {
return res;
}

} // namespace

OpResult<uint32_t> GenericFamily::OpDel(const OpArgs& op_args, const ShardArgs& keys) {
OpResult<uint32_t> OpDel(const OpArgs& op_args, const ShardArgs& keys) {
DVLOG(1) << "Del: " << keys.Front();
auto& db_slice = op_args.GetDbSlice();

Expand All @@ -727,6 +725,8 @@ OpResult<uint32_t> GenericFamily::OpDel(const OpArgs& op_args, const ShardArgs&
return res;
}

} // namespace

void GenericFamily::Del(CmdArgList args, ConnectionContext* cntx) {
Transaction* transaction = cntx->transaction;
VLOG(1) << "Del " << ArgS(args, 0);
Expand Down
1 change: 0 additions & 1 deletion src/server/generic_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class GenericFamily {

// Accessed by Service::Exec and Service::Watch as an utility.
static OpResult<uint32_t> OpExists(const OpArgs& op_args, const ShardArgs& keys);
static OpResult<uint32_t> OpDel(const OpArgs& op_args, const ShardArgs& keys);

private:
static void Del(CmdArgList args, ConnectionContext* cntx);
Expand Down
17 changes: 8 additions & 9 deletions src/server/string_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ OpStatus SetCmd::SetExisting(const SetParams& params, DbSlice::Iterator it,
uint64_t at_ms =
params.expire_after_ms ? params.expire_after_ms + op_args_.db_cntx.time_now_ms : 0;

if (params.expire_now) {
// past time
at_ms = op_args_.db_cntx.time_now_ms - 1;
}

if (!(params.flags & SET_KEEP_EXPIRE)) {
if (at_ms) { // Command has an expiry paramater.
if (IsValid(e_it)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do we delete the entry in this flow? can you point to the flow

Expand Down Expand Up @@ -788,17 +793,11 @@ void StringFamily::Set(CmdArgList args, ConnectionContext* cntx) {
if (abs_ms < 0)
return cntx->SendError(InvalidExpireTime("set"));

// Remove existed key if the key is expired already
if (rel_ms < 0) {
cntx->transaction->ScheduleSingleHop([key](const Transaction* tx, EngineShard* es) {
ShardArgs args = tx->GetShardArgs(es->shard_id());
GenericFamily::OpDel(tx->GetOpArgs(es), args);
return OpStatus::OK;
});
return builder->SendStored();
sparams.expire_now = true;
} else {
tie(sparams.expire_after_ms, ignore) = expiry.Calculate(now_ms, true);
}

tie(sparams.expire_after_ms, ignore) = expiry.Calculate(now_ms, true);
} else if (parser.Check("_MCFLAGS")) {
sparams.memcache_flags = parser.Next<uint32_t>();
} else {
Expand Down
1 change: 1 addition & 0 deletions src/server/string_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SetCmd {
uint16_t flags = SET_ALWAYS;
uint32_t memcache_flags = 0;
uint64_t expire_after_ms = 0; // Relative value based on now. 0 means no expiration.
bool expire_now = false; // Item will be added but as expired
StringValue* prev_val = nullptr; // If set, previous value is stored at pointer

constexpr bool IsConditionalSet() const {
Expand Down
Loading