Skip to content

Commit

Permalink
CLIENT-2764 Support persistent list indexes.
Browse files Browse the repository at this point in the history
Add as_operations_list_create_all().
  • Loading branch information
BrianNichols committed Jan 26, 2024
1 parent c489326 commit 998905f
Show file tree
Hide file tree
Showing 8 changed files with 873 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/include/aerospike/as_cdt_order.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2020 Aerospike, Inc.
* Copyright 2008-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -40,7 +40,7 @@ typedef enum as_list_order_e {
/**
* List is ordered.
*/
AS_LIST_ORDERED = 1,
AS_LIST_ORDERED = 1
} as_list_order;

/**
Expand Down
23 changes: 22 additions & 1 deletion src/include/aerospike/as_list_operations.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 Aerospike, Inc.
* Copyright 2008-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -302,6 +302,27 @@ as_operations_list_create(
as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list_order order, bool pad
);

/**
* Create list create operation.
* Server creates list at given context level.
*
* @param ops Target operations list.
* @param name Bin name.
* @param ctx Optional path to nested list. If not defined, the top-level list is used.
* @param order List order.
* @param pad If true, the context is allowed to be beyond list boundaries. In that case, nil
* list entries will be inserted to satisfy the context position.
* @param persist_index If true, persist list index. A list index improves lookup performance,
* but requires more storage. A list index can be created for a top-level
* ordered list only. Nested and unordered list indexes are not supported.
*
* @ingroup map_operations
*/
AS_EXTERN bool
as_operations_list_create_all(
as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list_order order, bool pad, bool persist_index
);

/**
* Create set list order operation.
* Server sets list order. Server returns null.
Expand Down
32 changes: 31 additions & 1 deletion src/main/aerospike/as_list_operations.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 Aerospike, Inc.
* Copyright 2008-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -104,6 +104,36 @@ as_operations_list_create(
return as_cdt_add_packed(&pk, ops, name, AS_OPERATOR_CDT_MODIFY);
}

bool
as_operations_list_create_all(
as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list_order order, bool pad, bool persist_index
)
{
// If context not defined, the set order for top-level bin list.
if (! ctx) {
uint64_t flag = (uint64_t)order;

if (persist_index) {
flag |= 0x10;
}

as_packer pk = as_cdt_begin();
as_cdt_pack_header(&pk, ctx, SET_TYPE, 1);
as_pack_uint64(&pk, flag);
as_cdt_end(&pk);
return as_cdt_add_packed(&pk, ops, name, AS_OPERATOR_CDT_MODIFY);
}

uint32_t flag = as_list_order_to_flag(order, pad);

// Create nested list. persist_index does not apply here, so ignore it.
as_packer pk = as_cdt_begin();
as_cdt_pack_header_flag(&pk, ctx, SET_TYPE, 1, flag);
as_pack_uint64(&pk, (uint64_t)order);
as_cdt_end(&pk);
return as_cdt_add_packed(&pk, ops, name, AS_OPERATOR_CDT_MODIFY);
}

bool
as_operations_list_set_order(
as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list_order order
Expand Down
6 changes: 3 additions & 3 deletions src/main/aerospike/as_map_operations.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2023 Aerospike, Inc.
* Copyright 2008-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -148,7 +148,7 @@ as_operations_map_create(
as_operations* ops, const char* name, as_cdt_ctx* ctx, as_map_order order
)
{
// If context not defined, the set order for top-level bin list.
// If context not defined, the set order for top-level bin map.
if (! ctx) {
as_map_policy policy;
as_map_policy_set(&policy, order, AS_MAP_UPDATE);
Expand All @@ -169,7 +169,7 @@ as_operations_map_create_all(
as_operations* ops, const char* name, as_cdt_ctx* ctx, as_map_order order, bool persist_index
)
{
// If context not defined, the set order for top-level bin list.
// If context not defined, the set order for top-level bin map.
if (! ctx) {
as_map_policy policy;
as_map_policy_set_all(&policy, order, AS_MAP_UPDATE, persist_index);
Expand Down
Loading

0 comments on commit 998905f

Please sign in to comment.