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

Implement watch #9

Closed
tirkarthi opened this issue May 14, 2018 · 4 comments
Closed

Implement watch #9

tirkarthi opened this issue May 14, 2018 · 4 comments

Comments

@tirkarthi
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Implement watch API that can be used to track the changes made to a key.

Describe the solution you'd like

Watch API is available in the Java client that can be used to track the changes made to the key with callbacks.

Additional context

I have tried an initial implementation of watch that works as below :

  (let [fd    (select-api-version 510)
       key    "foo"
       value  "bar"]
  (with-open [db (open fd)]
    (tr! db
         (clear-key tr key)
         (watch tr key #(println "key is set"))
         (set-val tr key value)
         (watch tr key #(println "key is changed to 1"))
         (set-val tr key value) ;; Doesn't trigger watch
         (set-val tr key "1")
         (watch tr key #(println "cleared key"))
         (clear-key tr key))))

  key is set
  key is changed to 1
  cleared key

Implementation

https://github.com/tirkarthi/clj-foundationdb/blob/37f39adca4069070fab2a4630b76b4fab22ead93/src/clj_foundationdb/core.clj#L176

Basic test with callback and future

https://github.com/tirkarthi/clj-foundationdb/blob/37f39adca4069070fab2a4630b76b4fab22ead93/test/clj_foundationdb/core_test.clj#L305

Java docs reference

https://apple.github.io/foundationdb/javadoc/com/apple/foundationdb/Transaction.html#watch-byte:A-

Python docs reference with example

https://apple.github.io/foundationdb/developer-guide.html#watches

Feedback welcome.

@tirkarthi
Copy link
Contributor Author

I did an initial implementation of this. But it seems the watch callback is executed only once for the change since I was thinking about pub/sub like use cases.

@vedang
Copy link
Owner

vedang commented May 20, 2018

Hi @tirkarthi :

While I appreciate the value of providing a callback based API in the library, I am not sure what the shape of this API should be.

In the meantime, would be be open to submitting a PR which implements a simple wrapper over the watch function in the src/clj_fdb/transaction.clj file? Let me know, and I will pick this up otherwise.

@vedang
Copy link
Owner

vedang commented May 20, 2018

I did an initial implementation of this. But it seems the watch callback is executed only once for the change since I was thinking about pub/sub like use cases.

Yes, this is why I want to understand the possibilities before putting helper fns in the library.

@tirkarthi
Copy link
Contributor Author

Thanks @vedang for the review. I proposed it for API parity and initially it seemed to be a useful addition. But once I implemented it I couldn't fit a good use case for it. Maybe I am missing something about the use case since I am still a beginner with respect to FoundationDB.

Unfortunately, I will not be able to pick this up due to lack of time. I am closing this in favour of #11

Thanks

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

No branches or pull requests

2 participants