You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by gk...@apache.org on 2025/10/15 15:58:47 UTC

(iggy) branch io_uring_tpc updated: feat(io_uring): fix data integrity test (#2263)

This is an automated email from the ASF dual-hosted git repository.

gkoszyk pushed a commit to branch io_uring_tpc
in repository https://gitbox.apache.org/repos/asf/iggy.git


The following commit(s) were added to refs/heads/io_uring_tpc by this push:
     new 36d46c21d feat(io_uring): fix data integrity test (#2263)
36d46c21d is described below

commit 36d46c21d0c6dcf7190c9a6cbd3d0489b94c1f3b
Author: Grzegorz Koszyk <11...@users.noreply.github.com>
AuthorDate: Wed Oct 15 17:58:43 2025 +0200

    feat(io_uring): fix data integrity test (#2263)
    
    Co-authored-by: Hubert Gruszecki <h....@gmail.com>
---
 core/bench/src/actors/producer/client/low_level.rs |  2 +-
 .../consumer_offsets/delete_consumer_offset.rs     |  2 +-
 .../consumer_offsets/get_consumer_offset.rs        |  2 +-
 .../consumer_offsets/store_consumer_offset.rs      |  2 +-
 core/common/src/commands/messages/poll_messages.rs |  2 +-
 core/integration/src/test_server.rs                | 48 ++++++-----
 .../data_integrity/verify_after_server_restart.rs  | 94 ++++++++++++++++------
 core/integration/tests/mcp/mod.rs                  | 20 ++---
 .../tests/server/scenarios/encryption_scenario.rs  |  8 +-
 .../tests/server/scenarios/tcp_tls_scenario.rs     |  2 +-
 core/server/server.http                            |  2 +-
 .../messages/flush_unsaved_buffer_handler.rs       | 21 ++---
 core/server/src/bootstrap.rs                       | 22 ++---
 core/server/src/http/messages.rs                   |  6 +-
 core/server/src/quic/quic_server.rs                |  3 +
 core/server/src/shard/mod.rs                       | 18 ++++-
 core/server/src/shard/system/messages.rs           | 87 +++++++++++++-------
 core/server/src/shard/transmission/event.rs        |  4 +
 core/server/src/shard/transmission/frame.rs        |  1 +
 core/server/src/shard/transmission/message.rs      |  3 +
 core/server/src/slab/streams.rs                    |  9 ++-
 core/server/src/tcp/tcp_listener.rs                |  7 ++
 core/server/src/tcp/tcp_tls_listener.rs            |  7 ++
 23 files changed, 250 insertions(+), 122 deletions(-)

diff --git a/core/bench/src/actors/producer/client/low_level.rs b/core/bench/src/actors/producer/client/low_level.rs
index 86d022648..fc2f483ed 100644
--- a/core/bench/src/actors/producer/client/low_level.rs
+++ b/core/bench/src/actors/producer/client/low_level.rs
@@ -49,7 +49,7 @@ impl LowLevelProducerClient {
             client: None,
             stream_id: Identifier::default(),
             topic_id: Identifier::default(),
-            partitioning: Partitioning::partition_id(1),
+            partitioning: Partitioning::partition_id(0),
         }
     }
 }
diff --git a/core/common/src/commands/consumer_offsets/delete_consumer_offset.rs b/core/common/src/commands/consumer_offsets/delete_consumer_offset.rs
index aab6c096d..8cfeac24d 100644
--- a/core/common/src/commands/consumer_offsets/delete_consumer_offset.rs
+++ b/core/common/src/commands/consumer_offsets/delete_consumer_offset.rs
@@ -54,7 +54,7 @@ impl Default for DeleteConsumerOffset {
             consumer: Consumer::default(),
             stream_id: Identifier::default(),
             topic_id: Identifier::default(),
-            partition_id: Some(1),
+            partition_id: Some(0),
         }
     }
 }
diff --git a/core/common/src/commands/consumer_offsets/get_consumer_offset.rs b/core/common/src/commands/consumer_offsets/get_consumer_offset.rs
index c2a3dda8e..a98ac6c4d 100644
--- a/core/common/src/commands/consumer_offsets/get_consumer_offset.rs
+++ b/core/common/src/commands/consumer_offsets/get_consumer_offset.rs
@@ -67,7 +67,7 @@ impl Command for GetConsumerOffset {
 }
 
 fn default_partition_id() -> Option<u32> {
-    Some(1)
+    Some(0)
 }
 
 impl Validatable<IggyError> for GetConsumerOffset {
diff --git a/core/common/src/commands/consumer_offsets/store_consumer_offset.rs b/core/common/src/commands/consumer_offsets/store_consumer_offset.rs
index ad3c4eae6..9500138d1 100644
--- a/core/common/src/commands/consumer_offsets/store_consumer_offset.rs
+++ b/core/common/src/commands/consumer_offsets/store_consumer_offset.rs
@@ -57,7 +57,7 @@ impl Default for StoreConsumerOffset {
             consumer: Consumer::default(),
             stream_id: Identifier::default(),
             topic_id: Identifier::default(),
-            partition_id: Some(1),
+            partition_id: Some(0),
             offset: 0,
         }
     }
