Skip to content

Commit 11180f6

Browse files
committed
misc: remove useless code
Signed-off-by: Anthony Griffon <[email protected]>
1 parent 81f06b8 commit 11180f6

File tree

6 files changed

+11
-189
lines changed

6 files changed

+11
-189
lines changed

app/roster/src/application/server/cmd/get.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use super::parse::Parse;
44
use super::CommandExecution;
55
use crate::application::server::connection::WriteConnection;
66
use crate::application::server::context::Context;
7-
use crate::application::server::crc_hash;
87
use crate::application::server::frame::Frame;
8+
use crate::infrastructure::hash::crc_hash;
99

1010
/// Get the value of key. If the key does not exist the special value nil is
1111
/// returned. An error is returned if the value stored at key is not a string,

app/roster/src/application/server/cmd/set.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ use std::time::Duration;
33
use bytes::Bytes;
44
use bytestring::ByteString;
55

6-
76
use super::parse::{Parse, ParseError};
87
use super::CommandExecution;
98
use crate::application::server::connection::WriteConnection;
109
use crate::application::server::context::Context;
1110
use crate::application::server::frame::Frame;
12-
use crate::application::server::{crc_hash};
1311
use crate::domain::storage::SetOptions;
12+
use crate::infrastructure::hash::crc_hash;
1413

1514
/// Set key to hold the string value. If key already holds a value, it is
1615
/// overwritten, regardless of its type.

app/roster/src/application/server/handle.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::cell::RefCell;
2-
use std::os::fd::{IntoRawFd};
2+
use std::os::fd::IntoRawFd;
33
use std::rc::Rc;
44
use std::time::Duration;
55

6-
7-
86
use sharded_thread::shard::Shard;
97

108
use super::cmd::Command;
@@ -38,6 +36,7 @@ impl Handler {
3836
self.run_internal(ctx, None).await
3937
}
4038

39+
#[allow(dead_code)]
4140
pub async fn continue_run(
4241
self,
4342
ctx: Context,

app/roster/src/application/server/mod.rs

+1-173
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
//! The whole redis server implementation is here.
22
use std::net::SocketAddr;
3-
4-
53
use std::sync::atomic::AtomicU16;
64
use std::sync::Arc;
75
use std::thread::JoinHandle;
86

9-
use crc::{Crc, CRC_16_XMODEM};
107
use derive_builder::Builder;
118

12-
13-
149
mod connection;
1510
mod context;
1611
pub mod frame;
1712
pub(crate) mod handle;
1813

19-
20-
21-
2214
mod cmd;
2315
mod server_thread;
2416

2517
use self::server_thread::ServerMonoThreadedHandle;
26-
27-
2818
use crate::application::server::handle::ConnectionMsg;
29-
3019
use crate::domain::dialer::{RootDialer, Slot};
3120
use crate::domain::storage::Storage;
21+
use crate::infrastructure::hash::HASH_SLOT_MAX;
3222

3323
#[derive(Debug, Builder, Clone)]
3424
#[builder(pattern = "owned", setter(into, strip_option))]
@@ -38,21 +28,6 @@ pub struct ServerConfig {
3828
connections_limit: Arc<AtomicU16>,
3929
}
4030

41-
cfg_if::cfg_if! {
42-
if #[cfg(target_os = "linux")] {
43-
type Driver = monoio::IoUringDriver;
44-
} else {
45-
type Driver = monoio::LegacyDriver;
46-
}
47-
}
48-
49-
const CRC: Crc<u16> = Crc::<u16>::new(&CRC_16_XMODEM);
50-
51-
pub const HASH_SLOT_MAX: u16 = 16384;
52-
pub const fn crc_hash(bytes: &[u8]) -> u16 {
53-
CRC.checksum(bytes) % HASH_SLOT_MAX
54-
}
55-
5631
impl ServerConfig {
5732
/// Initialize a Server by starting the thread for each core and assigning
5833
/// the storage segment & hash slots based on the configuration.
@@ -83,153 +58,6 @@ impl ServerConfig {
8358
threads.push(handle.initialize());
8459
}
8560

86-
/*
87-
let mut slots = Vec::new();
88-
for cpu in 0..cpus {
89-
let part_size: u16 = HASH_SLOT_MAX / cpus as u16;
90-
let remainder: u16 = HASH_SLOT_MAX % cpus as u16;
91-
92-
let start = cpu as u16 * part_size as u16;
93-
let end = if cpu == cpus - 1 {
94-
(cpu as u16 + 1) * part_size + remainder as u16
95-
} else {
96-
(cpu as u16 + 1) * part_size as u16
97-
};
98-
99-
let slot = start..end;
100-
slots.push(slot);
101-
}
102-
103-
for cpu in 0..cpus {
104-
let config = self.clone();
105-
let shard = mesh.join_with(cpu).unwrap();
106-
107-
let slot = slots.get(cpu).unwrap().clone();
108-
let slots = slots.clone();
109-
110-
let handle = std::thread::spawn(move || {
111-
monoio::utils::bind_to_cpu_set(Some(cpu)).unwrap();
112-
113-
let mut rt = monoio::RuntimeBuilder::<Driver>::new()
114-
.with_entries(1024)
115-
.enable_timer()
116-
.build()
117-
.expect("Cannot build runtime");
118-
119-
rt.block_on(async move {
120-
// Initialize domain
121-
let storage =
122-
domain::storage::StorageSegment::new(slots, slot);
123-
let shard = Rc::new(shard);
124-
125-
let listener = TcpListener::bind_with_config(
126-
config.bind_addr,
127-
&ListenerConfig::new().backlog(16192),
128-
)
129-
.expect("Couldn't listen to addr");
130-
131-
// Start the async task which is able to receive connection
132-
// from other thread
133-
let storage_inter_thread = storage.clone();
134-
let shard_inter_thread = shard.clone();
135-
monoio::spawn(async move {
136-
let storage = storage_inter_thread;
137-
let shard = shard_inter_thread;
138-
139-
let mut receiver = shard.receiver().unwrap();
140-
141-
loop {
142-
let shard = shard.clone();
143-
let ctx = Context::new(storage.clone());
144-
145-
// Pre-allocate next buffer;
146-
147-
if let Some(ConnectionMsg {
148-
fd,
149-
current_command,
150-
rest_frame,
151-
}) = receiver.next().await
152-
{
153-
let _spawned = monoio::spawn(async move {
154-
// TODO: We miss things in the buffer right
155-
// now &
156-
// pipelining
157-
// Already accepted tcp stream, we don't
158-
// need to
159-
// accept it again.
160-
let tcp = unsafe {
161-
std::net::TcpStream::from_raw_fd(fd)
162-
};
163-
let conn =
164-
TcpStream::from_std(tcp).unwrap();
165-
conn.set_nodelay(true).unwrap();
166-
167-
let (connection, r) =
168-
WriteConnection::new(conn, 4 * 1024);
169-
170-
let handler = Handler {
171-
connection,
172-
connection_r: r,
173-
shard,
174-
};
175-
176-
if let Err(err) = handler
177-
.continue_run(ctx, current_command)
178-
.await
179-
{
180-
dbg!(err.backtrace());
181-
dbg!(&err);
182-
// error!(?err);
183-
panic!("blbl");
184-
}
185-
// handler.connection.stop().await.unwrap();
186-
});
187-
} else {
188-
break;
189-
}
190-
}
191-
});
192-
193-
loop {
194-
let storage = storage.clone();
195-
let shard = shard.clone();
196-
197-
// We accept the TCP Connection
198-
let (conn, _addr) = listener
199-
.accept()
200-
.await
201-
.expect("Unable to accept connections");
202-
203-
conn.set_nodelay(true).unwrap();
204-
let ctx = Context::new(storage);
205-
206-
// We map it to an `Handler` which is able to understand
207-
// the Redis protocol
208-
let _spawned = monoio::spawn(async move {
209-
let (connection, r) =
210-
WriteConnection::new(conn, 4 * 1024);
211-
212-
let handler = Handler {
213-
connection,
214-
connection_r: r,
215-
shard: shard.clone(),
216-
};
217-
218-
if let Err(err) = handler.run(ctx).await {
219-
dbg!(err.backtrace());
220-
dbg!(&err);
221-
// error!(?err);
222-
panic!("blbl");
223-
}
224-
// handler.connection.stop().await.unwrap();
225-
});
226-
}
227-
});
228-
});
229-
threads.push(handle);
230-
}
231-
*/
232-
23361
ServerHandle { threads }
23462
}
23563
}

