Skip to content

Commit c073f30

Browse files
pimpinclaude
andcommitted
Fix check_doc_in_cbs to query tombstones via XATTRs
The previous implementation used META().deleted which does not exist in Couchbase N1QL. Tombstones cannot be queried directly via standard N1QL queries. With enable_shared_bucket_access: true, Sync Gateway stores metadata in extended attributes (XATTRs). The _sync xattr contains the deleted status and other sync metadata. Changes: - Query META().xattrs._sync.deleted instead of non-existent META().deleted - Use USE KEYS syntax for direct document lookup - Parse and display tombstone status clearly (TOMBSTONE vs LIVE document) - Improve output messages to distinguish between purged vs existing docs This fix enables the tests to properly detect tombstones in CBS and verify whether they persist or get purged after compaction. References: - Sync Gateway docs on shared bucket access and tombstones - Couchbase N1QL docs on XATTRs querying 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 67e9863 commit c073f30

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

examples/utils/cbs_admin.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ pub fn compact_cbs_bucket() {
4242

4343
pub fn check_doc_in_cbs(doc_id: &str) {
4444
// Use port 8093 for Query service (not 8091 which is admin/REST API)
45+
// Query XATTRs to see tombstones in shared bucket access mode
46+
// The _sync xattr contains Sync Gateway metadata including deleted status
4547
let url = "http://localhost:8093/query/service";
4648
let query = format!(
47-
"SELECT META().id, META().deleted FROM `{CBS_BUCKET}` WHERE META().id = '{doc_id}'"
49+
"SELECT META().id, META().xattrs._sync.deleted as deleted FROM `{CBS_BUCKET}` USE KEYS ['{doc_id}']"
4850
);
4951
let body = serde_json::json!({"statement": query});
5052

@@ -63,12 +65,25 @@ pub fn check_doc_in_cbs(doc_id: &str) {
6365
if let Some(results) = json["results"].as_array() {
6466
if results.is_empty() {
6567
println!(
66-
"CBS check for {doc_id}: ✓ Document not found (successfully purged)"
68+
"CBS check for {doc_id}: ✓ Document not found (completely purged)"
6769
);
6870
} else {
6971
println!("CBS check for {doc_id}: Found {} result(s)", results.len());
7072
for result in results {
71-
println!(" - {}", serde_json::to_string_pretty(result).unwrap());
73+
let is_deleted = result["deleted"].as_bool().unwrap_or(false);
74+
if is_deleted {
75+
println!(" - Document exists as TOMBSTONE (deleted: true)");
76+
println!(
77+
" {}",
78+
serde_json::to_string_pretty(result).unwrap()
79+
);
80+
} else {
81+
println!(" - Document exists as LIVE document");
82+
println!(
83+
" {}",
84+
serde_json::to_string_pretty(result).unwrap()
85+
);
86+
}
7287
}
7388
}
7489
} else {

0 commit comments

Comments
 (0)