unknowntpo commented on code in PR #5905:
URL: https://github.com/apache/gravitino/pull/5905#discussion_r1984374159


##########
clients/filesystem-fuse/src/fuse_api_handle_debug.rs:
##########
@@ -0,0 +1,829 @@
+/*
+ * 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 crate::config::AppConfig;
+use crate::filesystem::{FileSystemContext, RawFileSystem};
+use crate::fuse_api_handle::FuseApiHandle;
+use chrono::DateTime;
+use fuse3::path::prelude::{ReplyData, ReplyOpen, ReplyStatFs, ReplyWrite};
+use fuse3::path::Request;
+use fuse3::raw::prelude::{
+    FileAttr, ReplyAttr, ReplyCreated, ReplyDirectory, ReplyDirectoryPlus, 
ReplyEntry, ReplyInit,
+};
+use fuse3::raw::reply::{DirectoryEntry, DirectoryEntryPlus};
+use fuse3::raw::Filesystem;
+use fuse3::{Inode, SetAttr, Timestamp};
+use futures_util::stream::{self, BoxStream};
+use futures_util::StreamExt;
+use std::ffi::OsStr;
+use std::fmt::Write;
+use tracing::{debug, error};
+
+/// Log the result without printing the reply
+macro_rules! log_status {
+    ($method_call:expr, $method_name:expr, $req:ident) => {
+        match $method_call.await {
+            Ok(reply) => {
+                debug!($req.unique, "{} completed", 
$method_name.to_uppercase());
+                Ok(reply)
+            }
+            Err(e) => {
+                error!($req.unique, ?e, "{} failed", 
$method_name.to_uppercase());
+                Err(e)
+            }
+        }
+    };
+}
+
+/// Log the result with default Debug formatting
+macro_rules! log_value {
+    ($method_call:expr, $method_name:expr, $req:ident) => {
+        match $method_call.await {
+            Ok(reply) => {
+                debug!(
+                    $req.unique,
+                    ?reply,
+                    "{} completed",
+                    $method_name.to_uppercase()
+                );
+                Ok(reply)
+            }
+            Err(e) => {
+                error!($req.unique, ?e, "{} failed", 
$method_name.to_uppercase());
+                Err(e)
+            }
+        }
+    };
+}
+
+/// Log the result with custom formatting
+macro_rules! log_value_custom {
+    ($method_call:expr, $method_name:expr, $req:ident, $format_reply_fn:ident) 
=> {
+        match $method_call.await {
+            Ok(reply) => {
+                debug!(
+                    $req.unique,
+                    reply = $format_reply_fn(&reply),
+                    "{} completed",
+                    $method_name.to_uppercase()
+                );
+                Ok(reply)
+            }
+            Err(e) => {
+                error!($req.unique, ?e, "{} failed", 
$method_name.to_uppercase());
+                Err(e)
+            }
+        }
+    };
+}
+
+/// Log the result for readdir operations
+macro_rules! log_readdir {
+    ($method_call:expr, $req:ident) => {{
+        match $method_call.await {
+            Ok(mut reply_dir) => {
+                let mut entries = Vec::new();
+
+                while let Some(entry_result) = reply_dir.entries.next().await {
+                    match entry_result {
+                        Ok(entry) => {
+                            entries.push(entry);
+                        }
+                        Err(e) => {
+                            return Err(e.into());
+                        }
+                    }
+                }
+
+                let entries_info = format!(
+                    "[{}]",
+                    entries
+                        .iter()
+                        .map(|entry| directory_entry_to_desc_str(entry))
+                        .collect::<Vec<String>>()
+                        .join(", ")
+                );
+
+                debug!($req.unique, entries = entries_info, "READDIR 
completed");
+
+                Ok(ReplyDirectory {
+                    entries: stream::iter(entries.into_iter().map(Ok)).boxed(),
+                })
+            }
+            Err(e) => {
+                error!($req.unique, ?e, "READDIR failed");
+                Err(e)
+            }
+        }
+    }};
+}
+
+/// Log the result for readdirplus operations
+macro_rules! log_readdirplus {
+    ($method_call:expr, $req:ident) => {{
+        match $method_call.await {
+            Ok(mut reply_dir) => {
+                let mut entries = Vec::new();
+
+                while let Some(entry_result) = reply_dir.entries.next().await {
+                    match entry_result {
+                        Ok(entry) => {
+                            entries.push(entry);
+                        }
+                        Err(e) => {
+                            return Err(e.into());
+                        }
+                    }
+                }
+
+                let entries_info = format!(
+                    "[{}]",
+                    entries
+                        .iter()
+                        .map(|entry| directory_entry_plus_to_desc_str(entry))
+                        .collect::<Vec<String>>()
+                        .join(", ")
+                );
+
+                debug!($req.unique, entries = entries_info, "READDIRPLUS 
completed");
+
+                Ok(ReplyDirectoryPlus {
+                    entries: stream::iter(entries.into_iter().map(Ok)).boxed(),
+                })
+            }
+            Err(e) => {
+                error!($req.unique, ?e, "READDIRPLUS failed");
+                Err(e)
+            }
+        }
+    }};
+}

Review Comment:
   The format function and return type is different (for `readdir`, we need 
`ReplyDirectory`, for `re`addirplus`, we need `ReplyDirectoryPlus`), if I make 
them use the same macro:
   
   ```
   /// Log the result for readdir operations
   macro_rules! log_readdir {
       ($method_call:expr, $req:ident, $reply_type:ident) => {{
           match $method_call.await {
               Ok(mut reply_dir) => {
                   let mut entries = Vec::new();
   
                   while let Some(entry_result) = 
reply_dir.entries.next().await {
                       match entry_result {
                           Ok(entry) => {
                               entries.push(entry);
                           }
                           Err(e) => {
                               return Err(e.into());
                           }
                       }
                   }
   
                   let format_fn = if stringify!($reply_type) == 
"ReplyDirectory" {
                       directory_entry_to_desc_str
                   } else {
                       directory_entry_plus_to_desc_str
                   };
   
                   let entries_info = format!(
                       "[{}]",
                       entries
                           .iter()
                           .map(|entry| format_fn(entry))
                           .collect::<Vec<String>>()
                           .join(", ")
                   );
   
                   debug!($req.unique, entries = entries_info, "READDIR 
completed");
   
                   if stringify!($reply_type) == "ReplyDirectory" {
                       Ok(ReplyDirectory {
                           entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
                       })
                   } else {
                       Ok(ReplyDirectoryPlus {
                           entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
                       })
                   }
               }
               Err(e) => {
                   error!($req.unique, ?e, "READDIR failed");
                   Err(e)
               }
           }
       }};
   }
   ```
   In `readdir`:
   ```
           log_readdir!(
               self.inner.readdir(req, parent, fh, offset),
               req,
               ReplyDirectory
           )
   ```
   In `readdirplus`:
   ```
   log_readdir!(
               self.inner.readdirplus(req, parent, fh, offset, lock_owner),
               req,
               ReplyDirectoryPlus
           )
   ```
   
   I got mismatched type error:
   
   ```
      --> src/fuse_api_handle_debug.rs:134:24
       |
   134 |                       Ok(ReplyDirectoryPlus {
       |  _____________________--_^
       | |                     |
       | |                     arguments to this enum variant are incorrect
   135 | |                         entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
   136 | |                     })
       | |_____________________^ expected `ReplyDirectory<Pin<Box<...>>>`, 
found `ReplyDirectoryPlus<Pin<Box<...>>>`
   ...
   795 | /         log_readdir!(
   796 | |             self.inner.readdir(req, parent, fh, offset),
   797 | |             req,
   798 | |             ReplyDirectory
   799 | |         )
       | |_________- in this macro invocation
       |
       = note: expected struct `fuse3::raw::reply::ReplyDirectory<Pin<Box<dyn 
Stream<Item = std::result::Result<fuse3::raw::reply::DirectoryEntry, Errno>> + 
std::marker::Send>>>`
                  found struct 
`fuse3::raw::reply::ReplyDirectoryPlus<Pin<Box<dyn Stream<Item = 
std::result::Result<fuse3::raw::reply::DirectoryEntry, _>> + 
std::marker::Send>>>`
   help: the type constructed contains 
`fuse3::raw::reply::ReplyDirectoryPlus<Pin<Box<dyn Stream<Item = 
std::result::Result<fuse3::raw::reply::DirectoryEntry, _>> + 
std::marker::Send>>>` due to the type of the argument passed
      --> src/fuse_api_handle_debug.rs:134:21
       |
   134 |                        Ok(ReplyDirectoryPlus {
       |   _____________________^  -
       |  |________________________|
   135 | ||                         entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
   136 | ||                     })
       | ||_____________________-^
       | |______________________|
       |                        this argument influences the type of `Ok`
   ...
   795 |  /         log_readdir!(
   796 |  |             self.inner.readdir(req, parent, fh, offset),
   797 |  |             req,
   798 |  |             ReplyDirectory
   799 |  |         )
       |  |_________- in this macro invocation
   note: tuple variant defined here
      --> 
/Users/unknowntpo/.rustup/toolchains/1.82.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:531:5
       |
   531 |     Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
       |     ^^
       = note: this error originates in the macro `log_readdir` (in Nightly 
builds, run with -Z macro-backtrace for more info)
   
   error[E0308]: `if` and `else` have incompatible types
      --> src/fuse_api_handle_debug.rs:115:21
       |
   112 |                   let format_fn = if stringify!($reply_type) == 
"ReplyDirectory" {
       |  _________________________________-
   113 | |                     directory_entry_to_desc_str
       | |                     --------------------------- expected because of 
this
   114 | |                 } else {
   115 | |                     directory_entry_plus_to_desc_str
       | |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 
`fuse3::raw::reply::DirectoryEntry`, found `DirectoryEntryPlus`
   116 | |                 };
       | |_________________- `if` and `else` have incompatible types
   ...
   885 | /         log_readdir!(
   886 | |             self.inner.readdirplus(req, parent, fh, offset, 
lock_owner),
   887 | |             req,
   888 | |             ReplyDirectoryPlus
   889 | |         )
       | |_________- in this macro invocation
       |
       = note: expected fn item `for<'a> fn(&'a 
fuse3::raw::reply::DirectoryEntry) -> std::string::String 
{directory_entry_to_desc_str}`
                  found fn item `for<'a> fn(&'a 
fuse3::raw::reply::DirectoryEntryPlus) -> std::string::String 
{directory_entry_plus_to_desc_str}`
       = note: this error originates in the macro `log_readdir` (in Nightly 
builds, run with -Z macro-backtrace for more info)
   
   error[E0271]: type mismatch resolving `<Pin<Box<dyn Stream<Item = 
Result<DirectoryEntryPlus, _>> + Send>> as Stream>::Item == 
Result<DirectoryEntry, Errno>`
      --> src/fuse_api_handle_debug.rs:131:34
       |
   131 |                           entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
       |                                    
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 
`Result<DirectoryEntry, Errno>`, found `Result<DirectoryEntryPlus, _>`
   ...
   885 | /         log_readdir!(
   886 | |             self.inner.readdirplus(req, parent, fh, offset, 
lock_owner),
   887 | |             req,
   888 | |             ReplyDirectoryPlus
   889 | |         )
       | |_________- in this macro invocation
       |
       = note: expected enum 
`std::result::Result<fuse3::raw::reply::DirectoryEntry, Errno>`
                  found enum 
`std::result::Result<fuse3::raw::reply::DirectoryEntryPlus, _>`
   note: required by a bound in `fuse3::raw::reply::ReplyDirectory`
      --> 
/Users/unknowntpo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fuse3-0.8.1/src/raw/reply.rs:253:37
       |
   253 | pub struct ReplyDirectory<S: Stream<Item = Result<DirectoryEntry>>> {
       |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
required by this bound in `ReplyDirectory`
       = note: this error originates in the macro `log_readdir` (in Nightly 
builds, run with -Z macro-backtrace for more info)
   
   error[E0308]: mismatched types
      --> src/fuse_api_handle_debug.rs:130:24
       |
   130 |                       Ok(ReplyDirectory {
       |  _____________________--_^
       | |                     |
       | |                     arguments to this enum variant are incorrect
   131 | |                         entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
   132 | |                     })
       | |_____________________^ expected `ReplyDirectoryPlus<Pin<Box<...>>>`, 
found `ReplyDirectory<Pin<Box<...>>>`
   ...
   885 | /         log_readdir!(
   886 | |             self.inner.readdirplus(req, parent, fh, offset, 
lock_owner),
   887 | |             req,
   888 | |             ReplyDirectoryPlus
   889 | |         )
       | |_________- in this macro invocation
       |
       = note: expected struct 
`fuse3::raw::reply::ReplyDirectoryPlus<Pin<Box<dyn Stream<Item = 
std::result::Result<fuse3::raw::reply::DirectoryEntryPlus, Errno>> + 
std::marker::Send>>>`
                  found struct `fuse3::raw::reply::ReplyDirectory<Pin<Box<dyn 
Stream<Item = std::result::Result<fuse3::raw::reply::DirectoryEntryPlus, _>> + 
std::marker::Send>>>`
   help: the type constructed contains 
`fuse3::raw::reply::ReplyDirectory<Pin<Box<dyn Stream<Item = 
std::result::Result<fuse3::raw::reply::DirectoryEntryPlus, _>> + 
std::marker::Send>>>` due to the type of the argument passed
      --> src/fuse_api_handle_debug.rs:130:21
       |
   130 |                        Ok(ReplyDirectory {
       |   _____________________^  -
       |  |________________________|
   131 | ||                         entries: 
stream::iter(entries.into_iter().map(Ok)).boxed(),
   132 | ||                     })
       | ||_____________________-^
       | |______________________|
       |                        this argument influences the type of `Ok`
   ...
   885 |  /         log_readdir!(
   886 |  |             self.inner.readdirplus(req, parent, fh, offset, 
lock_owner),
   887 |  |             req,
   888 |  |             ReplyDirectoryPlus
   889 |  |         )
       |  |_________- in this macro invocation
   note: tuple variant defined here
      --> 
/Users/unknowntpo/.rustup/toolchains/1.82.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:531:5
       |
   531 |     Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
       |     ^^
       = note: this error originates in the macro `log_readdir` (in Nightly
   ```
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to