Skip to content

Commit

Permalink
remove more dead code
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Jul 9, 2024
1 parent 7d15a7b commit 9d320bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 48 deletions.
12 changes: 4 additions & 8 deletions src/meta/node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Context;
use either::Either;
use etcd_client::ConnectOptions;
use otlp_embedded::TraceServiceServer;
use regex::Regex;
Expand Down Expand Up @@ -292,7 +291,7 @@ pub async fn rpc_serve_with_store(
let follower_handle = tokio::spawn(start_service_as_election_follower(
follower_shutdown.clone(),
address_info.clone(),
Some(election_client.clone()),
election_client.clone(),
));

// Watch and wait until we become the leader.
Expand Down Expand Up @@ -341,12 +340,9 @@ pub async fn rpc_serve_with_store(
pub async fn start_service_as_election_follower(
shutdown: CancellationToken,
address_info: AddressInfo,
election_client: Option<ElectionClientRef>,
election_client: ElectionClientRef,
) {
let meta_member_srv = MetaMemberServiceImpl::new(match election_client {
None => Either::Right(address_info.clone()),
Some(election_client) => Either::Left(election_client),
});
let meta_member_srv = MetaMemberServiceImpl::new(election_client);

let health_srv = HealthServiceImpl::new();

Expand Down Expand Up @@ -463,7 +459,7 @@ pub async fn start_service_as_election_leader(
.unwrap();
let object_store_media_type = hummock_manager.object_store_media_type();

let meta_member_srv = MetaMemberServiceImpl::new(Either::Left(election_client.clone()));
let meta_member_srv = MetaMemberServiceImpl::new(election_client.clone());

let prometheus_client = opts.prometheus_endpoint.as_ref().map(|x| {
use std::str::FromStr;
Expand Down
57 changes: 17 additions & 40 deletions src/meta/service/src/meta_member_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use either::Either;
use risingwave_common::util::addr::HostAddr;
use risingwave_meta::rpc::ElectionClientRef;
use risingwave_pb::common::HostAddress;
use risingwave_pb::meta::meta_member_service_server::MetaMemberService;
use risingwave_pb::meta::{MembersRequest, MembersResponse, MetaMember};
use tonic::{Request, Response, Status};

use crate::AddressInfo;
#[derive(Clone)]
pub struct MetaMemberServiceImpl {
election_client_or_self: Either<ElectionClientRef, AddressInfo>,
election_client: ElectionClientRef,
}

impl MetaMemberServiceImpl {
pub fn new(election_client_or_self: Either<ElectionClientRef, AddressInfo>) -> Self {
MetaMemberServiceImpl {
election_client_or_self,
}
pub fn new(election_client: ElectionClientRef) -> Self {
MetaMemberServiceImpl { election_client }
}
}

Expand All @@ -41,39 +37,20 @@ impl MetaMemberService for MetaMemberServiceImpl {
&self,
_request: Request<MembersRequest>,
) -> Result<Response<MembersResponse>, Status> {
let members = match &self.election_client_or_self {
Either::Left(election_client) => {
let mut members = vec![];
for member in election_client.get_members().await? {
let host_addr = member
.id
.parse::<HostAddr>()
.map_err(|err| Status::from_error(err.into()))?;
members.push(MetaMember {
address: Some(HostAddress {
host: host_addr.host,
port: host_addr.port.into(),
}),
is_leader: member.is_leader,
})
}

members
}
Either::Right(self_as_leader) => {
let host_addr = self_as_leader
.advertise_addr
.parse::<HostAddr>()
.map_err(|err| Status::from_error(err.into()))?;
vec![MetaMember {
address: Some(HostAddress {
host: host_addr.host,
port: host_addr.port.into(),
}),
is_leader: true,
}]
}
};
let mut members = vec![];
for member in self.election_client.get_members().await? {
let host_addr = member
.id
.parse::<HostAddr>()
.map_err(|err| Status::from_error(err.into()))?;
members.push(MetaMember {
address: Some(HostAddress {
host: host_addr.host,
port: host_addr.port.into(),
}),
is_leader: member.is_leader,
})
}

Ok(Response::new(MembersResponse { members }))
}
Expand Down

0 comments on commit 9d320bf

Please sign in to comment.