Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/xxchan/fluvio/pull/1 #10

Open
juntao opened this issue Apr 29, 2023 · 3 comments
Open

https://github.com/xxchan/fluvio/pull/1 #10

juntao opened this issue Apr 29, 2023 · 3 comments

Comments

@juntao
Copy link
Contributor

juntao commented Apr 29, 2023

No description provided.

Copy link
Contributor Author

juntao commented Apr 29, 2023

Hello, I am a code review bot on flows.network. Here are my reviews of changed source code files in this PR.


Cargo.lock

As the code is quite long, here's a summary of what I found broken down into categories:

General review:

  1. The code seems to be related to a Cargo.lock file, which implies this is not proper source code, but a locked dependencies file for a Rust project. In general, no major issues can be found in such files due to them being automatically generated.

Minor issues:

  1. There is a missing space after the version attribute in the following package entries:
  • admin
  • futures 0.3.28
  • getrandom 0.2.9
  • rustc_version 0.4.0
  • syn 1.0.109
  • rustix 0.37.15
  • time 0.3.20
  • webpki 0.22.0
  • windows-sys 0.48.0

These entries should look like this:

  - admin (0.0.0)
  - futures (0.3.28)
  - getrandom (0.2.9)
  - rustc_version (0.4.0)
  - syn (1.0.109)
  - rustix (0.37.15)
  - time (0.3.20)
  - webpki (0.22.0)
  - windows-sys (0.48.0)
  1. There are multiple entries for different versions of some packages:
  • aho-corasick (0.7.20, 1.0.1)
  • async-rwlock (0.9.0, 0.10.4)
  • base64 (0.12.3, 0.13.1, 0.21.0)
  • block-buffer (0.9.0, 0.10.4)
  • bytes (0.4.12, 1.4.0)

It's better to use one version of a package to avoid conflicts and potential issues in your project. To resolve this, consider removing the older versions and adjusting your source code accordingly.

As for the rest of the code, there are no significant issues that need immediate attention. Given that the extracted code snippet is a Cargo.lock file and not actual source code, no more in-depth analysis seems to be necessary.

The patch introduces the following key changes:

  1. Added new packages and their dependencies:

    • bindgen (0.61.0)
    • cexpr (0.6.0)
    • clang-sys (1.6.1)
    • cmake (0.1.50)
    • lazycell (1.3.0)
    • libloading (0.7.4)
    • num-derive (0.3.3)
    • peeking_take_while (0.1.2)
    • rustc-hash (1.1.0)
    • shlex (1.1.0)
    • wasmedge-macro (0.3.0)
    • wasmedge-sdk (0.8.0)
    • wasmedge-sys (0.12.3)
    • wasmedge-types (0.4.0)
  2. Introduced the dependency of the existing package on the newly added packages:

    • Added "wasmedge-sdk" as a dependency of the existing package "diceos".

The addition of these new packages and dependencies broadens the functionality of the project by including packages related to the WebAssembly system (wasmedge-*), Rust code bindings (bindgen), C-style expressions parsing (cexpr), and more.

crates/fluvio-smartengine/Cargo.toml

Overall, the source code is clean and well-organized, though it is truncated and thus might be missing some essential parts. Here are a few observations and suggestions for potential improvements:

  1. Consider adding a [documentation] field to the [package] section. This field is critical for new users who want to understand how to use the Fluvio SmartEngine library. Including a direct link to the documentation site in the Cargo.toml file makes it easier for developers to access it.

Example:

[package]
# ...
documentation = "https://docs.fluvio.io/smartengine"
  1. Provide a better description of the features in the [features] section. Each feature should have a brief description in the form of comments, explaining its purpose and how it contributes to the package.

Example:

[features]
# The engine feature includes both Wasmtime and WasmEdge engines
engine = ["wasmtime-engine", "wasmedge-engine"]

# The wasi feature is a WebAssembly System Interface (WASI) for the engines
wasi = ["wasmtime-wasi", "wasmtime-engine", "engine"]

# The transformation feature enables JSON and YAML data serialization and deserialization
transformation = ["serde_json", "serde_yaml"]

default = ["engine"]

# Wasmtime engine for WebAssembly execution
wasmtime-engine = ["wasmtime"]

# WasmEdge engine for WebAssembly execution
wasmedge-engine = ["wasmedge-sdk"]
  1. In the [dependencies] section, ensure consistent formatting for readability. Some dependencies include comments, while others do not. Also, "workspace = true" is used for most dependencies, except "wasmedge-sdk", which should be kept consistent as well.

Eg.: Add a comment to the wasmedge-sdk dependency to maintain consistency:

# WasmEdge SDK for WebAssembly execution
wasmedge-sdk = { git = "https://github.com/WasmEdge/WasmEdge", rev = "fe5fe2c", optional = true }

Other than these minor improvements, the source code appears well structured and organized, and it adheres to good practices in dependency management, feature flag usage, and consistent formatting.

The key changes in this patch are:

  1. The [features] section has been updated:

    • A new feature engine = ["wasmtime-engine", "wasmedge-engine"] is added to include both Wasmtime and WasmEdge engines.
    • The engine feature has been added as a dependency to the wasi feature. Now, wasi = ["wasmtime-wasi", "wasmtime-engine", "engine"].
    • Two new features have been added for Wasmtime and WasmEdge engines:
      • wasmtime-engine = ["wasmtime"] for Wasmtime engine.
      • wasmedge-engine = ["wasmedge-sdk"] for WasmEdge engine.
  2. A comment # Use the Clone trait has been added before the wasmedge-sdk dependency in the [dependencies] section. This comment highlights that the Clone trait is being used for the WasmEdge SDK dependency.

Other aspects of the code remain the same, and the patch focuses on enhancing the engine features and their dependencies, leading to cleaner and more modular management of the engines.

crates/fluvio-smartengine/src/engine/common.rs

Overall, the code seems to be well-wrapped, and no critical problems could be found considering the part that we have. However, there are a few suggestions and observations that can be made:

  1. Code Documentation: Add comments to your code to explain what each function and struct does. This will make the code more readable and maintainable.

  2. Error handling: In the create_transform function, the error handling could be improved. The code currently checks each type of transform function one by one, and if none of them matches, it returns the UnknownSmartModule error (else block). You can refactor this part to make it more elegant and avoid duplicating the error handling for each case.

  3. Reusability and Modularity: Make sure that the code is structured in a way that allows flexible modification and extension easily.

  4. Unnecessary Visibility: There's a #[cfg(test)] mark with a #[allow(clippy::borrowed_box)] attribute for the transform function. This can be a sign of an issue in the design if such code is required. Consider rethinking this part of the code if it is required to expose an internal component for tests.

  5. Code formatting: Make sure that the code is well-formatted and follows a consistent coding style. This will make the code easier to read and maintain.

Please note that since the code might be truncated, the evaluation is only based on the provided code snippet. There might be some other issues or improvements that can be suggested when reviewing the complete codebase.

This patch introduces several key changes:

  1. It defines new traits WasmInstance, WasmFn, and SmartModuleTransform. These traits describe the behavior of WebAssembly instances, WebAssembly functions, and SmartModule transformations, respectively.

  2. It implements a new struct SimpleTransform that can perform simple SmartModule transformations based on a provided WebAssembly function. The SimpleTransform struct works with the WasmInstance trait and is generic over a concrete implementation of the WasmFn trait.

  3. It adds a method create_transform that attempts to create a SimpleTransform instance for a given WebAssembly instance by trying various function names such as "filter", "map", "filter_map", and "array_map".

  4. It adds a new struct SmartModuleInit that wraps a WebAssembly function to initialize SmartModules. This struct provides a method initialize to call the wrapped initialization function.

  5. It introduces a new struct SmartModuleInstance which combines a WebAssembly instance, a SmartModule transformation, and an optional SmartModule initialization function. This struct provides methods for processing input data and initializing the SmartModule.

Overall, the patch aims to improve code organization, abstraction, and modularity. It allows for better interoperability between WebAssembly instances, functions, and SmartModule transformations.

crates/fluvio-smartengine/src/engine/mod.rs

Overall, the code is well-formatted and looks clean. However, I spotted a few points of improvement:

  1. Add documentation/comments: Some of the structs and functions are missing comments explaining their functionality which makes it difficult to understand the code at a glance. Make sure to include comments/documentation wherever necessary.
/// Represents an instance of a SmartModule chain.
pub struct SmartModuleChainInstance {
    pub(crate) inner: SmartModuleChainInstanceImp,
}
  1. In SmartModuleChainBuilder, there is a hard-coded error message that may not be relevant as the check is commented out:
cfg_if::cfg_if! {
    // TODO: turn on this check when ready
    // #[cfg(all(feature = "wasmedge_engine", feature = "wasmtime_engine"))]
    // compile_error!(
    //     "Both `wasmedge_engine` and `wasmtime_engine` features are enabled, but \
    //     only one WASM runtime is supported at a time"
    // );

Remember to resolve the TODO and uncomment the check when it's relevant.

  1. It's unclear what the WasmSlice and Version type aliases are used for in this code snippet, as they are not utilized in the provided code. You may want to either use them in the code or remove them if they are not necessary.
pub type WasmSlice = (i32, i32, u32);
pub type Version = i16;
  1. Consider splitting the source code into smaller modules. As there are multiple structs and much functionality implemented in the main source file, it may be beneficial to have separate modules for each functionality, like smart_engine, smart_module_chain_builder, and smart_module_chain_instance.

  2. The code uses cfg_if to conditionally import and use different engine implementations (Wasmer and WasmEdge). Make sure to include the following dependencies in the Cargo.toml file to use cfg_if.

[dependencies]
cfg-if = "1.0.0"

This should give you an overall review of the code and some suggestions for improvement.

The key changes in the provided patch are:

  1. Addition of a new struct SmartEngine along with its implementation, which represents the WASM engine and is derived from Clone. It has a single method, new(), for creating a new instance of the SmartEngine.
#[derive(Clone)]
pub struct SmartEngine {
    pub(crate) inner: SmartEngineImp,
}
  1. Introduction of a new struct SmartModuleChainBuilder with a default implementation, which is responsible for building the SmartModule chain. It comprises methods like add_smart_module to add a SmartModule to the chain and initialize to initialize it.
#[derive(Default)]
pub struct SmartModuleChainBuilder {
    smart_modules: Vec<(SmartModuleConfig, Vec<u8>)>,
}
  1. A new struct SmartModuleChainInstance representing an instance of the SmartModule chain along with its Debug implementation. It has a method process to process a single record through all the SmartModules in the chain.
pub struct SmartModuleChainInstance {
    pub(crate) inner: SmartModuleChainInstanceImp,
}
  1. The patch included conditional compilation code for two different engine features: wasmtime-engine and wasmedge-engine:
cfg_if::cfg_if! {
    if #[cfg(feature = "wasmtime-engine")] {
    //...
    }
}

cfg_if::cfg_if! {
    if #[cfg(feature = "wasmedge-engine")] {
        mod wasmedge;
        use self::wasmedge::{SmartEngineImp, initialize_imp, SmartModuleChainInstanceImp};
    }
}

Overall, the update adds structs and functionality to create a SmartEngine, build a SmartModule chain, and process records through the chain for different engine configurations.

crates/fluvio-smartengine/src/engine/wasmedge/instance.rs

Here is a code review of the given source code, mentioning potential issues and suggestions for improvements:

  1. Error handling
  • In the get_fn function, the function name lookup error is silently consumed and returns None. It might be better to return a Result<Option<Self::Func>, HostFuncError> so that the caller can handle errors properly.
  1. Synchronization
  • WasmedgeInstance uses an internal Arc<RecordsCallBack> for shared record access. However, it is not clear if get, set, and clear methods of RecordsCallback are thread-safe. If not, consider adding synchronization mechanisms (e.g., Mutex, RwLock) to make it thread-safe.
  1. Code documentation:
  • There are very few comments throughout the code. Although it is mostly self-explanatory, it can be difficult for others (or even you) to understand the intent and functionality of certain parts of the code in the future. Adding doc comments to structs, functions, and important logic can improve readability and maintainability.
  1. Lifetime management
  • In the instantiate function, there is a use of std::mem::forget to avoid dropping import and module. Please note that using std::mem::forget may cause memory leaks. To resolve this, you can try to manage their lifetimes properly or utilize other mechanisms, such as Arc or Rc, to keep shared references.
  1. Code readability:
  • In the write_input function, improve the formatting for the debug! macro to be consistent with other debug macros in the code.

Overall, the code looks good but can benefit from a few minor improvements for better maintainability and performance.

This patch provides various adjustments to the original source code. Key changes include:

  1. Minor changes to imports and formatting to keep the code consistent and clean.
  2. No functional changes or additions to the previous code review suggestions.

The patch mainly serves as a reiteration of the existing code with minor adjustments. No new issues or improvements have been introduced. The previous code review suggestions still apply for potential improvements in error handling, synchronization, code documentation, lifetime management, and code readability.

crates/fluvio-smartengine/src/engine/wasmedge/memory.rs

Here are a few observations and potential problems:

  1. Use of unwrap():
    There are a couple of usages of unwrap() in the code, which might lead to unexpected panics if the Result has an Err value or the Option is None. It's recommended to use more idiomatic error handling using ? instead.

  2. Potential issues with naming:
    The naming of the struct RecordsCallBack isn't consistent with the function names from the related module RecordsMemory. To maintain uniformity, you can consider renaming RecordsCallBack to something like RecordsMemoryHandler.

  3. Functions can be more modular:
    Functions like copy_memory_to_instance perform more than one task, making them less modular. To make the code more maintainable and easier to debug, it’d be better to break them into smaller reusable functions.

  4. Missing documentation:
    There isn't enough documentation in the form of comments for the structs and some functions. Going forward, adding more documentation would enhance the code's readability and help other developers understand the code better without having to dig through the entire implementation.

  5. Unused commented-out constants:

    // const ARRAY_SUM_FN: &str = "array_sum";
    // const UPPER_FN: &str = "upper";
    // const DEALLOC_FN: &str = "dealloc";

    They should be either removed or used if needed.

Overall, apart from the mentioned concerns, the code seems to compile and run as expected. Making the implied changes would result in better-quality, maintainable and readable code.

The provided patch primarily retains the original source code without any significant changes. Here's a summary of the existing code:

  1. It imports the necessary modules and defines main constants (ALLOC_FN and MEMORY) used in the code.

  2. The copy_memory_to_instance function copies a byte array into an instance’s linear memory and returns the resulting offset relative to the module's memory.

  3. It defines a RecordsMemory struct, which holds ptr, len, and memory properties. The clone attribute is set to the struct, and a copy_memory_from function is implemented, which reads data from the memory and returns a Result with a byte vector.

  4. The RecordsCallBack struct definition is provided, creating a wrapper around a Mutex<Option<RecordsMemory>>. It has helper methods that allow creating a new RecordsCallBack, setting and clearing the internal RecordsMemory, and getting the current value.

Overall, the patch maintains the previous code but does not address the concerns or recommendations mentioned in the previous response.

crates/fluvio-smartengine/src/engine/wasmedge/mod.rs

The source code seems to be clean and well-organized. However, I have a few minor suggestions that could improve the code quality:

  1. Remove unnecessary mutable variable structures:

In the initialize_imp function, you have let mut store = Store::new().expect("Failed to create WasmEdge store");. However, it looks like store is not mutated anywhere in the function. You can remove the mut keyword:

let store = Store::new().expect("Failed to create WasmEdge store");
  1. Provide more helpful comments:

It would be helpful to add comments throughout the codebase to describe what each function does and, if necessary, the inner workings of any complex code. For example, you could add comments to the process function in the SmartModuleChainInstanceImp struct to make it clear what's happening inside the function.

  1. Custom error messages:

Instead of using Result, you could consider creating a custom error type for your module. It could help with debugging and make your error handling more explicit.

  1. Improve the naming of the variables and types:

In some places, the naming could be more descriptive to provide a better understanding of the variables and types being used. For example, instead of SmartEngineImp, you might consider renaming the type to SmartEngineImpl to better align with the common Rust convention of using "Impl" for implementations. Similarly, think about renaming variables like ctx to context, providing more context.

  1. Use the ? operator instead of unwrapping with expect:

In some places, like creating the Executor and Store, the code uses expect to unwrap the result. This could cause the program to panic if any issues arise. Instead of using expect, consider using the ? operator to propagate the error:

let executor = Executor::new(None, None)?;
let store = Store::new()?;

Keep in mind that you need to change the function signature to support the error type returned by Executor::new and Store::new.

Overall, the code looks good, and with these minor suggestions, it can be improved.

The patch provided introduces a new implementation for the WasmEdge engine, along with the use of several modules (instance, memory, and transforms). Key changes in the implementation include:

  1. Creation of the SmartEngineImp struct, which is used to instantiate a new instance of the SmartEngineImp type.

  2. initialize_imp function: Takes a SmartModuleChainBuilder and a reference to SmartEngineImp as input and returns a Result containing a SmartModuleChainInstanceImp. It initializes a WasmedgeContext using the WasmEdge executor and iterates over each smart module in the builder, instantiating a WasmedgeInstance and initializing it with the appropriate configuration parameters.

  3. SmartModuleChainInstanceImp struct: Contains the WasmedgeContext and a vector of SmartModuleInstance. It has a method called process, which takes a SmartModuleInput and a reference to SmartModuleChainMetrics as parameters. The method sequentially processes data through each smart module instance in the chain.

  4. The output of one smart module is transformed and passed as input to the next smart module in the chain. If any errors are encountered, a partial output is returned. The output of the last smart module is added to the output of the entire chain.

crates/fluvio-smartengine/src/engine/wasmedge/transforms/filter.rs

Here are some observations after reviewing the source code:

  1. Missing documentation: The code would benefit from more comments and explanations of what each test is supposed to test or verify. This would make it easier for future developers to understand the intent and expectations of each test.

  2. Test naming: Some of your tests begin with test_ (like test_filter()) while others don't (like #[test] fn test_filter_with_init_invalid_param()). It would be best to keep the naming convention consistent throughout the tests.

  3. #[ignore] attributes:
    It seems that some tests are marked with #[ignore], which means these tests will not be executed when you run cargo test. If these tests are meant to be run, you should remove the #[ignore] attribute. If they are intentionally ignored and should not be run in normal test execution, it would be helpful to add a comment explaining why these tests are ignored.

  4. Magic strings/numbers:
    There are a few instances of hard-coded strings and numbers in the tests like Record::new("hello world") or Record::new("apple") or output.successes.len(), 0. These would be better as constants or variables with meaningful names at the top of the testing module, so it's clear what they represent and they can be easily reused or updated as needed.

  5. Repeated code: Both test_filter() and test_filter_with_init_ok() tests use similar code for processing input records and asserting the success count. If you find yourself using the same code in multiple tests, consider refactoring the code into helper functions to enhance code reuse and maintainability.

Overall, the code appears to be functional and does perform tests on the engine's capabilities. However, improvements can be made in terms of commenting, consistent naming and formatting, and refactoring some parts of the test code to make it more maintainable and reusable.

The key changes in this patch are as follows:

  1. Added a new testing module (#[cfg(test)] mod test) with test functions.

  2. Imported necessary dependencies, including SmartEngine, SmartModuleChainBuilder, SmartModuleConfig, and SmartModuleInput.

  3. Defined constants SM_FILTER and SM_FILTER_INIT representing module strings.

  4. Created and used a new test_filter() function that initializes the SmartEngine, creates instances of SmartModuleChainBuilder, and processes input records. The test checks for the expected length of the output successes.

  5. Added two test functions with #[ignore] attribute: test_filter_with_init_invalid_param() and test_filter_with_init_ok(). Both tests validate the behavior of SmartModuleChainBuilder initialization and input processing with specific parameters.

  6. The test_filter_with_init_ok() function checks multiple scenarios, including processing input records with different parameters and validates the success counts after processing.

crates/fluvio-smartengine/src/engine/wasmedge/transforms/mod.rs

As the given code snippet is incomplete and provides only a module declaration, it is not possible to identify potential issues in the actual code. To provide appropriate suggestions, please present more of the source code to be reviewed.

The patch introduced a single line of code which adds a module called filter. This change creates a new module inside the current package or project, allowing for better organization and separation of code. The actual logic to be included in the filter module is not provided in this snippet.

crates/fluvio-smartengine/src/engine/wasmtime/engine.rs

The code is overall well-written, and it seems to follow best practices. However, there are a few observations and recommendations:

  1. Code documentation and comments
  • It's recommended to include more detailed in-code documentation, especially for public types and functions, as this will help users of the codebase to understand the code better. Rustdoc-style comments (///) should be added for public types and functions.
  1. Error handling
  • In the SmartEngineImp::new() function, there is an expect("Config is static") call after creating a new engine. Using expect() implies that there might be a case where it could panic. Instead, it would be better to propagate the error using the ? operator and return a Result<Self> from the function.
  1. Tests coverage
  • There are a few tests available in the test module. However, it's recommended to expand the test coverage to cover more scenarios and edge cases to ensure the code works as expected.
  1. Using cfg_attr
  • Instead of using #[allow(clippy::new_without_default)], you can conditionally apply this attribute:
#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]

This way, the attribute will only be applied when running Clippy, and it won't affect other tools and regular compilation.

This patch includes the following key changes:

  1. Renamed SmartEngine to SmartEngineImp.
  2. Removed the Debug implementation for SmartEngine and SmartModuleChainInstance.
  3. Removed SmartModuleChainBuilder struct and its associated methods, moving the initialize method outside the struct, now called initialize_imp.
  4. Changed the initialize_imp function to directly take super::SmartModuleChainBuilder and SmartEngineImp as arguments and return a Result<SmartModuleChainInstance>.
  5. Modified the corresponding test cases to adapt to the new initialize_imp function signature and extracted the inner property for the created SmartModuleChainInstance.

These changes simplify the code and make it more straightforward for users to work with.

crates/fluvio-smartengine/src/engine/wasmtime/imp.rs

Overall, the code looks clean and well-organized. Here are some suggestions on potential improvements and issues:

  1. In the WasmTimeFn and WasmTimeContext struct definitions, consider adding the #[derive(Debug)] attribute to automatically derive a default implementation of the Debug trait. This will enable easier debugging, if necessary.
#[derive(Debug)]
pub struct WasmTimeContext {
    store: Store<()>,
}

#[derive(Debug)]
pub type WasmTimeFn = wasmtime::TypedFunc<(i32, i32, i32), i32>;
  1. In the WasmTimeInstance struct, consider storing a reference to WasmTimeContext instead of the actual context struct. This way, the same context could be reused across multiple WasmTimeInstances, and you avoid unnecessary clones.
pub struct WasmTimeInstance<'a> {
    instance: Instance,
    records_cb: Arc<RecordsCallBack>,
    params: SmartModuleExtraParams,
    version: i16,
    context: &'a WasmTimeContext,
}
  1. In the get_fn method, there is an or_else statement that attempts to call the typed method with the same parameters. This code doesn't seem to be useful and may lead to the same errors being returned. Consider removing the or_else block unless it has a specific purpose.

  2. In the read_output method, the unwrap_or_default method is used. If there is an issue retrieving the data, this method returns an empty Vec. Instead of hiding the error, consider returning a proper error message if something goes wrong.

