forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_granule_util.cpp
More file actions
597 lines (571 loc) · 27.3 KB
/
Copy pathob_granule_util.cpp
File metadata and controls
597 lines (571 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL_EXE
#include "ob_granule_util.h"
#include "share/ob_i_tablet_scan.h"
#include "share/config/ob_server_config.h"
#include "lib/ob_errno.h"
#include "sql/ob_sql_define.h"
#include "sql/optimizer/ob_table_partition_info.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/engine/px/ob_px_util.h"
#include "ob_granule_pump.h"
#include "storage/tx_storage/ob_access_service.h"
#include "share/schema/ob_table_param.h"
#include "sql/engine/ob_engine_op_traits.h"
#include "share/external_table/ob_external_table_file_mgr.h"
#include "share/external_table/ob_external_table_utils.h"
#include "sql/engine/table/ob_external_table_access_service.h"
#include "sql/das/ob_das_simple_op.h"
using namespace oceanbase::common;
using namespace oceanbase::share;
namespace oceanbase
{
namespace sql
{
void ObParallelBlockRangeTaskParams::reset()
{
parallelism_ = 0;
expected_task_load_ = sql::OB_EXPECTED_TASK_LOAD;
min_task_count_per_thread_ = sql::OB_MIN_PARALLEL_TASK_COUNT;
max_task_count_per_thread_ = sql::OB_MAX_PARALLEL_TASK_COUNT;
min_task_access_size_ = GCONF.px_task_size >> 20;
}
int ObParallelBlockRangeTaskParams::valid() const
{
int ret = OB_SUCCESS;
if (min_task_count_per_thread_ <= 0
|| max_task_count_per_thread_ <= 0
|| min_task_access_size_ <= 0
|| parallelism_ <= 0
|| expected_task_load_ <= 0) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("params is invalid", K(*this), K(ret));
}
return ret;
}
bool ObGranuleUtil::is_partition_granule(int64_t partition_count,
int64_t parallelism,
int64_t partition_scan_hold,
int64_t hash_partition_scan_hold,
bool hash_part)
{
bool partition_granule = false;
// if parallelism is too small, we use partition granule.
if (hash_part) {
partition_granule = partition_count >= hash_partition_scan_hold * parallelism || 1 == parallelism;
} else {
partition_granule = partition_count >= partition_scan_hold * parallelism || 1 == parallelism;
}
return partition_granule;
}
int ObGranuleUtil::split_granule_for_external_table(ObIAllocator &allocator,
const ObTableScanSpec *tsc,
const ObIArray<ObNewRange> &ranges,
const ObIArray<ObDASTabletLoc *> &tablets,
const ObIArray<ObExternalFileInfo> &external_table_files,
int64_t parallelism,
ObIArray<ObDASTabletLoc *> &granule_tablets,
ObIArray<ObNewRange> &granule_ranges,
ObIArray<int64_t> &granule_idx)
{
UNUSED(parallelism);
UNUSED(tsc);
int ret = OB_SUCCESS;
if (ranges.count() < 1 || tablets.count() < 1 || OB_ISNULL(tsc)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("the invalid argument", K(ret), K(ranges.count()), K(tablets.count()));
} else if (external_table_files.count() == 1 &&
external_table_files.at(0).file_id_ == INT64_MAX) {
// dealing dummy file
ObNewRange new_range;
if (OB_FAIL(ObExternalTableUtils::convert_external_table_empty_range(
external_table_files.at(0).file_url_,
external_table_files.at(0).file_id_,
tsc->get_ref_table_id(),
allocator,
new_range))) {
LOG_WARN("failed to convert external table empty range", K(ret));
} else if (OB_FAIL(granule_ranges.push_back(new_range)) ||
OB_FAIL(granule_idx.push_back(external_table_files.at(0).file_id_)) ||
OB_FAIL(granule_tablets.push_back(tablets.at(0)))) {
LOG_WARN("fail to push back", K(ret));
}
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < ranges.count(); ++i) {
for (int64_t j = 0; OB_SUCC(ret) && j < external_table_files.count(); ++j) {
ObNewRange new_range;
bool is_valid = false;
if (OB_FAIL(ObExternalTableUtils::convert_external_table_new_range(
external_table_files.at(j).file_url_,
external_table_files.at(j).file_id_,
tsc->get_ref_table_id(),
ranges.at(i),
allocator,
new_range,
is_valid))) {
LOG_WARN("failed to convert external table new range", K(ret));
} else if (is_valid && (OB_FAIL(granule_ranges.push_back(new_range)) ||
OB_FAIL(granule_idx.push_back(external_table_files.at(j).file_id_)) ||
OB_FAIL(granule_tablets.push_back(tablets.at(0))))) {
LOG_WARN("fail to push back", K(ret));
}
}
}
}
LOG_DEBUG("check external split ranges", K(ranges), K(granule_ranges), K(external_table_files));
return ret;
}
int ObGranuleUtil::split_block_ranges(ObExecContext &exec_ctx,
ObIAllocator &allocator,
const ObTableScanSpec *tsc,//may be is null, attention use
const ObIArray<common::ObNewRange> &in_ranges,
const ObIArray<ObDASTabletLoc*> &tablets,
int64_t parallelism,
int64_t tablet_size,
bool force_partition_granule,
common::ObIArray<ObDASTabletLoc*> &granule_tablets,
common::ObIArray<common::ObNewRange> &granule_ranges,
common::ObIArray<int64_t> &granule_idx,
bool range_independent)
{
int ret = OB_SUCCESS;
int64_t total_macros_count = 0;
int64_t total_task_count = 1;
int64_t macros_count_per_task = 0;
common::ObSEArray<uint64_t, 16> macros_count_by_partition;
common::ObSEArray<int64_t, 16> macros_count_by_partition_int64;
common::ObSEArray<int64_t, 16> task_count_by_partition;
common::ObSEArray<common::ObNewRange, 16> ranges;
bool only_empty_range = false;
/**
* prepare
*/
if (in_ranges.count() <= 0 || tablets.count() <= 0) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("ranges/tablets is empty", K(in_ranges), K(tablets), K(ret));
} else if (OB_FAIL(remove_empty_range(in_ranges, ranges, only_empty_range))) {
LOG_WARN("failed to remove empty range", K(ret));
} else if (force_partition_granule
|| only_empty_range) {
// partition granule iterator
// 按照partition粒度切分任务的情况下,任务的个数等于partition的个数(`tablets.count()`)
int64_t pk_idx = 0;
FOREACH_CNT_X(tablet, tablets, OB_SUCC(ret)) {
FOREACH_CNT_X(range, ranges, OB_SUCC(ret)) {
if (OB_FAIL(granule_tablets.push_back(*tablet))) {
LOG_WARN("push basck tablet failed", K(ret));
} else if (OB_FAIL(granule_ranges.push_back(*range))) {
LOG_WARN("push back range failed", K(ret));
} else if (OB_FAIL(granule_idx.push_back(pk_idx))) {
LOG_WARN("push back pk_idx failed", K(ret));
} else if (range_independent) {
pk_idx++;
}
}
if (!range_independent) {
pk_idx++;
}
}
LOG_TRACE("gi partition granule");
} else if (OB_FAIL(split_block_granule(exec_ctx,
allocator,
tsc,
ranges,
tablets,
parallelism,
tablet_size,
granule_tablets,
granule_ranges,
granule_idx,
range_independent))) {
LOG_WARN("failed to split block granule tasks", K(ret));
} else {
LOG_TRACE("get the splited results through the new gi split method",
K(ret), K(granule_tablets.count()), K(granule_ranges.count()), K(granule_idx));
}
LOG_TRACE("split ranges to granule", K(ret), K(total_task_count), K(parallelism),
K(total_macros_count), K(macros_count_by_partition), K(macros_count_per_task),
K(granule_tablets.count()), K(granule_tablets), K(granule_ranges.count()), K(granule_ranges),
K(granule_idx.count()), K(granule_idx), K(tablets), K(task_count_by_partition));
return ret;
}
int ObGranuleUtil::remove_empty_range(const common::ObIArray<common::ObNewRange> &in_ranges,
common::ObIArray<common::ObNewRange> &ranges,
bool &only_empty_range) {
int ret = OB_SUCCESS;
for (int64_t i = 0; i < in_ranges.count() && OB_SUCC(ret); ++i) {
if (!in_ranges.at(i).empty()) {
if (OB_FAIL(ranges.push_back(in_ranges.at(i)))) {
LOG_WARN("fail to push back ranges", K(ret));
}
}
}
if (OB_SUCC(ret) && ranges.empty()) {
if (OB_FAIL(ranges.assign(in_ranges))) {
LOG_WARN("failed to assign ranges", K(ret));
} else {
only_empty_range = true;
}
}
return ret;
}
int ObGranuleUtil::split_block_granule(ObExecContext &exec_ctx,
ObIAllocator &allocator,
const ObTableScanSpec *tsc,//may be is null, attention use!
const ObIArray<ObNewRange> &input_ranges,
const ObIArray<ObDASTabletLoc*> &tablets,
int64_t parallelism,
int64_t tablet_size,
ObIArray<ObDASTabletLoc*> &granule_tablets,
ObIArray<ObNewRange> &granule_ranges,
ObIArray<int64_t> &granule_idx,
bool range_independent)
{
// the step for split task by block granule method:
// 1. check the validity of input parameters
// 2. get size for each partition, and calc the total size for all partitions
// 3. calculate the total number of tasks
// 4. each partition gets its number of tasks by the weight of partition data in the total data
// 5. calculate task ranges for each partition, and get the result
int ret = OB_SUCCESS;
ObAccessService *access_service = MTL(ObAccessService *);
// 1. check the validity of input parameters
if (input_ranges.count() < 1 || tablets.count() < 1 || parallelism < 1 || tablet_size < 1) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("the invalid argument",
K(ret), K(input_ranges.count()), K(tablets.count()), K(parallelism), K(tablet_size));
}
// 2. get size for each partition, and calc the total size for all partitions
common::ObSEArray<int64_t, 16> size_each_partitions;
int64_t total_size = 0;
int64_t empty_partition_cnt = 0;
ObSEArray<ObStoreRange, 16> input_store_ranges;
bool need_convert_new_range = true;//only rowid range need extra convert.
if (OB_SUCC(ret)) {
for (int i = 0; i < tablets.count() && OB_SUCC(ret); i++) {
const ObDASTabletLoc &tablet = *tablets.at(i);
int64_t partition_size = 0;
// get partition size from storage
if (need_convert_new_range &&
OB_FAIL(convert_new_range_to_store_range(allocator,
tsc,
tablet.tablet_id_,
input_ranges,
input_store_ranges,
need_convert_new_range))) {
LOG_WARN("failed to convert new range to store range", K(ret));
} else if (OB_FAIL(ObDASSimpleUtils::get_multi_ranges_cost(exec_ctx, tablets.at(i),
input_store_ranges,
partition_size))) {
LOG_WARN("failed to get multi ranges cost", K(ret), K(tablet));
} else {
// B to MB
partition_size = partition_size / 1024 / 1024;
}
if (OB_SUCC(ret)) {
if (partition_size == 0) {
empty_partition_cnt++;
}
if (OB_FAIL(size_each_partitions.push_back(partition_size))) {
LOG_WARN("failed to push partition size", K(ret));
} else {
total_size += partition_size;
}
}
}
}
// 3. calc the total number of tasks for all partitions
int64_t esti_task_cnt_by_data_size = 0;
if (OB_SUCC(ret)) {
ObParallelBlockRangeTaskParams params;
params.parallelism_ = parallelism;
params.expected_task_load_ = tablet_size/1024/1024;
if (OB_FAIL(compute_total_task_count(params, total_size, esti_task_cnt_by_data_size))) {
LOG_WARN("compute task count failed", K(ret));
} else {
esti_task_cnt_by_data_size += empty_partition_cnt;
// 确保total task count是大于等于partition的个数的
if (esti_task_cnt_by_data_size < tablets.count()) {
esti_task_cnt_by_data_size = tablets.count();
}
}
}
// 4. split the total number of tasks into each partition
common::ObSEArray<int64_t, 16> task_cnt_each_partitions;
if (OB_SUCC(ret)) {
if (OB_FAIL(compute_task_count_each_partition(total_size,
esti_task_cnt_by_data_size,
size_each_partitions,
task_cnt_each_partitions))) {
LOG_WARN("failed to compute task count for each partition", K(ret));
}
}
// 5. calc task ranges for each partition, and get the result
if (OB_SUCC(ret)) {
int64_t tablet_idx = 0;
for (int i = 0; i < tablets.count() && OB_SUCC(ret); i++) {
ObDASTabletLoc *tablet = tablets.at(i);
int64_t expected_task_cnt = task_cnt_each_partitions.at(i);
// split input ranges to n task by PG interface
if (need_convert_new_range &&
OB_FAIL(convert_new_range_to_store_range(allocator,
tsc,
tablet->tablet_id_,
input_ranges,
input_store_ranges,
need_convert_new_range))) {
LOG_WARN("failed to convert new range to store range", K(ret));
} else if (OB_FAIL(get_tasks_for_partition(exec_ctx,
allocator,
expected_task_cnt,
*tablet,
input_store_ranges,
granule_tablets,
granule_ranges,
granule_idx,
tablet_idx,
range_independent))) {
LOG_WARN("failed to get tasks for partition", K(ret));
} else {
LOG_TRACE("get tasks for partition",
K(ret), KPC(tablet), K(granule_ranges.count()), K(granule_tablets), K(granule_idx));
}
}
if (OB_SUCC(ret)) {
if (granule_tablets.empty() ||
granule_tablets.count() != granule_ranges.count() ||
granule_tablets.count() != granule_idx.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("the ranges or offsets are empty",
K(ret), K(granule_tablets.count()), K(granule_ranges.count()), K(granule_idx.count()));
}
}
}
return ret;
}
int ObGranuleUtil::compute_total_task_count(const ObParallelBlockRangeTaskParams ¶ms,
int64_t total_size,
int64_t &total_task_count)
{
int ret = OB_SUCCESS;
int64_t tmp_total_task_count = -1;
if (OB_FAIL(params.valid())) {
LOG_WARN("params is invalid" , K(ret));
} else {
// total size
int64_t total_access_size = total_size;
// default value is 2 MB
int64_t min_task_access_size = NON_ZERO_VALUE(params.min_task_access_size_);
// default value of expected_task_load_ is 128 MB
int64_t expected_task_load = max(params.expected_task_load_, min_task_access_size);
// lower bound size: dop*128M*13
int64_t lower_bound_size = params.parallelism_ * expected_task_load * params.min_task_count_per_thread_;
// hight bound size: dop*128M*100
int64_t upper_bound_size = params.parallelism_ * expected_task_load * params.max_task_count_per_thread_;
if (total_access_size < 0 || lower_bound_size < 0 || upper_bound_size < 0 ) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("params is invalid",
K(total_access_size), K(lower_bound_size), K(upper_bound_size), K(params));
} else if (total_access_size < lower_bound_size) {
// the data size is less than lower bound size
// when the amount of data is small,
// more tasks can easily achieve better dynamic load balancing
tmp_total_task_count = min(params.min_task_count_per_thread_ * params.parallelism_,
total_access_size/min_task_access_size);
tmp_total_task_count = max(tmp_total_task_count, total_access_size / expected_task_load);
LOG_TRACE("the data is less than lower bound size", K(ret), K(tmp_total_task_count));
} else if (total_access_size > upper_bound_size) {
// the data size is greater than upper bound size
tmp_total_task_count = params.max_task_count_per_thread_ * params.parallelism_;
LOG_TRACE("the data size is greater upper bound size", K(ret), K(tmp_total_task_count));
} else {
// the data size is between lower bound size and upper bound size
tmp_total_task_count = total_access_size / expected_task_load;
LOG_TRACE("the data size is between lower bound size and upper bound size",
K(ret), K(tmp_total_task_count));
}
}
if (OB_SUCC(ret)) {
// the result of task count must be greater than or equal to zero
total_task_count = tmp_total_task_count;
}
return ret;
}
int ObGranuleUtil::compute_task_count_each_partition(int64_t total_size,
int64_t total_task_cnt,
const common::ObIArray<int64_t> &size_each_partition,
common::ObIArray<int64_t> &task_cnt_each_partition)
{
int ret = OB_SUCCESS;
// must ensure at least one task per partition.
if (total_size <=0 || total_task_cnt == size_each_partition.count()) {
// if the total count of tasks is equal to the number of partitions,
// each partition just has one task.
for (int i = 0; i < size_each_partition.count() && OB_SUCC(ret); i++) {
// only one task for each partition
if (OB_FAIL(task_cnt_each_partition.push_back(1))) {
LOG_WARN("failed to push back array", K(ret));
}
}
LOG_TRACE("compute task count for each partition, each partition has only one task", K(ret));
} else {
// allocate task count for each partition by the weight of partition data in the total data
int64_t alloc_task_cnt = 0;
for (int i = 0; i < size_each_partition.count() && OB_SUCC(ret); i++) {
int64_t partition_size = size_each_partition.at(i);
int64_t task_cnt = ((double) partition_size / (double) total_size) * total_task_cnt;
// if the data volume of a partition is very small, but it still needs a task.
if (task_cnt == 0) {
task_cnt = 1;
}
alloc_task_cnt += task_cnt;
if (OB_FAIL(task_cnt_each_partition.push_back(task_cnt))) {
LOG_WARN("failed to push task cnt", K(ret));
}
}
LOG_TRACE("compute task count for partition, allocate task count",
K(ret), K(alloc_task_cnt), K(total_task_cnt));
}
// check the size of task_cnt_each_partition array
if (OB_SUCC(ret) && task_cnt_each_partition.count() != size_each_partition.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("the size of task count each partition is not right",
K(ret), K(size_each_partition.count()), K(task_cnt_each_partition.count()));
}
// check the returned result
for (int i = 0; i < task_cnt_each_partition.count() && OB_SUCC(ret); i++) {
if (task_cnt_each_partition.at(i) < 1) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("the partition has error task number", K(ret), K(task_cnt_each_partition.at(i)));
}
}
return ret;
}
int ObGranuleUtil::get_tasks_for_partition(ObExecContext &exec_ctx,
ObIAllocator &allocator,
int64_t expected_task_cnt,
ObDASTabletLoc &tablet,
ObIArray<ObStoreRange> &input_storage_ranges,
common::ObIArray<ObDASTabletLoc*> &granule_tablets,
common::ObIArray<common::ObNewRange> &granule_ranges,
common::ObIArray<int64_t> &granule_idx,
int64_t &tablet_idx,
bool range_independent)
{
int ret = OB_SUCCESS;
ObAccessService *access_service = MTL(ObAccessService *);
ObArrayArray<ObStoreRange> multi_range_split_array;
if (expected_task_cnt < 1) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arg", K(ret), K(expected_task_cnt));
} else if (expected_task_cnt == 1) {
// no need to split the input_ranges, if the expected count of task.
for (int i = 0; i < input_storage_ranges.count() && OB_SUCC(ret); i++) {
ObNewRange new_range;
input_storage_ranges.at(i).to_new_range(new_range);
if (OB_FAIL(granule_tablets.push_back(&tablet))) {
LOG_WARN("failed to push back tablet", K(ret));
} else if (OB_FAIL(granule_ranges.push_back(new_range))) {
LOG_WARN("failed to push back range", K(ret));
} else if (OB_FAIL(granule_idx.push_back(tablet_idx))) {
LOG_WARN("failed to push back idx", K(ret));
} else if (range_independent) {
tablet_idx++;
}
}
if (!range_independent) {
tablet_idx++;
}
} else if (OB_FAIL(ObDASSimpleUtils::split_multi_ranges(exec_ctx,
&tablet,
input_storage_ranges,
expected_task_cnt,
multi_range_split_array))) {
LOG_WARN("failed to split multi ranges", K(ret), K(tablet), K(expected_task_cnt));
} else {
LOG_TRACE("split multi ranges",
K(ret), K(tablet), K(input_storage_ranges),
K(expected_task_cnt == multi_range_split_array.count()), K(multi_range_split_array));
// convert ObStoreRange array to ObNewRange array
for (int i = 0; i < multi_range_split_array.count() && OB_SUCC(ret); i++) {
ObIArray<ObStoreRange> &storage_task_ranges = multi_range_split_array.at(i);
for (int j = 0; j < storage_task_ranges.count() && OB_SUCC(ret); j++) {
ObNewRange new_range;
storage_task_ranges.at(j).to_new_range(new_range);
if (OB_INVALID_INDEX == new_range.table_id_) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid table id", K(ret), K(new_range), K(multi_range_split_array.at(i)));
} else if (OB_FAIL(granule_tablets.push_back(&tablet))) {
LOG_WARN("failed to push back tablet", K(ret), K(tablet));
} else if (OB_FAIL(granule_ranges.push_back(new_range))) {
LOG_WARN("failed to push back new task range", K(ret), K(new_range));
} else if (OB_FAIL(granule_idx.push_back(tablet_idx))) {
LOG_WARN("failed to push back idx", K(ret), K(tablet_idx));
} else if (range_independent) {
tablet_idx++;
}
}
if (!range_independent) {
tablet_idx++;
}
}
}
return ret;
}
int ObGranuleUtil::convert_new_range_to_store_range(ObIAllocator &allocator,
const ObTableScanSpec *tsc,
const ObTabletID &tablet_id,
const ObIArray<ObNewRange> &input_ranges,
ObIArray<ObStoreRange> &input_store_ranges,
bool &need_convert_new_range)
{
int ret = OB_SUCCESS;
ObStoreRange store_range;
input_store_ranges.reuse();
need_convert_new_range = false;
for (int64_t i = 0; OB_SUCC(ret) && i < input_ranges.count(); i++) {
if (input_ranges.at(i).is_physical_rowid_range_) {
ObNewRange new_range;
if (OB_ISNULL(tsc) || OB_UNLIKELY(tsc->get_columns_desc().count() < 1)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error", K(ret), K(tsc));
} else {
ObArrayWrap<ObColDesc> rowkey_descs(&tsc->get_columns_desc().at(0),
tsc->get_rowkey_cnt());
if (OB_FAIL(deep_copy_range(allocator, input_ranges.at(i), new_range))) {
LOG_WARN("failed to deep copy range", K(ret));
} else if (OB_FAIL(ObTableScanOp::transform_physical_rowid(allocator,
tablet_id,
rowkey_descs,
new_range))) {
LOG_WARN("transform physical rowid for range failed", K(ret), K(new_range));
} else {
store_range.assign(new_range);
if (OB_FAIL(input_store_ranges.push_back(store_range))) {
LOG_WARN("failed to push back input store range", K(ret));
} else {
need_convert_new_range = true;
}
}
}
} else {
store_range.assign(input_ranges.at(i));
if (OB_FAIL(input_store_ranges.push_back(store_range))) {
LOG_WARN("failed to push back input store range", K(ret));
}
}
}
return ret;
}
}
}