Skip to content

Commit d7baf2a

Browse files
committed
Add persist support for building CTX.
1 parent 8c0c820 commit d7baf2a

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

src/include/aerospike/as_cdt_ctx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ as_cdt_ctx_add_list_index(as_cdt_ctx* ctx, int index)
168168
static inline void
169169
as_cdt_ctx_add_list_index_create(as_cdt_ctx* ctx, int index, as_list_order order, bool pad)
170170
{
171+
if (ctx->list.size != 0) {
172+
order &= ~AS_LIST_FLAG_PERSIST_INDEX;
173+
}
174+
171175
as_cdt_ctx_item item;
172176
item.type = AS_CDT_CTX_LIST_INDEX | as_list_order_to_flag(order, pad);
173177
item.val.ival = index;
@@ -278,6 +282,10 @@ as_cdt_ctx_add_map_key(as_cdt_ctx* ctx, as_val* key)
278282
static inline void
279283
as_cdt_ctx_add_map_key_create(as_cdt_ctx* ctx, as_val* key, as_map_order order)
280284
{
285+
if (ctx->list.size != 0) {
286+
order &= ~AS_MAP_FLAG_PERSIST_INDEX;
287+
}
288+
281289
as_cdt_ctx_item item;
282290
item.type = AS_CDT_CTX_MAP_KEY | as_map_order_to_flag(order);
283291
item.val.pval = key;

src/include/aerospike/as_cdt_order.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ typedef enum as_list_order_e {
4141
* List is ordered.
4242
*/
4343
AS_LIST_ORDERED = 1,
44+
45+
/**
46+
* Persist index on server.
47+
*/
48+
AS_LIST_FLAG_PERSIST_INDEX = 0x10
49+
4450
} as_list_order;
4551

4652
/**
@@ -62,7 +68,12 @@ typedef enum as_map_order_e {
6268
/**
6369
* Order map by key, then value.
6470
*/
65-
AS_MAP_KEY_VALUE_ORDERED = 3
71+
AS_MAP_KEY_VALUE_ORDERED = 3,
72+
73+
/**
74+
* Persist index on server.
75+
*/
76+
AS_MAP_FLAG_PERSIST_INDEX = 0x10
6677
} as_map_order;
6778

6879
/******************************************************************************
@@ -72,22 +83,30 @@ typedef enum as_map_order_e {
7283
static inline uint32_t
7384
as_list_order_to_flag(as_list_order order, bool pad)
7485
{
75-
return (order == AS_LIST_ORDERED)? 0xc0 : pad ? 0x80 : 0x40;
86+
if ((order & AS_LIST_ORDERED) != 0) {
87+
return ((order & AS_LIST_FLAG_PERSIST_INDEX) != 0) ? 0x1c0 : 0xc0;
88+
}
89+
90+
return (pad ? 0x80 : 0x40) |
91+
(((order & AS_LIST_FLAG_PERSIST_INDEX) != 0) ? 0x100 : 0x0);
7692
}
7793

7894
static inline uint32_t
7995
as_map_order_to_flag(as_map_order order)
8096
{
81-
switch (order) {
97+
switch (order & 0x3) {
8298
default:
8399
case AS_MAP_UNORDERED:
84-
return 0x40;
100+
return 0x40 |
101+
(((order & AS_LIST_FLAG_PERSIST_INDEX) != 0) ? 0x100 : 0x0);
85102

86103
case AS_MAP_KEY_ORDERED:
87-
return 0x80;
104+
return 0x80 |
105+
(((order & AS_LIST_FLAG_PERSIST_INDEX) != 0) ? 0x100 : 0x0);
88106

89107
case AS_MAP_KEY_VALUE_ORDERED:
90-
return 0xc0;
108+
return 0xc0 |
109+
(((order & AS_LIST_FLAG_PERSIST_INDEX) != 0) ? 0x100 : 0x0);
91110
}
92111
}
93112

src/test/aerospike_list/list_basics.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ TEST(list_persist_index, "test persist index")
29802980
// Test ctx create.
29812981
as_operations_init(&ops, 1);
29822982
as_cdt_ctx_init(&ctx, 1);
2983-
as_cdt_ctx_add_list_index_create(&ctx, 0, AS_LIST_UNORDERED | AS_MAP_FLAG_PERSIST_INDEX, false);
2983+
as_cdt_ctx_add_list_index_create(&ctx, 0, AS_LIST_UNORDERED | AS_LIST_FLAG_PERSIST_INDEX, false);
29842984
as_operations_list_append(&ops, BIN_NAME, &ctx, NULL, (as_val*)as_integer_new(1));
29852985

29862986
status = aerospike_key_operate(as, &err, NULL, &rkey, &ops, &rec);
@@ -3010,7 +3010,7 @@ TEST(list_persist_index, "test persist index")
30103010

30113011
as_operations_init(&ops, 1);
30123012
as_cdt_ctx_init(&ctx, 1);
3013-
as_cdt_ctx_add_list_index_create(&ctx, 10, AS_LIST_UNORDERED | AS_MAP_FLAG_PERSIST_INDEX, true);
3013+
as_cdt_ctx_add_list_index_create(&ctx, 10, AS_LIST_UNORDERED | AS_LIST_FLAG_PERSIST_INDEX, true);
30143014
as_operations_list_append(&ops, BIN_NAME, &ctx, NULL, (as_val*)as_integer_new(1));
30153015

30163016
status = aerospike_key_operate(as, &err, NULL, &rkey, &ops, &rec);
@@ -3031,15 +3031,17 @@ TEST(list_persist_index, "test persist index")
30313031
as_record_destroy(rec);
30323032
rec = NULL;
30333033

3034-
// Test ctx create sub presist.
3034+
// Test ctx create sub presist rejection.
30353035
status = aerospike_key_remove(as, &err, NULL, &rkey);
30363036
assert_true(status == AEROSPIKE_OK);
30373037

30383038
as_operations_init(&ops, 1);
30393039

30403040
as_cdt_ctx_init(&ctx, 2);
30413041
as_cdt_ctx_add_list_index_create(&ctx, 0, AS_LIST_UNORDERED, false);
3042-
as_cdt_ctx_add_list_index_create(&ctx, 0, AS_LIST_ORDERED | AS_MAP_FLAG_PERSIST_INDEX, false);
3042+
as_cdt_ctx_add_list_index_create(&ctx, 0, AS_LIST_ORDERED, false);
3043+
as_cdt_ctx_item* hack_item = as_vector_get(&ctx.list, ctx.list.size - 1);
3044+
hack_item->type |= 0x100; // hack in a persist flag, do not do this normally
30433045

30443046
as_operations_list_append(&ops, BIN_NAME, &ctx, NULL, (as_val*)as_integer_new(1));
30453047

src/test/aerospike_map/map_basics.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,16 +3368,17 @@ TEST(map_persist_index, "Test Map Persist Index")
33683368
as_record_destroy(rec);
33693369
rec = NULL;
33703370

3371-
// Test ctx create sub presist.
3371+
// Test ctx create sub presist rejection.
33723372
status = aerospike_key_remove(as, &err, NULL, &rkey);
33733373
assert_true(status == AEROSPIKE_OK);
33743374

33753375
as_operations_init(&ops, 1);
33763376

33773377
as_cdt_ctx_init(&ctx, 2);
33783378
as_cdt_ctx_add_list_index_create(&ctx, 0, AS_LIST_UNORDERED, false);
3379-
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(0),
3380-
AS_MAP_KEY_ORDERED | AS_MAP_FLAG_PERSIST_INDEX);
3379+
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(0), AS_MAP_KEY_ORDERED);
3380+
as_cdt_ctx_item* hack_item = as_vector_get(&ctx.list, ctx.list.size - 1);
3381+
hack_item->type |= 0x100; // hack in a persist flag, do not do this normally
33813382

33823383
as_operations_list_append(&ops, BIN_NAME, &ctx, NULL, (as_val*)as_integer_new(1));
33833384

@@ -3388,7 +3389,7 @@ TEST(map_persist_index, "Test Map Persist Index")
33883389
as_operations_destroy(&ops);
33893390
as_cdt_ctx_destroy(&ctx);
33903391

3391-
// Test ctx create sub presist 2.
3392+
// Test ctx create sub presist rejection 2.
33923393
as_cdt_ctx_init(&ctx, 1);
33933394
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(0), AS_MAP_FLAG_PERSIST_INDEX);
33943395

@@ -3402,15 +3403,19 @@ TEST(map_persist_index, "Test Map Persist Index")
34023403
as_cdt_ctx_destroy(&ctx);
34033404

34043405
as_cdt_ctx_init(&ctx, 3);
3405-
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(0), AS_MAP_FLAG_PERSIST_INDEX);
34063406
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(1), AS_MAP_FLAG_PERSIST_INDEX);
3407+
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(1), AS_MAP_FLAG_PERSIST_INDEX);
3408+
hack_item = as_vector_get(&ctx.list, ctx.list.size - 1);
3409+
hack_item->type |= 0x100; // hack in a persist flag, do not do this normally
34073410
as_cdt_ctx_add_map_key_create(&ctx, (as_val*)as_integer_new(2), AS_MAP_FLAG_PERSIST_INDEX);
3411+
hack_item = as_vector_get(&ctx.list, ctx.list.size - 1);
3412+
hack_item->type |= 0x100; // hack in a persist flag, do not do this normally
34083413

34093414
as_operations_init(&ops, 1);
34103415
as_operations_list_append(&ops, BIN_NAME, &ctx, NULL, (as_val*)as_integer_new(1));
34113416

34123417
status = aerospike_key_operate(as, &err, NULL, &rkey, &ops, &rec);
3413-
assert_int_ne(status, AEROSPIKE_OK); // rejected
3418+
assert_int_ne(status, AEROSPIKE_OK); // should be rejected
34143419
as_record_destroy(rec);
34153420
rec = NULL;
34163421
as_operations_destroy(&ops);
@@ -3446,7 +3451,7 @@ TEST(map_persist_index, "Test Map Persist Index")
34463451

34473452
as_map_policy pol;
34483453
as_map_policy_init(&pol);
3449-
as_map_policy_set_flags(&pol, AS_MAP_FLAG_PERSIST_INDEX, 0);
3454+
as_map_policy_set_all(&pol, AS_MAP_UNORDERED, 0, true);
34503455
as_operations_init(&ops, 1);
34513456
as_operations_add_map_set_policy(&ops, BIN_NAME, &pol);
34523457

0 commit comments

Comments
 (0)