Skip to content

Commit

Permalink
CLIENT-2647 Support default ttl in as_policy_write, as_policy_batch_w…
Browse files Browse the repository at this point in the history
…rite, as_policy_operate and as_policy_scan. If "as_record.ttl", "as_operations.ttl", "as_scan.ttl" or "as_query.ttl" is AS_RECORD_CLIENT_DEFAULT_TTL, the corresponding default client policy ttl will be used.
  • Loading branch information
BrianNichols committed Oct 31, 2023
1 parent 15bb8f8 commit 600d2d2
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 68 deletions.
10 changes: 9 additions & 1 deletion src/include/aerospike/as_operations.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 Aerospike, Inc.
* Copyright 2008-2023 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -260,6 +260,14 @@ typedef struct as_operations_s {

/**
* The time-to-live (expiration) of the record in seconds.
*
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* <li>AS_RECORD_CLIENT_DEFAULT_TTL: Use the default client ttl in as_policy_operate.</li>
* </ul>
*/
uint32_t ttl;

Expand Down
99 changes: 76 additions & 23 deletions src/include/aerospike/as_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,20 @@ typedef struct as_policy_write_s {
*/
as_policy_exists exists;

/**
* The default time-to-live (expiration) of the record in seconds. This field will
* only be used if "as_record.ttl" is set to AS_RECORD_CLIENT_DEFAULT_TTL. The
* as_record instance is passed in to write functions along with as_policy_write.
*
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* </ul>
*/
uint32_t ttl;

/**
* Minimum record size beyond which it is compressed and sent to the server.
*/
Expand Down Expand Up @@ -636,18 +650,15 @@ typedef struct as_policy_apply_s {
as_policy_commit_level commit_level;

/**
* The time-to-live (expiration) of the record in seconds.
* There are also special values that can be set in the record TTL:
* (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the
* record will adopt the default TTL value from the namespace.
* (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int)
* (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record
* will get an internal "void_time" of zero, and thus will never expire.
* (*) 0xFFFFFFFE (also, -2 in a signed 32 bit int)
* (defined as AS_RECORD_NO_CHANGE_TTL), which means that the record
* ttl will not change when the record is updated.
* The time-to-live (expiration) of the record in seconds. Note that ttl
* is only used on write/update calls.
*
* Note that the TTL value will be employed ONLY on write/update calls.
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* </ul>
*/
uint32_t ttl;

Expand Down Expand Up @@ -712,6 +723,20 @@ typedef struct as_policy_operate_s {
*/
as_policy_exists exists;

/**
* 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.
*
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* </ul>
*/
uint32_t ttl;

/**
* 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.
Expand Down Expand Up @@ -980,6 +1005,20 @@ typedef struct as_policy_batch_write_s {
*/
as_policy_exists exists;

/**
* 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 batch write functions along with as_policy_batch_write.
*
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* </ul>
*/
uint32_t ttl;

/**
* If the transaction results in a record deletion, leave a tombstone for the record.
* This prevents deleted records from reappearing after node failures.
Expand Down Expand Up @@ -1021,18 +1060,15 @@ typedef struct as_policy_batch_apply_s {
as_policy_commit_level commit_level;

/**
* The time-to-live (expiration) of the record in seconds.
* There are also special values that can be set in the record TTL:
* (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the
* record will adopt the default TTL value from the namespace.
* (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int)
* (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record
* will get an internal "void_time" of zero, and thus will never expire.
* (*) 0xFFFFFFFE (also, -2 in a signed 32 bit int)
* (defined as AS_RECORD_NO_CHANGE_TTL), which means that the record
* ttl will not change when the record is updated.
* The time-to-live (expiration) of the record in seconds. Note that ttl
* is only used on write/update calls.
*
* Note that the TTL value will be employed ONLY on write/update calls.
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* </ul>
*/
uint32_t ttl;

Expand Down Expand Up @@ -1185,6 +1221,19 @@ typedef struct as_policy_scan_s {
*/
as_policy_replica replica;

/**
* The default time-to-live (expiration) of the record in seconds. This field will only be
* used on background scan writes if "as_scan.ttl" is set to AS_RECORD_CLIENT_DEFAULT_TTL.
*
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* </ul>
*/
uint32_t ttl;

/**
* If the transaction results in a record deletion, leave a tombstone for the record.
* This prevents deleted records from reappearing after node failures.
Expand Down Expand Up @@ -1426,6 +1475,7 @@ as_policy_write_init(as_policy_write* p)
p->commit_level = AS_POLICY_COMMIT_LEVEL_DEFAULT;
p->gen = AS_POLICY_GEN_DEFAULT;
p->exists = AS_POLICY_EXISTS_DEFAULT;
p->ttl = 0; // AS_RECORD_DEFAULT_TTL
p->compression_threshold = AS_POLICY_COMPRESSION_THRESHOLD_DEFAULT;
p->durable_delete = false;
return p;
Expand Down Expand Up @@ -1464,6 +1514,7 @@ as_policy_operate_init(as_policy_operate* p)
p->commit_level = AS_POLICY_COMMIT_LEVEL_DEFAULT;
p->gen = AS_POLICY_GEN_DEFAULT;
p->exists = AS_POLICY_EXISTS_DEFAULT;
p->ttl = 0; // AS_RECORD_DEFAULT_TTL
p->deserialize = true;
p->durable_delete = false;
p->async_heap_rec = false;
Expand Down Expand Up @@ -1632,6 +1683,7 @@ as_policy_batch_write_init(as_policy_batch_write* p)
p->commit_level = AS_POLICY_COMMIT_LEVEL_DEFAULT;
p->gen = AS_POLICY_GEN_DEFAULT;
p->exists = AS_POLICY_EXISTS_DEFAULT;
p->ttl = 0; // AS_RECORD_DEFAULT_TTL
p->durable_delete = false;
return p;
}
Expand All @@ -1646,7 +1698,7 @@ as_policy_batch_apply_init(as_policy_batch_apply* p)
p->filter_exp = NULL;
p->key = AS_POLICY_KEY_DEFAULT;
p->commit_level = AS_POLICY_COMMIT_LEVEL_DEFAULT;
p->ttl = 0;
p->ttl = 0; // AS_RECORD_DEFAULT_TTL
p->durable_delete = false;
return p;
}
Expand Down Expand Up @@ -1682,6 +1734,7 @@ as_policy_scan_init(as_policy_scan* p)
p->max_records = 0;
p->records_per_second = 0;
p->replica = AS_POLICY_REPLICA_SEQUENCE;
p->ttl = 0; // AS_RECORD_DEFAULT_TTL
p->durable_delete = false;
return p;
}
Expand Down
20 changes: 9 additions & 11 deletions src/include/aerospike/as_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,18 +544,16 @@ typedef struct as_query_s {
uint32_t records_per_second;

/**
* The time-to-live (expiration) of the record in seconds.
* There are also special values that can be set in the record TTL:
* (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the
* record will adopt the default TTL value from the namespace.
* (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int)
* (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record
* will get an internal "void_time" of zero, and thus will never expire.
* (*) 0xFFFFFFFE (also, -2 in a signed 32 bit int)
* (defined as AS_RECORD_NO_CHANGE_TTL), which means that the record
* ttl will not change when the record is updated.
* The time-to-live (expiration) of the record in seconds. Note that ttl
* is only used on background query writes.
*
* Note that the TTL value will be employed ONLY on background query writes.
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* <li>AS_RECORD_CLIENT_DEFAULT_TTL: Use the default client ttl in as_policy_write.</li>
* </ul>
*/
uint32_t ttl;

Expand Down
28 changes: 16 additions & 12 deletions src/include/aerospike/as_record.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 Aerospike, Inc.
* Copyright 2008-2023 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -186,17 +186,14 @@ typedef struct as_record_s {

/**
* The time-to-live (expiration) of the record in seconds.
* There are also special values that can be set in the record TTL:
* (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the
* record will adopt the default TTL value from the namespace.
* (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int)
* (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record
* will get an internal "void_time" of zero, and thus will never expire.
* (*) 0xFFFFFFFE (also, -2 in a signed 32 bit int)
* (defined as AS_RECORD_NO_CHANGE_TTL), which means that the record
* ttl will not change when the record is updated.
*
* Note that the TTL value will be employed ONLY on write/update calls.
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* <li>AS_RECORD_CLIENT_DEFAULT_TTL: Use the default client ttl in as_policy_write.</li>
* </ul>
*/
uint32_t ttl;

Expand All @@ -209,7 +206,7 @@ typedef struct as_record_s {

/**
* When the record is given a TTL value of ZERO, it will adopt the TTL value
* that is the default TTL value for the namespace (defined in the config file).
* that is the server default TTL value for the namespace (defined in the config file).
*/
#define AS_RECORD_DEFAULT_TTL 0

Expand All @@ -226,6 +223,13 @@ typedef struct as_record_s {
*/
#define AS_RECORD_NO_CHANGE_TTL 0xFFFFFFFE

/**
* When the record is given a TTL value of 0xFFFFFFFD, the default client ttl in
* in as_policy_write or as_policy_operate will be used. This value must only be
* used in as_record.ttl or as_operations.ttl.
*/
#define AS_RECORD_CLIENT_DEFAULT_TTL 0xFFFFFFFD

/******************************************************************************
* MACROS
*****************************************************************************/
Expand Down
20 changes: 9 additions & 11 deletions src/include/aerospike/as_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,16 @@ typedef struct as_scan_s {
as_partitions_status* parts_all;

/**
* The time-to-live (expiration) of the record in seconds.
* There are also special values that can be set in the record TTL:
* (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the
* record will adopt the default TTL value from the namespace.
* (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int)
* (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record
* will get an internal "void_time" of zero, and thus will never expire.
* (*) 0xFFFFFFFE (also, -2 in a signed 32 bit int)
* (defined as AS_RECORD_NO_CHANGE_TTL), which means that the record
* ttl will not change when the record is updated.
* The time-to-live (expiration) of the record in seconds. Note that ttl
* is only used on background scan writes.
*
* Note that the TTL value will be employed ONLY on background scan writes.
* There are also special values that can be set in the record ttl:
* <ul>
* <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
* <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
* <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
* <li>AS_RECORD_CLIENT_DEFAULT_TTL: Use the default client ttl in as_policy_write.</li>
* </ul>
*/
uint32_t ttl;

Expand Down
8 changes: 4 additions & 4 deletions src/main/aerospike/aerospike_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ as_batch_attr_read_adjust(as_batch_attr* attr, bool read_all_bins)
}

static void
as_batch_attr_write_header(as_batch_attr* attr, as_operations* ops)
as_batch_attr_write_header(as_batch_attr* attr, const as_policy_batch_write* p, as_operations* ops)
{
attr->filter_exp = NULL;
attr->read_attr = 0;
Expand All @@ -1162,7 +1162,7 @@ as_batch_attr_write_header(as_batch_attr* attr, as_operations* ops)
}

attr->info_attr = 0;
attr->ttl = ops->ttl;
attr->ttl = (ops->ttl == AS_RECORD_CLIENT_DEFAULT_TTL && p)? p->ttl : ops->ttl;
attr->gen = 0;
attr->has_write = true;
attr->send_key = false;
Expand All @@ -1171,7 +1171,7 @@ as_batch_attr_write_header(as_batch_attr* attr, as_operations* ops)
static void
as_batch_attr_write_row(as_batch_attr* attr, const as_policy_batch_write* p, as_operations* ops)
{
as_batch_attr_write_header(attr, ops);
as_batch_attr_write_header(attr, p, ops);
attr->filter_exp = p->filter_exp;
attr->send_key = (p->key == AS_POLICY_KEY_SEND);

Expand Down Expand Up @@ -1466,7 +1466,7 @@ as_batch_records_write_new(
as_batch_attr_write_row(&attr, bw->policy, bw->ops);
}
else {
as_batch_attr_write_header(&attr, bw->ops);
as_batch_attr_write_header(&attr, NULL, bw->ops);
}
p = as_batch_write_operations(p, &bw->key, &attr, attr.filter_exp, bw->ops,
bb->buffers);
Expand Down
6 changes: 4 additions & 2 deletions src/main/aerospike/aerospike_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,10 @@ as_put_write(void* udata, uint8_t* buf)
as_put* put = udata;
const as_policy_write* policy = put->policy;
as_record* rec = put->rec;
uint32_t ttl = (rec->ttl == AS_RECORD_CLIENT_DEFAULT_TTL)? policy->ttl : rec->ttl;

uint8_t* p = as_command_write_header_write(buf, &policy->base, policy->commit_level,
policy->exists, policy->gen, rec->gen, rec->ttl, put->n_fields, put->n_bins,
policy->exists, policy->gen, rec->gen, ttl, put->n_fields, put->n_bins,
policy->durable_delete, 0, AS_MSG_INFO2_WRITE, 0);

p = as_command_write_key(p, policy->key, put->key);
Expand Down Expand Up @@ -917,9 +918,10 @@ as_operate_write(void* udata, uint8_t* buf)
as_operate* oper = udata;
const as_policy_operate* policy = oper->policy;
const as_operations* ops = oper->ops;
uint32_t ttl = (ops->ttl == AS_RECORD_CLIENT_DEFAULT_TTL)? policy->ttl : ops->ttl;

uint8_t* p = as_command_write_header_write(buf, &policy->base, policy->commit_level,
policy->exists, policy->gen, ops->gen, ops->ttl, oper->n_fields,
policy->exists, policy->gen, ops->gen, ttl, oper->n_fields,
oper->n_operations, policy->durable_delete, oper->read_attr, oper->write_attr,
oper->info_attr);

Expand Down
9 changes: 8 additions & 1 deletion src/main/aerospike/aerospike_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,21 @@ as_query_command_init(
else if (query->ops) {
// Background query with operations.
uint32_t ttl = (query->ttl)? query->ttl : query->ops->ttl;

if (ttl == AS_RECORD_CLIENT_DEFAULT_TTL) {
ttl = write_policy->ttl;
}

p = as_command_write_header_write(cmd, base_policy, write_policy->commit_level,
write_policy->exists, AS_POLICY_GEN_IGNORE, 0, ttl, qb->n_fields, qb->n_ops,
write_policy->durable_delete, 0, AS_MSG_INFO2_WRITE, 0);
}
else {
// Background query with UDF.
uint32_t ttl = (query->ttl == AS_RECORD_CLIENT_DEFAULT_TTL)? write_policy->ttl : query->ttl;

p = as_command_write_header_write(cmd, base_policy, write_policy->commit_level,
write_policy->exists, AS_POLICY_GEN_IGNORE, 0, query->ttl, qb->n_fields, qb->n_ops,
write_policy->exists, AS_POLICY_GEN_IGNORE, 0, ttl, qb->n_fields, qb->n_ops,
write_policy->durable_delete, 0, AS_MSG_INFO2_WRITE, 0);
}

Expand Down
Loading

0 comments on commit 600d2d2

Please sign in to comment.