From 528788341a67cf09e94ced56dafc8dbd09904b7b Mon Sep 17 00:00:00 2001 From: Brian Nichols Date: Wed, 20 Mar 2024 19:50:06 -0400 Subject: [PATCH] CLIENT-2817 Support read_touch_ttl_percent in as_policy_read, as_policy_operate, as_policy_batch and as_policy_batch_read. Requires server version 7.1+. --- src/include/aerospike/as_command.h | 7 +- src/include/aerospike/as_policy.h | 101 +++++++++++++++++++++++++-- src/main/aerospike/aerospike_batch.c | 69 ++++++++++-------- src/main/aerospike/aerospike_key.c | 30 ++++++-- src/main/aerospike/aerospike_query.c | 2 +- src/main/aerospike/aerospike_scan.c | 2 +- src/main/aerospike/as_command.c | 13 ++-- src/test/aerospike_batch/batch.c | 56 ++++++++++++++- src/test/aerospike_key/key_basics.c | 61 +++++++++++++++- src/test/aerospike_key/key_operate.c | 63 ++++++++++++++++- 10 files changed, 351 insertions(+), 53 deletions(-) diff --git a/src/include/aerospike/as_command.h b/src/include/aerospike/as_command.h index f26f68c87..ad13a6d0e 100644 --- a/src/include/aerospike/as_command.h +++ b/src/include/aerospike/as_command.h @@ -366,8 +366,8 @@ as_command_write_header_write( uint8_t* as_command_write_header_read( uint8_t* cmd, const as_policy_base* policy, as_policy_read_mode_ap read_mode_ap, - as_policy_read_mode_sc read_mode_sc, uint32_t timeout, uint16_t n_fields, uint16_t n_bins, - uint8_t read_attr, uint8_t write_attr, uint8_t info_attr + as_policy_read_mode_sc read_mode_sc, int read_ttl, uint32_t timeout, uint16_t n_fields, + uint16_t n_bins, uint8_t read_attr, uint8_t write_attr, uint8_t info_attr ); /** @@ -377,7 +377,8 @@ as_command_write_header_read( uint8_t* as_command_write_header_read_header( uint8_t* cmd, const as_policy_base* policy, as_policy_read_mode_ap read_mode_ap, - as_policy_read_mode_sc read_mode_sc, uint16_t n_fields, uint16_t n_bins, uint8_t read_attr + as_policy_read_mode_sc read_mode_sc, int read_ttl, uint16_t n_fields, uint16_t n_bins, + uint8_t read_attr ); /** diff --git a/src/include/aerospike/as_policy.h b/src/include/aerospike/as_policy.h index 61c41abf5..a107ae773 100644 --- a/src/include/aerospike/as_policy.h +++ b/src/include/aerospike/as_policy.h @@ -576,6 +576,28 @@ typedef struct as_policy_read_s { */ as_policy_read_mode_sc read_mode_sc; + /** + * Determine how record TTL (time to live) is affected on reads. When enabled, the server can + * efficiently operate as a read-based LRU cache where the least recently used records are expired. + * The value is expressed as a percentage of the TTL sent on the most recent write such that a read + * within this interval of the record’s end of life will generate a touch. + * + * For example, if the most recent write had a TTL of 10 hours and read_touch_ttl_percent is set to + * 80, the next read within 8 hours of the record's end of life (equivalent to 2 hours after the most + * recent write) will result in a touch, resetting the TTL to another 10 hours. + * + * Values: + * + *
  • + * + * Default: 0 + */ + int read_touch_ttl_percent; + /** * Should raw bytes representing a list or map be deserialized to as_list or as_map. * Set to false for backup programs that just need access to raw bytes. @@ -768,8 +790,9 @@ typedef struct as_policy_operate_s { /** * The default time-to-live (expiration) of the record in seconds. This field will - * only be used if "as_operations.ttl" is set to AS_RECORD_CLIENT_DEFAULT_TTL. The - * as_operations instance is passed in to operate functions along with as_policy_operate. + * only be used if one or more of the operations is a write operation and if "as_operations.ttl" + * is set to AS_RECORD_CLIENT_DEFAULT_TTL. The as_operations instance is passed in to + * operate functions along with as_policy_operate. * * There are also special values that can be set in the record ttl: *