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

Enable SURREALDB_CHANGE_FEED_LIVE_QUERIES for tests #3729

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7a92035
Enable SURREALDB_CHANGE_FEED_LIVE_QUERIES for tests
phughk Mar 20, 2024
8345169
Fix test
phughk Mar 20, 2024
fb109ea
Add some test fixes
phughk Mar 26, 2024
3c45276
Rverts
phughk Mar 26, 2024
1beef8d
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Mar 26, 2024
75a719d
Fixes for tests
phughk Mar 26, 2024
fbcc4e9
Add errors for mis-created LQs
phughk Mar 26, 2024
93c5967
Additional LQ api test
phughk Mar 26, 2024
9aed019
clippy
phughk Mar 26, 2024
cce5f06
Merge branch 'sur-347-lq-error-no-cf' into enable-fflag-test-SURREALD…
phughk Mar 26, 2024
d6ff2b7
Simplify tests
phughk Mar 26, 2024
e687655
WIP live stuffs
phughk Mar 27, 2024
0428e63
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Mar 27, 2024
97e30e5
Some logs
phughk Mar 27, 2024
f4917b6
Lil refactor
phughk Mar 27, 2024
43e544a
Working build
phughk Mar 27, 2024
3b99897
Move refactor code
phughk Mar 27, 2024
76b43de
Lint
phughk Mar 27, 2024
d88faa7
Merge remote-tracking branch 'surrealdb/main' into refactor-lq-v2-steps
phughk Mar 28, 2024
6f57a5e
Fixup
phughk Mar 28, 2024
a765a4f
Merge remote-tracking branch 'phughk/refactor-lq-v2-steps' into refac…
phughk Mar 28, 2024
f688181
Merge branch 'refactor-lq-v2-steps' into enable-fflag-test-SURREALDB_…
phughk Mar 28, 2024
32d7717
Before merge
phughk Apr 2, 2024
9d4a246
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 2, 2024
cb129a7
Unit test document construction for lives
phughk Apr 2, 2024
852cce9
Progress towards tested lq v2
phughk Apr 2, 2024
d34d3c5
Adding droppyboi
phughk Apr 3, 2024
6e8bf0e
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 3, 2024
a03ee39
Add warning to droppy boy
phughk Apr 3, 2024
3de416c
Tests make sense
phughk Apr 3, 2024
2bdc241
Working test
phughk Apr 4, 2024
9dbff6c
Working delete test????
phughk Apr 4, 2024
86dc166
Adding before fflag switch
phughk Apr 4, 2024
c888edb
Working aggregation of notifications
phughk Apr 5, 2024
2713565
WIP fixes to timestamp tracking
phughk Apr 5, 2024
6940f6c
Commit before the refactor
phughk Apr 15, 2024
810fca8
WIP refactor
phughk Apr 15, 2024
8b19a9a
Working unit tests
phughk Apr 16, 2024
a870e37
enclose
phughk Apr 16, 2024
8bce6da
Add some cf scan tests
phughk Apr 16, 2024
722f017
Working LQ...?
phughk Apr 16, 2024
346bb9b
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 17, 2024
bc71557
Fixup format
phughk Apr 17, 2024
69ae8e1
Clippy
phughk Apr 17, 2024
6c75b5c
Clippy
phughk Apr 17, 2024
5e7e292
Fixes for tests
phughk Apr 17, 2024
81426c4
Some test fixes but not all tests fixed
phughk Apr 17, 2024
5e4c7da
Fixup doc/document
phughk Apr 17, 2024
f74469f
Some fixes to make diffs easier
phughk Apr 17, 2024
7bd5e1a
Fixes
phughk Apr 18, 2024
459ba0e
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 18, 2024
31b9c60
Remove TODO from fut
phughk Apr 18, 2024
e8766c6
Remove droppy boy
phughk Apr 18, 2024
6708ef6
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 18, 2024
20d1eb1
Fixes
phughk Apr 18, 2024
a14bc20
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 22, 2024
3255ce4
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 23, 2024
4837264
Resolve conflicts
phughk Apr 23, 2024
0a6489c
Change how diffs are recorded
phughk Apr 23, 2024
cbd5049
Cargo lint
phughk Apr 23, 2024
357d64a
Update core/src/cf/writer.rs
phughk Apr 24, 2024
25f9fa1
Remove warn
phughk Apr 25, 2024
429b3d3
Merge remote-tracking branch 'phughk/sur-344-correct-diff-value' into…
phughk Apr 25, 2024
d649588
Merge branch 'sur-344-correct-diff-value' into enable-fflag-test-SURR…
phughk Apr 25, 2024
f89c2e3
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 25, 2024
0440fb7
Format
phughk Apr 25, 2024
f4421fc
Changes to test
phughk Apr 25, 2024
19fcfba
Working tests
phughk Apr 25, 2024
34930bc
:babushka-agony:
phughk Apr 26, 2024
a4c2e82
Cleanup
phughk Apr 29, 2024
8aeddd2
Merge branch 'main' into enable-fflag-test-SURREALDB_CHANGE_FEED_LIVE…
phughk Apr 29, 2024
f387c40
Fix some changefeed shenanigans
phughk Apr 29, 2024
9990d2b
Lint
phughk Apr 29, 2024
7017631
Merge remote-tracking branch 'surrealdb/main' into enable-fflag-test-…
phughk Apr 29, 2024
1005787
Lint
phughk Apr 29, 2024
264c6a3
Lint
phughk Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions core/src/cf/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,18 @@ impl TableMutation {
h
}
TableMutation::SetWithDiff(_thing, current, operations) => {
h.insert("current".to_string(), current);
h.insert(
"update".to_string(),
Value::Array(Array(
// derive the original
let mut original = current.clone();
original
.patch(Value::Array(Array(
operations
.clone()
.into_iter()
.map(|x| Value::Object(Object::from(x)))
.map(|op| Value::Object(Object::from(op)))
.collect(),
)),
);
)))
.unwrap();
h.insert("update".to_string(), current);
h
}
TableMutation::Del(t) => {
Expand Down
7 changes: 6 additions & 1 deletion core/src/cf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::borrow::Cow;
use std::collections::HashMap;

use crate::cf::{TableMutation, TableMutations};
use crate::fflags::FFLAGS;
use crate::kvs::Key;
use crate::sql::statements::DefineTableStatement;
use crate::sql::thing::Thing;
Expand Down Expand Up @@ -75,14 +76,18 @@ impl Writer {
current: Cow<'_, Value>,
store_difference: bool,
) {
warn!(
"Recording difference for cf: id={}, previous={:?}, current={:?}, store_difference={}",
id, previous, current, store_difference
);
if current.is_some() {
self.buf.push(
ns.to_string(),
db.to_string(),
tb.to_string(),
match store_difference {
true => {
if previous.is_none() {
if (!FFLAGS.change_feed_live_queries.enabled()) || previous.is_none() {
TableMutation::Set(id, current.into_owned())
} else {
// We intentionally record the patches in reverse (current -> previous)
Expand Down
4 changes: 2 additions & 2 deletions core/src/fflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub static FFLAGS: FFlags = FFlags {
// TODO(fflag-lqcf): This TODO signature marks tests that are affected by the fflag that do not have access to the fflag (scope)
change_feed_live_queries: FFlagEnabledStatus {
enabled_release: false,
enabled_debug: false,
enabled_test: false,
enabled_debug: true,
enabled_test: true,
env_override: "SURREALDB_CHANGE_FEED_LIVE_QUERIES",
owner: "Hugh Kaznowski",
description: "Disables live queries as a separate feature and moves to using change feeds as the underlying mechanism",
Expand Down
10 changes: 10 additions & 0 deletions core/src/kvs/lq_cf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ impl LiveQueryTracker {
&self,
selector: &LqSelector,
) -> Vec<(LqIndexKey, LqIndexValue)> {
#[cfg(debug_assertions)]
trace!(
"Finding live queries for selector {:?},\n{}",
selector,
self.local_live_queries
.iter()
.map(|(k, v)| format!("{:?} -> {:?}", k, v))
.collect::<Vec<String>>()
.join("\n\n")
);
Self::live_queries_for_selector_impl(&self.local_live_queries, selector)
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/kvs/lq_v2_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(in crate::kvs) fn construct_document(
) -> Result<Option<Document>, Error> {
match mutation {
TableMutation::Set(id, current_value) => {
trace!("Reconstructing document from Set {} with current value {}", id, current_value);
let doc = Document::new_artificial(
None,
Some(id),
Expand Down Expand Up @@ -42,6 +43,7 @@ pub(in crate::kvs) fn construct_document(
}
TableMutation::Def(_) => Ok(None),
TableMutation::SetWithDiff(id, current_value, operations) => {
trace!("Reconstructing document from SetWithDiff {} with current value {} and operations {:?}", id, current_value, operations);
// We need a previous value otherwise the Value::compute function won't work correctly
// This is also how IDs are carried into notifications, not via doc.rid
let mut copy = current_value.clone();
Expand Down
3 changes: 2 additions & 1 deletion core/src/kvs/lq_v2_fut.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Handles the main-loop of the live query notifications on top of change feeds
use crate::cf;
use crate::cf::{ChangeSet, TableMutation};
use crate::dbs::{Options, Statement};
Expand Down Expand Up @@ -141,7 +142,7 @@ async fn process_change_set_for_notifications(
lq_pairs: &[(LqIndexKey, LqIndexValue)],
) -> Result<(), Error> {
#[cfg(debug_assertions)]
trace!("Moving to next change set, {:?}", change_set);
trace!("Moving to next change set, {:?} for {} lq_pairs", change_set, lq_pairs.len());
for (lq_key, lq_value) in lq_pairs.iter() {
#[cfg(debug_assertions)]
trace!("Processing live query for notification key={:?} and value={:?}", lq_key, lq_value);
Expand Down
128 changes: 56 additions & 72 deletions lib/tests/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,13 +1074,15 @@ async fn changefeed() {
let (permit, db) = new_db().await;
db.use_ns(NS).use_db(Ulid::new().to_string()).await.unwrap();
// Enable change feeds
let sql = "
DEFINE TABLE user CHANGEFEED 1h;
";
let sql = match FFLAGS.change_feed_live_queries.enabled() {
true => "DEFINE TABLE user CHANGEFEED 1h INCLUDE ORIGINAL;",
false => "DEFINE TABLE user CHANGEFEED 1h;",
};
let response = db.query(sql).await.unwrap();
drop(permit);
response.check().unwrap();
// Create and update users

// Create and update users - this all happens in a single changefeed entry
let sql = "
CREATE user:amos SET name = 'Amos';
CREATE user:jane SET name = 'Jane';
Expand Down Expand Up @@ -1109,6 +1111,8 @@ async fn changefeed() {
assert_eq!(users, expected);
let users: Vec<RecordBuf> = db.select(table).await.unwrap();
assert_eq!(users, expected);

// Fetch all changes
let sql = "
SHOW CHANGES FOR TABLE user SINCE 0 LIMIT 10;
";
Expand Down Expand Up @@ -1140,50 +1144,51 @@ async fn changefeed() {
)
.unwrap()
);
// UPDATE user:amos

// Validate CREATE user:amos
let a = array.get(1).unwrap();
let Value::Object(a) = a else {
unreachable!()
};
let Value::Number(versionstamp1) = a.get("versionstamp").unwrap() else {
unreachable!()
};

let changes = a.get("changes").unwrap().to_owned();
match FFLAGS.change_feed_live_queries.enabled() {
true => {
assert_eq!(
changes,
surrealdb::sql::value(
r#"[
// The first amos is created
if FFLAGS.change_feed_live_queries.enabled() {
assert_eq!(
changes,
surrealdb::sql::value(
r#"[
{
create: {
id: user:amos,
name: 'Amos'
}
}
]"#
)
.unwrap()
);
}
false => {
assert_eq!(
changes,
surrealdb::sql::value(
r#"[
)
.unwrap()
);
} else {
assert_eq!(
changes,
surrealdb::sql::value(
r#"[
{
update: {
id: user:amos,
name: 'Amos'
}
}
]"#
)
.unwrap()
);
}
)
.unwrap()
);
}
// UPDATE user:jane

// Validate CREATE user:jane
let a = array.get(2).unwrap();
let Value::Object(a) = a else {
unreachable!()
Expand All @@ -1193,41 +1198,39 @@ async fn changefeed() {
};
assert!(versionstamp1 < versionstamp2);
let changes = a.get("changes").unwrap().to_owned();
match FFLAGS.change_feed_live_queries.enabled() {
true => {
assert_eq!(
changes,
surrealdb::sql::value(
"[
if FFLAGS.change_feed_live_queries.enabled() {
assert_eq!(
changes,
surrealdb::sql::value(
"[
{
create: {
id: user:jane,
name: 'Jane'
}
}
]"
)
.unwrap()
);
}
false => {
assert_eq!(
changes,
surrealdb::sql::value(
"[
)
.unwrap()
);
} else {
assert_eq!(
changes,
surrealdb::sql::value(
"[
{
update: {
id: user:jane,
name: 'Jane'
}
}
]"
)
.unwrap()
);
}
)
.unwrap()
);
}
// UPDATE user:amos

// Validate UPDATE user:amos
let a = array.get(3).unwrap();
let Value::Object(a) = a else {
unreachable!()
Expand All @@ -1237,40 +1240,21 @@ async fn changefeed() {
};
assert!(versionstamp2 < versionstamp3);
let changes = a.get("changes").unwrap().to_owned();
match FFLAGS.change_feed_live_queries.enabled() {
true => {
assert_eq!(
changes,
surrealdb::sql::value(
"[
{
create: {
id: user:amos,
name: 'AMOS'
}
}
]"
)
.unwrap()
);
}
false => {
assert_eq!(
changes,
surrealdb::sql::value(
"[
assert_eq!(
changes,
surrealdb::sql::value(
"[
{
update: {
id: user:amos,
name: 'AMOS'
}
}
]"
)
.unwrap()
);
}
};
)
.unwrap()
);

// UPDATE table
let a = array.get(4).unwrap();
let Value::Object(a) = a else {
Expand Down