diff --git a/core/common/src/commands/messages/poll_messages.rs b/core/common/src/commands/messages/poll_messages.rs
index 3f4045bbd..e51b03ef6 100644
--- a/core/common/src/commands/messages/poll_messages.rs
+++ b/core/common/src/commands/messages/poll_messages.rs
@@ -24,7 +24,7 @@ use bytes::{BufMut, Bytes, BytesMut};
 use serde::{Deserialize, Serialize};
 use std::fmt::Display;
 
-pub const DEFAULT_PARTITION_ID: u32 = 1;
+pub const DEFAULT_PARTITION_ID: u32 = 0;
 pub const DEFAULT_NUMBER_OF_MESSAGES_TO_POLL: u32 = 10;
 
 /// `PollMessages` command is used to poll messages from a topic in a stream.
diff --git a/core/integration/src/test_server.rs b/core/integration/src/test_server.rs
index 7914c4c2e..160094d26 100644
--- a/core/integration/src/test_server.rs
+++ b/core/integration/src/test_server.rs
@@ -408,33 +408,41 @@ impl TestServer {
         });
 
         if let Some(config) = config {
-            let quic_addr: SocketAddr = config.quic.address.parse().unwrap();
-            if quic_addr.port() == 0 {
-                panic!("Quic address port is 0!");
+            // Only validate and add enabled protocols
+            if config.quic.enabled {
+                let quic_addr: SocketAddr = config.quic.address.parse().unwrap();
+                if quic_addr.port() == 0 {
+                    panic!("Quic address port is 0!");
+                }
+                self.server_addrs
+                    .push(ServerProtocolAddr::QuicUdp(quic_addr));
             }
 
-            let tcp_addr: SocketAddr = config.tcp.address.parse().unwrap();
-            if tcp_addr.port() == 0 {
-                panic!("Tcp address port is 0!");
+            if config.tcp.enabled {
+                let tcp_addr: SocketAddr = config.tcp.address.parse().unwrap();
+                if tcp_addr.port() == 0 {
+                    panic!("Tcp address port is 0!");
+                }
+                self.server_addrs.push(ServerProtocolAddr::RawTcp(tcp_addr));
             }
 
-            let http_addr: SocketAddr = config.http.address.parse().unwrap();
-            if http_addr.port() == 0 {
-                panic!("Http address port is 0!");
+            if config.http.enabled {
+                let http_addr: SocketAddr = config.http.address.parse().unwrap();
+                if http_addr.port() == 0 {
+                    panic!("Http address port is 0!");
+                }
+                self.server_addrs
+                    .push(ServerProtocolAddr::HttpTcp(http_addr));
             }
 
-            let websocket_addr: SocketAddr = config.websocket.address.parse().unwrap();
-            if websocket_addr.port() == 0 {
-                panic!("WebSocket address port is 0!");
+            if config.websocket.enabled {
+                let websocket_addr: SocketAddr = config.websocket.address.parse().unwrap();
+                if websocket_addr.port() == 0 {
+                    panic!("WebSocket address port is 0!");
+                }
+                self.server_addrs
+                    .push(ServerProtocolAddr::WebSocket(websocket_addr));
             }
-
-            self.server_addrs
-                .push(ServerProtocolAddr::QuicUdp(quic_addr));
-            self.server_addrs.push(ServerProtocolAddr::RawTcp(tcp_addr));
-            self.server_addrs
-                .push(ServerProtocolAddr::HttpTcp(http_addr));
-            self.server_addrs
-                .push(ServerProtocolAddr::WebSocket(websocket_addr));
         } else {
             panic!(
                 "Failed to load config from file {config_path} in {MAX_PORT_WAIT_DURATION_S} s!"
diff --git a/core/integration/tests/data_integrity/verify_after_server_restart.rs b/core/integration/tests/data_integrity/verify_after_server_restart.rs
index 17e029e0d..32e7c1c54 100644
--- a/core/integration/tests/data_integrity/verify_after_server_restart.rs
+++ b/core/integration/tests/data_integrity/verify_after_server_restart.rs
@@ -28,10 +28,6 @@ use serial_test::parallel;
 use std::{collections::HashMap, str::FromStr};
 use test_case::test_matrix;
 
-/*
- * Helper functions for test matrix parameters
- */
-
 fn cache_open_segment() -> &'static str {
     "open_segment"
 }
@@ -46,7 +42,7 @@ fn cache_none() -> &'static str {
 
 // TODO(numminex) - Move the message generation method from benchmark run to a special method.
 #[test_matrix(
-    [cache_open_segment(), cache_all(), cache_none()]
+    [cache_all(), cache_open_segment(), cache_none()]
 )]
 #[tokio::test]
 #[parallel]
@@ -85,17 +81,6 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
         amount_of_data_to_process,
     );
 
-    let default_bench_stream_identifiers: [Identifier; 8] = [
-        Identifier::numeric(3000001).unwrap(),
-        Identifier::numeric(3000002).unwrap(),
-        Identifier::numeric(3000003).unwrap(),
-        Identifier::numeric(3000004).unwrap(),
-        Identifier::numeric(3000005).unwrap(),
-        Identifier::numeric(3000006).unwrap(),
-        Identifier::numeric(3000007).unwrap(),
-        Identifier::numeric(3000008).unwrap(),
-    ];
-
     // 4. Connect and login to newly started server
     let client = TcpClientFactory {
         server_addr,
@@ -103,12 +88,15 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
     }
     .create_client()
     .await;
+
     let client = IggyClient::create(client, None, None);
     login_root(&client).await;
-    let topic_id = Identifier::numeric(1).unwrap();
-    for stream_id in default_bench_stream_identifiers {
+
+    let topic_id = Identifier::numeric(0).unwrap();
+    for i in 0..7 {
+        let stream_id = Identifier::numeric(i).unwrap();
         client
-            .flush_unsaved_buffer(&stream_id, &topic_id, 1, false)
+            .flush_unsaved_buffer(&stream_id, &topic_id, 0, true)
             .await
             .unwrap();
     }
@@ -133,7 +121,50 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
     test_server.start();
     let server_addr = test_server.get_raw_tcp_addr().unwrap();
 
-    // 8. Run send bench again to add more data
+    // 8. Verify stats are preserved after restart (before adding more data)
+    let client_after_restart = IggyClient::create(
+        TcpClientFactory {
+            server_addr: server_addr.clone(),
+            ..Default::default()
+        }
+        .create_client()
+        .await,
+        None,
+        None,
+    );
+    login_root(&client_after_restart).await;
+
+    let stats_after_restart = client_after_restart.get_stats().await.unwrap();
+    assert_eq!(
+        expected_messages_count, stats_after_restart.messages_count,
+        "Messages count should be preserved after restart (before: {}, after: {})",
+        expected_messages_count, stats_after_restart.messages_count
+    );
+    assert_eq!(
+        expected_messages_size_bytes.as_bytes_usize(),
+        stats_after_restart.messages_size_bytes.as_bytes_usize(),
+        "Messages size bytes should be preserved after restart (before: {}, after: {})",
+        expected_messages_size_bytes.as_bytes_usize(),
+        stats_after_restart.messages_size_bytes.as_bytes_usize()
+    );
+    assert_eq!(
+        expected_streams_count, stats_after_restart.streams_count,
+        "Streams count should be preserved after restart"
+    );
+    assert_eq!(
+        expected_topics_count, stats_after_restart.topics_count,
+        "Topics count should be preserved after restart"
+    );
+    assert_eq!(
+        expected_partitions_count, stats_after_restart.partitions_count,
+        "Partitions count should be preserved after restart"
+    );
+    assert_eq!(
+        expected_segments_count, stats_after_restart.segments_count,
+        "Segments count should be preserved after restart"
+    );
+
+    // 9. Run send bench again to add more data
     run_bench_and_wait_for_finish(
         &server_addr,
         &TransportProtocol::Tcp,
@@ -141,15 +172,16 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
         amount_of_data_to_process,
     );
 
-    // 9. Run poll bench again to check if all data is still there
+    // 10. Run poll bench again to check if all data is still there
     run_bench_and_wait_for_finish(
         &server_addr,
         &TransportProtocol::Tcp,
         "pinned-consumer",
         IggyByteSize::from(amount_of_data_to_process.as_bytes_u64() * 2),
     );
+    drop(client_after_restart);
 
-    // 10. Connect and login to newly started server
+    // 11. Connect and login to newly started server
     let client = IggyClient::create(
         TcpClientFactory {
             server_addr: server_addr.clone(),
@@ -162,7 +194,17 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
     );
     login_root(&client).await;
 
-    // 11. Save stats from the second server (should have double the data)
+    // 12. Flush unsaved buffer
+    let topic_id = Identifier::numeric(0).unwrap();
+    for i in 0..7 {
+        let stream_id = Identifier::numeric(i).unwrap();
+        client
+            .flush_unsaved_buffer(&stream_id, &topic_id, 0, true)
+            .await
+            .unwrap();
+    }
+
+    // 13. Save stats from the second server (should have double the data)
     let stats = client.get_stats().await.unwrap();
     let actual_messages_size_bytes = stats.messages_size_bytes;
     let actual_streams_count = stats.streams_count;
@@ -173,7 +215,7 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
     let actual_clients_count = stats.clients_count;
     let actual_consumer_groups_count = stats.consumer_groups_count;
 
-    // 12. Compare stats (expecting double the messages/size after second bench run)
+    // 14. Compare stats (expecting double the messages/size after second bench run)
     assert_eq!(
         expected_messages_size_bytes.as_bytes_usize() * 2,
         actual_messages_size_bytes.as_bytes_usize(),
@@ -206,7 +248,7 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
         "Consumer groups count"
     );
 
-    // 13. Run poll bench to check if all data (10MB total) is still there
+    // 15. Run poll bench to check if all data (10MB total) is still there
     run_bench_and_wait_for_finish(
         &server_addr,
         &TransportProtocol::Tcp,
@@ -214,6 +256,6 @@ async fn should_fill_data_and_verify_after_restart(cache_setting: &'static str)
         IggyByteSize::from(amount_of_data_to_process.as_bytes_u64() * 2),
     );
 
-    // 14. Manual cleanup
+    // 16. Manual cleanup
     std::fs::remove_dir_all(local_data_path).unwrap();
 }
diff --git a/core/integration/tests/mcp/mod.rs b/core/integration/tests/mcp/mod.rs
index 635b88990..3ffd8fc51 100644
--- a/core/integration/tests/mcp/mod.rs
+++ b/core/integration/tests/mcp/mod.rs
@@ -179,7 +179,7 @@ async fn mcp_server_should_create_topic() {
         "create_topic",
         Some(json!({ "stream_id": STREAM_NAME, "name": name, "partitions_count": 1})),
         |topic| {
-            assert_eq!(topic.id, 2);
+            assert_eq!(topic.id, 1);
             assert_eq!(topic.name, name);
             assert_eq!(topic.partitions_count, 1);
             assert_eq!(topic.messages_count, 0);
@@ -244,7 +244,7 @@ async fn mcp_server_should_delete_partitions() {
 async fn mcp_server_should_delete_segments() {
     assert_empty_response(
         "delete_segments",
-        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "segments_count": 1 })),
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 0, "segments_count": 1 })),
     )
     .await;
 }
@@ -254,7 +254,7 @@ async fn mcp_server_should_delete_segments() {
 async fn mcp_server_should_poll_messages() {
     assert_response::<PolledMessages>(
         "poll_messages",
-        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "offset": 0 })),
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 0, "offset": 0 })),
         |messages| {
             assert_eq!(messages.messages.len(), 1);
             let message = &messages.messages[0];
@@ -271,7 +271,7 @@ async fn mcp_server_should_poll_messages() {
 async fn mcp_server_should_send_messages() {
     assert_empty_response(
         "send_messages",
-        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "messages": [
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 0, "messages": [
             {
                 "payload": "test"
             }
@@ -375,11 +375,11 @@ async fn mcp_server_should_delete_consumer_group() {
 async fn mcp_server_should_return_consumer_offset() {
     assert_response::<Option<ConsumerOffsetInfo>>(
         "get_consumer_offset",
-        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1 })),
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 0 })),
         |offset| {
             assert!(offset.is_some());
             let offset = offset.unwrap();
-            assert_eq!(offset.partition_id, 1);
+            assert_eq!(offset.partition_id, 0);
             assert_eq!(offset.stored_offset, 0);
             assert_eq!(offset.current_offset, 0);
         },
@@ -392,7 +392,7 @@ async fn mcp_server_should_return_consumer_offset() {
 async fn mcp_server_should_store_consumer_offset() {
     assert_empty_response(
         "store_consumer_offset",
-        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "offset": 0 })),
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 0, "offset": 0 })),
     )
     .await;
 }
