Loading...
Searching...
No Matches
as_partition_filter.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2023 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <aerospike/as_std.h>
20#include <aerospike/as_atomic.h>
21#include <aerospike/as_key.h>
22#include <citrusleaf/alloc.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/******************************************************************************
29 * TYPES
30 *****************************************************************************/
31
32struct as_node_s;
33
34/**
35 * Status of a single partition.
36 */
37typedef struct as_partition_status_s {
38 uint16_t part_id;
40 bool retry;
42 uint64_t bval;
43 struct as_node_s* node;
45
46/**
47 * Status of all partitions after scan/query has ended.
48 */
49typedef struct as_partitions_status_s {
50 uint32_t ref_count;
51 uint16_t part_begin;
52 uint16_t part_count;
53 bool done;
54 bool retry;
55 char pad[6];
58
59/**
60 * Partition filter.
61 */
62typedef struct as_partition_filter_s {
63 uint16_t begin;
64 uint16_t count;
68
69/******************************************************************************
70 * FUNCTIONS
71 ******************************************************************************/
72
73/**
74 * Read all partitions.
75 *
76 * @param pf Partition filter.
77 */
78static inline void
80{
81 pf->begin = 0;
82 pf->count = 4096;
83 pf->digest.init = false;
84 pf->parts_all = NULL;
85}
86
87/**
88 * Filter by partition id.
89 *
90 * @param pf Partition filter.
91 * @param part_id Partition id (0 - 4095).
92 */
93static inline void
95{
96 pf->begin = part_id;
97 pf->count = 1;
98 pf->digest.init = false;
99 pf->parts_all = NULL;
100}
101
102/**
103 * Return records after key's digest in a single partition containing the digest.
104 * Note that digest order is not the same as user key order. This function only
105 * works for scan or query without a where clause.
106 *
107 * @param pf Partition filter.
108 * @param digest Return records after this key's digest.
109 */
110static inline void
112{
113 pf->begin = 0;
114 pf->count = 1;
115 pf->digest = *digest;
116 pf->parts_all = NULL;
117}
118
119/**
120 * Filter by partition range.
121 *
122 * @param pf Partition filter.
123 * @param begin Start partition id (0 - 4095).
124 * @param count Number of partitions.
125 */
126static inline void
127as_partition_filter_set_range(as_partition_filter* pf, uint32_t begin, uint32_t count)
128{
129 pf->begin = begin;
130 pf->count = count;
131 pf->digest.init = false;
132 pf->parts_all = NULL;
133}
134
135/**
136 * Filter by status of all partitions obtained from a previous scan/query that was terminated
137 * before reading all records.
138 *
139 * @param pf Partition filter.
140 * @param parts_all Completion status of all partitions.
141 */
142static inline void
144{
145 pf->begin = parts_all->part_begin;
146 pf->count = parts_all->part_count;
147 pf->digest.init = false;
148 pf->parts_all = parts_all;
149}
150
151/**
152 * Reserve status of all partitions.
153 */
154static inline as_partitions_status*
156{
157 as_partitions_status* pa = (as_partitions_status*)as_load_ptr((void* const*)&parts_all);
159 return pa;
160}
161
162/**
163 * Release status of all partitions.
164 */
165static inline void
167{
168 if (as_aaf_uint32_rls(&parts_all->ref_count, -1) == 0) {
169 cf_free(parts_all);
170 }
171}
172
173#ifdef __cplusplus
174} // end extern "C"
175#endif
#define as_load_ptr(_target)
#define as_incr_uint32(_target)
#define as_aaf_uint32_rls(_target, _value)
static as_partitions_status * as_partitions_status_reserve(as_partitions_status *parts_all)
static void as_partition_filter_set_all(as_partition_filter *pf)
static void as_partition_filter_set_partitions(as_partition_filter *pf, as_partitions_status *parts_all)
static void as_partition_filter_set_after(as_partition_filter *pf, as_digest *digest)
static void as_partitions_status_release(as_partitions_status *parts_all)
static void as_partition_filter_set_range(as_partition_filter *pf, uint32_t begin, uint32_t count)
static void as_partition_filter_set_id(as_partition_filter *pf, uint32_t part_id)
bool init
Definition as_key.h:77
as_partitions_status * parts_all
struct as_node_s * node