let bytes = self
    .records_cb
    .get()
    .and_then(|m| m.copy_memory_from(&ctx.store).ok())
    .ok_or_else(|| anyhow::anyhow!("Failed to read output from callback"))?;
  1. The write_input and read_output method signatures include the Self::Context type with a mutable reference. If you plan to use the Context across multiple threads or need thread-safety guarantees, consider using a Mutex or RwLock from the std::sync module.
use std::sync::Mutex;

pub struct WasmTimeContext {
    store: Mutex<Store<()>>,
}

Please note that without complete context on how this code is being used, these suggestions may need to be modified or may not apply to your specific use case.

This patch introduces two structs, WasmTimeInstance and WasmTimeContext along with a type alias WasmTimeFn, which represents a typed Wasm function with a specific signature.

The WasmTimeInstance struct holds information about a Wasm instance, such as an Instance, a reference-counted RecordsCallBack (using Arc), a SmartModuleExtraParams, and a version number.

The WasmTimeContext struct stores a wasmtime::Store, which is used for interacting with Wasm functions.

Key changes in the patch include:

  1. Implementing the WasmInstance trait for WasmTimeInstance. This adds methods like get_fn, write_input, read_output, and params to the struct.
  2. Implementing the WasmFn trait for WasmTimeFn, enabling the call method to be used on it along with a mutable reference to a WasmTimeContext.

The code primarily focuses on defining data structures for the Wasm instance and context, implementing traits for them, and providing methods for working with Wasm functions, handling input/output, and managing extra parameters.

crates/fluvio-smartengine/src/engine/wasmtime/instance.rs

Below are some potential issues and suggestions in the provided code:

  1. Missing documentation: Add documentation to describe the purpose and functionality of each struct and function in the code. This is helpful for other developers to understand the code.

  2. Clippy warning: In the function transform(&self), remove the #[allow(clippy::borrowed_box)] attribute, and instead, return a reference to the trait object itself:

#[cfg(test)]
pub(crate) fn transform(&self) -> &dyn DowncastableTransform {
    &*self.transform
}
  1. Error handling: The RecordsMemory::copy_memory_from() function returns a Result, but in SmartModuleInstanceContext::read_output(), it is not properly handled:
let bytes = self
    .records_cb
    .get()
    .and_then(|m| m.copy_memory_from(store).ok()) // Here `ok()` is called, converting the Result to an Option
    .unwrap_or_default(); // If the copy failed, an empty Vec is used

Instead of silently using an empty Vec, consider propagating the error:

let bytes = self
    .records_cb
    .get()
    .ok_or_else(|| Error::new("Failed to obtain memory"))?
    .copy_memory_from(store)?;
  1. Misleading debug messages: In SmartModuleInstanceContext::instantiate() function, the message says "creating WasmModuleInstance", but it is actually creating a SmartModuleInstanceContext. Update the debug message to reflect the actual operation:
debug!("creating SmartModuleInstanceContext");
  1. Unclear naming: The struct RecordsCallBack could be renamed to a more descriptive name like RecordsBuffer to explain its purpose better.

  2. Better encapsulation: The functions get(), set() and clear() in RecordsCallBack could be marked pub(crate) since they are only used within the crate. This will help with better encapsulation.

  3. Mutex usage: Using Mutex can potentially block the execution, and in environments like async code, this might cause issues. If this code is planned to be used in an async environment, consider using async-std or tokio mutexes.

  4. Error types: Use custom error types and thiserror crate to have more readable and actionable errors, instead of using generic errors like Error::new(), anyhow::bail!.

  5. Input checks: Verify that the input values passed to the functions are valid. For example, in the RecordsMemory struct, check for negative values for ptr and len.

  6. Unit tests: Include unit tests to verify the functionality of the code.

After addressing these issues, the reviewed code would be more efficient, maintainable, and comprehensible to developers.

In the provided patch, the visibility of the copy_memory_from() function within the RecordsMemory struct has been changed from private (implicitly) to public. This change allows other modules or structs outside of the RecordsMemory struct to directly call the copy_memory_from() function to copy memory from a given context (store).

crates/fluvio-smartengine/src/engine/wasmtime/mod.rs

In the provided source code snippet, there doesn't seem to be any obvious issues, such as syntax errors or bad practices. However, to better evaluate the overall quality and functionality of the code, a more extensive code snippet would be needed. Regardless, there are a couple of general suggestions that can be made based on what is provided:

  1. Documentation: Although the code seems to be properly structured, it lacks documentation. Adding comments and inline documentation, especially for public-facing functions and modules, will improve the code's maintainability and make it more user-friendly.

  2. Specific module re-exports: The last line re-exports several items from the engine module. It might be useful to add comments/documentation to explain why these are re-exported or what their purpose is in the scope of the current module.

  3. Unit tests: Obviously, the code snippet provided does not include any unit tests. Ensuring that your code is accompanied by comprehensive testing will increase its long-term reliability and stability.

  4. Code organization: Group the pub(crate) exports together and the pub use together for the sake of organization and easier readability.

Remember that without a full context or functionality of the code, it is quite difficult to provide more specific or detailed feedback. Nonetheless, these general suggestions will hopefully be helpful in improving the quality of your Rust code.

