Extend the generic skeleton to opening non-owned shared memory objects.#482
Conversation
ShmPathBuilder extension to inject inter-VM–specific path elements while constructing shared memory paths from inter-VM shared memory configuration.
ShmPathBuilder extension to inject inter-VM–specific path elements while constructing shared memory paths from inter-VM shared memory configuration.ShmPathBuilder extension for inter-VM shm path construction.
|
|
||
| // Inter-VM shared-memory backends can have a short NAME_MAX, use compact 5-digit service ID instead of the default | ||
| // 16-digit padding | ||
| void AppendServiceAndInstanceCompact(std::ostream& out, |
There was a problem hiding this comment.
You can leave out this "compacting". If we would takes this over from the PoC ... then we would really materialize all the bugs/short-commings, which BlackBerry had in their sample-contribution :) (namely they had a weird restriction in their qvmshm implementation regarding path-name-sizes).
There was a problem hiding this comment.
removed compacting, spilt the pr and updated to: #492
| { | ||
| public: | ||
| explicit ShmPathBuilder(const std::uint16_t service_id) noexcept : IShmPathBuilder{}, service_id_{service_id} {} | ||
| explicit ShmPathBuilder(const std::uint16_t service_id, const bool inter_vm_support = false) noexcept |
There was a problem hiding this comment.
Add a doxygen comment to this ctor.
document/comment the inter_vm_support parameter. Note, that it is an interim solution, to express the intent to have a shm-object, which supports sharing across VMs by encoding it into the path-name. A future solution will be based on a redesigned lib/memory/shared API abstraction.
There was a problem hiding this comment.
updated the doxygen comment and spilt the pr and updated to: #492 https://github.com/eclipse-score/communication/pull/492/changes#diff-23baa8b4571febbd6ac770b38d32efd5fdba6b4a52c5ed12e37d03531ef2ef0dR32-R44
| gateway_shm_ready_ = false; | ||
| break; | ||
|
|
||
| case ShmReuseStrategy::kUnknownStrategy: |
There was a problem hiding this comment.
You should have a "fal through" here:
case ShmReuseStrategy::kUnknownStrategy:
default:
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(false, "Unknown SHM reuse strategy.");
break;
There was a problem hiding this comment.
Adapted the changes, thanks
| "Could not open existing shared memory region for gateway-forwarded service."); | ||
| } | ||
| was_old_shm_region_reopened_ = false; | ||
| gateway_shm_ready_ = true; |
There was a problem hiding this comment.
I guess, we should rename gateway_shm_ready_ -> use_gateway_forwarded_shm_
midterm we might need some refactoring imho ... because now we have different flags, which are mutual exclusive (was_old_shm_region_reopened_ , use_gateway_forwarded-shm_) which is a bit ugly...
So from a high-level perspective, we have either a "normal" skeleton ... or a "forwarding" skeleton.
So - for now we express the latter only with this flag use_gateway_forwarded_shm_ ... which looks a bit "hacky" as a lot of behaviour is different in this case. So I'm thinking in the direction to introduce a more generic "mode" attribute in our skeleton class, which is either "REGULAR" or "FORWARDING" ... but this is - as I said - for future refactorings.
There was a problem hiding this comment.
remanned gateway_shm_ready_ -> use_gateway_forwarded_shm_, thanks
| // re-open that shared memory in PrepareOffer(). In that case, we should retrieved the EventDataControl and | ||
| // EventDataStorage from the shared memory and attempt to rollback the Skeleton tracing transaction log. | ||
| if (was_old_shm_region_reopened_) | ||
| if (gateway_shm_ready_) |
There was a problem hiding this comment.
We should do an assert here! If we end up in this template-function call AND gateway_shm_ready_ (now - see above use_gateway_forwarded_shm_ ) is true, something went wrong.
Why? Because this specific interVM functionality is only used in our gateway setups, where always GenericSkeleton is used - no "typed skeletons". But in case of a GenericSkeleton this template-func will never be called! Because in this case we only deal with GenericSkeletonEvents, which do not call this template func, but instead the non-template func Skeleton::RegisterGeneric()!
So - make an assert here and document, that use_gateway_forwarded_shm_ == true is only expected in gateway-use-cases, where GenericSkeletons are used ...
There was a problem hiding this comment.
updated the changes, Thanks
| const auto event_metainfo_it = find_element(storage_->events_metainfo_, element_fq_id); | ||
| const auto event_data_storage_it = find_element(storage_->events_, element_fq_id); | ||
|
|
||
| if (lola_service_instance_deployment_.inter_vm_support_ && lola_service_instance_deployment_.inter_vm_forwarded_) |
There was a problem hiding this comment.
See argumentation above! In case we are in the interVM-gateway case, we expect a GenericSkeleton being used. But then, we would NOT end up in this template func as it is only used within "typed skeletons".
There was a problem hiding this comment.
Updated the changes. Thanks
| return quality_type_; | ||
| } | ||
|
|
||
| Result<void> Skeleton::ValidateDataShmObject(const SkeletonEventBindings& events, |
There was a problem hiding this comment.
I did not see any calls to this method (and also not to ValidateControlShmObject)
Where did you expect the validation calls to happen?
My 1st guess would be directly after opening the shm-objects in PrepareOffer?
But now I had a 2nd look... and I'm not sure, whether this validation you implemented here is "added value".
My thoughts:
- in
Skeleton::RegisterGeneric()further down you have the code everyGenericSkeletonEvent(and later also field) will run through, to register at its parent skeleton, thereby also "checking" the shared memory (CONTROL and DATA). I.e. at least it checks, whether for itsElementFqIdthe expected control/data artefact exists in shared-memory ... so if in the interVM use case, the shm, which we opened would be a wrong one,Skeleton::RegisterGeneric()would fail. - do you really check much more here, than what is implicitly checked in Skeleton::RegisterGeneric()?
You are even hyper-strict here - as you check, that the shm conains exactly the number of events/fields as you have here with events/ fields params ... if the shm-object would contain additional ones ... that would not even be a real problem/error. The Skeleton::RegisterGeneric() is more "flexible" ... it just checks, that the things at least exist in shm, which we expect ... if there is even more ... no problem.
My proposal:
- remove
ValidateDataShmObjectandValidateControlShmObject - if you feel that some consistency checks are missing within
Skeleton::RegisterGeneric()... add them there.
There was a problem hiding this comment.
yes, you are right i feel Skeleton::RegisterGeneric() is enough to verify, removed both functions, Thanks
| const size_t sample_alignment) noexcept -> GenericRegistrationResult | ||
| { | ||
| if (was_old_shm_region_reopened_) | ||
| if (gateway_shm_ready_) |
There was a problem hiding this comment.
This can be optimized:
the if/else branch basically just differ regarding rollback! Only in one case a rollback is done - in the other not.
if (use_gateway_forwarded_shm_ || was_old_shm_region_reopened_)
{
auto [event_data_control_qm, event_data_control_asil_b] =
memory_manager_.RetrieveEventControlsFromOpenedSharedMemory(element_fq_id);
auto& event_data_storage = memory_manager_.RetrieveEventDataFromOpenedSharedMemory<std::uint8_t>(element_fq_id);
if (!use_gateway_forwarded_shm_)
{
memory_manager_.RollbackSkeletonTracingTransactions(event_data_control_qm);
if (event_data_control_asil_b != nullptr)
{
memory_manager_.RollbackSkeletonTracingTransactions(*event_data_control_asil_b);
}
}
return {static_cast<void*>(&event_data_storage), event_data_control_qm, event_data_control_asil_b};
}
There was a problem hiding this comment.
Optimized the code, Thanks
84454fd to
22b416d
Compare
22b416d to
ed155b6
Compare
ShmPathBuilder extension for inter-VM shm path construction.
Issue: #387