• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paticcaa / pain / 17470377484

04 Sep 2025 04:24PM UTC coverage: 54.644%. First build
17470377484

Pull #10

github

web-flow
Merge c11cc5401 into e6f85a326
Pull Request #10: check index

1512 of 3772 branches covered (40.08%)

Branch coverage included in aggregate %.

80 of 104 new or added lines in 4 files covered. (76.92%)

1759 of 2214 relevant lines covered (79.45%)

425.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.2
/src/deva/deva.cc
1
#include "deva/deva.h"
2
#include <pain/base/plog.h>
3
#include <pain/base/uuid.h>
4
#include "common/txn_manager.h"
5
#include "deva/macro.h"
6

7
#define DEVA_METHOD(name)                                                                                              \
8
    Status Deva::name([[maybe_unused]] int32_t version,                                                                \
9
                      [[maybe_unused]] const pain::proto::deva::store::name##Request* request,                         \
10
                      [[maybe_unused]] pain::proto::deva::store::name##Response* response,                             \
11
                      [[maybe_unused]] int64_t index)
12

13
namespace pain::deva {
14

15
Status Deva::create(const std::string& path, const UUID& id, FileType type) {
75✔
16
    SPAN(span);
374!
17
    PLOG_DEBUG(("desc", "create")("path", path)("id", id.str())("type", type));
74✔
18
    // get parent
19
    std::filesystem::path file_path(path);
75!
20
    auto dir = file_path.parent_path();
75!
21
    auto filename = file_path.filename();
75!
22
    auto file_type = FileType::kFile;
75✔
23
    UUID parent_dir_uuid;
75✔
24
    auto status = _namespace.lookup(dir.c_str(), &parent_dir_uuid, &file_type);
75!
25
    if (!status.ok()) {
75✔
26
        return status;
1!
27
    }
28

29
    if (file_type != FileType::kDirectory) {
73!
30
        return Status(EINVAL, fmt::format("{} is not a directory", dir.c_str()));
×
31
    }
32

33
    UUID file_uuid(id.high(), id.low());
73✔
34
    status = _namespace.create(parent_dir_uuid, filename, type, file_uuid);
73!
35
    if (!status.ok()) {
75!
36
        return status;
×
37
    }
38

39
    return Status::OK();
75✔
40
}
223✔
41

42
DEVA_METHOD(CreateFile) {
36✔
43
    SPAN(span);
180!
44
    PLOG_DEBUG(("desc", "create_file")("version", version)("index", index)("request", request->DebugString()));
36✔
45
    auto& path = request->path();
36!
46
    auto& file_id = request->file_id();
36!
47
    UUID file_uuid(file_id.high(), file_id.low());
36!
48
    auto status = create(path, file_uuid, FileType::kFile);
36!
49
    if (!status.ok()) {
36!
50
        return status;
×
51
    }
52
    auto file_info = response->mutable_file_info();
36!
53
    file_info->mutable_file_id()->set_high(file_uuid.high());
36!
54
    file_info->mutable_file_id()->set_low(file_uuid.low());
36!
55
    file_info->set_type(pain::proto::FileType::FILE_TYPE_FILE);
36!
56
    file_info->set_size(0);
36!
57
    file_info->set_atime(request->atime());
36!
58
    file_info->set_mtime(request->mtime());
36!
59
    file_info->set_ctime(request->ctime());
36!
60
    file_info->set_mode(request->mode());
36!
61
    file_info->set_uid(request->uid());
36!
62
    file_info->set_gid(request->gid());
36!
63
    _file_infos[file_uuid] = *file_info;
36!
64
    return Status::OK();
36✔
65
}
108✔
66

67
DEVA_METHOD(CreateDir) {
38✔
68
    SPAN(span);
193!
69
    PLOG_DEBUG(("desc", "create_dir")("version", version)("index", index)("request", request->DebugString()));
39✔
70
    auto& path = request->path();
39!
71
    auto& dir_id = request->dir_id();
39!
72
    UUID dir_uuid(dir_id.high(), dir_id.low());
39!
73
    auto status = create(path, dir_uuid, FileType::kDirectory);
39!
74
    if (!status.ok()) {
39!
75
        return status;
×
76
    }
77
    auto file_info = response->mutable_file_info();
39!
78
    file_info->mutable_file_id()->set_high(dir_uuid.high());
39!
79
    file_info->mutable_file_id()->set_low(dir_uuid.low());
39!
80
    file_info->set_type(pain::proto::FileType::FILE_TYPE_DIRECTORY);
39!
81
    file_info->set_size(0);
39!
82
    file_info->set_atime(request->atime());
39!
83
    file_info->set_mtime(request->mtime());
39!
84
    file_info->set_ctime(request->ctime());
39!
85
    file_info->set_mode(request->mode());
39!
86
    file_info->set_uid(request->uid());
39!
87
    file_info->set_gid(request->gid());
39!
88
    _file_infos[dir_uuid] = *file_info;
39!
89
    return Status::OK();
39✔
90
}
117✔
91

92
DEVA_METHOD(ReadDir) {
2✔
93
    SPAN(span);
10!
94
    PLOG_DEBUG(("desc", "read_dir")("version", version)("index", index)("request", request->DebugString()));
2✔
95
    auto& path = request->path();
2!
96
    UUID parent_dir_uuid;
2✔
97
    FileType file_type = FileType::kNone;
2✔
98
    auto status = _namespace.lookup(path.c_str(), &parent_dir_uuid, &file_type);
2!
99
    if (!status.ok()) {
2!
100
        return status;
×
101
    }
102
    if (file_type != FileType::kDirectory) {
2!
103
        return Status(EINVAL, fmt::format("{} is not a directory", path.c_str()));
×
104
    }
105
    std::list<DirEntry> entries;
2✔
106
    _namespace.list(parent_dir_uuid, &entries);
2!
107
    for (auto& entry : entries) {
23✔
108
        auto dir_entry = response->add_entries();
21!
109
        dir_entry->mutable_file_id()->set_high(entry.inode.high());
21!
110
        dir_entry->mutable_file_id()->set_low(entry.inode.low());
21!
111
        dir_entry->set_type(static_cast<pain::proto::FileType>(entry.type));
21!
112
        dir_entry->set_name(std::move(entry.name));
21✔
113
    }
114
    return Status::OK();
2✔
115
}
6✔
116

117
DEVA_METHOD(RemoveFile) {
×
118
    SPAN(span);
×
119
    PLOG_INFO(("desc", "remove_file")("version", version)("index", index));
×
120
    return Status::OK();
×
121
}
×
122

123
DEVA_METHOD(SealFile) {
×
124
    SPAN(span);
×
125
    PLOG_INFO(("desc", "seal_file")("version", version)("index", index));
×
126
    return Status::OK();
×
127
}
×
128

129
DEVA_METHOD(CreateChunk) {
×
130
    SPAN(span);
×
131
    PLOG_INFO(("desc", "remove")("version", version)("index", index));
×
132
    return Status::OK();
×
133
}
×
134

135
DEVA_METHOD(CheckInChunk) {
×
136
    SPAN(span);
×
137
    PLOG_INFO(("desc", "seal")("version", version)("index", index));
×
138
    return Status::OK();
×
139
}
×
140

141
DEVA_METHOD(SealChunk) {
×
142
    SPAN(span);
×
143
    PLOG_INFO(("desc", "create_chunk")("version", version)("index", index));
×
144
    return Status::OK();
×
145
}
×
146

147
DEVA_METHOD(SealAndNewChunk) {
×
148
    SPAN(span);
×
149
    PLOG_INFO(("desc", "remove_chunk")("version", version)("index", index));
×
150
    return Status::OK();
×
151
}
×
152

153
Status Deva::set_applied_index(int64_t index) {
75✔
154
    if (index <= _applied_index) {
75!
NEW
155
        PLOG_WARN(("desc", "index is applied already")("index", index));
×
NEW
156
        return Status::OK();
×
157
    }
158
    auto in_txn = common::TxnManager::instance().in_txn();
75!
159
    auto this_txn = _store->begin_txn();
75!
160
    auto txn = in_txn ? common::TxnManager::instance().get_txn_store() : this_txn.get();
75!
161
    if (txn == nullptr) {
75!
NEW
162
        return Status(EIO, "Failed to begin transaction");
×
163
    }
164
    auto status = txn->hset(_meta_key, _applied_index_key, std::to_string(index));
75!
165
    return status;
75!
166
    if (in_txn) {
167
        return Status::OK();
168
    }
169

170
    status = txn->commit();
171
    return status;
172
}
75✔
173

174
Status Deva::save_snapshot(std::string_view path, std::vector<std::string>* files) {
3✔
175
    return _store->check_point(path.data(), files);
3✔
176
}
177

178
Status Deva::load_snapshot(std::string_view path) {
3✔
179
    auto status = _store->recover(path.data());
3!
180
    if (!status.ok()) {
3!
NEW
181
        return status;
×
182
    }
183
    // get applied index
184
    std::string applied_index_str;
3✔
185
    status = _store->hget(_meta_key, _applied_index_key, &applied_index_str);
3!
186
    if (!status.ok()) {
3!
NEW
187
        return status;
×
188
    }
189
    _applied_index = std::stoll(applied_index_str);
3!
190
    return Status::OK();
3✔
191
}
3✔
192

193
} // namespace pain::deva
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc