acelyc111 commented on code in PR #2185:
URL:
https://github.com/apache/incubator-pegasus/pull/2185#discussion_r1929712790
##########
src/server/pegasus_write_service_impl.h:
##########
@@ -569,6 +663,83 @@ class pegasus_write_service::impl : public
dsn::replication::replica_base
return raw_key;
}
+ // Calculate expire timestamp in seconds for the keys not contained in the
storage
+ // according to `req`.
+ template <typename TRequest>
+ static inline int32_t calc_expire_on_non_existent(const TRequest &req)
+ {
+ return req.expire_ts_seconds > 0 ? req.expire_ts_seconds : 0;
+ }
+
+ // Calculate new expire timestamp in seconds for the keys contained in the
storage
+ // according to `req` and their current expire timestamp in `get_ctx`.
+ template <typename TRequest>
+ static inline int32_t calc_expire_on_existing(const TRequest &req,
+ const db_get_context
&get_ctx)
+ {
+ if (req.expire_ts_seconds == 0) {
+ // Still use current expire timestamp of the existing key as the
new value.
+ return static_cast<int32_t>(get_ctx.expire_ts);
+ }
+
+ if (req.expire_ts_seconds < 0) {
+ // Reset expire timestamp to 0.
+ return 0;
+ }
+
+ return req.expire_ts_seconds;
+ }
+
+ // Build a single-put request by provided int64 value.
+ static inline void make_idempotent_request(const dsn::blob &key,
+ int64_t value,
+ int32_t expire_ts_seconds,
+ dsn::apps::update_type::type
type,
+ dsn::apps::update_request
&update)
+ {
+ update.key = key;
+ update.value = dsn::blob::create_from_numeric(value);
+ update.expire_ts_seconds = expire_ts_seconds;
+ update.__set_type(type);
+ }
+
+ // Build corresponding single-put request for a incr request, and return
current status
Review Comment:
```suggestion
// Build corresponding single-put request for an incr request, and
return current status
```
##########
src/server/pegasus_write_service_impl.h:
##########
@@ -569,6 +663,83 @@ class pegasus_write_service::impl : public
dsn::replication::replica_base
return raw_key;
}
+ // Calculate expire timestamp in seconds for the keys not contained in the
storage
+ // according to `req`.
+ template <typename TRequest>
+ static inline int32_t calc_expire_on_non_existent(const TRequest &req)
+ {
+ return req.expire_ts_seconds > 0 ? req.expire_ts_seconds : 0;
+ }
+
+ // Calculate new expire timestamp in seconds for the keys contained in the
storage
+ // according to `req` and their current expire timestamp in `get_ctx`.
+ template <typename TRequest>
+ static inline int32_t calc_expire_on_existing(const TRequest &req,
+ const db_get_context
&get_ctx)
+ {
+ if (req.expire_ts_seconds == 0) {
+ // Still use current expire timestamp of the existing key as the
new value.
+ return static_cast<int32_t>(get_ctx.expire_ts);
+ }
+
+ if (req.expire_ts_seconds < 0) {
Review Comment:
When will `expire_ts_seconds` to be less than 0?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]