@@ -402,7 +402,7 @@ async fn mcp_server_should_store_consumer_offset() {
 async fn mcp_server_should_delete_consumer_offset() {
     assert_empty_response(
         "delete_consumer_offset",
-        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "offset": 0 })),
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 0, "offset": 0 })),
     )
     .await;
 }
@@ -630,7 +630,7 @@ async fn seed_data(iggy_server_address: &str) {
         .send_messages(
             &STREAM_ID,
             &TOPIC_ID,
-            &Partitioning::partition_id(1),
+            &Partitioning::partition_id(0),
             &mut messages,
         )
         .await
@@ -640,7 +640,7 @@ async fn seed_data(iggy_server_address: &str) {
         Consumer::new(Identifier::named(CONSUMER_NAME).expect("Failed to create consumer"));
 
     iggy_client
-        .store_consumer_offset(&consumer, &STREAM_ID, &TOPIC_ID, Some(1), 0)
+        .store_consumer_offset(&consumer, &STREAM_ID, &TOPIC_ID, Some(0), 0)
         .await
         .expect("Failed to store consumer offset");
 
diff --git a/core/integration/tests/server/scenarios/encryption_scenario.rs b/core/integration/tests/server/scenarios/encryption_scenario.rs
index 88c115851..77a81a6c1 100644
--- a/core/integration/tests/server/scenarios/encryption_scenario.rs
+++ b/core/integration/tests/server/scenarios/encryption_scenario.rs
@@ -130,7 +130,7 @@ async fn should_fill_data_with_headers_and_verify_after_restart_using_api(encryp
         .send_messages(
             &Identifier::numeric(stream_id).unwrap(),
             &Identifier::numeric(topic_id).unwrap(),
-            &Partitioning::partition_id(1),
+            &Partitioning::partition_id(0),
             &mut messages_batch_1,
         )
         .await
@@ -160,7 +160,7 @@ async fn should_fill_data_with_headers_and_verify_after_restart_using_api(encryp
         .poll_messages(
             &Identifier::numeric(stream_id).unwrap(),
             &Identifier::numeric(topic_id).unwrap(),
-            Some(1),
+            Some(0),
             &consumer,
             &PollingStrategy::offset(0),
             messages_per_batch.try_into().unwrap(),
@@ -275,7 +275,7 @@ async fn should_fill_data_with_headers_and_verify_after_restart_using_api(encryp
         .send_messages(
             &Identifier::numeric(stream_id).unwrap(),
             &Identifier::numeric(topic_id).unwrap(),
-            &Partitioning::partition_id(1), // Use specific partition for testing
+            &Partitioning::partition_id(0), // Use specific partition for testing
             &mut messages_batch_2,
         )
         .await
@@ -300,7 +300,7 @@ async fn should_fill_data_with_headers_and_verify_after_restart_using_api(encryp
         .poll_messages(
             &Identifier::numeric(stream_id).unwrap(),
             &Identifier::numeric(topic_id).unwrap(),
-            Some(1),
+            Some(0),
             &consumer,
             &PollingStrategy::offset(0),
             messages_per_batch as u32 * 2,
diff --git a/core/integration/tests/server/scenarios/tcp_tls_scenario.rs b/core/integration/tests/server/scenarios/tcp_tls_scenario.rs
index bac2b1858..4aa3e70c1 100644
--- a/core/integration/tests/server/scenarios/tcp_tls_scenario.rs
+++ b/core/integration/tests/server/scenarios/tcp_tls_scenario.rs
@@ -69,7 +69,7 @@ pub async fn run(client: &IggyClient) {
         .poll_messages(
             &Identifier::named(stream_name).unwrap(),
             &Identifier::named(topic_name).unwrap(),
-            Some(1),
+            Some(0),
             &Consumer::default(),
             &PollingStrategy::offset(0),
             1,
diff --git a/core/server/server.http b/core/server/server.http
index cb46d4213..19ceb0861 100644
--- a/core/server/server.http
+++ b/core/server/server.http
@@ -18,7 +18,7 @@
 @url = http://localhost:3000
 @stream_id = 1
 @topic_id = 1
-@partition_id = 1
+@partition_id = 0
 @consumer_group_id = 1
 @consumer_id = 1
 @client_id = 1
diff --git a/core/server/src/binary/handlers/messages/flush_unsaved_buffer_handler.rs b/core/server/src/binary/handlers/messages/flush_unsaved_buffer_handler.rs
index a799cfc4d..00f1f8aba 100644
--- a/core/server/src/binary/handlers/messages/flush_unsaved_buffer_handler.rs
+++ b/core/server/src/binary/handlers/messages/flush_unsaved_buffer_handler.rs
@@ -43,26 +43,27 @@ impl ServerCommandHandler for FlushUnsavedBuffer {
     ) -> Result<(), IggyError> {
         debug!("session: {session}, command: {self}");
 
+        let user_id = session.get_user_id();
         let stream_id = self.stream_id.clone();
         let topic_id = self.topic_id.clone();
-        let partition_id = self.partition_id as usize;
+        let partition_id = self.partition_id;
         let fsync = self.fsync;
+
         shard
-            .flush_unsaved_buffer(session, &stream_id, &topic_id, partition_id, fsync)
+            .flush_unsaved_buffer(
+                user_id,
+                self.stream_id,
+                self.topic_id,
+                partition_id as usize,
+                fsync,
+            )
             .await
             .with_error_context(|error| {
                 format!(
                     "{COMPONENT} (error: {error}) - failed to flush unsaved buffer for stream_id: {}, topic_id: {}, partition_id: {}, session: {}",
-                    self.stream_id, self.topic_id, self.partition_id, session
+                    stream_id, topic_id, partition_id, session
                 )
             })?;
-        let event = ShardEvent::FlushUnsavedBuffer {
-            stream_id,
-            topic_id,
-            partition_id,
-            fsync,
-        };
-        let _responses = shard.broadcast_event_to_all_shards(event).await;
         sender.send_empty_ok_response().await?;
         Ok(())
     }
diff --git a/core/server/src/bootstrap.rs b/core/server/src/bootstrap.rs
index 5beb6f41e..a103e8ae1 100644
--- a/core/server/src/bootstrap.rs
+++ b/core/server/src/bootstrap.rs
@@ -38,7 +38,7 @@ use crate::{
         streams::stream2,
         topics::{consumer_group2, topic2},
         users::user::User,
-        utils::file::overwrite,
+        utils::{crypto, file::overwrite},
     },
     versioning::SemanticVersion,
 };
@@ -48,8 +48,8 @@ use error_set::ErrContext;
 use iggy_common::{
     ConsumerKind, IggyByteSize, IggyError,
     defaults::{
-        DEFAULT_ROOT_PASSWORD, DEFAULT_ROOT_USERNAME, MAX_PASSWORD_LENGTH, MAX_USERNAME_LENGTH,
-        MIN_PASSWORD_LENGTH, MIN_USERNAME_LENGTH,
+        DEFAULT_ROOT_USERNAME, MAX_PASSWORD_LENGTH, MAX_USERNAME_LENGTH, MIN_PASSWORD_LENGTH,
+        MIN_USERNAME_LENGTH,
     },
 };
 use std::{collections::HashSet, env, path::Path, sync::Arc};
@@ -289,9 +289,8 @@ pub async fn create_directories(config: &SystemConfig) -> Result<(), IggyError>
 }
 
 pub fn create_root_user() -> User {
-    info!("Creating root user...");
-    let username = env::var(IGGY_ROOT_USERNAME_ENV);
-    let password = env::var(IGGY_ROOT_PASSWORD_ENV);
+    let mut username = env::var(IGGY_ROOT_USERNAME_ENV);
+    let mut password = env::var(IGGY_ROOT_PASSWORD_ENV);
     if (username.is_ok() && password.is_err()) || (username.is_err() && password.is_ok()) {
         panic!(
             "When providing the custom root user credentials, both username and password must be set."
@@ -300,11 +299,15 @@ pub fn create_root_user() -> User {
     if username.is_ok() && password.is_ok() {
         info!("Using the custom root user credentials.");
     } else {
-        info!("Using the default root user credentials.");
+        info!("Using the default root user credentials...");
+        username = Ok(DEFAULT_ROOT_USERNAME.to_string());
+        let generated_password = crypto::generate_secret(20..40);
+        println!("Generated root user password: {generated_password}");
+        password = Ok(generated_password);
     }
 
-    let username = username.unwrap_or(DEFAULT_ROOT_USERNAME.to_string());
-    let password = password.unwrap_or(DEFAULT_ROOT_PASSWORD.to_string());
+    let username = username.expect("Root username is not set.");
+    let password = password.expect("Root password is not set.");
     if username.is_empty() || password.is_empty() {
         panic!("Root user credentials are not set.");
     }
@@ -320,6 +323,7 @@ pub fn create_root_user() -> User {
     if password.len() > MAX_PASSWORD_LENGTH {
         panic!("Root password is too long.");
     }
+
     User::root(&username, &password)
 }
 
diff --git a/core/server/src/http/messages.rs b/core/server/src/http/messages.rs
index 61a5b95d2..61d1ee13a 100644
--- a/core/server/src/http/messages.rs
+++ b/core/server/src/http/messages.rs
@@ -135,9 +135,9 @@ async fn flush_unsaved_buffer(
     let session = Session::stateless(identity.user_id, identity.ip_address);
 
     let flush_future = SendWrapper::new(state.shard.shard().flush_unsaved_buffer(
-        &session,
-        &stream_id,
-        &topic_id,
+        identity.user_id,
+        stream_id,
+        topic_id,
         partition_id,
         fsync,
     ));
diff --git a/core/server/src/quic/quic_server.rs b/core/server/src/quic/quic_server.rs
index 1a67d64d8..c5033213a 100644
--- a/core/server/src/quic/quic_server.rs
+++ b/core/server/src/quic/quic_server.rs
@@ -127,6 +127,9 @@ pub async fn spawn_quic_server(
         shard.quic_bound_address.set(Some(actual_addr));
 
         if addr.port() == 0 {
+            // Notify config writer on shard 0
+            let _ = shard.config_writer_notify.try_send(());
+
             // Broadcast to other shards for SO_REUSEPORT binding
             let event = ShardEvent::AddressBound {
                 protocol: iggy_common::TransportProtocol::Quic,
diff --git a/core/server/src/shard/mod.rs b/core/server/src/shard/mod.rs
index 0996e1fc1..b0bc3058e 100644
--- a/core/server/src/shard/mod.rs
+++ b/core/server/src/shard/mod.rs
@@ -135,7 +135,7 @@ pub struct IggyShard {
     pub(crate) quic_bound_address: Cell<Option<SocketAddr>>,
     pub(crate) websocket_bound_address: Cell<Option<SocketAddr>>,
     pub(crate) http_bound_address: Cell<Option<SocketAddr>>,
-    config_writer_notify: async_channel::Sender<()>,
+    pub(crate) config_writer_notify: async_channel::Sender<()>,
     config_writer_receiver: async_channel::Receiver<()>,
     pub(crate) task_registry: Rc<TaskRegistry>,
 }
@@ -309,7 +309,7 @@ impl IggyShard {
     }
 
     pub async fn run(self: &Rc<Self>) -> Result<(), IggyError> {
-        let now = Instant::now();
+        let now: Instant = Instant::now();
 
         // Workaround to ensure that the statistics are initialized before the server
         // loads streams and starts accepting connections. This is necessary to
@@ -510,6 +510,11 @@ impl IggyShard {
                 }
                 Ok(ShardResponse::PollMessages((metadata, batches)))
             }
+            ShardRequestPayload::FlushUnsavedBuffer { fsync } => {
+                self.flush_unsaved_buffer_base(&stream_id, &topic_id, partition_id, fsync)
+                    .await?;
+                Ok(ShardResponse::FlushUnsavedBuffer)
+            }
         }
     }
 
@@ -847,12 +852,17 @@ impl IggyShard {
                 stream_id,
                 topic_id,
                 partition_id,
-                ..
+                fsync,
             } => {
-                self.flush_unsaved_buffer_bypass_auth(&stream_id, &topic_id, partition_id)
+                self.flush_unsaved_buffer_base(&stream_id, &topic_id, partition_id, fsync)
                     .await?;
                 Ok(())
             }
+            ShardEvent::ClientDisconnected { client_id, user_id } => {
+                self.delete_client(client_id);
+                self.remove_active_session(user_id);
+                Ok(())
+            }
         }
     }
 
diff --git a/core/server/src/shard/system/messages.rs b/core/server/src/shard/system/messages.rs
index 7c543c3b7..74e0add16 100644
--- a/core/server/src/shard/system/messages.rs
+++ b/core/server/src/shard/system/messages.rs
@@ -29,7 +29,7 @@ use crate::streaming::segments::{IggyIndexesMut, IggyMessagesBatchMut, IggyMessa
 use crate::streaming::session::Session;
 use crate::streaming::traits::MainOps;
 use crate::streaming::utils::PooledBuffer;
-use crate::streaming::{streams, topics};
+use crate::streaming::{partitions, streams, topics};
 use error_set::ErrContext;
 use iggy_common::{
     BytesSerializable, Consumer, EncryptorKind, IGGY_MESSAGE_HEADER_SIZE, Identifier, IggyError,
@@ -277,59 +277,82 @@ impl IggyShard {
 
     pub async fn flush_unsaved_buffer(
         &self,
-        session: &Session,
-        stream_id: &Identifier,
-        topic_id: &Identifier,
+        user_id: u32,
+        stream_id: Identifier,
+        topic_id: Identifier,
         partition_id: usize,
-        _fsync: bool,
+        fsync: bool,
     ) -> Result<(), IggyError> {
-        self.ensure_authenticated(session)?;
+        self.ensure_partition_exists(&stream_id, &topic_id, partition_id)?;
+
         let numeric_stream_id = self
             .streams2
-            .with_stream_by_id(stream_id, streams::helpers::get_stream_id());
+            .with_stream_by_id(&stream_id, streams::helpers::get_stream_id());
 
         let numeric_topic_id =
             self.streams2
-                .with_topic_by_id(stream_id, topic_id, topics::helpers::get_topic_id());
+                .with_topic_by_id(&stream_id, &topic_id, topics::helpers::get_topic_id());
 
         // Validate permissions for given user on stream and topic.
         self.permissioner
             .borrow()
-            .append_messages(
-                session.get_user_id(),
-                numeric_stream_id,
-                numeric_topic_id,
-            )
+            .append_messages(user_id, numeric_stream_id, numeric_topic_id)
             .with_error_context(|error| {
-                format!("{COMPONENT} (error: {error}) - permission denied to append messages for user {} on stream ID: {}, topic ID: {}", session.get_user_id(), numeric_stream_id as u32, numeric_topic_id as u32)
+                format!("{COMPONENT} (error: {error}) - permission denied to flush unsaved buffer for user {} on stream ID: {}, topic ID: {}", user_id, numeric_stream_id as u32, numeric_topic_id as u32)
             })?;
 
-        self.flush_unsaved_buffer_base(stream_id, topic_id, partition_id)
-            .await?;
-        Ok(())
-    }
+        self.ensure_partition_exists(&stream_id, &topic_id, partition_id)?;
 
-    pub async fn flush_unsaved_buffer_bypass_auth(
-        &self,
-        stream_id: &Identifier,
-        topic_id: &Identifier,
-        partition_id: usize,
-    ) -> Result<(), IggyError> {
-        self.flush_unsaved_buffer_base(stream_id, topic_id, partition_id)
-            .await
+        let namespace = IggyNamespace::new(numeric_stream_id, numeric_topic_id, partition_id);
+        let payload = ShardRequestPayload::FlushUnsavedBuffer { fsync };
+        let request = ShardRequest::new(stream_id.clone(), topic_id.clone(), partition_id, payload);
+        let message = ShardMessage::Request(request);
+        match self
+            .send_request_to_shard_or_recoil(&namespace, message)
+            .await?
+        {
+            ShardSendRequestResult::Recoil(message) => {
+                if let ShardMessage::Request(ShardRequest {
+                    stream_id,
+                    topic_id,
+                    partition_id,
+                    payload,
+                }) = message
+                    && let ShardRequestPayload::FlushUnsavedBuffer { fsync } = payload
+                {
+                    self.flush_unsaved_buffer_base(&stream_id, &topic_id, partition_id, fsync)
+                        .await?;
+                    Ok(())
+                } else {
+                    unreachable!(
+                        "Expected a FlushUnsavedBuffer request inside of FlushUnsavedBuffer handler, impossible state"
+                    );
+                }
+            }
+            ShardSendRequestResult::Response(response) => match response {
+                ShardResponse::FlushUnsavedBuffer => Ok(()),
+                ShardResponse::ErrorResponse(err) => Err(err),
+                _ => unreachable!(
+                    "Expected a FlushUnsavedBuffer response inside of FlushUnsavedBuffer handler, impossible state"
+                ),
+            },
+        }?;
+
+        Ok(())
     }
 
-    async fn flush_unsaved_buffer_base(
+    pub(crate) async fn flush_unsaved_buffer_base(
         &self,
         stream_id: &Identifier,
         topic_id: &Identifier,
         partition_id: usize,
+        fsync: bool,
     ) -> Result<(), IggyError> {
         let batches = self.streams2.with_partition_by_id_mut(
             stream_id,
             topic_id,
             partition_id,
-            |(.., log)| log.journal_mut().commit(),
+            partitions::helpers::commit_journal(),
         );
 
         self.streams2
@@ -342,6 +365,14 @@ impl IggyShard {
                 &self.config.system,
             )
             .await?;
+
+        // Ensure all data is flushed to disk before returning
+        if fsync {
+            self.streams2
+                .fsync_all_messages(stream_id, topic_id, partition_id)
+                .await?;
+        }
+
         Ok(())
     }
 
diff --git a/core/server/src/shard/transmission/event.rs b/core/server/src/shard/transmission/event.rs
index 79c30edff..45f335878 100644
--- a/core/server/src/shard/transmission/event.rs
+++ b/core/server/src/shard/transmission/event.rs
@@ -134,6 +134,10 @@ pub enum ShardEvent {
         address: SocketAddr,
         transport: TransportProtocol,
     },
+    ClientDisconnected {
+        client_id: u32,
+        user_id: u32,
+    },
     JoinedConsumerGroup {
         client_id: u32,
         stream_id: Identifier,
diff --git a/core/server/src/shard/transmission/frame.rs b/core/server/src/shard/transmission/frame.rs
index 6539ec4c6..d36b92157 100644
--- a/core/server/src/shard/transmission/frame.rs
+++ b/core/server/src/shard/transmission/frame.rs
@@ -27,6 +27,7 @@ use crate::{
 pub enum ShardResponse {
     PollMessages((IggyPollMetadata, IggyMessagesBatchSet)),
     SendMessages,
+    FlushUnsavedBuffer,
     Event,
     ErrorResponse(IggyError),
 }
diff --git a/core/server/src/shard/transmission/message.rs b/core/server/src/shard/transmission/message.rs
index bf6537eb0..5a5d650e6 100644
--- a/core/server/src/shard/transmission/message.rs
+++ b/core/server/src/shard/transmission/message.rs
@@ -72,6 +72,9 @@ pub enum ShardRequestPayload {
         consumer: PollingConsumer,
         args: PollingArgs,
     },
+    FlushUnsavedBuffer {
+        fsync: bool,
+    },
 }
 
 impl From<ShardRequest> for ShardMessage {
diff --git a/core/server/src/slab/streams.rs b/core/server/src/slab/streams.rs
index 0ad76809c..7dccec27f 100644
--- a/core/server/src/slab/streams.rs
+++ b/core/server/src/slab/streams.rs
@@ -1337,9 +1337,16 @@ impl Streams {
         partition_id: usize,
     ) -> Result<(), IggyError> {
         let storage = self.with_partition_by_id(stream_id, topic_id, partition_id, |(.., log)| {
-            log.active_storage().clone()
+            if !log.has_segments() {
+                return None;
+            }
+            Some(log.active_storage().clone())
         });
 
+        let Some(storage) = storage else {
+            return Ok(());
+        };
+
         if storage.messages_writer.is_none() || storage.index_writer.is_none() {
             return Ok(());
         }
diff --git a/core/server/src/tcp/tcp_listener.rs b/core/server/src/tcp/tcp_listener.rs
index 580b7a60e..c963103da 100644
--- a/core/server/src/tcp/tcp_listener.rs
+++ b/core/server/src/tcp/tcp_listener.rs
@@ -103,6 +103,9 @@ pub async fn start(
         shard.tcp_bound_address.set(Some(actual_addr));
 
         if addr.port() == 0 {
+            // Notify config writer on shard 0
+            let _ = shard.config_writer_notify.try_send(());
+
             // Broadcast to other shards for SO_REUSEPORT binding
             let event = ShardEvent::AddressBound {
                 protocol: TransportProtocol::Tcp,
@@ -149,6 +152,7 @@ async fn accept_loop(
                         let _responses = shard_clone.broadcast_event_to_all_shards(event).await;
 
                         let client_id = session.client_id;
+                        let user_id = session.get_user_id();
                         shard_info!(shard.id, "Created new session: {}", session);
                         let mut sender = SenderKind::get_tcp_sender(stream);
 
@@ -159,9 +163,12 @@ async fn accept_loop(
                         let registry_clone = registry.clone();
                         registry.spawn_connection(async move {
                             if let Err(error) = handle_connection(&session, &mut sender, &shard_for_conn, conn_stop_receiver).await {
+                                shard_for_conn.delete_client(session.client_id);
                                 handle_error(error);
                             }
                             registry_clone.remove_connection(&client_id);
+                            let event = ShardEvent::ClientDisconnected { client_id, user_id };
+                            let _responses = shard_for_conn.broadcast_event_to_all_shards(event).await;
 
                             if let Err(error) = sender.shutdown().await {
                                 shard_error!(shard.id, "Failed to shutdown TCP stream for client: {}, address: {}. {}", client_id, address, error);
diff --git a/core/server/src/tcp/tcp_tls_listener.rs b/core/server/src/tcp/tcp_tls_listener.rs
index 7dc419603..56504df36 100644
--- a/core/server/src/tcp/tcp_tls_listener.rs
+++ b/core/server/src/tcp/tcp_tls_listener.rs
@@ -72,6 +72,9 @@ pub(crate) async fn start(
     if shard.id == 0 {
         shard.tcp_bound_address.set(Some(actual_addr));
         if addr.port() == 0 {
+            // Notify config writer on shard 0
+            let _ = shard.config_writer_notify.try_send(());
+
             let event = ShardEvent::AddressBound {
                 protocol: TransportProtocol::Tcp,
                 address: actual_addr,
@@ -207,15 +210,19 @@ async fn accept_loop(
                                     let _responses = shard_clone.broadcast_event_to_all_shards(event).await;
 
                                     let client_id = session.client_id;
+                                    let user_id = session.get_user_id();
                                     shard_info!(shard_clone.id, "Created new session: {}", session);
 
                                     let conn_stop_receiver = registry_clone.add_connection(client_id);
                                     let shard_for_conn = shard_clone.clone();
                                     let mut sender = SenderKind::get_tcp_tls_sender(tls_stream);
                                     if let Err(error) = handle_connection(&session, &mut sender, &shard_for_conn, conn_stop_receiver).await {
+                                        shard_for_conn.delete_client(session.client_id);
                                         handle_error(error);
                                     }
                                     registry_clone.remove_connection(&client_id);
+                                    let event = ShardEvent::ClientDisconnected { client_id, user_id };
+                                    let _responses = shard_for_conn.broadcast_event_to_all_shards(event).await;
 
                                     if let Err(error) = sender.shutdown().await {
                                         shard_error!(shard.id, "Failed to shutdown TCP TLS stream for client: {}, address: {}. {}", client_id, address, error);