Skip to content

Commit 676eeaf

Browse files
pimpinclaude
andcommitted
Fix metadata purge interval configuration to use REST API
The previous implementation used couchbase-cli setting-compaction which only sets cluster-wide defaults, not per-bucket settings. This resulted in autoCompactionSettings: false at bucket level. Changes: - Use REST API POST to /pools/default/buckets/{bucket} instead of CLI - Add required parameters: - autoCompactionDefined=true (enables per-bucket override) - purgeInterval=0.04 (1 hour minimum) - parallelDBAndViewCompaction=false (required parameter) - Add get_metadata_purge_interval() to verify configuration - Add check_cbs_config example to inspect current settings - Improve get function to search purgeInterval in multiple locations Per-bucket configuration overrides cluster-wide defaults and allows independent purge interval settings for testing. Verified: purgeInterval now appears at bucket root level and is set to 0.04 days (1 hour). References: - https://docs.couchbase.com/server/current/rest-api/rest-autocompact-per-bucket.html - Couchbase docs on cluster-wide vs per-bucket auto-compaction 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9fb1f99 commit 676eeaf

File tree

3 files changed

+99
-6
lines changed

3 files changed

+99
-6
lines changed

examples/check_cbs_config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mod utils;
2+
3+
use utils::*;
4+
5+
fn main() {
6+
println!("=== CBS Configuration Check ===\n");
7+
8+
println!("Checking current metadata purge interval configuration:");
9+
get_metadata_purge_interval();
10+
11+
println!("\n=== Check complete ===");
12+
}

examples/docker-conf/couchbase-server-dev/configure-server.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ function configureBucketCompaction() {
5353
# Configure metadata purge interval to 1 hour (0.04 days) - CBS minimum
5454
# This is important for tombstone purge testing with Sync Gateway
5555
# Default is 3 days, which is too long for testing
56-
couchbase-cli setting-compaction \
57-
-c 127.0.0.1:8091 \
58-
--username $COUCHBASE_ADMINISTRATOR_USERNAME \
59-
--password $COUCHBASE_ADMINISTRATOR_PASSWORD \
60-
--bucket $COUCHBASE_BUCKET \
61-
--metadata-purge-interval 0.04
56+
#
57+
# IMPORTANT: Must use REST API to configure per-bucket auto-compaction
58+
# The couchbase-cli setting-compaction command only sets cluster-wide defaults
59+
#
60+
# Required parameters:
61+
# - autoCompactionDefined=true: Enable per-bucket auto-compaction override
62+
# - purgeInterval=0.04: Metadata purge interval (1 hour minimum)
63+
# - parallelDBAndViewCompaction: Required parameter for auto-compaction
64+
curl -X POST \
65+
-u "$COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD" \
66+
"http://127.0.0.1:8091/pools/default/buckets/$COUCHBASE_BUCKET" \
67+
-d "autoCompactionDefined=true" \
68+
-d "purgeInterval=0.04" \
69+
-d "parallelDBAndViewCompaction=false"
70+
6271
if [[ $? != 0 ]]; then
6372
return 1
6473
fi

examples/utils/cbs_admin.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,74 @@ pub fn check_doc_in_cbs(doc_id: &str) {
143143
}
144144
}
145145

146+
pub fn get_metadata_purge_interval() {
147+
let url = format!("{CBS_URL}/pools/default/buckets/{CBS_BUCKET}");
148+
149+
let response = reqwest::blocking::Client::new()
150+
.get(&url)
151+
.basic_auth(CBS_ADMIN_USER, Some(CBS_ADMIN_PWD))
152+
.send();
153+
154+
match response {
155+
Ok(resp) => {
156+
let status = resp.status();
157+
if let Ok(text) = resp.text() {
158+
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&text) {
159+
// Search for purgeInterval in multiple possible locations
160+
let locations = vec![
161+
(
162+
"autoCompactionSettings.purgeInterval",
163+
json.get("autoCompactionSettings")
164+
.and_then(|a| a.get("purgeInterval")),
165+
),
166+
("purgeInterval", json.get("purgeInterval")),
167+
];
168+
169+
let mut found = false;
170+
for (path, value) in locations {
171+
if let Some(purge_interval) = value {
172+
println!(
173+
"✓ CBS metadata purge interval (at {path}): {}",
174+
purge_interval
175+
);
176+
if let Some(days) = purge_interval.as_f64() {
177+
println!(
178+
" = {days} days (~{:.1} hours, ~{:.0} minutes)",
179+
days * 24.0,
180+
days * 24.0 * 60.0
181+
);
182+
}
183+
found = true;
184+
break;
185+
}
186+
}
187+
188+
if !found {
189+
println!("⚠ purgeInterval not found in bucket config");
190+
if let Some(auto_compact) = json.get("autoCompactionSettings") {
191+
println!(" autoCompactionSettings content:");
192+
println!(" {}", serde_json::to_string_pretty(auto_compact).unwrap());
193+
}
194+
println!("\n Searching for 'purge' related fields...");
195+
if let Some(obj) = json.as_object() {
196+
for (key, value) in obj {
197+
if key.to_lowercase().contains("purge") {
198+
println!(" Found: {} = {}", key, value);
199+
}
200+
}
201+
}
202+
}
203+
} else {
204+
println!("Get metadata purge interval: status={status}, could not parse JSON");
205+
}
206+
} else {
207+
println!("Get metadata purge interval: status={status}, could not read response");
208+
}
209+
}
210+
Err(e) => println!("Get metadata purge interval error: {e}"),
211+
}
212+
}
213+
146214
pub fn set_metadata_purge_interval(days: f64) {
147215
const MIN_PURGE_INTERVAL_DAYS: f64 = 0.04; // 1 hour minimum per CBS spec
148216

@@ -180,4 +248,8 @@ pub fn set_metadata_purge_interval(days: f64) {
180248
}
181249
Err(e) => println!("Set metadata purge interval error: {e}"),
182250
}
251+
252+
// Verify the setting was applied
253+
println!("\nVerifying configuration:");
254+
get_metadata_purge_interval();
183255
}

0 commit comments

Comments
 (0)