Skip to content

Fixed locking between connection_reader and connection#84

Merged
merlimat merged 1 commit into
apache:masterfrom
merlimat:master
Nov 9, 2019
Merged

Fixed locking between connection_reader and connection#84
merlimat merged 1 commit into
apache:masterfrom
merlimat:master

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented Nov 4, 2019

Motivation

Fixed locking around the mapMutex in consumer. The current behavior is mixing read-write and read-only locks even when modifying the map.

The pendingReqs was really meant to be accessed by a single go-routine. Changed the logic to pass the received commands on a channel, to be processed in the connection's own go-routine.

cc/ @cckellogg

Copy link
Copy Markdown
Member

@wolfstudy wolfstudy left a comment

Choose a reason for hiding this comment

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

The changes LGTM+1.

In here, i am a bit confused. Go officially provided bytes.Buffer can not meet our needs? Why do we have to repackage a Buffer?

@wolfstudy
Copy link
Copy Markdown
Member

The package of this Buffer structure is more similar to the way Java buffer is used, but may not be very friendly to developers of the go community.

writeRequestsCh chan []byte

mapMutex sync.RWMutex
pendingReqs map[uint64]*request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment on how this should only be accessed in certain places?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree with @cckellogg

The pendingReqs was really meant to be accessed by a single go-routine.

pendingReqs not concurrently safe, so it is necessary for the user a comment.

@merlimat
Copy link
Copy Markdown
Contributor Author

merlimat commented Nov 5, 2019

In here, i am a bit confused. Go officially provided bytes.Buffer can not meet our needs? Why do we have to repackage a Buffer?

We need more functionalities like efficiently reading int32 and int16 while encapsulating the details.

The package of this Buffer structure is more similar to the way Java buffer is used, but may not be very friendly to developers of the go community.

The ideas of Buffer are taken from Netty ByteBuf (rather than Java ByteBuffer) because the API is an excellent example of good abstractions for working with buffers and parsing/writing network protocols. The abstractions are not language specific.

@merlimat
Copy link
Copy Markdown
Contributor Author

merlimat commented Nov 6, 2019

run integration tests

@merlimat merlimat merged commit 3378790 into apache:master Nov 9, 2019
@wolfstudy wolfstudy added this to the 0.1.0 milestone Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants