fix: ignore incomplete WAL entries during read (#6251)

* fix: ignore incomplete entry

* fix: fix unit tests
This commit is contained in:
Weny Xu
2025-06-04 19:16:42 +08:00
committed by GitHub
parent 7afb77fd35
commit 80c5af0ecf
6 changed files with 78 additions and 40 deletions

View File

@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::fmt::{Display, Formatter};
use std::mem::size_of;
use crate::logstore::provider::Provider;
@@ -30,6 +31,15 @@ pub enum Entry {
MultiplePart(MultiplePartEntry),
}
impl Display for Entry {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Entry::Naive(entry) => write!(f, "{}", entry),
Entry::MultiplePart(entry) => write!(f, "{}", entry),
}
}
}
impl Entry {
/// Into [NaiveEntry] if it's type of [Entry::Naive].
pub fn into_naive_entry(self) -> Option<NaiveEntry> {
@@ -56,6 +66,16 @@ pub struct NaiveEntry {
pub data: Vec<u8>,
}
impl Display for NaiveEntry {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"NaiveEntry(provider={:?}, region_id={}, entry_id={})",
self.provider, self.region_id, self.entry_id,
)
}
}
impl NaiveEntry {
/// Estimates the persisted size of the entry.
fn estimated_size(&self) -> usize {
@@ -79,6 +99,19 @@ pub struct MultiplePartEntry {
pub parts: Vec<Vec<u8>>,
}
impl Display for MultiplePartEntry {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"MultiplePartEntry(provider={:?}, region_id={}, entry_id={}, len={})",
self.provider,
self.region_id,
self.entry_id,
self.parts.len()
)
}
}
impl MultiplePartEntry {
fn is_complete(&self) -> bool {
self.headers.contains(&MultiplePartHeader::First)

View File

@@ -69,10 +69,10 @@ impl Display for Provider {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
Provider::RaftEngine(provider) => {
write!(f, "region: {}", RegionId::from_u64(provider.id))
write!(f, "RaftEngine(region={})", RegionId::from_u64(provider.id))
}
Provider::Kafka(provider) => write!(f, "topic: {}", provider.topic),
Provider::Noop => write!(f, "noop"),
Provider::Kafka(provider) => write!(f, "Kafka(topic={})", provider.topic),
Provider::Noop => write!(f, "Noop"),
}
}
}