1 | /* |
2 | * scan_job.h |
3 | * |
4 | * Copyright (C) 2019 Aerospike, Inc. |
5 | * |
6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
7 | * license agreements. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it under |
10 | * the terms of the GNU Affero General Public License as published by the Free |
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
12 | * later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
17 | * details. |
18 | * |
19 | * You should have received a copy of the GNU Affero General Public License |
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | //========================================================== |
26 | // Includes. |
27 | // |
28 | |
29 | #include <stdbool.h> |
30 | #include <stdint.h> |
31 | #include <sys/types.h> |
32 | |
33 | #include "base/proto.h" |
34 | |
35 | |
36 | //========================================================== |
37 | // Forward declarations. |
38 | // |
39 | |
40 | struct as_mon_jobstat_s; |
41 | struct as_namespace_s; |
42 | struct as_partition_reservation_s; |
43 | struct as_scan_job_s; |
44 | |
45 | |
46 | //========================================================== |
47 | // Typedefs & constants. |
48 | // |
49 | |
50 | // Same as proto result codes so connected scans don't have to convert: |
51 | #define AS_SCAN_ERR_UNKNOWN AS_ERR_UNKNOWN |
52 | #define AS_SCAN_ERR_PARAMETER AS_ERR_PARAMETER |
53 | #define AS_SCAN_ERR_CLUSTER_KEY AS_ERR_CLUSTER_KEY_MISMATCH |
54 | #define AS_SCAN_ERR_USER_ABORT AS_ERR_SCAN_ABORT |
55 | #define AS_SCAN_ERR_FORBIDDEN AS_ERR_FORBIDDEN |
56 | |
57 | // These result codes can't make it back to the client, but show in monitor: |
58 | #define AS_SCAN_ERR_RESPONSE_ERROR (-1) |
59 | #define AS_SCAN_ERR_RESPONSE_TIMEOUT (-2) |
60 | |
61 | typedef void (*as_scan_slice_fn)(struct as_scan_job_s* _job, struct as_partition_reservation_s* rsv); |
62 | typedef void (*as_scan_finish_fn)(struct as_scan_job_s* _job); |
63 | typedef void (*as_scan_destroy_fn)(struct as_scan_job_s* _job); |
64 | typedef void (*as_scan_info_fn)(struct as_scan_job_s* _job, struct as_mon_jobstat_s* stat); |
65 | |
66 | typedef struct as_scan_vtable_s { |
67 | as_scan_slice_fn slice_fn; |
68 | as_scan_finish_fn finish_fn; |
69 | as_scan_destroy_fn destroy_fn; |
70 | as_scan_info_fn info_mon_fn; |
71 | } as_scan_vtable; |
72 | |
73 | typedef struct as_scan_job_s { |
74 | // Mandatory interface for derived classes: |
75 | as_scan_vtable vtable; |
76 | |
77 | // Unique identifier: |
78 | uint64_t trid; |
79 | |
80 | // Job scope: |
81 | struct as_namespace_s* ns; |
82 | uint16_t set_id; |
83 | |
84 | // Handle active phase: |
85 | uint32_t n_threads; |
86 | uint32_t pid; |
87 | volatile int abandoned; |
88 | |
89 | // For throttling: |
90 | uint32_t rps; |
91 | bool started; |
92 | pid_t base_sys_tid; |
93 | uint64_t base_us; |
94 | uint64_t base_count; |
95 | uint64_t streak_us; |
96 | |
97 | // For tracking: |
98 | char client[64]; |
99 | uint64_t start_us; |
100 | uint64_t finish_us; |
101 | uint64_t n_throttled; |
102 | uint64_t n_filtered_meta; |
103 | uint64_t n_filtered_bins; |
104 | uint64_t n_succeeded; |
105 | uint64_t n_failed; |
106 | } as_scan_job; |
107 | |
108 | |
109 | //========================================================== |
110 | // Public API. |
111 | // |
112 | |
113 | void as_scan_job_init(as_scan_job* _job, const as_scan_vtable* vtable, uint64_t trid, struct as_namespace_s* ns, uint16_t set_id, uint32_t rps, const char* client); |
114 | void as_scan_job_add_thread(as_scan_job* _job); |
115 | uint32_t as_scan_job_throttle(as_scan_job* _job); |
116 | void as_scan_job_destroy(as_scan_job* _job); |
117 | void as_scan_job_info(as_scan_job* _job, struct as_mon_jobstat_s* stat); |
118 | |