Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDSTOR-11579. expose chunk and chunkSelector Header #157

Merged
merged 6 commits into from
Sep 13, 2023

Conversation

JacksonYao287
Copy link
Contributor

No description provided.

Copy link
Collaborator

@xiaoxichen xiaoxichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@xiaoxichen xiaoxichen requested review from yamingk and szmyd September 6, 2023 05:42
szmyd
szmyd previously requested changes Sep 6, 2023
src/include/homestore/chunk.h Outdated Show resolved Hide resolved
src/include/homestore/homestore_decl.hpp Outdated Show resolved Hide resolved
@JacksonYao287 JacksonYao287 force-pushed the migrate-chunk-to-include-folder branch from d7dc214 to 1a0db6d Compare September 7, 2023 12:07
@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2023

Codecov Report

Patch coverage: 35.29% and project coverage change: -0.14% ⚠️

Comparison is base (91b264a) 54.10% compared to head (87070a1) 53.96%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #157      +/-   ##
==========================================
- Coverage   54.10%   53.96%   -0.14%     
==========================================
  Files          96       98       +2     
  Lines        8922     8941      +19     
  Branches     1112     1116       +4     
==========================================
- Hits         4827     4825       -2     
- Misses       3685     3706      +21     
  Partials      410      410              
Files Changed Coverage Δ
src/lib/blkdata_svc/blkdata_service.cpp 74.60% <ø> (ø)
src/lib/device/chunk.h 89.47% <0.00%> (-4.98%) ⬇️
src/lib/device/device_manager.cpp 76.30% <ø> (ø)
src/lib/device/journal_vdev.cpp 17.22% <ø> (ø)
src/lib/device/physical_dev.cpp 76.79% <ø> (ø)
src/lib/device/round_robin_chunk_selector.h 100.00% <ø> (ø)
src/lib/device/vchunk.cpp 0.00% <0.00%> (ø)
src/lib/device/virtual_dev.hpp 88.23% <ø> (ø)
src/lib/index/wb_cache.cpp 0.00% <ø> (ø)
src/lib/logstore/log_store_service.cpp 62.93% <ø> (ø)
... and 7 more

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

xiaoxichen
xiaoxichen previously approved these changes Sep 8, 2023
Copy link
Collaborator

@xiaoxichen xiaoxichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

src/lib/device/vchunk.cpp Outdated Show resolved Hide resolved
src/lib/device/vchunk.cpp Show resolved Hide resolved

namespace homestore {
RoundRobinChunkSelector::RoundRobinChunkSelector(bool dynamic_chunk_add) : m_dynamic_chunk_add{dynamic_chunk_add} {
RELEASE_ASSERT_EQ(dynamic_chunk_add, false,
"Dynamically adding chunk to chunkselector is not supported, need RCU to make it thread safe");
}

void RoundRobinChunkSelector::add_chunk(cshared< Chunk >& chunk) { m_chunks.push_back(chunk); }
void RoundRobinChunkSelector::add_chunk(VChunk chunk) { m_chunks.push_back(chunk); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do std::move(chunk) instead of copy VChunk, which does increment and decrement of atomic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is back to the https://ebay-eng.slack.com/archives/CAVQXEAKS/p1694203171225199 discussion, vchunk only has single member <cshared_ptr>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

void foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) override;
void add_chunk(VChunk chunk) override;
Chunk* select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) override;
void foreach_chunks(std::function< void(VChunk&) >&& cb) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid std::function, to auto& and make use of lambda. If not, we don't want to call foreach_chunks on very critical path. I know it is a micro optimization, but one that accumulates over time.

Copy link
Contributor Author

@JacksonYao287 JacksonYao287 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is declared in a virtual class as a param of a virtual function. it tried , but the compiler throws an error that we can not use auto& or auto&& as parameter in a virtual function declaration.
we can keep it like this for now , and find another method to change it to lambda until it is necessary in the critical path

ChunkSelector() = default;
virtual void add_chunk(VChunk chunk) = 0;
virtual void foreach_chunks(std::function< void(VChunk&) >&& cb) = 0;
virtual Chunk* select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) = 0;
Copy link
Contributor

@yamingk yamingk Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to derive or not-derive, which you can decide, is there any challenge or reason that we need to expose two different types VChunk/Chunk* to consumer with add/select?
Can we either return VChunk or Chunk for both add/select apis?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customer code can use

ChunkSelector::add_chunk(chunk *)
chunk *p_chunk = ChunkSelector:select()

Copy link
Contributor Author

@JacksonYao287 JacksonYao287 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yamingk i change it to return cshared< Chunk > in both add/select apis to keep the style consistent, and do the transition inside homestore

@JacksonYao287 JacksonYao287 force-pushed the migrate-chunk-to-include-folder branch from 849de5f to 87070a1 Compare September 12, 2023 10:38
@@ -197,7 +197,7 @@ BlkAllocStatus VirtualDev::do_alloc_blk(blk_count_t nblks, const blk_alloc_hints
size_t attempt{0};

do {
chunk = m_chunk_selector->select(nblks, hints);
chunk = m_chunk_selector->select_chunk(nblks, hints).get();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkadayam This is dangerous as raw ptr/shared ptr are mixed used.

The cshare was born in PhysicalDev::create_chunks and all the way pass to chunkSelector, however the consumer part(allocator, etc) use raw ptr get from the cshare.

It is functioning fine as a reference to every chunk was kept at m_chunks_map but it is a bad practice. Maybe lets have a ticket to move those *chunk to cshare ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with this change of doing a .get() and select_chunk() returning a shared_ptr. Why incrementing atomic reference when all you are doing is accessing an in-memory member. I am not asking to change now, but will change in next PR.

I would rather return a chunk_id and look it up on the all chunks in vdev. If vdev doesn't maintain all chunks, then I would rather ask it to return a reference to chunks. This is a critical path for homestore, don't want unneccessary atomic reference increment and decrements.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the upstream (PhysicalDev::create_chunks ) use shared_ptr, if we dont want ref counting we can change the interface of add/select to ref/raw_ptr. It could work as pdev holds the shared_ptr that ensuring the chunks will not be de-construct, just not safe.

@xiaoxichen xiaoxichen merged commit ecb93eb into eBay:master Sep 13, 2023
@JacksonYao287 JacksonYao287 deleted the migrate-chunk-to-include-folder branch September 13, 2023 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants