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

WIP: Consistent hashing for balancer #258

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/deferer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace utils
{

template<typename F>
class Deferer
{
F action_;

public:
Deferer(F&& action) :
action_{std::move(action)}
{}
Deferer(const Deferer& other) = delete;
Deferer(Deferer&& other) = delete;
Deferer& operator=(const Deferer& other) = delete;
Deferer& operator=(Deferer&& other) = delete;
~Deferer()
{
action_();
}
};

} // namespace utils
6 changes: 3 additions & 3 deletions dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "worker_gc.h"

#include "common/counters.h"
#include "common/deferer.h"
#include "common/define.h"

#include "debug_latch.h"
Expand Down Expand Up @@ -1612,6 +1613,7 @@ balancer_real_id_t* generation::rebuild_service_ring_one_wrr(
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service)
{
utils::Deferer defer([]() { YADECAP_MEMORY_BARRIER_COMPILE; });
for (uint32_t real_idx = service->real_start;
Copy link
Collaborator

@ol-imorozko ol-imorozko Dec 12, 2024

Choose a reason for hiding this comment

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

IMHO this makes code unnecessary complex. Maybe with more complex logic it will be fine, but here I feel like just doing

//...
	if (start == do_not_exceed)
	
		YANET_LOG_ERROR("Balancer service exceeded ring chunk bounds\n");
		YADECAP_MEMORY_BARRIER_COMPILE
		return start;
	}
//...
	YADECAP_MEMORY_BARRIER_COMPILE;
	return start;
}

is sufficient enough

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to YADECAP_MEMORY_BARRIER_COMPILE at each function exit path. Using it at each existing function exit doesn't convey this intent to future function changes.

How about using a DEFERED_MEMORY_BARRIER_COMPILE macro?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, maybe your solution makes more sense that I've thought initially.
smth like this will suffice?

struct MemoryBarrierGuard {
    ~MemoryBarrierGuard() {
        YADECAP_MEMORY_BARRIER_COMPILE;
    }
};

And do that at the start of every method:

Result cControlPlane::init(bool use_kernel_interface)
{
    MemoryBarrierGuard guard;
    //...

real_idx < service->real_start + service->real_size;
++real_idx)
Expand All @@ -1631,15 +1633,13 @@ balancer_real_id_t* generation::rebuild_service_ring_one_wrr(
if (start == do_not_exceed)
{
YANET_LOG_ERROR("Balancer service exceeded ring chunk bounds\n");
goto finish;
return start;
}
*start = real_id;
++start;
}
}

finish:
YADECAP_MEMORY_BARRIER_COMPILE;
return start;
}

Expand Down
Loading