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

Map counters holder component #394

Conversation

bogdan-rosianu
Copy link
Contributor

added new components so we can have different circular queues for each observer type (normal / snapshotless)

@sstanculeanu sstanculeanu self-requested a review September 25, 2023 12:40
availabilityProvider := availabilityCommon.AvailabilityProvider{}
dataAvailabilityTypes := availabilityProvider.GetAllAvailabilityTypes()

countersMap := make(map[data.ObserverDataAvailabilityType]*mapCounter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
countersMap := make(map[data.ObserverDataAvailabilityType]*mapCounter)
countersMap := make(map[data.ObserverDataAvailabilityType]*mapCounter, len(dataAvailabilityTypes))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)

// MapCountersHolder handles multiple counters map based on the data availability
type MapCountersHolder struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

can be unexported and use an interface on circularQueueNodesProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done

countersMap map[uint32]uint32
counterForAllNodes uint32
mutCounters sync.RWMutex
positionsHolder *mapCounters.MapCountersHolder
Copy link
Contributor

Choose a reason for hiding this comment

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

interface instead?

Copy link
Contributor Author

@bogdan-rosianu bogdan-rosianu Sep 25, 2023

Choose a reason for hiding this comment

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

done. but didn't pass it to the constructor since the functionality of the circularQueueNodesProvider depends a lot on the actual implementation, so stubs in tests wouldn't help.

I just wanted to extract some code in new components so the code is easier to read :D

sstanculeanu
sstanculeanu previously approved these changes Sep 25, 2023
@bogdan-rosianu bogdan-rosianu changed the base branch from MX-14354-snapshotless-observers to feat/snapshotless-observer-support September 26, 2023 10:55
@bogdan-rosianu bogdan-rosianu dismissed sstanculeanu’s stale review September 26, 2023 10:55

The base branch was changed.

sstanculeanu
sstanculeanu previously approved these changes Sep 26, 2023
@iulianpascalau iulianpascalau self-requested a review September 26, 2023 11:01
iulianpascalau
iulianpascalau previously approved these changes Sep 26, 2023
return 0, errInvalidAvailability
}

if numNodes == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be placed on L37

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right. done


// ComputeShardPosition returns the shard position based on the availability and the shard
func (mch *mapCountersHolder) ComputeShardPosition(availability data.ObserverDataAvailabilityType, shardID uint32, numNodes uint32) (uint32, error) {
counterMap, exists := mch.countersMap[availability]
Copy link
Contributor

Choose a reason for hiding this comment

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

no protection needed because we set once and read many times

return 0, errInvalidAvailability
}

if numNodes == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can be moved on L52

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right. done

@bogdan-rosianu bogdan-rosianu merged commit bea1ef6 into feat/snapshotless-observer-support Sep 29, 2023
4 checks passed
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