Skip to content

Commit d1392ce

Browse files
authored
Merge pull request #396 from eBay/jkou-dev
Rebase & merge V4 back to main
2 parents f72bec0 + 7cf0dbc commit d1392ce

33 files changed

+1120
-264
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.idea/**
33
.cache
44
.clangd
5+
.claude/*
56

67
build
78
test_package/build

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class HomeObjectConan(ConanFile):
1212
name = "homeobject"
13-
version = "3.0.20"
13+
version = "4.1.0"
1414

1515
homepage = "https://github.com/eBay/HomeObject"
1616
description = "Blob Store built on HomeStore"

src/include/homeobject/blob_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BlobManager : public Manager< BlobError > {
4343
public:
4444
virtual AsyncResult< blob_id_t > put(shard_id_t shard, Blob&&, trace_id_t tid = 0) = 0;
4545
virtual AsyncResult< Blob > get(shard_id_t shard, blob_id_t const& blob, uint64_t off = 0, uint64_t len = 0,
46-
trace_id_t tid = 0) const = 0;
46+
bool allow_skip_verify = false, trace_id_t tid = 0) const = 0;
4747
virtual NullAsyncResult del(shard_id_t shard, blob_id_t const& blob, trace_id_t tid = 0) = 0;
4848
};
4949

src/include/homeobject/shard_manager.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct ShardError {
2525
};
2626

2727
struct ShardInfo {
28+
static constexpr uint64_t meta_length = 1024 + 1;
2829
enum class State : uint8_t {
2930
OPEN = 0,
3031
SEALED = 1,
@@ -40,6 +41,7 @@ struct ShardInfo {
4041
uint64_t available_capacity_bytes;
4142
uint64_t total_capacity_bytes;
4243
std::optional< peer_id_t > current_leader{std::nullopt};
44+
uint8_t meta[meta_length]{};
4345

4446
auto operator<=>(ShardInfo const& rhs) const { return id <=> rhs.id; }
4547
auto operator==(ShardInfo const& rhs) const { return id == rhs.id; }
@@ -55,7 +57,7 @@ class ShardManager : public Manager< ShardError > {
5557

5658
virtual AsyncResult< ShardInfo > get_shard(shard_id_t id, trace_id_t tid = 0) const = 0;
5759
virtual AsyncResult< InfoList > list_shards(pg_id_t id, trace_id_t tid = 0) const = 0;
58-
virtual AsyncResult< ShardInfo > create_shard(pg_id_t pg_owner, uint64_t size_bytes, trace_id_t tid = 0) = 0;
60+
virtual AsyncResult< ShardInfo > create_shard(pg_id_t pg_owner, uint64_t size_bytes, std::string meta, trace_id_t tid = 0) = 0;
5961
virtual AsyncResult< ShardInfo > seal_shard(shard_id_t id, trace_id_t tid = 0) = 0;
6062
};
6163

src/lib/blob_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace homeobject {
55
std::shared_ptr< BlobManager > HomeObjectImpl::blob_manager() { return shared_from_this(); }
66

77
BlobManager::AsyncResult< Blob > HomeObjectImpl::get(shard_id_t shard, blob_id_t const& blob_id, uint64_t off,
8-
uint64_t len, trace_id_t tid) const {
8+
uint64_t len, bool allow_skip_verify, trace_id_t tid) const {
99
return _get_shard(shard, tid)
10-
.thenValue([this, blob_id, off, len, tid](auto const e) -> BlobManager::AsyncResult< Blob > {
10+
.thenValue([this, blob_id, off, len, allow_skip_verify, tid](auto const e) -> BlobManager::AsyncResult< Blob > {
1111
if (!e) return folly::makeUnexpected(BlobError(BlobErrorCode::UNKNOWN_SHARD));
12-
return _get_blob(e.value(), blob_id, off, len, tid);
12+
return _get_blob(e.value(), blob_id, off, len, allow_skip_verify, tid);
1313
});
1414
}
1515

src/lib/homeobject_impl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ class HomeObjectImpl : public HomeObject,
8888
public std::enable_shared_from_this< HomeObjectImpl > {
8989

9090
/// Implementation defines these
91-
virtual ShardManager::AsyncResult< ShardInfo > _create_shard(pg_id_t, uint64_t size_bytes, trace_id_t tid) = 0;
91+
virtual ShardManager::AsyncResult< ShardInfo > _create_shard(pg_id_t, uint64_t size_bytes, std::string meta, trace_id_t tid) = 0;
9292
virtual ShardManager::AsyncResult< ShardInfo > _seal_shard(ShardInfo const&, trace_id_t tid) = 0;
9393

9494
virtual BlobManager::AsyncResult< blob_id_t > _put_blob(ShardInfo const&, Blob&&, trace_id_t tid) = 0;
9595
virtual BlobManager::AsyncResult< Blob > _get_blob(ShardInfo const&, blob_id_t, uint64_t off, uint64_t len,
96-
trace_id_t tid) const = 0;
96+
bool allow_skip_verify, trace_id_t tid) const = 0;
9797
virtual BlobManager::NullAsyncResult _del_blob(ShardInfo const&, blob_id_t, trace_id_t tid) = 0;
9898
///
9999

@@ -189,15 +189,15 @@ class HomeObjectImpl : public HomeObject,
189189

190190
/// ShardManager
191191
ShardManager::AsyncResult< ShardInfo > get_shard(shard_id_t id, trace_id_t tid) const final;
192-
ShardManager::AsyncResult< ShardInfo > create_shard(pg_id_t pg_owner, uint64_t size_bytes, trace_id_t tid) final;
192+
ShardManager::AsyncResult< ShardInfo > create_shard(pg_id_t pg_owner, uint64_t size_bytes, std::string meta, trace_id_t tid) final;
193193
ShardManager::AsyncResult< InfoList > list_shards(pg_id_t pg, trace_id_t tid) const final;
194194
ShardManager::AsyncResult< ShardInfo > seal_shard(shard_id_t id, trace_id_t tid) final;
195195
uint64_t get_current_timestamp();
196196

197197
/// BlobManager
198198
BlobManager::AsyncResult< blob_id_t > put(shard_id_t shard, Blob&&, trace_id_t tid) final;
199199
BlobManager::AsyncResult< Blob > get(shard_id_t shard, blob_id_t const& blob, uint64_t off, uint64_t len,
200-
trace_id_t tid) const final;
200+
bool allow_skip_verify, trace_id_t tid) const final;
201201
BlobManager::NullAsyncResult del(shard_id_t shard, blob_id_t const& blob, trace_id_t tid) final;
202202
};
203203

src/lib/homestore_backend/gc_manager.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ void GCManager::start() {
122122
gc_actor->start();
123123
LOGINFOMOD(gcmgr, "start gc actor for pdev={}", pdev_id);
124124
}
125+
start_gc_scan_timer();
126+
}
125127

128+
void GCManager::start_gc_scan_timer() {
126129
const auto gc_scan_interval_sec = HS_BACKEND_DYNAMIC_CONFIG(gc_scan_interval_sec);
127130

128131
// the initial idea here is that we want gc timer to run in a reactor that not shared with other fibers that
@@ -146,9 +149,7 @@ void GCManager::start() {
146149
LOGINFOMOD(gcmgr, "gc scheduler timer has started, interval is set to {} seconds", gc_scan_interval_sec);
147150
}
148151

149-
bool GCManager::is_started() { return m_gc_timer_hdl != iomgr::null_timer_handle; }
150-
151-
void GCManager::stop() {
152+
void GCManager::stop_gc_scan_timer() {
152153
if (m_gc_timer_hdl == iomgr::null_timer_handle) {
153154
LOGWARNMOD(gcmgr, "gc scheduler timer is not running, no need to stop it");
154155
return;
@@ -162,6 +163,10 @@ void GCManager::stop() {
162163
m_gc_timer_hdl = iomgr::null_timer_handle;
163164
});
164165
m_gc_timer_fiber = nullptr;
166+
}
167+
168+
void GCManager::stop() {
169+
stop_gc_scan_timer();
165170

166171
for (const auto& [pdev_id, gc_actor] : m_pdev_gc_actors) {
167172
gc_actor->stop();
@@ -170,9 +175,20 @@ void GCManager::stop() {
170175
}
171176

172177
folly::SemiFuture< bool > GCManager::submit_gc_task(task_priority priority, chunk_id_t chunk_id) {
173-
if (!is_started()) return folly::makeFuture< bool >(false);
178+
auto ex_vchunk = m_chunk_selector->get_extend_vchunk(chunk_id);
179+
if (ex_vchunk == nullptr) {
180+
LOGERRORMOD(gcmgr, "chunk {} not found when submit gc task!", chunk_id);
181+
return folly::makeFuture< bool >(false);
182+
}
183+
184+
// if the chunk has no garbage to be reclaimed, we don`t need to gc it , return true directly
185+
const auto defrag_blk_num = ex_vchunk->get_defrag_nblks();
186+
if (!defrag_blk_num && task_priority::normal == priority) {
187+
LOGERRORMOD(gcmgr, "chunk {} has no garbage to be reclaimed, skip gc for this chunk!", chunk_id);
188+
return folly::makeFuture< bool >(true);
189+
}
174190

175-
auto pdev_id = m_chunk_selector->get_extend_vchunk(chunk_id)->get_pdev_id();
191+
auto pdev_id = ex_vchunk->get_pdev_id();
176192
auto it = m_pdev_gc_actors.find(pdev_id);
177193
if (it == m_pdev_gc_actors.end()) {
178194
LOGINFOMOD(gcmgr, "pdev gc actor not found for pdev_id={}, chunk={}", pdev_id, chunk_id);
@@ -218,7 +234,7 @@ bool GCManager::is_eligible_for_gc(chunk_id_t chunk_id) {
218234

219235
const auto total_blk_num = chunk->get_total_blks();
220236
const auto gc_garbage_rate_threshold = HS_BACKEND_DYNAMIC_CONFIG(gc_garbage_rate_threshold);
221-
bool should_gc = 100 * defrag_blk_num >= total_blk_num * gc_garbage_rate_threshold;
237+
bool should_gc = 100 * defrag_blk_num > total_blk_num * gc_garbage_rate_threshold;
222238

223239
LOGDEBUGMOD(gcmgr,
224240
"gc scan chunk_id={}, use_blks={}, available_blks={}, total_blks={}, defrag_blks={}, should_gc={}",
@@ -334,6 +350,11 @@ void GCManager::pdev_gc_actor::add_reserved_chunk(
334350
}
335351

336352
folly::SemiFuture< bool > GCManager::pdev_gc_actor::add_gc_task(uint8_t priority, chunk_id_t move_from_chunk) {
353+
if (m_is_stopped.load()) {
354+
LOGWARNMOD(gcmgr, "pdev gc actor for pdev_id={} is not started yet or already stopped, cannot add gc task!",
355+
m_pdev_id);
356+
return folly::makeSemiFuture< bool >(false);
357+
}
337358
auto EXvchunk = m_chunk_selector->get_extend_vchunk(move_from_chunk);
338359
// it does not belong to any pg, so we don't need to gc it.
339360
if (!EXvchunk->m_pg_id.has_value()) {

src/lib/homestore_backend/gc_manager.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ class GCManager {
310310

311311
void start();
312312
void stop();
313-
bool is_started();
313+
314+
// the following two functions should not be called concurrently. if we need to call them concurrently, we need to
315+
// add lock to protect
316+
void start_gc_scan_timer();
317+
void stop_gc_scan_timer();
314318

315319
void scan_chunks_for_gc();
316320
void drain_pg_pending_gc_task(const pg_id_t pg_id);

0 commit comments

Comments
 (0)