Skip to content

Commit 2ebf3c0

Browse files
committed
Refactor some types in rpc/pd
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 8da60f2 commit 2ebf3c0

File tree

3 files changed

+9
-79
lines changed

3 files changed

+9
-79
lines changed

src/rpc/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl RpcClient {
372372
inner.locate_key(scan.start_key()).and_then(|location| {
373373
let region = location;
374374
let cf = scan.state.cf.clone();
375-
Self::region_context_by_id(Arc::clone(&inner), region.id)
375+
Self::region_context_by_id(Arc::clone(&inner), region.id())
376376
.map_ok(|(region, client)| {
377377
(scan, region.range(), RawContext::new(region, client, cf))
378378
})
@@ -428,7 +428,7 @@ impl RpcClient {
428428
inner.locate_key(scan.start_key()).and_then(|location| {
429429
let region = location;
430430
let cf = scan.state.clone();
431-
Self::region_context_by_id(Arc::clone(&inner), region.id)
431+
Self::region_context_by_id(Arc::clone(&inner), region.id())
432432
.map_ok(|(region, client)| {
433433
(scan, region.range(), RawContext::new(region, client, cf))
434434
})
@@ -484,9 +484,9 @@ impl RegionContext {
484484
impl From<RegionContext> for kvrpcpb::Context {
485485
fn from(mut ctx: RegionContext) -> kvrpcpb::Context {
486486
let mut kvctx = kvrpcpb::Context::default();
487-
kvctx.set_region_id(ctx.region.id);
488-
kvctx.set_region_epoch(ctx.region.take_region_epoch());
489-
kvctx.set_peer(ctx.region.peer().expect("leader must exist").into_inner());
487+
kvctx.set_region_id(ctx.region.id());
488+
kvctx.set_region_epoch(ctx.region.region.take_region_epoch());
489+
kvctx.set_peer(ctx.region.peer().expect("leader must exist"));
490490
kvctx
491491
}
492492
}

src/rpc/pd/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl PdClient {
195195
cli.get_store_async_opt(&req, opt).map(Compat01As03::new)
196196
},
197197
))
198-
.map_ok(|mut resp| resp.take_store().into())
198+
.map_ok(|mut resp| resp.take_store())
199199
}
200200

201201
pub fn get_region(&self, key: &[u8]) -> impl Future<Output = Result<Region>> {

src/rpc/pd/mod.rs

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// TODO: Remove this when txn is done.
44
#![allow(dead_code)]
55

6-
use std::ops::{Deref, DerefMut};
7-
6+
pub use kvproto::metapb::{Peer, Store};
87
use kvproto::{kvrpcpb, metapb};
98

109
pub use crate::rpc::pd::client::PdClient;
@@ -32,26 +31,9 @@ pub struct Region {
3231
pub leader: Option<Peer>,
3332
}
3433

35-
impl Deref for Region {
36-
type Target = metapb::Region;
37-
38-
fn deref(&self) -> &Self::Target {
39-
&self.region
40-
}
41-
}
42-
43-
impl DerefMut for Region {
44-
fn deref_mut(&mut self) -> &mut Self::Target {
45-
&mut self.region
46-
}
47-
}
48-
4934
impl Region {
5035
pub fn new(region: metapb::Region, leader: Option<metapb::Peer>) -> Self {
51-
Region {
52-
region,
53-
leader: leader.map(Peer),
54-
}
36+
Region { region, leader }
5537
}
5638

5739
pub fn switch_peer(&mut self, _to: StoreId) -> Result<()> {
@@ -109,59 +91,7 @@ impl Region {
10991
}
11092

11193
pub fn meta(&self) -> metapb::Region {
112-
Clone::clone(&self.region)
113-
}
114-
}
115-
116-
#[derive(Clone, Debug, PartialEq)]
117-
pub struct Store(metapb::Store);
118-
119-
impl From<metapb::Store> for Store {
120-
fn from(store: metapb::Store) -> Store {
121-
Store(store)
122-
}
123-
}
124-
125-
impl Deref for Store {
126-
type Target = metapb::Store;
127-
128-
fn deref(&self) -> &Self::Target {
129-
&self.0
130-
}
131-
}
132-
133-
impl DerefMut for Store {
134-
fn deref_mut(&mut self) -> &mut Self::Target {
135-
&mut self.0
136-
}
137-
}
138-
139-
#[derive(Clone, Default, Debug, PartialEq)]
140-
pub struct Peer(metapb::Peer);
141-
142-
impl From<metapb::Peer> for Peer {
143-
fn from(peer: metapb::Peer) -> Peer {
144-
Peer(peer)
145-
}
146-
}
147-
148-
impl Deref for Peer {
149-
type Target = metapb::Peer;
150-
151-
fn deref(&self) -> &Self::Target {
152-
&self.0
153-
}
154-
}
155-
156-
impl DerefMut for Peer {
157-
fn deref_mut(&mut self) -> &mut Self::Target {
158-
&mut self.0
159-
}
160-
}
161-
162-
impl Peer {
163-
pub fn into_inner(self) -> metapb::Peer {
164-
self.0
94+
self.region.clone()
16595
}
16696
}
16797

0 commit comments

Comments
 (0)