app/roster/src/application/server/server_thread.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::rc::Rc;
22
use std::thread::JoinHandle;
33

4-
54
use monoio::net::{ListenerConfig, TcpListener};
65

76
use super::ServerConfig;
@@ -31,10 +30,6 @@ pub struct ServerMonoThreadedHandle {
3130
storage: StorageSegment,
3231
}
3332

34-
pub struct ServerMonoThreadedInitialized {
35-
handle: JoinHandle<()>,
36-
}
37-
3833
impl ServerMonoThreadedHandle {
3934
/// Start a new server thread on the cpu_core
4035
pub fn new(
@@ -55,8 +50,6 @@ impl ServerMonoThreadedHandle {
5550
}
5651

5752
pub fn initialize(self) -> JoinHandle<()> {
58-
59-
6053
std::thread::spawn(move || {
6154
monoio::utils::bind_to_cpu_set(Some(self.cpu)).unwrap();
6255

@@ -112,7 +105,8 @@ impl ServerMonoThreadedHandle {
112105

113106
#[allow(unreachable_code)]
114107
Ok::<(), anyhow::Error>(())
115-
});
108+
})
109+
.unwrap();
116110
})
117111
}
118112
}

app/roster/src/domain/dialer/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::ops::{Deref, Range};
22

3-
4-
53
use sharded_thread::mesh::MeshBuilder;
64
use sharded_thread::shard::Shard;
75

@@ -69,12 +67,16 @@ impl RootDialer {
6967
#[derive(Debug)]
7068
pub struct Dialer {
7169
pub shard: Shard<ConnectionMsg>,
70+
#[allow(dead_code)]
7271
cluster: Cluster,
7372
/// The current local slot of the Dialer
73+
#[allow(dead_code)]
7474
local_slot: Slot,
7575
/// The whole slice of the current server
76+
#[allow(dead_code)]
7677
global_slot: Slot,
7778
/// Slot -> part based on index
79+
#[allow(dead_code)]
7880
inner_slots: Vec<Slot>,
7981
}
8082

0 commit comments

Comments
 (0)