A summary of the key changes in the provided patch:

  1. A new module imp has been added as a pub(crate) module.
  2. The public exports from the engine module have been updated:
    • Removed: SmartEngine, SmartModuleChainBuilder, and SmartModuleChainInstance.
    • Added: SmartEngineImp, initialize_imp, and SmartModuleChainInstanceImp.

These changes suggest a potential refactoring of the code, possibly introducing a new implementation or changing the public-facing API within this module.

crates/fluvio-smartengine/src/engine/wasmtime/transforms/aggregate.rs

The provided code overall looks good in terms of structure and readability. However, there are a few potential problems that could be addressed or improved:

  1. Missing comments/Documentation: The code lacks documentation and comments on functions and structs. Adding documentation could make it easier for others to understand the purpose of these functions and structs.

  2. Error messages: In general, it's a good idea to make error messages as informative as possible. In the test_aggregate_ok and test_aggregate_with_initial tests, the expect calls could have more descriptive error messages for better debugging.

  3. The #[ignore] attributes in tests: The #[ignore] attribute on both test cases indicates that these tests are ignored when running cargo test. If the reason for this is temporary, it should be mentioned in a comment. If not, consider enabling these tests to ensure that testing is complete.

  4. Magic numbers in tests: In the test functions test_aggregate_ok and test_aggregate_with_initial, there are several magic numbers for array lengths and expected values. Consider defining constants or using descriptive variable names for these values to make the tests more maintainable and easier to read.

  5. Error Handling: In the process function for SmartModuleTransform, the returned Result is only checked if its less than 0. Even though it's mentioned that if an error occurs, the value should be less than 0, there might be cases where some functions might return an unexpected positive value, which might get overlooked by the current check.

  6. Use references instead of cloning: The .clone() function is called on self.accumulator in the process function of the SmartModuleTransform implementation. It might be more efficient to use references or Cow (Clone on Write) to avoid unnecessary cloning of the accumulator data.

In summary, adding comments and documentation, using more descriptive error messages, enabling ignored tests, defining constants for magic numbers, improving error handling, and considering more efficient accumulator usage could improve the code quality.

The key change in the provided patch is the addition of the .inner field access:

let mut chain = chain_builder
    .initialize(&engine)
    .expect("failed to build chain")
    .inner; // This line has been added.

This change ensures that the chain's inner structure is accessed and assigned to chain after the initialization process.

crates/fluvio-smartengine/src/engine/wasmtime/transforms/array_map.rs

The code provided is a Rust test module for testing the array_map feature in a smart module chain. Here are my observations and recommendations:

  1. In the imports section, it would be better to group crate imports together and separate them from the others to improve code organization.

    use std::{convert::TryFrom};
    
    use fluvio_smartmodule::{
        dataplane::smartmodule::{SmartModuleInput},
        Record,
    };
    
    use crate::engine::{
        SmartEngine, SmartModuleChainBuilder, SmartModuleConfig, metrics::SmartModuleChainMetrics,
        wasmtime::transforms::simple_transform::ARRAY_MAP_FN_NAME,
    };
    
    const SM_ARRAY_MAP: &str = "fluvio_smartmodule_array_map_array";
    
    use crate::engine::fixture::read_wasm_module;

    Updated version:

    use std::{convert::TryFrom};
    use fluvio_smartmodule::{
        dataplane::smartmodule::{SmartModuleInput},
        Record,
    };
    
    use crate::{
        engine::{
            SmartEngine, SmartModuleChainBuilder, SmartModuleConfig,
            metrics::SmartModuleChainMetrics, wasmtime::transforms::simple_transform::ARRAY_MAP_FN_NAME,
            fixture::read_wasm_module,
        }
    };
    
    const SM_ARRAY_MAP: &str = "fluvio_smartmodule_array_map_array";
  2. The test function test_array_map is annotated with #[ignore], causing the test runner to skip it by default. If this test should be executed normally, you should remove the #[ignore]. Alternatively, if there's a valid temporary reason for ignoring this specific test, adding a comment explaining the reason would be helpful.

  3. The array elements being mapped are hard-coded. If these are expected to change, it would be better to define them as constants or read them from a configuration file.

  4. The test module should test more scenarios to validate the functionality, such as testing empty input, invalid input, and different expected outputs. Multiple test functions can be created to cover various cases.

  5. One more thing to consider is error handling in case the test modules fail. In this specific case, using expect() is reasonable because it provides a clear error message in the resulting panic. However, creating custom error types and error handling strategies can help produce more informative errors with better context.

Overall, the code looks well-written, and the concerns are mostly related to organization, readability, and test coverage. With some minor improvements mentioned above, the code should be more maintainable and easier to understand.

In this patch, a single line change was made within the test_array_map function:

  1. The chain variable assignment was updated. Previously, there was a small issue where the assignment didn't include the .inner attribute, which was required to access chain's inner value to perform further operations on it. The patch fixes this by appending .inner at the end of the expression:

    Previous code:

    let mut chain = chain_builder
        .initialize(&engine)
        .expect("failed to build chain");

    Updated code:

    let mut chain = chain_builder
        .initialize(&engine)
        .expect("failed to build chain")
        .inner;

This change ensures that the chain variable contains the correct value, which enables further operations and assertions to be performed as intended in the test function.

crates/fluvio-smartengine/src/engine/wasmtime/transforms/filter.rs

The source code appears to be a set of test cases for a module dealing with smart module chains and filtering. Overall, the code seems well organized, but there are a few improvements that could be made. Here's a list of potential issues and suggestions:

  1. Unused import: The import use std::{convert::TryFrom}; is not required as it is already imported in the line use fluvio_smartmodule::{dataplane::smartmodule::{SmartModuleInput}, Record,};.
// Remove this import
// use std::{convert::TryFrom};
  1. It would be better to use assert! for checking if the value is equal to true, and assert_eq! for comparisons.
// Replace this line:
// assert_eq!(instance.get_init().is_some(), true);
// With this line:
assert!(instance.get_init().is_some());
  1. It's not clear why the tests are marked as ignored. If these tests should run as part of the test suite, consider removing the #[ignore] attribute.

Other than these minor issues, the code seems well-structured and easy to understand. I see no major issues with the test cases. However, as the code is part of a test module, it's essential to review the production code being tested to ensure that it does not have any problems or vulnerabilities.

The key changes in this patch involve modifying instances of .expect("failed to build chain") to include the .inner field as part of the chain object creation:

  1. In the test_filter test case, the following lines have been updated:

    // Changed from:
    .expect("failed to build chain");
    // To:
    .expect("failed to build chain")
    .inner;
  2. Similarly, in the test_filter_with_init_ok test case, the same modification is made:

    // Changed from:
    .expect("failed to build chain");
    // To:
    .expect("failed to build chain")
    .inner;

In both cases, the changes ensure that the chain objects are created with the .inner attribute while maintaining the original error handling using .expect().

crates/fluvio-smartengine/src/engine/wasmtime/transforms/filter_map.rs

