Skip to content

Commit

Permalink
refactor: refactor XlineServer
Browse files Browse the repository at this point in the history
Read issue xline-kv#293 for more details

Closes xline-kv#293
  • Loading branch information
Phoenix500526 committed Jun 2, 2023
1 parent d9b6038 commit 68b3b80
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 220 deletions.
8 changes: 4 additions & 4 deletions xline/src/header_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use parking_lot::Mutex;

use crate::{revision_number::RevisionNumber, rpc::ResponseHeader};
use crate::{revision_number::RevisionNumberGenerator, rpc::ResponseHeader};

/// Generator of `ResponseHeader`
#[derive(Debug)]
Expand All @@ -14,7 +14,7 @@ pub(crate) struct HeaderGenerator {
/// term of curp
term: Arc<Mutex<u64>>,
/// revision of kv store
revision: Arc<RevisionNumber>,
revision: Arc<RevisionNumberGenerator>,
}

impl HeaderGenerator {
Expand All @@ -24,7 +24,7 @@ impl HeaderGenerator {
cluster_id,
member_id,
term: Arc::new(Mutex::new(0)),
revision: Arc::new(RevisionNumber::default()),
revision: Arc::new(RevisionNumberGenerator::default()),
}
}

Expand Down Expand Up @@ -60,7 +60,7 @@ impl HeaderGenerator {
}

/// Return Arc of revision
pub(crate) fn revision_arc(&self) -> Arc<RevisionNumber> {
pub(crate) fn revision_arc(&self) -> Arc<RevisionNumberGenerator> {
Arc::clone(&self.revision)
}
}
7 changes: 2 additions & 5 deletions xline/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,13 @@ async fn main() -> Result<()> {
cluster_config.name().clone(),
cluster_config.members().clone(),
*cluster_config.is_leader(),
key_pair,
cluster_config.curp_config().clone(),
*cluster_config.client_timeout(),
*cluster_config.server_timeout(),
config.storage().clone(),
db_proxy,
)
.await;
);
debug!("{:?}", server);
server.start(self_addr).await?;
server.start(self_addr, db_proxy, key_pair).await?;
global::shutdown_tracer_provider();
Ok(())
}
8 changes: 4 additions & 4 deletions xline/src/revision_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::sync::atomic::{AtomicI64, Ordering};

/// Revision number
#[derive(Debug)]
pub(crate) struct RevisionNumber(AtomicI64);
pub(crate) struct RevisionNumberGenerator(AtomicI64);

impl RevisionNumber {
impl RevisionNumberGenerator {
/// Create a new revision
pub(crate) fn new(rev: i64) -> Self {
Self(AtomicI64::new(rev))
Expand All @@ -26,9 +26,9 @@ impl RevisionNumber {
}
}

impl Default for RevisionNumber {
impl Default for RevisionNumberGenerator {
#[inline]
fn default() -> Self {
RevisionNumber::new(1)
RevisionNumberGenerator::new(1)
}
}
10 changes: 5 additions & 5 deletions xline/src/server/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};

use super::barriers::{IdBarrier, IndexBarrier};
use crate::{
revision_number::RevisionNumber,
revision_number::RevisionNumberGenerator,
rpc::{RequestBackend, RequestWithToken, RequestWrapper, ResponseWrapper},
storage::{db::WriteOp, storage_api::StorageApi, AuthStore, ExecuteError, KvStore, LeaseStore},
};
Expand Down Expand Up @@ -217,9 +217,9 @@ where
/// Barrier for propose id
id_barrier: Arc<IdBarrier>,
/// Revision Number generator for KV request and Lease request
general_rev: Arc<RevisionNumber>,
general_rev: Arc<RevisionNumberGenerator>,
/// Revision Number generator for Auth request
auth_rev: Arc<RevisionNumber>,
auth_rev: Arc<RevisionNumberGenerator>,
}

impl<S> CommandExecutor<S>
Expand All @@ -235,8 +235,8 @@ where
persistent: Arc<S>,
index_barrier: Arc<IndexBarrier>,
id_barrier: Arc<IdBarrier>,
general_rev: Arc<RevisionNumber>,
auth_rev: Arc<RevisionNumber>,
general_rev: Arc<RevisionNumberGenerator>,
auth_rev: Arc<RevisionNumberGenerator>,
) -> Self {
Self {
kv_storage,
Expand Down
Loading

0 comments on commit 68b3b80

Please sign in to comment.