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

couchbase: allow to configure bucket replicas and default to 0. #5840

Merged
merged 1 commit into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -29,10 +29,32 @@ public class BucketDefinition {

private int quota = 100;

private int numReplicas = 0;

public BucketDefinition(final String name) {
this.name = name;
}

/**
* Allows to configure the number of replicas on a bucket (defaults to 0).
* <p>
* By default the bucket is initialized with 0 replicas since only a single container is launched. Modifying
* this value can still be useful in some test scenarios (i.e. to test failures with the wrong number of replicas
* and durability requirements on operations).
* <p>
* Couchbase buckets can have a maximum of three replicas configured.
*
* @param numReplicas the number of replicas to configure.
* @return this {@link BucketDefinition} for chaining purposes.
*/
public BucketDefinition withReplicas(final int numReplicas) {
if (numReplicas < 0 || numReplicas > 3) {
throw new IllegalArgumentException("The number of replicas must be between 0 and 3 (inclusive)");
}
this.numReplicas = numReplicas;
return this;
}

/**
* Enables flush for this bucket (disabled by default).
*
Expand All @@ -45,9 +67,9 @@ public BucketDefinition withFlushEnabled(final boolean flushEnabled) {
}

/**
* Sets a custom bucket quota (100MB by default).
* Sets a custom bucket quota (100MiB by default).
*
* @param quota the quota to set for the bucket.
* @param quota the quota to set for the bucket in mebibytes.
* @return this {@link BucketDefinition} for chaining purposes.
*/
public BucketDefinition withQuota(final int quota) {
Expand Down Expand Up @@ -84,4 +106,8 @@ public boolean hasPrimaryIndex() {
public int getQuota() {
return quota;
}

public int getNumReplicas() {
return numReplicas;
}
}
Expand Up @@ -573,6 +573,7 @@ private void createBuckets() {
.add("name", bucket.getName())
.add("ramQuotaMB", Integer.toString(bucket.getQuota()))
.add("flushEnabled", bucket.hasFlushEnabled() ? "1" : "0")
.add("replicaNumber", Integer.toString(bucket.getNumReplicas()))
.build(),
true
);
Expand Down