forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic leader balance for storage, keep trying to trans leader from host with most leader to host with least leader, until all balanced. Modify/Add two command in console: 1. "show host" will also display total leader count and leader count in each space 2. add command "balance leader", which will try to balance leader between different hosts
- Loading branch information
1 parent
3b2f3cf
commit c7c1818
Showing
57 changed files
with
1,739 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#include "graph/BalanceExecutor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
BalanceExecutor::BalanceExecutor(Sentence *sentence, | ||
ExecutionContext *ectx) : Executor(ectx) { | ||
sentence_ = static_cast<BalanceSentence*>(sentence); | ||
} | ||
|
||
Status BalanceExecutor::prepare() { | ||
return Status::OK(); | ||
} | ||
|
||
void BalanceExecutor::execute() { | ||
auto showType = sentence_->subType(); | ||
switch (showType) { | ||
case BalanceSentence::SubType::kLeader: | ||
balanceLeader(); | ||
break; | ||
case BalanceSentence::SubType::kUnknown: | ||
onError_(Status::Error("Type unknown")); | ||
break; | ||
} | ||
} | ||
|
||
void BalanceExecutor::balanceLeader() { | ||
auto future = ectx()->getMetaClient()->balanceLeader(); | ||
auto *runner = ectx()->rctx()->runner(); | ||
|
||
auto cb = [this] (auto &&resp) { | ||
if (!resp.ok()) { | ||
DCHECK(onError_); | ||
onError_(std::move(resp).status()); | ||
return; | ||
} | ||
auto ret = std::move(resp).value(); | ||
if (!ret) { | ||
DCHECK(onError_); | ||
onError_(Status::Error("Balance leader failed")); | ||
return; | ||
} | ||
DCHECK(onFinish_); | ||
onFinish_(); | ||
}; | ||
|
||
auto error = [this] (auto &&e) { | ||
LOG(ERROR) << "Exception caught: " << e.what(); | ||
DCHECK(onError_); | ||
onError_(Status::Error("Internal error")); | ||
return; | ||
}; | ||
|
||
std::move(future).via(runner).thenValue(cb).thenError(error); | ||
} | ||
|
||
} // namespace graph | ||
} // namespace nebula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#ifndef GRAPH_BALANCEEXECUTOR_H_ | ||
#define GRAPH_BALANCEEXECUTOR_H_ | ||
|
||
#include "base/Base.h" | ||
#include "graph/Executor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
class BalanceExecutor final : public Executor { | ||
public: | ||
BalanceExecutor(Sentence *sentence, ExecutionContext *ectx); | ||
|
||
const char* name() const override { | ||
return "BalanceExecutor"; | ||
} | ||
|
||
Status MUST_USE_RESULT prepare() override; | ||
|
||
void execute() override; | ||
|
||
void balanceLeader(); | ||
|
||
private: | ||
BalanceSentence *sentence_{nullptr}; | ||
std::unique_ptr<cpp2::ExecutionResponse> resp_; | ||
}; | ||
|
||
} // namespace graph | ||
} // namespace nebula | ||
|
||
#endif // GRAPH_BALANCEEXECUTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.