jorgehermo9 commented on code in PR #6366: URL: https://github.com/apache/opendal/pull/6366#discussion_r2259605008
########## core/src/layers/foyer.rs: ########## @@ -0,0 +1,458 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::{ + future::Future, + ops::{Bound, Deref, Range, RangeBounds}, + sync::Arc, +}; + +use foyer::{Code, CodeError, Error as FoyerError, HybridCache}; + +use crate::raw::oio::*; +use crate::raw::*; +use crate::*; + +fn extract_err(e: FoyerError) -> Error { + let e = match e.downcast::<Error>() { + Ok(e) => return e, + Err(e) => e, + }; + Error::new(ErrorKind::Unexpected, e.to_string()) +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct FoyerKey { + pub path: String, + pub version: Option<String>, +} + +impl Code for FoyerKey { + fn encode(&self, writer: &mut impl std::io::Write) -> std::result::Result<(), CodeError> { + let path_len = self.path.len() as u64; + writer.write_all(&path_len.to_le_bytes())?; + writer.write_all(self.path.as_bytes())?; + if let Some(ref version) = self.version { + let version_len = version.len() as u64; + writer.write_all(&version_len.to_le_bytes())?; + writer.write_all(version.as_bytes())?; + } else { + writer.write_all(&0u64.to_le_bytes())?; Review Comment: This way, the version `""` (empty string) would have the same serialization as `None` and its decoding would always be `None` (per the condition of L72, where `if version_len == 0`, then `None` is returned. I think it is wrong to assume `None==""` in the version. It is a corner case but it is weird to me Maybe we could use some "magic" len value such as len = -1 (and storing that magic value in a constant?) to represente the `None` value? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@opendal.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org