-
Notifications
You must be signed in to change notification settings - Fork 301
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
feat(transaction-is-ended): add IsEnded() method (#995) #998
base: develop
Are you sure you want to change the base?
Conversation
49b889a
to
544fb31
Compare
Thanks for the PR, I like the idea. I would like to spend a little time next week to vet that this will be thread safe before moving forward with these changes, but I enabled the automated tests. |
@frknikiz before we merge this, would you mind making the following changes to follow our style and avoid race conditions: First, create a method of thread in func (thd *thread) IsEnded() bool {
txn := thd.txn
txn.Lock()
defer txn.Unlock()
return txn.finished
} Then, invoke that from // IsEnded returns transaction end status.
// If the transaction is nil, the thread is nil, or the transaction is finished, it returns true.
// Otherwise, it returns thread.finished value.
func (txn *Transaction) IsEnded() bool {
if nilTransaction(txn) {
return true
}
return txn.thread.IsEnded()
} A final thought, should a An alternative solution could look like this: var ErrorCheckIsEndedOnNil = errors.New("a Transaction must not be `nil` in order to call `IsEnded` on it")
func (txn *Transaction) IsEnded() (bool, error) {
if nilTransaction(txn) {
return false, ErrorCheckIsEndedOnNil
}
return txn.thread.IsEnded(), nil
} |
we also introduced a new function you can invoke to check for nil transactions which has just been merged into develop, and will be released this week. I will update the suggestion above to implement it. // nilTransaction guards against nil errors when handling a transaction.
func nilTransaction(txn *Transaction) bool {
return txn == nil || txn.thread == nil || txn.thread.txn == nil
} |
The IsEnded method gives us information about whether the transaction has actually ended or not. For this reason, I think this error should not be returned. If the transaction is somehow nil,i think it's fine then the transaction is finished. |
544fb31
to
59443d1
Compare
bba2784
to
73b5bba
Compare
To clarify, the Go Agent will never make a transaction, its data, or a pointer to a transaction The tests look good, thanks for updating this! |
Thanks for your support 🙏 |
Links
Details
This pull request introduces a new
IsEnded()
method for theTransaction
type. It addresses the issue raised in #995 where there was no straightforward way to determine if a transaction has ended.Changes include:
New Method Implementation:
The
IsEnded()
method has been added to check the internal transaction state. It ensures that a transaction is considered ended if it is nil, if its thread is nil, or if the underlying transaction'sfinished
flag is set.Unit Tests:
Unit tests have been added to verify that:
These changes ensure robust transaction state checking across different scenarios.
Closes #995.