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

#1008: Added Q.WATCH support to Websocket #1090

Merged
merged 33 commits into from
Oct 21, 2024

Conversation

psrvere
Copy link
Contributor

@psrvere psrvere commented Oct 14, 2024

Closes #1008

This PR

  1. adds support for Q.WATCH command on Websocket server
  2. changes Websocket server logic
    a. updates WebsocketServer struct to use ioChan and qwatchResponseChan
    b. extracts out response processing logic to a function
    c. adds a function to process Q.WATCH updates
  3. changes command parsing logic in ParseWebsocketMessage to support Q.WATCH command
  4. adds more unit tests to increase coverage of parsing logic
  5. adds unit tests for Q.WATCH
  6. adds integration tests for Q.WATCH
  7. updates Q.WATCH docs

@psrvere psrvere changed the title Added QWATCH and QUNWATCH support to Websocket Added QWATCH support to Websocket Oct 14, 2024
@psrvere psrvere marked this pull request as ready for review October 16, 2024 07:09
@psrvere
Copy link
Contributor Author

psrvere commented Oct 16, 2024

@lucifercr07 @pratikpandey21 - Added Qwatch to Websocket. Please review.

Copy link
Contributor

@pratikpandey21 pratikpandey21 left a comment

Choose a reason for hiding this comment

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

I'd recommend waiting for #1086
and leverage the code there as that would enable multithreading in WS.

Will review once those changes are there

internal/server/utils/redisCmdAdapter_test.go Show resolved Hide resolved
@psrvere psrvere changed the title Added QWATCH support to Websocket Added Q.WATCH support to Websocket Oct 18, 2024
for {
// read incoming message
_, msg, err := conn.ReadMessage()
if err != nil {
writeResponse(conn, []byte("error: command reading failed"))
continue
break
}

// parse message to dice command
diceDBCmd, err := utils.ParseWebsocketMessage(msg)
if errors.Is(err, diceerrors.ErrEmptyCommand) {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we log a warn here? Or return an error to client. As client is just receiving an empty response in this case which doesn't seem to be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a warning here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@psrvere not able to see the log statement added here, is commit pushed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lucifercr07 - the warning was added as part of #1142 - please see here

That was important for integration tests to work so had to move to that PR.

internal/server/websocketServer.go Show resolved Hide resolved
internal/server/websocketServer.go Show resolved Hide resolved
internal/server/utils/redisCmdAdapter_test.go Show resolved Hide resolved
"-2", // Represents a RESP Integer with value -2.
"*0", // Represents an empty RESP Array.
// start a goroutine for subsequent updates
go s.processQwatchUpdates(clientIdentifierID, conn, diceDBCmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we refactor this such that we don't spawn new go routine for each qwatch cmd subscription?
We can create another channel at start for QWATCH and keep registering clients to it and handle all responses in a single event loop.

This can also be taken as enhancement on top of this PR, not a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is absolutely critical. I realised this while writing tests with multiple subscribers. Have created a follow up issue #1153

}
case <-s.shutdownChan:
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we explicitly send qunwatch command from here and de-register the client?
Currently the cleanup happens after the key is triggered with a error message as websocket closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Let me also figure out how q.unwatch will work in websocket. Will address this comment as part of #1154

"github.com/stretchr/testify/assert"
)

func TestQWatch(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a test where multiple subscribers are there for query and responses are triggered for them.

Copy link
Contributor Author

@psrvere psrvere Oct 19, 2024

Choose a reason for hiding this comment

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

Added the test but with single subscriber right now. As part of #1153, I will increase the number of subscribers to 5 (arbitrary)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test also will come as part of #1153. Currently previous tests leave a subscriber which also receive response when value of a key is updated. So it become multi subscriber problem again.

@psrvere
Copy link
Contributor Author

psrvere commented Oct 19, 2024

@lucifercr07 - have addressed all comments and created new issues where needed. Please review again.

for {
// read incoming message
_, msg, err := conn.ReadMessage()
if err != nil {
writeResponse(conn, []byte("error: command reading failed"))
continue
break
}

// parse message to dice command
diceDBCmd, err := utils.ParseWebsocketMessage(msg)
if errors.Is(err, diceerrors.ErrEmptyCommand) {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

@psrvere not able to see the log statement added here, is commit pushed?

@psrvere
Copy link
Contributor Author

psrvere commented Oct 20, 2024

@lucifercr07 - merging with latest master and resolving a few conflicts.

@psrvere
Copy link
Contributor Author

psrvere commented Oct 20, 2024

@lucifercr07 - good to go, please check.

Copy link
Contributor

@lucifercr07 lucifercr07 left a comment

Choose a reason for hiding this comment

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

LGTM

@JyotinderSingh JyotinderSingh changed the title Added Q.WATCH support to Websocket #1008: Added Q.WATCH support to Websocket Oct 21, 2024
@JyotinderSingh JyotinderSingh merged commit 846cef3 into DiceDB:master Oct 21, 2024
2 checks passed
KanniShashankh pushed a commit to KanniShashankh/dice that referenced this pull request Oct 21, 2024
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.

Add QWatch support to Websocket
4 participants