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

EBP-18: As a developer I can submit a cache request and terminate without issue #80

Open
wants to merge 45 commits into
base: SOL-62456
Choose a base branch
from

Conversation

TrentDaniel
Copy link

Refer to EBP-18 for details on acceptance criteria and contents of this PR.

This PR contains the implementation necessary to submit a cache request and manage cache lifecycle. During planning it was believed that the cache responses and received data messages could be ignored to simplify the testing and implementation. During implementation it was found that ignoring these would cause a nil pointer dereference error that was unavoidable without making a backwards incompatible change that would affect other features, so these implementations had to be included in this story. This may not have been reflected in the story description in full detail, so if more detail on this is required please let me know.

Copy link

gitstream-cm bot commented Jan 10, 2025

Please mark whether you used Copilot to assist coding in this PR

  • Copilot Assisted

Copy link

@sdewilde sdewilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not looking at the tests yet, tagging new code with TODO/FFC comments that may need to be addressed as mentioned in the scrum

internal/ccsmp/ccsmp_cache.go Outdated Show resolved Hide resolved
) *SolClientErrorInfoWrapper {

cacheToEventCallbackMap.Store(cacheSessionP, eventCallback)
/* NOTE: Do we need to add the dispatch callback to the map here, or is that already done by the receiver in calls to Receive() or ReceiveAsync()? */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to answer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a different event callback. The question is where we need a map at all, and if we do, seeing as we adding the 'send' we should delete in the cache-complete, ... i.e. when we invoke the callback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question was about when we need to add the dispatch callback to a separate map. IIRC, that is already done as a part of startup of the receiver and we did not need to explicitly add it as a part of this feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question will be removed in a future commit.

errorInfo := handleCcsmpError(func() SolClientReturnCode {
return C.CacheSessionSendCacheRequest(
C.solClient_uint64_t(dispatchID),
// TODO: rework this, we should probably just have a pointer and not a whole object.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was reworked, it will be removed in the next commit.

type SolClientCacheEvent = C.solCache_event_t

type SolClientCacheEventInfo struct {
/* TODO: Rename this to CacheEventInfo to better distinguish it from CCSMP objects, since it now has more than

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment was addressed, change is in next commit.

@@ -71,6 +71,11 @@ type Receiver interface {
IncrementDuplicateAckCount()
// Creates a new persistent receiver with the given callback
NewPersistentReceiver(properties []string, callback RxCallback, eventCallback PersistentEventCallback) (PersistentReceiver, ErrorInfo)
/* TODO: The `GetSessionPointer` method seems a litte out of place here. For now it works, but it might be an,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I haven't found a better way of accomplishing what is necessary. Also, this interface is internal so we can change it in the future if it is determined that this is a bug. Such a CoA would require identifying an alternative solution to the problem solved by this method anyways, since without providing the receiver with the session pointer the whole feature is busted, and I expect that we would rather tolerate a potential anti-pattern or code smell instead of canning a feature that we've already been working on.

I'll switch the TODO to FFC in the next commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed as a part of the requested refactor.

@@ -376,6 +381,11 @@ func (receiver *ccsmpBackedReceiver) NewPersistentReceiver(properties []string,
}, nil
}

/* FFC: It might be better if this were in ccsmp_core.go? */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider in this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After inspecting the source, I believe that the current implementation is sufficient. I will remove this comment in the next commit. Please see the response to the previous comment for more details relevant to this decision.

* directMessageReceiverImpl.cacheResponseChanCounter. */
// cacheResponseChanCounter is used to prevent cache requests from being submitted if the
// cacheResponseChan buffer is full.
cacheResponseChanCounter atomic.Int32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing compatibility check errors on the atomic stuff (Int32, Bool)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this will be fixed in the next commit.

return err
}

// isAvailableForCache returns true if the receiver is ready to send a cache request, or false if it is not.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment says returns true/false but method returns error, mis-named?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original impl returned bool, but the state checks became to complicated to be summarized by that data type, so now it returns error. I will fix the doc string in the next commit.

internal/impl/receiver/direct_message_receiver_impl.go Outdated Show resolved Hide resolved
// resulting from outstanding cache requests. Data messages related to the cache response willbe passed through the
// conventional [Receiver] interfaces of [Receive()] and [ReceiveAsync()].
type ReceiverCacheRequests interface {
/* TODO: Check the error types in this doc string are correct. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Comment (and same below)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already checked the error types but forgot to remove the comment. It will be removed in a future commit.

Copy link

@RagnarPaulson RagnarPaulson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Barely started on Friday, just a couple of comments so far.

internal/ccsmp/ccsmp_cache.go Show resolved Hide resolved
internal/ccsmp/ccsmp_cache.go Outdated Show resolved Hide resolved
internal/ccsmp/ccsmp_cache.go Outdated Show resolved Hide resolved
}

func (eventInfo *SolClientCacheEventInfo) String() string {
return fmt.Sprintf("SolClientCacheEventInfo:\n\tcacheSesionP: 0x%x\n\tevent: %d\n\ttopic: %s\n\treturnCode: %d\n\tsubCode: %d\n\tcacheRequestID: %d\n\terr: %s", eventInfo.cacheSessionP, eventInfo.event, eventInfo.topic, eventInfo.returnCode, eventInfo.subCode, eventInfo.cacheRequestID, eventInfo.err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing an 's' in cacheSesionP ...should be cacheSessionP.
Do you have to test for null on eventInfo.err?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in the next commit

sessionFuncInfo.rxMsgInfo.callback_p = (C.solClient_session_rxMsgCallbackFunc_t)(unsafe.Pointer(C.defaultMessageReceiveCallback))
sessionFuncInfo.rxMsgInfo.user_p = nil
sessionFuncInfo.eventInfo.callback_p = (C.solClient_session_eventCallbackFunc_t)(unsafe.Pointer(C.eventCallback))
sessionFuncInfo.eventInfo.user_p = nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this local variable isn't used

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I think this is an artifact from the merge of the 1.8.1 release back into this branch. It will be removed in the next commit.

internal/ccsmp/ccsmp_cache.go Outdated Show resolved Hide resolved
Copy link

@RagnarPaulson RagnarPaulson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments throughout for change requests.

Condensed the channel and callback version of these impl structs into a
single struct. Fixed linter error
channel init. Removed dead comment. Clarified existing comment.
ccsmp.SolClientCacheEventCallback.
interface ReceiverCacheRequests to clarify usage of timeout.
requests are prioritized over errors from failed resource cleanup. Added
comment clarifying use cases of teardownCache(). Added logic so cache
session is removed from cache request table when cache request send
fails.
const WithCacheSessionPointer = "with cache session pointer:"

// FailedToDestroyCacheSession error string
const FailedToDestroyCacheSession = "Failed to destroy cache session"
Copy link

@RagnarPaulson RagnarPaulson Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we adding more of these strings and partial strings? I thought we were going to remove these?

receiver.logger.Debug("cacheResponseChan was closed, exiting PollAndProcessCacheResponseChannel loop.")
}
break
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't check channelIsOpen here and rely instead on a null return to indicate we've processed all the events, this lines up with earlier comments on tearDown.

Copy link

@RagnarPaulson RagnarPaulson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple more comments/edits.

Copy link

@RagnarPaulson RagnarPaulson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all good, see two comments. Be sure to point back at trunk after merge and choose for yourself whether we need 1 or 2 debug logs when exiting from the go routine to process cache events.

Jenkinsfile Show resolved Hide resolved
@@ -1131,6 +1125,7 @@ func (receiver *directMessageReceiverImpl) PollAndProcessCacheResponseChannel()
* requests ASAP.*/
receiver.internalReceiver.CacheRequestor().ProcessCacheEvent(&receiver.cacheRequestMap, cacheEventInfo)
}
receiver.logger.Debug("Application has finished processing cache responses, exiting go routine now.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the only way to get here via the break statement when the channel is closed, resulting in 2 debug logs that say more or less the same thing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I added the second log as a part of a prior change that I intended to make. That change was not functional, so I backed it out but forgot to delete the comment. I'll clean this now.

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

Successfully merging this pull request may close these issues.

4 participants