The code looks decent, but there are some improvements that can be made. Here are my observations:

  1. Instead of using raw string references like in const SM_FILTER_MAP: &str = "fluvio_smartmodule_filter_map";, you may consider either creating a constant in a relevant module or using an enum structure to represent the available wasm modules. This will make your code more maintainable and less prone to typos or hard-to-find bugs.

  2. The unwrap() calls in the test are unlikely to cause problems since it's a test environment. However, consider replacing them with expect() to provide more context on the type of error in case of a panic.

  3. The test is marked with #[ignore]. If it's a valid test and doesn't require any preconditions to run, consider removing that attribute to include it in your regular test suite.

  4. It could be helpful to add comments explaining the purpose of the test and the expected behavior of the filter_map function. This will make it easier for others to understand the codebase.

  5. The test function is called test_filter_map(), which is descriptive enough. However, you may consider following a more consistent test naming convention, such as test_<module_name>_<function_name>_<behavior_under_test> or any other convention that suits your project. This will make it easier to identify relevant tests for specific scenarios or modules.

  6. Consider using an IDE or a linter to help evaluate your code. These tools can help you find potential issues, such as incorrect imports or unused variables, more easily during development.

Finally, although you mentioned the code is truncated, It's essential to ensure that all necessary imports and relevant constants are included at the beginning of the source file to ensure it compiles and runs correctly.

The key change in this patch is the addition of .inner after the expect("failed to build chain") call. This change is made to extract the inner field from the SmartModuleChain struct, allowing the following code to access and process the data inside the inner field.

crates/fluvio-smartengine/src/engine/wasmtime/transforms/map.rs

Overall, the code appears to be well-written and follows Rust's best practices. Here are a few observations and suggestions:

  1. Consider adding comments to the code, especially for the test function and the constants used in it. This would help others understand the purpose of the test and the meaning of the constants.

  2. The use std::{convert::TryFrom}; import line contains only one item. It may be simplified to use std::convert::TryFrom;.

  3. It would be helpful to add a brief description about the ignored test test_map(), explaining why it is ignored and under what conditions it should be enabled. You can do this using comments or even better, by adding a message to the #[ignore] attribute, like so:

#[ignore = "reason why this test is ignored"]
  1. In this snippet:
let engine = SmartEngine::new();
let mut chain_builder = SmartModuleChainBuilder::default();

engine is used to initialize the chain. Still, it is not evident how SmartEngine and SmartModuleChainBuilder are related. Consider adding some comments to explain the relationship between them and their purpose in the test function.

  1. While building the SmartModuleConfig in the following code:
SmartModuleConfig::builder().build().unwrap(),

Consider setting any needed configuration options using the builder methods. If all the default values are needed for the test, then it's fine to use it as is. However, if there are any specific configuration options relevant to the test, make sure to set them using the builder.

  1. Use more descriptive variable names. Instead of input, use something like input_records to make it clear that it is a collection of records you are providing as input. And the same goes for output -> output_records.

  2. In the assertion of successes:

assert_eq!(output.successes.len(), 2); // one record passed

The comment ("one record passed") might be misleading, as the assertion checks that there are two successes, not one. Please revise the comment to accurately reflect the reality.

These are suggestions to improve code comprehension, and they would not affect the functionality of the script. The code provided looks functional and well-structured as it is.

The key change in this patch is the addition of .inner to the result of the chain_builder.initialize() method when initializing the chain variable. This change unwraps the inner value of the chain after initializing it with the given SmartEngine. This update allows access to the inner chain structure for subsequent testing and assertions.

cc xxchan/fluvio#1

@juntao
Copy link
Contributor Author

juntao commented Apr 29, 2023

Flows summarize

Copy link
Contributor Author

juntao commented Apr 29, 2023

Hello, I am a code review bot on flows.network. Here are my reviews of code commits in this PR.


This pull request introduces a number of changes to the fluvio-smartengine crate, with some focused on code refactoring, implementing new features, renaming items for consistency, and relocating files to improve organization. The primary changes relate to the introduction of the wasmedge-engine feature, SimpleTransformImpl struct and related traits, support for initialization functions in the wasmedge/common module, and code reorganization for transform unit tests.

Potential issues include but are not limited to:

  1. Compatibility issues with existing codebase due to renaming, relocation, and visibility changes.
  2. Potential test cases being ignored, leading to undetected bugs in added functionality.
  3. Proper error handling and validation issues for added features such as the aggregate transform and initialization functions.
  4. Possible build/runtime errors due to changes in feature sections and dependencies in the Cargo.toml file.
  5. Memory management of the engine might have issues, such as in the implementation of RecordsMemory and RecordsCallBack.

Important findings to consider are:

  1. Refactored code, reorganized files and directories, and code cleanup for better readability and organization.
  2. Implemented new features, such as the wasmedge engine, initialization functions, and transforms.
  3. Introduced compile-time checks to prevent enabling both wasmtime-engine and wasmedge-engine features simultaneously.
  4. Renamed items throughout the code base to follow proper naming conventions, which can improve the consistency and maintainability.
  5. Updated the crate to the latest version of fluvio-socket in the Cargo.lock file.

Overall, this pull request makes several key improvements to the fluvio-smartengine crate, addressing both code quality and the addition of new engine features. Careful attention should be paid to potential issues and ensuring that tests and documentation are updated to reflect the changes in the codebase.

Details

Commit fb5b2fe2be03997469db74f8abf3ad5d0c53e374

This patch aims to make the public API clear and initializes the work for the wasmedge_engine feature. The key changes to note are:

  1. Two features, wasmtime-engine and wasmedge-engine are introduced in Cargo.toml. Later on, it's expected that only one WASM runtime can be chosen at a time.
  2. A new file config.rs is added, which introduces SmartModuleInitialData, SmartModuleConfig, SmartModuleConfigBuilder, and their implementations.
  3. Code related to SmartModuleConfig and SmartModuleInitialData is extracted from engine.rs to the new config.rs file.
  4. A new file wasmedge_engine/mod.rs is added, which introduces SmartEngine, SmartModuleChainBuilder, and SmartModuleChainInstance for wasmedge_engine.
  5. In lib.rs, a TODO comment is added for a future check which ensures that not both wasmedge_engine and wasmtime_engine features are enabled simultaneously.

Potential problems:

  1. There's a TODO comment to turn on the check for enabling only one of the wasmedge_engine and wasmtime_engine features in the future. This may lead to unintended behavior if both these features are enabled simultaneously.
  2. The wasmedge-engine feature isn't fully implemented yet; the added structures and functions in wasmedge_engine/mod.rs contain todo!() blocks. More work is needed for completion, so using this feature in its current state may lead to issues.

Commit 7a300061f072df1061489c09604f646b554f21a7

This patch implements a filter transform in the fluvio-smartengine crate. The key changes include:

  1. Creation of several new modules including instance, memory, transforms, and init inside the wasmedge_engine folder.
  2. Creation of a SmartModuleInstance struct to manage the filter transform instance.
  3. Modification of Cargo.toml and Cargo.lock to include the necessary dependencies including wasmedge-sdk and wasmedge-macro.
  4. Implementation of SmartModuleTransform trait to handle transformations.
  5. Modification of the SmartEngine struct to support the new transform.
  6. Implementation of an initialize method to create a SmartModuleChainInstance.

Potential problems:

  1. Unclear lifetime management of the import and module objects in the SmartModuleInstanceContext::instantiate() function, as they are both intentionally leaked using std::mem::forget.
  2. A Clone trait is possibly unnecessary for the RecordsMemory struct but has been implemented.

Possible areas for improvements:

  1. The management of the lifetimes for the import and module objects should be investigated further and improved if possible.
  2. The necessity of the DowncastableTransform trait could be reviewed and possibly removed or simplified if possible.

