Fix some warnings

This commit is contained in:
Arthur Petukhovsky
2023-07-28 21:37:16 +00:00
parent 095747afc0
commit cb6a8d3fe3
5 changed files with 19 additions and 17 deletions

View File

@@ -117,10 +117,10 @@ walprop_async_read(WalProposerConn *conn, char **buf, int *amount)
Assert(event.tag == Message);
Assert(event.any_message == Bytes);
msg = sim_msg_get_bytes(&len);
msg = (char*) sim_msg_get_bytes(&len);
*buf = msg;
*amount = len;
walprop_log(INFO, "walprop_async_read: %d", len);
walprop_log(INFO, "walprop_async_read: %d", (int) len);
return PG_ASYNC_READ_SUCCESS;
}

View File

@@ -86,9 +86,9 @@ void sim_msg_set_repl_cell(uint32_t value, uint32_t client_id, uint32_t seqno);
/**
* Write AnyMessage::Bytes message.
*/
void sim_msg_set_bytes(const uint8_t *bytes, uintptr_t len);
void sim_msg_set_bytes(const char *bytes, uintptr_t len);
/**
* Read AnyMessage::Bytes message.
*/
const uint8_t *sim_msg_get_bytes(uintptr_t *len);
const char *sim_msg_get_bytes(uintptr_t *len);

View File

@@ -1,5 +1,5 @@
use safekeeper::simlib::proto::{AnyMessage, ReplCell};
use std::cell::RefCell;
use std::{cell::RefCell, ffi::c_char};
pub(crate) fn anymessage_tag(msg: &AnyMessage) -> AnyMessageTag {
match msg {
@@ -58,13 +58,13 @@ pub extern "C" fn sim_msg_set_repl_cell(value: u32, client_id: u32, seqno: u32)
#[no_mangle]
/// Write AnyMessage::Bytes message.
pub extern "C" fn sim_msg_set_bytes(bytes: *const u8, len: usize) {
pub extern "C" fn sim_msg_set_bytes(bytes: *const c_char, len: usize) {
MESSAGE_BUF.with(|cell| {
// copy bytes to a Rust Vec
let mut v = Vec::with_capacity(len);
let mut v: Vec<u8> = Vec::with_capacity(len);
unsafe {
v.set_len(len);
std::ptr::copy_nonoverlapping(bytes, v.as_mut_ptr(), len);
std::ptr::copy_nonoverlapping(bytes as *const u8, v.as_mut_ptr(), len);
}
*cell.borrow_mut() = AnyMessage::Bytes(v.into());
});
@@ -72,12 +72,12 @@ pub extern "C" fn sim_msg_set_bytes(bytes: *const u8, len: usize) {
#[no_mangle]
/// Read AnyMessage::Bytes message.
pub extern "C" fn sim_msg_get_bytes(len: *mut usize) -> *const u8 {
pub extern "C" fn sim_msg_get_bytes(len: *mut usize) -> *const c_char {
MESSAGE_BUF.with(|cell| match &*cell.borrow() {
AnyMessage::Bytes(v) => {
unsafe {
*len = v.len();
v.as_ptr()
v.as_ptr() as *const i8
}
}
_ => panic!("expected Bytes message"),

View File

@@ -17,15 +17,15 @@ use crate::{
};
struct TestConfig {
network: Arc<NetworkOptions>,
network: NetworkOptions,
timeout: u64,
}
impl TestConfig {
fn new() -> Self {
Self {
network: Arc::new(NetworkOptions {
timeout: Some(1000),
network: NetworkOptions {
timeout: Some(2000),
connect_delay: Delay {
min: 1,
max: 5,
@@ -36,13 +36,13 @@ impl TestConfig {
max: 5,
fail_prob: 0.0,
},
}),
},
timeout: 1_000 * 10,
}
}
fn start(&self, seed: u64) -> Test {
let world = Arc::new(World::new(seed, self.network.clone(), c_context()));
let world = Arc::new(World::new(seed, Arc::new(self.network.clone()), c_context()));
world.register_world();
let servers = [world.new_node(), world.new_node(), world.new_node()];
@@ -205,7 +205,8 @@ fn sync_empty_safekeepers() {
fn run_walproposer_generate_wal() {
logging::init(logging::LogFormat::Plain).unwrap();
let config = TestConfig::new();
let mut config = TestConfig::new();
// config.network.timeout = Some(250);
let test = config.start(1337);
let lsn = test.sync_safekeepers().unwrap();

View File

@@ -472,7 +472,7 @@ SimWaitEventSetWait(Safekeeper **sk, long timeout, WaitEvent *occurred_events)
for (int i = 0; i < n_safekeepers; i++) {
if (safekeeper[i].conn && ((int64_t) walprop_socket(safekeeper[i].conn)) == event.tcp) {
*occurred_events = (WaitEvent) {
.events = WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE,
.events = WL_SOCKET_READABLE,
};
*sk = &safekeeper[i];
return 1;
@@ -559,6 +559,7 @@ WalProposerPoll(void)
*/
if (availableLsn != InvalidXLogRecPtr)
{
walprop_log(LOG, "no WAL generated during timeout, sending pool message");
BroadcastAppendRequest();
}