Skip to content

Commit

Permalink
Final review comments correction for autobootstrapper: Copyright, doc…
Browse files Browse the repository at this point in the history
…umentation and variable naming convention
  • Loading branch information
Chinmay Soman committed Sep 21, 2012
1 parent be12a28 commit 6889d34
Show file tree
Hide file tree
Showing 26 changed files with 498 additions and 149 deletions.
5 changes: 3 additions & 2 deletions src/java/voldemort/client/AbstractStoreClientFactory.java
Expand Up @@ -345,6 +345,7 @@ protected abstract FailureDetector initFailureDetector(final ClientConfig config

public FailureDetector getFailureDetector() {
if(this.cluster == null) {
logger.info("Cluster is null ! Getting cluster.xml again for setting up FailureDetector.");
String clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY,
bootstrapUrls);
this.cluster = clusterMapper.readCluster(new StringReader(clusterXml), false);
Expand All @@ -354,11 +355,11 @@ public FailureDetector getFailureDetector() {
FailureDetector result = failureDetector;

if(result == null) {
logger.debug("Failure detector is null. Creating a new FD.");
synchronized(this) {
// second check: avoids double initialization
result = failureDetector;
if(result == null) {
logger.info("Failure detector is null. Creating a new FD.");
failureDetector = result = initFailureDetector(config, this.cluster);
if(isJmxEnabled) {
JmxUtils.registerMbean(failureDetector,
Expand All @@ -373,7 +374,7 @@ public FailureDetector getFailureDetector() {
/*
* The existing failure detector might have an old state
*/
logger.debug("Failure detector already exists. Updating the state and flushing cached verifier stores.");
logger.info("Failure detector already exists. Updating the state and flushing cached verifier stores.");
synchronized(this) {
failureDetector.getConfig().setCluster(this.cluster);
failureDetector.getConfig().getStoreVerifier().flushCachedStores();
Expand Down
27 changes: 14 additions & 13 deletions src/java/voldemort/client/ClientConfig.java
Expand Up @@ -84,9 +84,9 @@ public class ClientConfig {
private volatile String clientContextName = "";

/* 5 second check interval, in ms */
private volatile long asyncCheckMetadataInterval = 5000;
private volatile long asyncCheckMetadataIntervalInMs = 5000;
/* 12 hr refresh internval, in seconds */
private volatile int clientRegistryRefreshInterval = 3600 * 12;
private volatile int clientRegistryRefreshIntervalInSecs = 3600 * 12;
private volatile int asyncJobThreadPoolSize = 2;

/* SystemStore client config */
Expand Down Expand Up @@ -136,10 +136,10 @@ public ClientConfig() {}
public static final String FAILUREDETECTOR_CATASTROPHIC_ERROR_TYPES_PROPERTY = "failuredetector_catastrophic_error_types";
public static final String FAILUREDETECTOR_REQUEST_LENGTH_THRESHOLD_PROPERTY = "failuredetector_request_length_threshold";
public static final String MAX_BOOTSTRAP_RETRIES = "max_bootstrap_retries";
public static final String CLIENT_CONTEXT_NAME = "voldemort_client_context";
public static final String ASYNC_CHECK_METADATA_INTERVAL = "check_metadata_interval";
public static final String CLIENT_CONTEXT_NAME = "voldemort_client_context_name";
public static final String ASYNC_CHECK_METADATA_INTERVAL = "check_metadata_interval_ms";
public static final String USE_DEFAULT_CLIENT = "use_default_client";
public static final String CLIENT_REGISTRY_REFRESH_INTERVAL = "client_registry_refresh_interval";
public static final String CLIENT_REGISTRY_REFRESH_INTERVAL = "client_registry_refresh_interval_seconds";
public static final String ASYNC_JOB_THREAD_POOL_SIZE = "async_job_thread_pool_size";
public static final String SYS_MAX_CONNECTIONS_PER_NODE = "sys_max_connections_per_node";
public static final String SYS_ROUTING_TIMEOUT_MS = "sys_routing_timeout_ms";
Expand Down Expand Up @@ -318,7 +318,7 @@ private void setProperties(Properties properties) {
}

if(props.containsKey(CLIENT_REGISTRY_REFRESH_INTERVAL)) {
this.setClientRegistryUpdateInSecs(props.getInt(CLIENT_REGISTRY_REFRESH_INTERVAL));
this.setClientRegistryUpdateIntervalInSecs(props.getInt(CLIENT_REGISTRY_REFRESH_INTERVAL));
}

if(props.containsKey(ASYNC_JOB_THREAD_POOL_SIZE)) {
Expand Down Expand Up @@ -852,7 +852,7 @@ public ClientConfig setClientContextName(String clientContextName) {
}

public long getAsyncMetadataRefreshInMs() {
return asyncCheckMetadataInterval;
return asyncCheckMetadataIntervalInMs;
}

/**
Expand All @@ -862,22 +862,23 @@ public long getAsyncMetadataRefreshInMs() {
*/
public ClientConfig setAsyncMetadataRefreshInMs(long asyncCheckMetadataInterval) {

this.asyncCheckMetadataInterval = asyncCheckMetadataInterval;
this.asyncCheckMetadataIntervalInMs = asyncCheckMetadataInterval;
return this;
}

public int getClientRegistryUpdateInSecs() {
return this.clientRegistryRefreshInterval;
public int getClientRegistryUpdateIntervalInSecs() {
return this.clientRegistryRefreshIntervalInSecs;
}

/**
* Set the interval on which client refreshes its corresponding entry of the
* client registry on the servers
*
* @param clientRegistryRefreshInterval The refresh interval in seconds
* @param clientRegistryRefreshIntervalInSecs The refresh interval in
* seconds
*/
public ClientConfig setClientRegistryUpdateInSecs(int clientRegistryRefrshInterval) {
this.clientRegistryRefreshInterval = clientRegistryRefrshInterval;
public ClientConfig setClientRegistryUpdateIntervalInSecs(int clientRegistryRefrshInterval) {
this.clientRegistryRefreshIntervalInSecs = clientRegistryRefrshInterval;
return this;
}

Expand Down
27 changes: 12 additions & 15 deletions src/java/voldemort/client/ClientInfo.java
Expand Up @@ -32,20 +32,17 @@
*/
public class ClientInfo implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

protected static final Logger logger = Logger.getLogger(ClientInfo.class);

private long bootstrapTime;
private long bootstrapTimestampMs;
private String storeName;
private String context;
private int sequence;
private String localHostName;
private String deploymentPath;
private long updateTime;
private long updateTimestampMs;
private String releaseVersion;
private ClientConfig config;
private long clusterMetadataVersion;
Expand All @@ -56,13 +53,13 @@ public ClientInfo(String storeName,
long bootstrapTime,
String version,
ClientConfig config) {
this.bootstrapTime = bootstrapTime;
this.bootstrapTimestampMs = bootstrapTime;
this.storeName = storeName;
this.context = clientContext;
this.sequence = clientSequence;
this.localHostName = createHostName();
this.deploymentPath = createDeploymentPath();
this.updateTime = bootstrapTime;
this.updateTimestampMs = bootstrapTime;
this.releaseVersion = version;
this.config = config;
this.clusterMetadataVersion = 0;
Expand Down Expand Up @@ -104,11 +101,11 @@ public synchronized String getStoreName() {
}

public synchronized void setBootstrapTime(long bootstrapTime) {
this.bootstrapTime = bootstrapTime;
this.bootstrapTimestampMs = bootstrapTime;
}

public synchronized long getBootstrapTime() {
return bootstrapTime;
return bootstrapTimestampMs;
}

public synchronized void setContext(String clientContext) {
Expand Down Expand Up @@ -144,11 +141,11 @@ public synchronized String getLocalHostName() {
}

public synchronized void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
this.updateTimestampMs = updateTime;
}

public synchronized long getUpdateTime() {
return this.updateTime;
return this.updateTimestampMs;
}

public synchronized void setReleaseVersion(String version) {
Expand Down Expand Up @@ -180,26 +177,26 @@ public boolean equals(Object object) {
if(!object.getClass().equals(ClientInfo.class))
return false;
ClientInfo clientInfo = (ClientInfo) object;
return (this.bootstrapTime == clientInfo.bootstrapTime)
return (this.bootstrapTimestampMs == clientInfo.bootstrapTimestampMs)
&& (this.context.equals(clientInfo.context))
&& (this.deploymentPath.equals(clientInfo.deploymentPath))
&& (this.localHostName.equals(clientInfo.localHostName))
&& (this.sequence == clientInfo.sequence)
&& (this.storeName.equals(clientInfo.storeName))
&& (this.updateTime == clientInfo.updateTime)
&& (this.updateTimestampMs == clientInfo.updateTimestampMs)
&& (this.releaseVersion == clientInfo.releaseVersion);
}

@Override
public synchronized String toString() {
StringBuilder builder = new StringBuilder();
builder.append("bootstrapTime=").append(bootstrapTime).append("\n");
builder.append("bootstrapTime=").append(bootstrapTimestampMs).append("\n");
builder.append("context=").append(context).append("\n");
builder.append("deploymentPath=").append(deploymentPath).append("\n");
builder.append("localHostName=").append(localHostName).append("\n");
builder.append("sequence=").append(sequence).append("\n");
builder.append("storeName=").append(storeName).append("\n");
builder.append("updateTime=").append(updateTime).append("\n");
builder.append("updateTime=").append(updateTimestampMs).append("\n");
builder.append("releaseVersion=").append(releaseVersion).append("\n");
builder.append("clusterMetadataVersion=").append(clusterMetadataVersion).append("\n");

Expand Down
23 changes: 22 additions & 1 deletion src/java/voldemort/client/SystemStore.java
@@ -1,3 +1,19 @@
/*
* Copyright 2008-2012 LinkedIn, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package voldemort.client;

import java.util.List;
Expand All @@ -14,10 +30,15 @@
import voldemort.versioning.Version;
import voldemort.versioning.Versioned;

/*
/**
* A client interface for interacting with System stores (managed by the
* cluster). The naming convention is kept consistent with SocketStore (which is
* also a client interface).
*
* @author csoman
*
* @param <K> Type of Key
* @param <V> Type of Value
*/
public class SystemStore<K, V> {

Expand Down
24 changes: 17 additions & 7 deletions src/java/voldemort/client/SystemStoreRepository.java
@@ -1,11 +1,27 @@
/*
* Copyright 2008-2009 LinkedIn, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package voldemort.client;

import java.util.concurrent.ConcurrentHashMap;

import voldemort.cluster.failuredetector.FailureDetector;
import voldemort.store.system.SystemStoreConstants;

/*
/**
* A repository that creates and maintains all the system stores in one place.
* The purpose is to act as a source of truth for all the system stores, since
* they can be recreated dynamically (in case cluster.xml changes).
Expand Down Expand Up @@ -35,12 +51,6 @@ public void createSystemStores(ClientConfig config, String clusterXml, FailureDe
}
}

public SystemStore<String, Long> getVersionStore() {
String name = SystemStoreConstants.SystemStoreName.voldsys$_metadata_version.name();
SystemStore<String, Long> sysVersionStore = sysStoreMap.get(name);
return sysVersionStore;
}

public SystemStore<String, String> getClientRegistryStore() {
String name = SystemStoreConstants.SystemStoreName.voldsys$_client_registry.name();
SystemStore<String, String> sysRegistryStore = sysStoreMap.get(name);
Expand Down
18 changes: 9 additions & 9 deletions src/java/voldemort/client/ZenStoreClient.java
Expand Up @@ -53,9 +53,6 @@
@JmxManaged(description = "A voldemort client")
public class ZenStoreClient<K, V> extends DefaultStoreClient<K, V> {

private static final int ASYNC_THREADS_COUNT = 2;
private static final boolean ALLOW_INTERRUPT_ASYNC = true;

private final Logger logger = Logger.getLogger(ZenStoreClient.class);

private final AbstractStoreClientFactory abstractStoreFactory;
Expand Down Expand Up @@ -116,11 +113,12 @@ public ZenStoreClient(String storeName,
config.getAsyncMetadataRefreshInMs());
}

clientRegistryRefresher = registerClient(clientId, config.getClientRegistryUpdateInSecs());
clientRegistryRefresher = registerClient(clientId,
config.getClientRegistryUpdateIntervalInSecs());
logger.info("Voldemort client created: " + clientId + "\n" + clientInfo);
}

private ClientRegistryRefresher registerClient(String jobId, int interval) {
private ClientRegistryRefresher registerClient(String jobId, int intervalInSecs) {
ClientRegistryRefresher refresher = null;
if(this.sysRepository.getClientRegistryStore() != null) {
try {
Expand All @@ -131,15 +129,16 @@ private ClientRegistryRefresher registerClient(String jobId, int interval) {
clientInfo,
version);
GregorianCalendar cal = new GregorianCalendar();
cal.add(Calendar.SECOND, interval);
cal.add(Calendar.SECOND, intervalInSecs);

if(scheduler != null) {
scheduler.schedule(jobId + refresher.getClass().getName(),
refresher,
cal.getTime(),
TimeUnit.MILLISECONDS.convert(interval, TimeUnit.SECONDS));
TimeUnit.MILLISECONDS.convert(intervalInSecs,
TimeUnit.SECONDS));
logger.info("Client registry refresher thread started, refresh interval: "
+ interval + " seconds");
+ intervalInSecs + " seconds");
} else {
logger.warn("Client registry won't run because scheduler service is not configured");
}
Expand All @@ -156,7 +155,7 @@ private ClientRegistryRefresher registerClient(String jobId, int interval) {
private AsyncMetadataVersionManager scheduleAsyncMetadataVersionManager(String jobId,
long interval) {
AsyncMetadataVersionManager asyncMetadataManager = null;
SystemStore<String, Long> versionStore = this.sysRepository.getVersionStore();
SystemStore<String, String> versionStore = this.sysRepository.getMetadataVersionStore();
if(versionStore == null) {
logger.warn("Metadata version system store not found. Cannot run Metadata version check thread.");
} else {
Expand Down Expand Up @@ -200,6 +199,7 @@ public void bootStrap() {
*/
clusterXml = abstractStoreFactory.bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);

// Get client store
this.store = abstractStoreFactory.getRawStore(storeName, resolver, null, clusterXml, null);

// Create system stores
Expand Down

0 comments on commit 6889d34

Please sign in to comment.