Coverage Report

Created: 2026-03-16 19:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/tablet_migration_action.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <deque>
21
#include <map>
22
#include <memory>
23
#include <mutex>
24
#include <sstream>
25
#include <string>
26
#include <utility>
27
28
#include "common/status.h"
29
#include "service/http/http_handler_with_auth.h"
30
#include "storage/tablet/tablet.h"
31
#include "util/threadpool.h"
32
33
namespace doris {
34
class DataDir;
35
class HttpRequest;
36
37
class ExecEnv;
38
class StorageEngine;
39
40
// Migrate a tablet from a disk to another.
41
class TabletMigrationAction : public HttpHandlerWithAuth {
42
public:
43
    TabletMigrationAction(ExecEnv* exec_env, StorageEngine& engine, TPrivilegeHier::type hier,
44
                          TPrivilegeType::type type)
45
0
            : HttpHandlerWithAuth(exec_env, hier, type), _engine(engine) {
46
0
        _init_migration_action();
47
0
    }
48
49
0
    ~TabletMigrationAction() override = default;
50
51
    void handle(HttpRequest* req) override;
52
53
    void _init_migration_action();
54
55
    Status _execute_tablet_migration(TabletSharedPtr tablet, DataDir* dest_store);
56
57
    Status _check_param(HttpRequest* req, int64_t& tablet_id, unsigned long& schema_hash,
58
                        std::string& dest_disk, std::string& goal);
59
    Status _check_migrate_request(int64_t tablet_id, unsigned long schema_hash,
60
                                  std::string dest_disk, TabletSharedPtr& tablet,
61
                                  DataDir** dest_store);
62
63
private:
64
    StorageEngine& _engine;
65
    std::unique_ptr<ThreadPool> _migration_thread_pool;
66
67
    struct MigrationTask {
68
        MigrationTask(int64_t tablet_id, unsigned long schema_hash)
69
0
                : _tablet_id(tablet_id), _schema_hash(schema_hash) {}
70
71
        MigrationTask(int64_t tablet_id, unsigned long schema_hash, std::string dest_disk)
72
0
                : _tablet_id(tablet_id), _schema_hash(schema_hash), _dest_disk(dest_disk) {}
73
74
0
        bool operator<(const MigrationTask& right) const {
75
0
            if (_tablet_id != right._tablet_id) {
76
0
                return _tablet_id < right._tablet_id;
77
0
            } else if (_schema_hash != right._schema_hash) {
78
0
                return _schema_hash < right._schema_hash;
79
0
            } else {
80
0
                return false;
81
0
            }
82
0
        }
83
84
0
        std::string to_string() const {
85
0
            std::stringstream ss;
86
0
            ss << "MigrationTask: tablet_id=" << _tablet_id << ", schema_hash=" << _schema_hash
87
0
               << ", dest_disk=" << _dest_disk;
88
0
            return ss.str();
89
0
        }
90
91
        int64_t _tablet_id;
92
        unsigned long _schema_hash;
93
        std::string _dest_disk;
94
    };
95
96
    std::mutex _migration_status_mutex;
97
    std::map<MigrationTask, std::string> _migration_tasks;
98
    std::deque<std::pair<MigrationTask, Status>> _finished_migration_tasks;
99
};
100
} // namespace doris