Why do I see the WARNING message “PRESCstReaderCollator_getKey:instance not found”?
When processing a metadata sample that indicates the instance transition change to NOT_ALIVE_NO_WRITERS or NOT_ALIVE_DISPOSED, you may see the following WARNING messages when calling the get_key_value API:
- WARNING PRESCstReaderCollator_getKey:instance not found
- WARNING PRESPsReader_getKey:!collator getKey no instance
These errors may occur when you call the get_key_value API using the received SampleInfo::instance_handle of an instance whose key is no longer available in the DataReader cache.
This issue may occur when processing a metadata sample that indicates an instance transition.
Processing a NOT_ALIVE_DISPOSED metadata sample
NOT_ALIVE_DISPOSED metadata are sent without a key by default, but can be sent with the key of the instance if the DataWriter sets serialize_key_with_dispose to TRUE in the DataWriterProctocol QoS policy.
The “PRESCstReaderCollator_getKey:instance not found” warning when processing a NOT_ALIVE_DISPOSED metadata sample can occur if:
- DataReader has not received any sample of the instance, it is set with propagate_dispose_of_unregistered_instances to TRUE, and it receives a NOT_ALIVE_DISPOSED metadata sample without key because:
- NOT_ALIVE_DISPOSED metadata sample was sent by a regular DataWriter not setting serialize_key_with_dispose to TRUE.
- NOT_ALIVE_DISPOSED metadata sample was sent by a Persistence Service DataWriter, as it never includes the key in the NOT_ALIVE_DISPOSED metadata sample.
- DataReader sets autopurge_disposed_instances_delay to 0 and:
- The read()/take() API you use returns a copy of the sample instead of a loaned sample.
- Calling the get_key_value API after the loaned sample is returned.
Processing a NOT_ALIVE_NO_WRITERS metadata sample
NOT_ALIVE_NO_WRITERS is the default state of an instance when no samples have been received. The metadata samples sent by DataWriters when unregistering an instance do not include the key of the instance.
The “PRESCstReaderCollator_getKey:instance not found” warning when processing a NOT_ALIVE_NO_WRITERS metadata sample can occur when:
- Processing a NOT_ALIVE_NO_WRITERS metadata sample after a NOT_ALIVE_DISPOSED and only if:
- Setting propagate_dispose_of_unregistered_instances and propagate_unregister_of_disposed_instances to TRUE and not having received the key with the previous NOT_ALIVE_DISPOSED metadata sample.
- Setting propagate_unregister_of_disposed_instances to TRUE and processing the NOT_ALIVE_NO_WRITERS metadata sample after the instance was purged due to setting autopurge_disposed_instances_delay to 0.
- DataReader sets autopurge_unregistered_instances_delay to 0 and:
- The read()/take() API you use returns a copy of the sample instead of a loaned sample.
- Calling the get_key_value API after the loaned sample is returned.
Please review the documentation of the API you are using to check whether the read()/take() operation you are using returns loaned samples or copied samples.
For example, in the modern C++ API:
- dds::sub::DataReader<T>::take () API returns loaned samples.
- dds::sub::DataReader<T>::take (SamplesFWIterator sfit, int32_t max_samples) API returns copied samples.