From 2eec036542a219aef0aa7eefea388ce0c6da153d Mon Sep 17 00:00:00 2001 From: CGodiksen <36046286+CGodiksen@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:02:02 +0200 Subject: [PATCH 1/5] Fix bug that caused size_in_bytes to be too large --- crates/modelardb_server/src/storage/compressed_data_buffer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/modelardb_server/src/storage/compressed_data_buffer.rs b/crates/modelardb_server/src/storage/compressed_data_buffer.rs index 3086e7573..a520c1253 100644 --- a/crates/modelardb_server/src/storage/compressed_data_buffer.rs +++ b/crates/modelardb_server/src/storage/compressed_data_buffer.rs @@ -103,9 +103,10 @@ impl CompressedDataBuffer { compressed_segments_size += Self::size_of_compressed_segments(&compressed_segment_batch); self.compressed_segments.push(compressed_segment_batch); - self.size_in_bytes += compressed_segments_size; } + self.size_in_bytes += compressed_segments_size; + self.batch_ids.extend(compressed_segment_batch.batch_ids); Ok(compressed_segments_size) From 709c476e51f2b30bdd7ca0cb408b1fa3055c21d7 Mon Sep 17 00:00:00 2001 From: CGodiksen <36046286+CGodiksen@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:17:25 +0200 Subject: [PATCH 2/5] Update compressed data buffer test to be exact --- .../modelardb_server/src/storage/compressed_data_buffer.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/modelardb_server/src/storage/compressed_data_buffer.rs b/crates/modelardb_server/src/storage/compressed_data_buffer.rs index a520c1253..adbe3a3a2 100644 --- a/crates/modelardb_server/src/storage/compressed_data_buffer.rs +++ b/crates/modelardb_server/src/storage/compressed_data_buffer.rs @@ -166,11 +166,14 @@ mod tests { let mut compressed_data_buffer = CompressedDataBuffer::new(table::time_series_table_metadata_arc()); - compressed_data_buffer + let size_in_bytes = compressed_data_buffer .append_compressed_segment_batch(compressed_segment_batch()) .unwrap(); - assert!(compressed_data_buffer.size_in_bytes > 0); + // The batch contains two compressed segments, so the size of both is added to the buffer. + // The returned size must match since the caller reserves memory based on it. + assert_eq!(size_in_bytes, 2 * COMPRESSED_SEGMENTS_SIZE); + assert_eq!(compressed_data_buffer.size_in_bytes, size_in_bytes); } #[tokio::test] From d0d472ca3dd3c6389bd2b2f7c7b85a8f059a98ea Mon Sep 17 00:00:00 2001 From: CGodiksen <36046286+CGodiksen@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:22:20 +0200 Subject: [PATCH 3/5] Update compressed data manager tests to be exact --- .../src/storage/compressed_data_manager.rs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/modelardb_server/src/storage/compressed_data_manager.rs b/crates/modelardb_server/src/storage/compressed_data_manager.rs index a726149ba..82017e08b 100644 --- a/crates/modelardb_server/src/storage/compressed_data_manager.rs +++ b/crates/modelardb_server/src/storage/compressed_data_manager.rs @@ -378,13 +378,15 @@ mod tests { assert!(data_manager.compressed_data_buffers.contains_key(key)); assert_eq!(data_manager.compressed_queue.pop().unwrap(), key); - assert!( + + // The batch contains two compressed segments, so the size of both is added to the buffer. + assert_eq!( data_manager .compressed_data_buffers .get(key) .unwrap() - .size_in_bytes - > 0 + .size_in_bytes, + 2 * COMPRESSED_SEGMENTS_SIZE ); } @@ -408,13 +410,15 @@ mod tests { .await .unwrap(); - assert!( + // Each insert adds the size of the two compressed segments in the batch. + assert_eq!(previous_size, 2 * COMPRESSED_SEGMENTS_SIZE); + assert_eq!( data_manager .compressed_data_buffers .get(TIME_SERIES_TABLE_NAME) .unwrap() - .size_in_bytes - > previous_size + .size_in_bytes, + 4 * COMPRESSED_SEGMENTS_SIZE ); } @@ -499,10 +503,13 @@ mod tests { .await .unwrap(); - assert!( - -1 < data_manager + // The remaining memory was set to -1 above, so saving the buffer returns exactly the + // memory reserved for its two compressed segments. + assert_eq!( + data_manager .memory_pool - .remaining_compressed_memory_in_bytes() + .remaining_compressed_memory_in_bytes(), + 2 * COMPRESSED_SEGMENTS_SIZE as i64 - 1 ); } @@ -535,6 +542,8 @@ mod tests { .await .unwrap(); + // Adjust the remaining memory to a negative value that equals the amount of memory + // currently used for the buffer. data_manager .adjust_compressed_remaining_memory_in_bytes( -(COMPRESSED_RESERVED_MEMORY_IN_BYTES as i64), @@ -542,11 +551,12 @@ mod tests { .await .unwrap(); + // All the memory used for the buffer is returned when the buffer is saved. assert_eq!( data_manager .memory_pool .remaining_compressed_memory_in_bytes(), - 1405 + 0 ); // There should no longer be any compressed data in memory. From 86ec1044e968eaa2833347ec12c8d9ea62ba237d Mon Sep 17 00:00:00 2001 From: CGodiksen <36046286+CGodiksen@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:36:55 +0200 Subject: [PATCH 4/5] Update naming in loop to make it consistent --- .../modelardb_server/src/storage/compressed_data_buffer.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/modelardb_server/src/storage/compressed_data_buffer.rs b/crates/modelardb_server/src/storage/compressed_data_buffer.rs index adbe3a3a2..ec9b88927 100644 --- a/crates/modelardb_server/src/storage/compressed_data_buffer.rs +++ b/crates/modelardb_server/src/storage/compressed_data_buffer.rs @@ -99,10 +99,9 @@ impl CompressedDataBuffer { } let mut compressed_segments_size = 0; - for compressed_segment_batch in compressed_segments.drain(0..) { - compressed_segments_size += - Self::size_of_compressed_segments(&compressed_segment_batch); - self.compressed_segments.push(compressed_segment_batch); + for compressed_segment in compressed_segments.drain(0..) { + compressed_segments_size += Self::size_of_compressed_segments(&compressed_segment); + self.compressed_segments.push(compressed_segment); } self.size_in_bytes += compressed_segments_size; From 680eae1380179c3178d47b84a7242527a7059807 Mon Sep 17 00:00:00 2001 From: CGodiksen <36046286+CGodiksen@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:52:52 +0200 Subject: [PATCH 5/5] Simplify test comments --- .../modelardb_server/src/storage/compressed_data_manager.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/modelardb_server/src/storage/compressed_data_manager.rs b/crates/modelardb_server/src/storage/compressed_data_manager.rs index 82017e08b..5a43a02df 100644 --- a/crates/modelardb_server/src/storage/compressed_data_manager.rs +++ b/crates/modelardb_server/src/storage/compressed_data_manager.rs @@ -503,8 +503,8 @@ mod tests { .await .unwrap(); - // The remaining memory was set to -1 above, so saving the buffer returns exactly the - // memory reserved for its two compressed segments. + // The remaining memory was set to -1 above. Saving the buffer returns exactly the memory + // reserved for its two compressed segments. assert_eq!( data_manager .memory_pool @@ -542,8 +542,6 @@ mod tests { .await .unwrap(); - // Adjust the remaining memory to a negative value that equals the amount of memory - // currently used for the buffer. data_manager .adjust_compressed_remaining_memory_in_bytes( -(COMPRESSED_RESERVED_MEMORY_IN_BYTES as i64),