Commit 685ae36618ddb62f922be9a480c393f64f9d2dd7

Summary:

  • The patch adds new file common.rs for WasmInstance, WasmFn, SmartModuleTransform, and DowncastableTransform traits, and SimpleTransformImpl struct.
  • Moves several files from src folder to src/engine folder, such as config.rs, engine.rs, error.rs, fixture.rs, init.rs, metrics.rs, and so on.
  • Renames the SmartEngine struct as SmartEngineImp.
  • Adds initialize_imp function for initializing SmartModuleChainInstanceImp.
  • Modifies some test modules for the new structure.

Potential Problems:

  • The instance.rshas been shortened, and some parts are missing.

Commit 15686cc0630a25efeed7731c15f459fca821cc8a

Summary of key changes:

  1. The public API has been made more clear.
  2. A new file "config.rs" was created to handle the configuration of the SmartModule.
  3. Several files were moved to the "engine" directory.
  4. The "engine" feature in "Cargo.toml" was renamed to "wasmtime-engine".
  5. Some types and struct fields had their visibility changed to pub(crate).

Potential problems:

  1. The large number of changes and file moves can make it difficult to follow what has been changed, increasing the possibility that some issues may be overlooked during the review process.
  2. With the removal of the pub keyword from the struct fields and renaming features in the Cargo.toml file, there may be potential compatibility issues with the existing codebase.
  3. The GitHub patch does not include any test changes or new tests, which is important when making changes to the public API. There might be potential issues not covered by tests.

Commit 1937438bb628ad317afff67dfadbeddadb87a564

This patch primarily moves the wasmtime_engine module to a different location in the crate fluvio-smartengine. The key changes are as follows:

  1. The wasmtime_engine module is moved from crates/fluvio-smartengine/src/engine to a new nested module in the same directory.
  2. The mod.rs file is updated to reflect this move, changing the usage of the wasmtime_engine module.
  3. Renamed and updated 13 files, moving them from the engine directory to the new wasmtime_engine module.

Potential problems:

  • There might be unseen dependencies or issues that arise due to this move, so it would be essential to ensure the tests are run to validate the changes.
  • There could be compatibility issues or implications on the usage of the crate, so it's important to verify documentation and examples are updated accordingly if necessary.

Commit 6f1604e47822f07d990e0b77a2b16943030fdfe9

This patch modifies the features section and their dependencies in the Cargo.toml file for the fluvio-smartengine crate. The key changes are as follows:

  1. The 'wasi' feature is changed to include "wasmtime-engine" as a dependency, in addition to the existing "wasmtime-wasi" and "engine".

  2. The 'wasmtime-engine' feature is modified to only depend on "wasmtime", with the dependency on "wasmtime-wasi" removed.

Potential problems:

  1. If the removed dependency on "wasmtime-wasi" from the 'wasmtime-engine' feature was actually required by the crate, this change might introduce build/runtime errors. The developer should ensure that the removed dependency is not used.
  2. The patch doesn't include any changes to the source code. If these feature modifications require any updates in the code, they should be added in subsequent patches.

Commit 6b8855529be62c405ab1cc8136e915c4b977ad28

This GitHub patch renames the module wasmtime_engine to wasmtime. The key changes are as follows:

  1. Rename the module: All instances of wasmtime_engine are replaced with wasmtime. This includes renaming the directory and references to the module in the code.

  2. Update import statements: Various import statements are modified to use the new module name wasmtime instead of wasmtime_engine.

Since this patch only changes the module name and updates the relevant import statements, there are no potential problems introduced by the changed code. It is a straightforward module renaming and refactoring patch.

Commit 86326da008b095c3d3ca73f5213462a1e3d6a9f0

This patch introduces several key changes to the fluvio-smartengine crate:

  1. Code reorganization involving the renaming of several files and moving them to the wasmtime subdirectory. The primary modules affected are engine, init, instance, and memory among others.
  2. The mod.rs file in the engine module has been modified to import the modules from the wasmtime directory.
  3. A new file wasmtime/mod.rs has been created, consolidating the module imports and addressing the organizational changes in the engine module.
  4. The patch corrects two instances where a module was referenced using the old structure instead of the new one, involving the RecordsCallBack and copy_memory_to_instance functions.

Overall, the changes seem to focus on code structure and organization. There are no added features or major adjustments to the code itself. The primary potential issue with this patch is that the changes may affect the build process or crate's functionality in unforeseen ways. To ensure that the crate still builds and operates as expected, it is essential to run tests, verify the build process, and ensure that all modules are still correctly referenced.

Possible issues:

  1. Build errors due to changes in file names or module organization.
  2. Functionality may be affected if any import or reference was missed during the restructuring process.

Commit f17b8ef6322129e965d46da6abf1e275982bba8c

This patch focuses on adding support for initialization functions in the wasmedge/common module.

Key changes:

  1. Added engine feature flag in Cargo.toml, which includes both wasmtime-engine and wasmedge-engine.
  2. Implemented initialization functions for the Wasm module in crates/fluvio-smartengine/src/engine/common.rs. This includes:
    • INIT_FN_NAME: A constant representing the initialization function name "init"
    • SmartModuleInit and its associated methods, which are the main components for handling module initialization
  3. Deleted crates/fluvio-smartengine/src/engine/wasmedge/init.rs as the functionality is now moved to the common module.
  4. Modified instance.rs to use the new implementation in the common module.
  5. Refactored mod.rs to use the updated SmartModuleInit implementation.

Potential problems:

  1. The initialization function is now optional, which could introduce issues related to initialization, especially if some users expect to have an init function always.
  2. Managing lifetimes in instance.rs using std::mem::forget could lead to memory leaks or unexpected issues if not properly managed.
  3. There might be integration issues with the wasmtime and wasmedge engines, especially if both are used together.

Commit 11e175105c813ef6c852ab49d57699b89f59d472

The key changes in the given GitHub patch are:

  1. Created a new common SmartModuleInstance in the engine/common.rs module.
  2. Modified the SmartModuleInstance in the engine/wasmedge/instance.rs module by importing and using the common SmartModuleInstance.
  3. Added a new field params to the SmartEngineImp struct.
  4. Updated the initialize_imp function signature and usage to reflect the new changes.

Potential problems:

  1. Code duplication: The initialize_imp function's code is duplicated both in engine/mod.rs and engine/wasmedge/mod.rs.
  2. Implementation disparities between SmartEngineImp and SmartEngine.
  3. The patch does not include any test adjustments or additions to reflect the new changes. It is important to ensure that the changes do not introduce new bugs or regressions.
  4. The code will need to be checked for proper module import statements for correct code processing.
  5. The code should be reviewed for missing or incorrect error-handling, especially around the new params() function in the WasmInstance trait.

To summarize, this patch introduces a new common SmartModuleInstance, modifies existing module instances to use the new common instance, and updates function signatures and usage accordingly. Some potential issues to look out for include insufficient test adjustments, code duplication, and discrepancies between implementations.

Commit abd4fb61fb6df8e9858059a75569aaeb757dfd7e

