Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm utilizing the
ExternalWorkload
to test custom layers within the FoundationDB simulation. The layers under test are authored in Rust and are based on the foundationdb-rs project. The workload API is defined by the C++ header fileClientWorkload.h
. Interoperability between Rust and C++ presents challenges, although creating a C++ to C shim was relatively straightforward. My main concern is the unstable ABI of the C++ API, as it relies on the compiler, linker, and system libraries. This proved to be an issue when transitioning from version 7.1 to 7.3, where the workload I was using suddenly broke due to a change in the representation of thestd::string
class as the fdbserver switched from gcc to clang, as detailed in this forum thread and issue #11298.To address this, I propose that alongside the existing C++ API (utilized by
JavaWorkload
), pure C bindings should be made available to ease integration with other languages and mitigate the impact of changes in compilation environments. This aligns well with the location ofClientWorkload.h
in thebindings/c
folder.I currently lack the necessary toolchain to compile the project, so it remains untested and likely doesn't compile. This PR is submitted to gather feedback on the proposed solution. Given my limited familiarity with the FoundationDB codebase, I resorted to various wrappers to minimize code changes. However, a more efficient approach might involve rewriting the
ExternalWorkload
or creating a dedicated C version.In this draft, I've divided
ClientWorkload.h
intoCWorkload.h
andCppWorkload.h
. ImportingCppWorkload.h
should mirror the behavior of the originalClientWorkload.h
, ensuring compatibility with existing workloads utilizing this API. The C bindings introduceBridgeToClient
andBridgeToServer
structs that encapsulate collections of function pointers. If the "useCAPI" option is enabled in theExternalWorkload
configuration file, it will load theworkloadInstantiate
symbol (instead ofworkloadFactory
) and invoke it with the server-bridge (allowing the C workload to interact with the C++FDBWorkloadContext
andGenericPromise<bool>
classes). The returned client-bridge is then encapsulated within a C++ "translator" workload and assigned as theworkloadImpl
for theExternalWorkload
.