Skip to content

Commit

Permalink
JCBC-426: Add support for manually disabling carrier or http bootstrap.
Browse files Browse the repository at this point in the history
This changeset adds the possibility to manually disable both carrier and
http bootstrap through system properties.

Carrier: System.setProperty("cbclient.disableCarrierBootstrap", "true");
Http: System.setProperty("cbclient.disableHttpBootstrap", "true");

If such a setting is issued, a INFO level message is logged to make it easier
during debugging and failure analysis. Note that in general, tweaking such
params is not necessary, althogh it might help in certain debugging and
failure conditions.

Change-Id: I654bcecd0a1ffa576b7a5c146dc4580e37a7995e
Reviewed-on: http://review.couchbase.org/34380
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information
daschl authored and Michael Nitschinger committed Mar 12, 2014
1 parent abf39bf commit 07c7ea3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Expand Up @@ -24,6 +24,7 @@

import com.couchbase.client.CouchbaseConnection;
import com.couchbase.client.CouchbaseConnectionFactory;
import com.couchbase.client.CouchbaseProperties;
import com.couchbase.client.vbucket.ConfigurationException;
import com.couchbase.client.vbucket.ConfigurationProviderHTTP;
import com.couchbase.client.vbucket.CouchbaseNodeOrder;
Expand Down Expand Up @@ -62,6 +63,7 @@
public class BucketConfigurationProvider extends SpyObject
implements ConfigurationProvider, Reconfigurable {


private static final int DEFAULT_BINARY_PORT = 11210;
private static final String ANONYMOUS_BUCKET = "default";

Expand All @@ -75,6 +77,8 @@ public class BucketConfigurationProvider extends SpyObject
private final AtomicReference<ConfigurationProviderHTTP> httpProvider;
private final AtomicBoolean refreshingHttp;
private final AtomicReference<CouchbaseConnection> binaryConnection;
private final boolean disableCarrierBootstrap;
private final boolean disableHttpBootstrap;
private volatile boolean isBinary;

public BucketConfigurationProvider(final List<URI> seedNodes,
Expand All @@ -94,6 +98,11 @@ public BucketConfigurationProvider(final List<URI> seedNodes,
this.password = password;
this.connectionFactory = connectionFactory;
potentiallyRandomizeNodeList(seedNodes);

disableCarrierBootstrap = Boolean.parseBoolean(
CouchbaseProperties.getProperty("disableCarrierBootstrap", "false"));
disableHttpBootstrap = Boolean.parseBoolean(
CouchbaseProperties.getProperty("disableHttpBootstrap", "false"));
}

@Override
Expand Down Expand Up @@ -124,6 +133,11 @@ public Bucket bootstrap() {
* @return true if the binary bootstrap process was successful.
*/
boolean bootstrapBinary() {
if (disableCarrierBootstrap) {
getLogger().info("Carrier bootstrap manually disabled, skipping.");
return false;
}

isBinary = true;
List<InetSocketAddress> nodes =
new ArrayList<InetSocketAddress>(seedNodes.size());
Expand Down Expand Up @@ -252,6 +266,11 @@ public void complete() {
* @return true if the http bootstrap process was successful.
*/
boolean bootstrapHttp() {
if (disableHttpBootstrap) {
getLogger().info("Http bootstrap manually disabled, skipping.");
return false;
}

try {
Bucket config = httpProvider.get().getBucketConfiguration(bucket);
setConfig(config);
Expand Down Expand Up @@ -371,8 +390,7 @@ public void signalOutdated() {
bootstrap();
} else {
try {
List<String> configs = getConfigsFromBinaryConnection(
binaryConnection.get());
List<String> configs = getConfigsFromBinaryConnection(binaryConnection.get());
if (configs.isEmpty()) {
bootstrap();
return;
Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.couchbase.client.CbTestConfig;
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.CouchbaseConnectionFactory;
import com.couchbase.client.CouchbaseProperties;
import com.couchbase.client.vbucket.ConfigurationException;
import com.couchbase.client.vbucket.config.Bucket;
import net.spy.memcached.TestConfig;
Expand All @@ -40,6 +41,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


Expand Down Expand Up @@ -90,6 +92,12 @@ public void setup() throws Exception {
password = "";
}

@Before
public void resetProperties() {
System.clearProperty("disableCarrierBootstrap");
System.clearProperty("disableHttpBootstrap");
}

@Test
public void shouldBootstrapBothBinaryAndHttp() throws Exception {
if (!isCCCPAware) {
Expand Down Expand Up @@ -195,7 +203,37 @@ public void shouldIgnoreInvalidNodeOnBootstrap() throws Exception {
provider.bootstrap();
}

@Test
public void shouldSkipBinaryOnManualDisable() throws Exception {
if (!isCCCPAware) {
LOGGER.info("Skipping Test because cluster is not CCCP aware.");
return;
}
System.setProperty("cbclient.disableCarrierBootstrap", "true");

BucketConfigurationProvider provider = new BucketConfigurationProvider(
seedNodes,
bucket,
password,
new CouchbaseConnectionFactory(seedNodes, bucket, password)
);

assertFalse(provider.bootstrapBinary());
}

@Test
public void shouldSkipHttpOnManualDisable() throws Exception {
System.setProperty("cbclient.disableHttpBootstrap", "true");

BucketConfigurationProvider provider = new BucketConfigurationProvider(
seedNodes,
bucket,
password,
new CouchbaseConnectionFactory(seedNodes, bucket, password)
);

assertFalse(provider.bootstrapHttp());
}

/**
* A provider that can fail either one or both of the bootstrap mechanisms.
Expand Down

0 comments on commit 07c7ea3

Please sign in to comment.