Summary of key changes:

  1. Refactored code to make a create_transform function common across different engines.
  2. Reorganized trait implementations.
  3. Updated the Cargo.lock file to use fluvio-socket version 0.14.1 instead of 0.14.0.
  4. Created new files for wasmedge including imp.rs, init.rs, and instance.rs.
  5. Created a new file for wasmtime: imp.rs.

Potential problems:

  1. Trait implementations have been moved around and may change their behavior.
  2. Changes in SmartModuleTransform, WasmFn, and WasmInstance traits can lead to altered behavior during processing or compilation.
  3. The create_transform function has been re-organized and abstracted, which might cause issues if it doesn't work with both wasmedge and wasm engines correctly.

Commit 66bcbddf333545c4a30ec5743fc9d495253af3f2

This patch includes changes to the fluvio-smartengine crate for the WasmEdge engine, with a substantial refactoring of the codebase. The key changes are as follows:

  1. Removing the imp.rs and init.rs files, and merging their contents into instance.rs.
  2. Modifying the common.rs file to reorder the import statements for better readability.
  3. Implementing the WasmInstance trait for WasmedgeInstance and the WasmFn trait for WasmedgeFn.
  4. Adding implementation details for RecordsMemory and RecordsCallBack in a new memory.rs file.

Potential problems:

  • The new implementation for RecordsMemory and RecordsCallBack might have issues with the memory management of the engine.
  • Deleting the imp.rs and init.rs files might lead to a loss of functionality or breaking changes if there are any dependencies on these files that are not addressed in the new implementation.
  • The alterations to the import statements in the common.rs file might introduce breaking changes if there are unresolved dependencies.
  • The changes are extensive, which might introduce new bugs or issues in the smart engine.

Commit da7a2e22f4fc5220d2d2eef049a6faa161b923e7

Summary of key changes:

  1. Added 3 new tests for wasmedge transforms:
    a. array_map.rs - Tests the array_map transform.
    b. filter_map.rs - Tests the filter_map transform.
    c. map.rs - Tests the map transform.
  2. Removed an unnecessary import in filter.rs.
  3. Updated the get_transform function in the common.rs file to use a match statement instead of .ok_or_else handling.

Potential problems:

  1. These new test cases have the #[ignore] attribute, so they will not run by default during testing, which might hide test failures. If you want these tests to run during normal test execution, you should remove the #[ignore] attribute.
  2. There is no newline at the end of the mod.rs file, which could potentially cause issues with certain tools or editors. It is recommended to add a newline at the end of the file.

Commit 26d90534629b271548b0707b7f378398d6d5d256

Summary of key changes in this patch:

  1. A new aggregate.rs file is created containing tests and implementation for the aggregate transform.
  2. Changes in common.rs include the addition of the AggregateTransform struct along with its try_instantiate and process methods. Code for instantiation and data processing in aggregate transform is added as well. A new constant AGGREGATE_FN_NAME is introduced and set to "aggregate".
  3. Modification in mod.rs adds a new module import for aggregate.

Potential problems to investigate:

  1. The new tests in aggregate.rs have the #[ignore] attribute which means those tests won't be run, allowing undetected bugs in the added functionality. It is recommended to carefully analyze the necessity of ignoring these tests.
  2. Proper error handling and validation regarding the newly added aggregate transform should be checked to ensure that the functionality does not break existing systems.
  3. Ensure that the changes are compatible with the rest of the project and that it doesn't introduce any unintended side effects or performance issues.

Commit 56de150fdda512694fda8f9718cc0aaab2c2f5f4

This patch contains changes across three files, mainly focused on implementing and utilizing the WasmEdge engine within the SmartEngine.

Key changes:

  1. The implementations related to SmartEngineImp, initialize_imp, and SmartModuleChainInstanceImp are moved from mod.rs to a new module imp.rs inside the wasmedge engine. imp.rs contains methods for initializing and processing the SmartModuleChainInstanceImp.
  2. The mod.rs file now only contains public API imports from imp.rs, along with imports of the other existing modules (instance, memory, and transforms).

Potential issues:

  1. Having instances stored in a Vec might not be the most efficient way for performance under large operation queues. However, as the code is already implementing the split_last_mut() and try_into() methods for handling input mutations, it might be an acceptable balance for now.

Commit 14c4c3c1f3a95f85318b1515977a446e027acb67

This patch refactors the wasmtime-related code in the Fluvio smart engine. The major changes include:

  1. Deleted crates/fluvio-smartengine/src/engine/wasmtime/engine.rs file and moved its contents to the more general crates/fluvio-smartengine/src/engine/wasmtime/imp.rs file.
  2. Defined SmartEngineImp in crates/fluvio-smartengine/src/engine/wasmtime/imp.rs as a new implementation.
  3. Modified crates/fluvio-smartengine/src/engine/mod.rs to use the new implementation for wasmtime.
  4. Created memory.rs to handle memory-related operations in wasmtime.
  5. Refactored code in the transforms module.

Potential issues:

  1. The patch has high insertion (+425) and deletion (-877) counts, indicating a full rewrite of the implementation. This can introduce new bugs and may require more extensive testing.

Commit 3d8f4bf3cc37add73354eb9e2b95641dac1f7fa6

This patch renames the WasmTime struct and related types, variables, and functions to follow proper naming conventions with Wasmtime.

Key changes:

  1. Renamed WasmTimeInstance to WasmtimeInstance.
  2. Renamed WasmTimeContext to WasmtimeContext.
  3. Renamed WasmTimeFn to WasmtimeFn.
  4. Updated various variable and function names to use the new naming convention, such as WasmTimeFn::call to WasmtimeFn::call.

Potential problems:

  1. If there are any external dependencies that rely on the previous naming convention, their code will need to be updated accordingly.
  2. Double-check the code to ensure that every instance of the old naming convention has been successfully updated to the new naming convention.

Commit d0bb940084f4376e206edf5abcb9f10c50d239e2

This patch moves the transform unit tests to a common directory, and mostly involves file relocation and renaming. It also adds a check to compile with an error if both "wasmedge-engine" and "wasmtime-engine" features are enabled at the same time.

Key changes:

  • Move and rename transform unit test files to the "common" directory
  • Update imports and type definitions to support the relocation
  • Create new files: init.rs and mod.rs in the "common" directory
  • Update Cargo.toml to include the changes
  • Add a compile check for both "wasmedge-engine" and "wasmtime-engine" features enabled

Potential problems:

  • No problems were found in the patch.

Commit 792483407a026b31c8f0aca97f1d17fd70a3d313

This patch is renaming the Wasmedge prefix to WasmEdge throughout the codebase for consistency reasons. The key changes are as follows:

  1. Renamed the following module names:

    • WasmedgeFn to WasmEdgeFn
    • WasmedgeInstance to WasmEdgeInstance
    • WasmedgeContext to WasmEdgeContext
  2. Updated type aliases and structural changes to maintain consistency with the new names:

    • Updated the import statements to use the new names.
    • Updated the types used in type aliases, function signatures, and structures.

Potential Problems:

  1. There could be other files or test cases that still refer to the old names, leading to compilation errors or broken dependencies.
  2. There might be documentation or comments that still refer to the old names, leading to inconsistencies in the codebase.

To address these potential problems, a thorough review of the entire codebase must be done to ensure all instances of the old names are replaced with the new names. In addition, any documentation or comments should be updated accordingly.

cc xxchan/fluvio#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant