-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: add support for key watches with notifications of changes #6130
Comments
@archiecobbs We've pondered about being able to "watch" for changes to a table, but it sounds like you're asking for the ability to watch for changes to a particular row. Do you have a use case where watching for changes to a particular row would be useful? What if there are limits (as in the FoundationDB case) regarding how many watches are allowed to be active concurrently? |
@petermattis Yes I'm envisioning being able to watch a specific row, or even a column in a row. Here's some more background... The use cases for this feature that I have encountered in the past generally involve a relatively small number of watched keys, and a small number of watches in effect on those keys, at any one time. For example, imagine a GUI session displaying some information X which is a small subset of the overall database. This GUI session wants notification every time any of the information it is displaying (X) is changed so it can automatically refresh its view, as this makes the view truly real-time and eliminates the need for a "Refresh" button. So while the GUI session is in existence, we create a single watchable key/object/row in the database that represents "a change has occurred in X". Note the notification granularity here is whatever the application deems appropriate, and often a conservative (i.e., not completely precise) approximation of whether X has changed is most efficient. That is, it's OK if the GUI refreshes more often than necessary, as long as it's not ridiculously often, if that makes the business logic that calculates whether X has changed simpler. Then a GUI session displaying X can register a key watch on that key/object/row. The business logic would toggle/increment/whatever this key/object/row whenever a change in X occurs (or is likely to have occurred). So there is a slight subtlety here - while it's nice to be able to watch for changes directly on the data directly, sometimes what you want to watch is not the actual data itself, but a sentinel or representative piece of data that represents a change in the actual data you care about. This extra level of indirection can make things more efficient when your subset X does not directly correspond to a simple set of database rows. To take a concrete example: suppose your GUI displays users from the In general then the number of watched keys scales with the number of types of things you may need to watch, while the number of watches in effect at any time scales with the number of users logged in to the GUI (which itself is bounded, on a per-node basis, by the number of GUI sessions that node can handle). |
+1 PostgreSQL does async notifying of clients with Using triggers for notification is gives user to decide when to and how to notify. And postgresql client support will be already ready. |
+1 |
+1 |
+1 |
Oracle's Continuous Query Notification/Database Change Notification can also be relevant here: Also see this for different use cases: |
+1 |
Is there any progress on this? |
@stellanhaglund this issue seems to conflate two feature requests: 1) triggers and 2) change data capture. Change data capture is scheduled to begin development in our next release cycle whereas triggers are not. You can track our progress in change data capture in issue #2656. Would this meet your use case? |
What i’m after is some way to have realtime data with all the other benefits of cockroach. |
I did some reading and looks like #2656 would be a good way to do it with something like kafka maybe? |
Polling would be an option, since you could poll as of a time stamp to keep
your polling queries from creating contention with your live workloads.
However, you would need to test whether the performance of polling meets
your needs, as well as keep an eye on the resource overhead associated with
polling. Regarding #2656 our first release would include a way to consume
the change log, and it’s likely we will take the Kafka approach first. If
you were to use that feature, a good approach might be to use PostgreSQL
while making sure your schema and workload are compatible with CRDB.
On Fri, Dec 8, 2017 at 4:21 PM Stellan Haglund ***@***.***> wrote:
I did some reading and looks like #2656
<#2656> would be a good
way to do it with something like kafka maybe?
Though I guess this will take some time since first you need to build the
cdc part then there needs to be some kind of module that can make some use
of that, or is the plan to do it similar to postgres so that existing tools
could be used?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#6130 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgDWNQHmr9aLombwr5unqJ3meC36OYiks5s-ahRgaJpZM4IKGiC>
.
--
Diana Hsieh
diana@cockroachlabs.com
407-690-9048
|
Thanks! |
Yep, precisely. Just double check that the queries you run work with
CockroachDB. We support a lot, but not all, of the PostgreSQL syntax.
On Fri, Dec 8, 2017 at 5:21 PM Stellan Haglund ***@***.***> wrote:
Thanks!
The schema things seems easy to keep track of, basically just relying on
stuff your schema can do. Right?
But for the workload im not quite sure what you are referring to, do you
mean that i use queries that are supported by CRDB?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#6130 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgDWLDi0ANyvLN4mBIrR5ZBpGH91Yukks5s-bZ7gaJpZM4IKGiC>
.
--
Diana Hsieh
diana@cockroachlabs.com
407-690-9048
|
I've done some additional thinking about this, and I'm having a hard time deciding how to proceed. |
Well, yes, it’s possible you would have to revise your connector logic, but
at least your application could still use the same queries?
If you are okay with working on top of CockroachDB without CDC for now,
that sounds like a good approach. Regarding upgrading, at the very least,
you should be able to do a rolling upgrade to the most recent version.
Before we implement this though, it’s hard to make any promises though.
Regarding timeline, CDC is currently planned for a late 2018 release (think
sometime in October).
On Tue, Dec 12, 2017 at 7:08 AM Stellan Haglund ***@***.***> wrote:
I've done some additional thinking about this, and I'm having a hard time
deciding how to proceed.
I've been looking on some ways to use a connector with Postgres and there
are some options, though they are not all the same.
So if I where to choose one of these and build my logic around that, it
might not match how cockroach does it, or am I wrong?
That makes me a little scared of the efforts of moving from Postgres to
cockroach once this feature is out.
If I where to start my new project with cockroach instead, I would have
the benefits of the ability to scale directly in my setup and I could then
add the cdc part to that when you release it.
The big questions then are when would you think it would be reasonable to
expect this feature is it like 6 months or even more? and at that point
would I be able to add it to my existing setup easily?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#6130 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgDWF9ikifWN-qEKgRRodFD0FbVoCRPks5s_mzXgaJpZM4IKGiC>
.
--
Diana Hsieh
diana@cockroachlabs.com
407-690-9048
|
The v2.1.0-alpha.20180702 binary released today contains our first CDC prototype. You can find the docs for CDC and the latest binary under testing releases with today's date (Jul 2) below. As always, please let us know of any issues or questions here on Github, or Forum or emailing me directly lakshmi@cockroachlabs.com Docs: https://www.cockroachlabs.com/docs/v2.1/change-data-capture.html |
I think we can close this out. CDC in CockroachDB 19.1 is ready for use, and the precise behavior motivating this thread (monitoring only a single key) even works, as follows: Get a table set up and enable the create table foo (a int primary key, b string);
insert into foo values (1, 'a');
set cluster setting kv.rangefeed.enabled = true; On a separate connection, run this and consume results as they're updated select * from [experimental changefeed for table foo with updated, resolved] where key = '[]' or key is null; |
The spreadsheet we discussed is unwieldy - hard to edit and impossible to keep up to date. If we write down blacklists in code, then we can use an approach like this to always have an up to date aggregation. So far it seems like there's just a lot of unknowns to categorize still. The output today: ``` === RUN TestBlacklists 648: unknown (unknown) 493: cockroachdb#5807 (sql: Add support for TEMP tables) 151: cockroachdb#17511 (sql: support stored procedures) 86: cockroachdb#26097 (sql: make TIMETZ more pg-compatible) 56: cockroachdb#10735 (sql: support SQL savepoints) 55: cockroachdb#32552 (multi-dim arrays) 55: cockroachdb#26508 (sql: restricted DDL / DML inside transactions) 52: cockroachdb#32565 (sql: support optional TIME precision) 39: cockroachdb#243 (roadmap: Blob storage) 33: cockroachdb#26725 (sql: support postgres' API to handle blob storage (incl lo_creat, lo_from_bytea)) 31: cockroachdb#27793 (sql: support custom/user-defined base scalar (primitive) types) 24: cockroachdb#12123 (sql: Can't drop and replace a table within a transaction) 24: cockroachdb#26443 (sql: support user-defined schemas between database and table) 20: cockroachdb#21286 (sql: Add support for geometric types) 18: cockroachdb#6583 (sql: explicit lock syntax (SELECT FOR {SHARE,UPDATE} {skip locked,nowait})) 17: cockroachdb#22329 (Support XA distributed transactions in CockroachDB) 16: cockroachdb#24062 (sql: 32 bit SERIAL type) 16: cockroachdb#30352 (roadmap:when CockroachDB will support cursor?) 12: cockroachdb#27791 (sql: support RANGE types) 8: cockroachdb#40195 (pgwire: multiple active result sets (portals) not supported) 8: cockroachdb#6130 (sql: add support for key watches with notifications of changes) 5: Expected Failure (unknown) 5: cockroachdb#23468 (sql: support sql arrays of JSONB) 5: cockroachdb#40854 (sql: set application_name from connection string) 4: cockroachdb#35879 (sql: `default_transaction_read_only` should also accept 'on' and 'off') 4: cockroachdb#32610 (sql: can't insert self reference) 4: cockroachdb#40205 (sql: add non-trivial implementations of FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR NO KEY SHARE) 4: cockroachdb#35897 (sql: unknown function: pg_terminate_backend()) 4: cockroachdb#4035 (sql/pgwire: missing support for row count limits in pgwire) 3: cockroachdb#27796 (sql: support user-defined DOMAIN types) 3: cockroachdb#3781 (sql: Add Data Type Formatting Functions) 3: cockroachdb#40476 (sql: support `FOR {UPDATE,SHARE} {SKIP LOCKED,NOWAIT}`) 3: cockroachdb#35882 (sql: support other character sets) 2: cockroachdb#10028 (sql: Support view queries with star expansions) 2: cockroachdb#35807 (sql: INTERVAL output doesn't match PG) 2: cockroachdb#35902 (sql: large object support) 2: cockroachdb#40474 (sql: support `SELECT ... FOR UPDATE OF` syntax) 1: cockroachdb#18846 (sql: Support CIDR column type) 1: cockroachdb#9682 (sql: implement computed indexes) 1: cockroachdb#31632 (sql: FK options (deferrable, etc)) 1: cockroachdb#24897 (sql: CREATE OR REPLACE VIEW) 1: pass? (unknown) 1: cockroachdb#36215 (sql: enable setting standard_conforming_strings to off) 1: cockroachdb#32562 (sql: support SET LOCAL and txn-scoped session variable changes) 1: cockroachdb#36116 (sql: psychopg: investigate how `'infinity'::timestamp` is presented) 1: cockroachdb#26732 (sql: support the binary operator: <int> / <float>) 1: cockroachdb#23299 (sql: support coercing string literals to arrays) 1: cockroachdb#36115 (sql: psychopg: investigate if datetimetz is being returned instead of datetime) 1: cockroachdb#26925 (sql: make the CockroachDB integer types more compatible with postgres) 1: cockroachdb#21085 (sql: WITH RECURSIVE (recursive common table expressions)) 1: cockroachdb#36179 (sql: implicity convert date to timestamp) 1: cockroachdb#36118 (sql: Cannot parse '24:00' as type time) 1: cockroachdb#31708 (sql: support current_time) ``` Release justification: non-production change Release note: None
The spreadsheet we discussed is unwieldy - hard to edit and impossible to keep up to date. If we write down blacklists in code, then we can use an approach like this to always have an up to date aggregation. So far it seems like there's just a lot of unknowns to categorize still. The output today: ``` === RUN TestBlacklists 648: unknown (unknown) 493: cockroachdb#5807 (sql: Add support for TEMP tables) 151: cockroachdb#17511 (sql: support stored procedures) 86: cockroachdb#26097 (sql: make TIMETZ more pg-compatible) 56: cockroachdb#10735 (sql: support SQL savepoints) 55: cockroachdb#32552 (multi-dim arrays) 55: cockroachdb#26508 (sql: restricted DDL / DML inside transactions) 52: cockroachdb#32565 (sql: support optional TIME precision) 39: cockroachdb#243 (roadmap: Blob storage) 33: cockroachdb#26725 (sql: support postgres' API to handle blob storage (incl lo_creat, lo_from_bytea)) 31: cockroachdb#27793 (sql: support custom/user-defined base scalar (primitive) types) 24: cockroachdb#12123 (sql: Can't drop and replace a table within a transaction) 24: cockroachdb#26443 (sql: support user-defined schemas between database and table) 20: cockroachdb#21286 (sql: Add support for geometric types) 18: cockroachdb#6583 (sql: explicit lock syntax (SELECT FOR {SHARE,UPDATE} {skip locked,nowait})) 17: cockroachdb#22329 (Support XA distributed transactions in CockroachDB) 16: cockroachdb#24062 (sql: 32 bit SERIAL type) 16: cockroachdb#30352 (roadmap:when CockroachDB will support cursor?) 12: cockroachdb#27791 (sql: support RANGE types) 8: cockroachdb#40195 (pgwire: multiple active result sets (portals) not supported) 8: cockroachdb#6130 (sql: add support for key watches with notifications of changes) 5: Expected Failure (unknown) 5: cockroachdb#23468 (sql: support sql arrays of JSONB) 5: cockroachdb#40854 (sql: set application_name from connection string) 4: cockroachdb#35879 (sql: `default_transaction_read_only` should also accept 'on' and 'off') 4: cockroachdb#32610 (sql: can't insert self reference) 4: cockroachdb#40205 (sql: add non-trivial implementations of FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR NO KEY SHARE) 4: cockroachdb#35897 (sql: unknown function: pg_terminate_backend()) 4: cockroachdb#4035 (sql/pgwire: missing support for row count limits in pgwire) 3: cockroachdb#27796 (sql: support user-defined DOMAIN types) 3: cockroachdb#3781 (sql: Add Data Type Formatting Functions) 3: cockroachdb#40476 (sql: support `FOR {UPDATE,SHARE} {SKIP LOCKED,NOWAIT}`) 3: cockroachdb#35882 (sql: support other character sets) 2: cockroachdb#10028 (sql: Support view queries with star expansions) 2: cockroachdb#35807 (sql: INTERVAL output doesn't match PG) 2: cockroachdb#35902 (sql: large object support) 2: cockroachdb#40474 (sql: support `SELECT ... FOR UPDATE OF` syntax) 1: cockroachdb#18846 (sql: Support CIDR column type) 1: cockroachdb#9682 (sql: implement computed indexes) 1: cockroachdb#31632 (sql: FK options (deferrable, etc)) 1: cockroachdb#24897 (sql: CREATE OR REPLACE VIEW) 1: pass? (unknown) 1: cockroachdb#36215 (sql: enable setting standard_conforming_strings to off) 1: cockroachdb#32562 (sql: support SET LOCAL and txn-scoped session variable changes) 1: cockroachdb#36116 (sql: psychopg: investigate how `'infinity'::timestamp` is presented) 1: cockroachdb#26732 (sql: support the binary operator: <int> / <float>) 1: cockroachdb#23299 (sql: support coercing string literals to arrays) 1: cockroachdb#36115 (sql: psychopg: investigate if datetimetz is being returned instead of datetime) 1: cockroachdb#26925 (sql: make the CockroachDB integer types more compatible with postgres) 1: cockroachdb#21085 (sql: WITH RECURSIVE (recursive common table expressions)) 1: cockroachdb#36179 (sql: implicity convert date to timestamp) 1: cockroachdb#36118 (sql: Cannot parse '24:00' as type time) 1: cockroachdb#31708 (sql: support current_time) ``` Release justification: non-production change Release note: None
41252: roachtest: add test that aggregates orm blacklist failures r=jordanlewis a=jordanlewis The spreadsheet we discussed is unwieldy - hard to edit and impossible to keep up to date. If we write down blacklists in code, then we can use an approach like this to always have an up to date aggregation. So far it seems like there's just a lot of unknowns to categorize still. The output today: ``` === RUN TestBlacklists 648: unknown (unknown) 493: #5807 (sql: Add support for TEMP tables) 151: #17511 (sql: support stored procedures) 86: #26097 (sql: make TIMETZ more pg-compatible) 56: #10735 (sql: support SQL savepoints) 55: #32552 (multi-dim arrays) 55: #26508 (sql: restricted DDL / DML inside transactions) 52: #32565 (sql: support optional TIME precision) 39: #243 (roadmap: Blob storage) 33: #26725 (sql: support postgres' API to handle blob storage (incl lo_creat, lo_from_bytea)) 31: #27793 (sql: support custom/user-defined base scalar (primitive) types) 24: #12123 (sql: Can't drop and replace a table within a transaction) 24: #26443 (sql: support user-defined schemas between database and table) 20: #21286 (sql: Add support for geometric types) 18: #6583 (sql: explicit lock syntax (SELECT FOR {SHARE,UPDATE} {skip locked,nowait})) 17: #22329 (Support XA distributed transactions in CockroachDB) 16: #24062 (sql: 32 bit SERIAL type) 16: #30352 (roadmap:when CockroachDB will support cursor?) 12: #27791 (sql: support RANGE types) 8: #40195 (pgwire: multiple active result sets (portals) not supported) 8: #6130 (sql: add support for key watches with notifications of changes) 5: Expected Failure (unknown) 5: #23468 (sql: support sql arrays of JSONB) 5: #40854 (sql: set application_name from connection string) 4: #35879 (sql: `default_transaction_read_only` should also accept 'on' and 'off') 4: #32610 (sql: can't insert self reference) 4: #40205 (sql: add non-trivial implementations of FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR NO KEY SHARE) 4: #35897 (sql: unknown function: pg_terminate_backend()) 4: #4035 (sql/pgwire: missing support for row count limits in pgwire) 3: #27796 (sql: support user-defined DOMAIN types) 3: #3781 (sql: Add Data Type Formatting Functions) 3: #40476 (sql: support `FOR {UPDATE,SHARE} {SKIP LOCKED,NOWAIT}`) 3: #35882 (sql: support other character sets) 2: #10028 (sql: Support view queries with star expansions) 2: #35807 (sql: INTERVAL output doesn't match PG) 2: #35902 (sql: large object support) 2: #40474 (sql: support `SELECT ... FOR UPDATE OF` syntax) 1: #18846 (sql: Support CIDR column type) 1: #9682 (sql: implement computed indexes) 1: #31632 (sql: FK options (deferrable, etc)) 1: #24897 (sql: CREATE OR REPLACE VIEW) 1: pass? (unknown) 1: #36215 (sql: enable setting standard_conforming_strings to off) 1: #32562 (sql: support SET LOCAL and txn-scoped session variable changes) 1: #36116 (sql: psychopg: investigate how `'infinity'::timestamp` is presented) 1: #26732 (sql: support the binary operator: <int> / <float>) 1: #23299 (sql: support coercing string literals to arrays) 1: #36115 (sql: psychopg: investigate if datetimetz is being returned instead of datetime) 1: #26925 (sql: make the CockroachDB integer types more compatible with postgres) 1: #21085 (sql: WITH RECURSIVE (recursive common table expressions)) 1: #36179 (sql: implicity convert date to timestamp) 1: #36118 (sql: Cannot parse '24:00' as type time) 1: #31708 (sql: support current_time) ``` Release justification: non-production change Release note: None Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
Yep, but how to watch since some revision? If watching connection interrupted and I restart watching, I might lose some events. does not it? In Etcd I can start watching since some exact revision (i.e. last revision that I was able to handle beforethe failure). It's a key feature in etcd watchers. |
This is a feature request.
Some key/value stores give clients the ability to register for notification (via returned
Future<?>
) when a transaction is committed that changes the value associated with a specific key. For example, FoundationDB provide(ed) this capability with Transaction.watch().This is especially useful with distributed databases, because it obviates the need to design and implement a separate change notification RPC mechanism between nodes.
This is fairly simple to implement at the key/value store level. Perhaps a harder question is how would you expose this through the SQL API? Perhaps via some (ab)use of triggers, where you could specify a specific table row to watch?
In any case, this would be a useful feature if it can be done.
The text was updated successfully, but these errors were encountered: