From 6889d34bcf012a360f1d526e30a9d205fca41dc8 Mon Sep 17 00:00:00 2001 From: Chinmay Soman Date: Thu, 20 Sep 2012 23:34:43 -0700 Subject: [PATCH] Final review comments correction for autobootstrapper: Copyright, documentation and variable naming convention --- .../client/AbstractStoreClientFactory.java | 5 +- src/java/voldemort/client/ClientConfig.java | 27 +++---- src/java/voldemort/client/ClientInfo.java | 27 +++---- src/java/voldemort/client/SystemStore.java | 23 +++++- .../client/SystemStoreRepository.java | 24 ++++-- src/java/voldemort/client/ZenStoreClient.java | 18 ++--- .../AsyncMetadataVersionManager.java | 33 ++++++-- .../FailureDetectorConfig.java | 16 +--- .../routing/RouteToAllLocalPrefStrategy.java | 25 ++++++ ...FileBackedCachingStorageConfiguration.java | 25 +++++- .../FileBackedCachingStorageEngine.java | 34 ++++++-- .../store/metadata/MetadataStore.java | 2 +- .../store/routed/PipelineRoutedStore.java | 47 +++++------ .../routed/action/ConfigureNodesByZone.java | 2 +- .../routed/action/ConfigureNodesDefault.java | 18 ++++- .../action/ConfigureNodesLocalHost.java | 18 ++++- .../action/ConfigureNodesLocalHostByZone.java | 18 ++++- .../store/system/SystemStoreConstants.java | 20 +---- .../utils/MetadataVersionStoreUtils.java | 23 ++++++ test/unit/voldemort/client/ClientJmxTest.java | 16 ++++ .../voldemort/client/ClientRegistryTest.java | 78 ++++++++++++++----- .../client/EndToEndRebootstrapTest.java | 47 +++++++++-- .../FileBackedCachingStorageEngineTest.java | 22 ++++++ .../action/ConfigureNodesLocalHostTest.java | 27 ++++++- .../AsyncMetadataVersionManagerTest.java | 29 +++++++ .../store/system/SystemStoreTest.java | 23 ++++++ 26 files changed, 498 insertions(+), 149 deletions(-) diff --git a/src/java/voldemort/client/AbstractStoreClientFactory.java b/src/java/voldemort/client/AbstractStoreClientFactory.java index e996937ab7..08502196cb 100644 --- a/src/java/voldemort/client/AbstractStoreClientFactory.java +++ b/src/java/voldemort/client/AbstractStoreClientFactory.java @@ -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); @@ -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, @@ -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(); diff --git a/src/java/voldemort/client/ClientConfig.java b/src/java/voldemort/client/ClientConfig.java index 59081b113d..66a3ec6d4d 100644 --- a/src/java/voldemort/client/ClientConfig.java +++ b/src/java/voldemort/client/ClientConfig.java @@ -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 */ @@ -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"; @@ -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)) { @@ -852,7 +852,7 @@ public ClientConfig setClientContextName(String clientContextName) { } public long getAsyncMetadataRefreshInMs() { - return asyncCheckMetadataInterval; + return asyncCheckMetadataIntervalInMs; } /** @@ -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; } diff --git a/src/java/voldemort/client/ClientInfo.java b/src/java/voldemort/client/ClientInfo.java index 0f28941176..f84e1e0c77 100644 --- a/src/java/voldemort/client/ClientInfo.java +++ b/src/java/voldemort/client/ClientInfo.java @@ -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; @@ -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; @@ -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) { @@ -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) { @@ -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"); diff --git a/src/java/voldemort/client/SystemStore.java b/src/java/voldemort/client/SystemStore.java index 4303002a75..4a79c91b25 100644 --- a/src/java/voldemort/client/SystemStore.java +++ b/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; @@ -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 Type of Key + * @param Type of Value */ public class SystemStore { diff --git a/src/java/voldemort/client/SystemStoreRepository.java b/src/java/voldemort/client/SystemStoreRepository.java index 38289a91b2..6f9cd42015 100644 --- a/src/java/voldemort/client/SystemStoreRepository.java +++ b/src/java/voldemort/client/SystemStoreRepository.java @@ -1,3 +1,19 @@ +/* + * 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; @@ -5,7 +21,7 @@ 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). @@ -35,12 +51,6 @@ public void createSystemStores(ClientConfig config, String clusterXml, FailureDe } } - public SystemStore getVersionStore() { - String name = SystemStoreConstants.SystemStoreName.voldsys$_metadata_version.name(); - SystemStore sysVersionStore = sysStoreMap.get(name); - return sysVersionStore; - } - public SystemStore getClientRegistryStore() { String name = SystemStoreConstants.SystemStoreName.voldsys$_client_registry.name(); SystemStore sysRegistryStore = sysStoreMap.get(name); diff --git a/src/java/voldemort/client/ZenStoreClient.java b/src/java/voldemort/client/ZenStoreClient.java index 6db6492cbf..ba18b5b13e 100644 --- a/src/java/voldemort/client/ZenStoreClient.java +++ b/src/java/voldemort/client/ZenStoreClient.java @@ -53,9 +53,6 @@ @JmxManaged(description = "A voldemort client") public class ZenStoreClient extends DefaultStoreClient { - 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; @@ -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 { @@ -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"); } @@ -156,7 +155,7 @@ private ClientRegistryRefresher registerClient(String jobId, int interval) { private AsyncMetadataVersionManager scheduleAsyncMetadataVersionManager(String jobId, long interval) { AsyncMetadataVersionManager asyncMetadataManager = null; - SystemStore versionStore = this.sysRepository.getVersionStore(); + SystemStore versionStore = this.sysRepository.getMetadataVersionStore(); if(versionStore == null) { logger.warn("Metadata version system store not found. Cannot run Metadata version check thread."); } else { @@ -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 diff --git a/src/java/voldemort/client/scheduler/AsyncMetadataVersionManager.java b/src/java/voldemort/client/scheduler/AsyncMetadataVersionManager.java index 972cadbf1e..71987c70a3 100644 --- a/src/java/voldemort/client/scheduler/AsyncMetadataVersionManager.java +++ b/src/java/voldemort/client/scheduler/AsyncMetadataVersionManager.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.scheduler; import java.util.Properties; @@ -8,7 +24,7 @@ import voldemort.client.SystemStoreRepository; import voldemort.utils.MetadataVersionStoreUtils; -/* +/** * The AsyncMetadataVersionManager is used to track the Metadata version on the * cluster and if necessary Re-bootstrap the client. * @@ -20,6 +36,9 @@ * * At the moment, this only tracks the cluster.xml changes. TODO: Extend this to * track other stuff (like stores.xml) + * + * @author csoman + * */ public class AsyncMetadataVersionManager implements Runnable { @@ -30,15 +49,15 @@ public class AsyncMetadataVersionManager implements Runnable { private final Logger logger = Logger.getLogger(this.getClass()); private Long currentClusterVersion; private final Callable storeClientThunk; - private final SystemStoreRepository sysRepository; + private final SystemStoreRepository systemStoreRepository; public boolean isActive = false; public AsyncMetadataVersionManager(SystemStoreRepository sysRepository, Callable storeClientThunk) { - this.sysRepository = sysRepository; + this.systemStoreRepository = sysRepository; // Get the properties object from the system store (containing versions) - Properties versionProps = MetadataVersionStoreUtils.getProperties(this.sysRepository.getMetadataVersionStore()); + Properties versionProps = MetadataVersionStoreUtils.getProperties(this.systemStoreRepository.getMetadataVersionStore()); try { this.currentClusterVersion = getCurrentVersion(CLUSTER_VERSION_KEY, versionProps); @@ -108,14 +127,14 @@ public void run() { * Get the properties object from the system store (containing * versions) */ - Properties versionProps = MetadataVersionStoreUtils.getProperties(this.sysRepository.getMetadataVersionStore()); + Properties versionProps = MetadataVersionStoreUtils.getProperties(this.systemStoreRepository.getMetadataVersionStore()); Long newClusterVersion = fetchNewVersion(CLUSTER_VERSION_KEY, currentClusterVersion, versionProps); // If nothing has been updated, continue if(newClusterVersion != null) { - logger.info("Metadata version mismatch detected. Re-bootstrapping !!!"); + logger.info("Metadata version mismatch detected. Re-bootstrapping!"); try { logger.info("Updating cluster version"); currentClusterVersion = newClusterVersion; @@ -141,7 +160,7 @@ public Long getClusterMetadataVersion() { // Fetch the latest versions for cluster metadata public void updateMetadataVersions() { - Properties versionProps = MetadataVersionStoreUtils.getProperties(this.sysRepository.getMetadataVersionStore()); + Properties versionProps = MetadataVersionStoreUtils.getProperties(this.systemStoreRepository.getMetadataVersionStore()); Long newVersion = fetchNewVersion(CLUSTER_VERSION_KEY, null, versionProps); if(newVersion != null) { this.currentClusterVersion = newVersion; diff --git a/src/java/voldemort/cluster/failuredetector/FailureDetectorConfig.java b/src/java/voldemort/cluster/failuredetector/FailureDetectorConfig.java index 5856d22254..6fc76aa1a1 100644 --- a/src/java/voldemort/cluster/failuredetector/FailureDetectorConfig.java +++ b/src/java/voldemort/cluster/failuredetector/FailureDetectorConfig.java @@ -547,7 +547,7 @@ public FailureDetectorConfig setRequestLengthThreshold(long requestLengthThresho * topology */ - public synchronized Cluster getCluster() { + public Cluster getCluster() { return this.cluster; } @@ -558,7 +558,7 @@ public synchronized Cluster getCluster() { * non-null */ - public synchronized FailureDetectorConfig setCluster(Cluster cluster) { + public FailureDetectorConfig setCluster(Cluster cluster) { Utils.notNull(cluster); this.cluster = cluster; return this; @@ -569,14 +569,10 @@ public synchronized FailureDetectorConfig setCluster(Cluster cluster) { * detector configuration. * * @return Collection of Node instances, usually determined from the Cluster - * - * EDIT: this should be deprecated in the future. We should not be - * making copies of the cluster state. It results in a series of - * inconsistency bugs. */ + @Deprecated public synchronized Collection getNodes() { - System.err.println("DEPRECATED !!! Please use getCluster().getNodes() method instead !"); return ImmutableSet.copyOf(this.cluster.getNodes()); } @@ -586,14 +582,10 @@ public synchronized Collection getNodes() { * * @param nodes Collection of Node instances, usually determined from the * Cluster; must be non-null - * - * EDIT: this should be deprecated in the future. We should not be - * making copies of the cluster state. It results in a series of - * inconsistency bugs. */ + @Deprecated public synchronized FailureDetectorConfig setNodes(Collection nodes) { - System.err.println("DEPRECATED !!! Please use setCluster method instead !"); Utils.notNull(nodes); this.nodes = new HashSet(nodes); return this; diff --git a/src/java/voldemort/routing/RouteToAllLocalPrefStrategy.java b/src/java/voldemort/routing/RouteToAllLocalPrefStrategy.java index 240aff1d49..f721312e7f 100644 --- a/src/java/voldemort/routing/RouteToAllLocalPrefStrategy.java +++ b/src/java/voldemort/routing/RouteToAllLocalPrefStrategy.java @@ -1,9 +1,34 @@ +/* + * 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.routing; import java.util.Collection; import voldemort.cluster.Node; +/** + * A class that denotes a route to all strategy with local preference. This + * class is meant to be consistent with the routing hierarchy convention. It + * simply returns the list of all nodes (just like RouteToAllStrategy) but is + * used to indicate that extra processing will be done down the pipeline. + * + * @author csoman + * + */ public class RouteToAllLocalPrefStrategy extends RouteToAllStrategy { public RouteToAllLocalPrefStrategy(Collection nodes) { diff --git a/src/java/voldemort/store/configuration/FileBackedCachingStorageConfiguration.java b/src/java/voldemort/store/configuration/FileBackedCachingStorageConfiguration.java index 069a6907c1..8cd93aa82c 100644 --- a/src/java/voldemort/store/configuration/FileBackedCachingStorageConfiguration.java +++ b/src/java/voldemort/store/configuration/FileBackedCachingStorageConfiguration.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.store.configuration; import voldemort.server.VoldemortConfig; @@ -6,9 +22,16 @@ import voldemort.store.StoreDefinition; import voldemort.utils.ByteArray; +/** + * Storage configuration class for FileBackedCachingStorageEngine + * + * @author csoman + * + */ + public class FileBackedCachingStorageConfiguration implements StorageConfiguration { - public static final String TYPE_NAME = "file"; + public static final String TYPE_NAME = "file-backed-cache"; private final String inputPath; public FileBackedCachingStorageConfiguration(VoldemortConfig config) { diff --git a/src/java/voldemort/store/configuration/FileBackedCachingStorageEngine.java b/src/java/voldemort/store/configuration/FileBackedCachingStorageEngine.java index ac9216e4cf..38817ce272 100644 --- a/src/java/voldemort/store/configuration/FileBackedCachingStorageEngine.java +++ b/src/java/voldemort/store/configuration/FileBackedCachingStorageEngine.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.store.configuration; import java.io.BufferedReader; @@ -31,7 +47,7 @@ import voldemort.versioning.Version; import voldemort.versioning.Versioned; -/* +/** * A Storage Engine used to persist the keys and values in a human readable * format on disk. The data is primarily served off of the cache. After each * put, the entire cache state is flushed to the backing file. The data is UTF-8 @@ -39,11 +55,15 @@ * * The primary purpose of this storage engine is for maintaining the cluster * metadata which is characterized by low QPS and not latency sensitive. + * + * @author csoman + * */ public class FileBackedCachingStorageEngine implements StorageEngine { private final static Logger logger = Logger.getLogger(FileBackedCachingStorageEngine.class); private static final CharSequence NEW_PROPERTY_SEPARATOR = "[name="; + private static final String NEW_LINE = System.getProperty("line.separator"); private final String inputPath; private final String inputDirectory; @@ -60,7 +80,7 @@ public FileBackedCachingStorageEngine(String name, String inputDirectory) { + " does not exist or can not be read."); } - this.inputPath = inputDirectory + "/" + name; + this.inputPath = inputDirectory + System.getProperty("file.separator") + name; this.metadataMap = new HashMap(); this.loadData(); if(logger.isDebugEnabled()) { @@ -112,7 +132,7 @@ private void loadData() { String line = reader.readLine(); while(line != null) { - if(line.contains(NEW_PROPERTY_SEPARATOR)) { + if(line.startsWith(NEW_PROPERTY_SEPARATOR.toString())) { String key = null; StringBuilder value = new StringBuilder(); String parts[] = line.split("="); @@ -124,11 +144,11 @@ private void loadData() { // Now read the value block ! while((line = reader.readLine()) != null && line.length() != 0 - && !line.contains(NEW_PROPERTY_SEPARATOR)) { + && !line.startsWith(NEW_PROPERTY_SEPARATOR.toString())) { if(value.length() == 0) { value.append(line); } else { - value.append("\n" + line); + value.append(NEW_LINE + line); } } @@ -152,9 +172,9 @@ private synchronized void flushData() { try { writer = new BufferedWriter(new FileWriter(new File(this.inputPath))); for(String key: this.metadataMap.keySet()) { - writer.write(NEW_PROPERTY_SEPARATOR + key.toString() + "]\n"); + writer.write(NEW_PROPERTY_SEPARATOR + key.toString() + "]" + NEW_LINE); writer.write(this.metadataMap.get(key).toString()); - writer.write("\n\n"); + writer.write("" + NEW_LINE + "" + NEW_LINE); } writer.flush(); } catch(IOException e) { diff --git a/src/java/voldemort/store/metadata/MetadataStore.java b/src/java/voldemort/store/metadata/MetadataStore.java index 93fd015d49..97a31aba64 100644 --- a/src/java/voldemort/store/metadata/MetadataStore.java +++ b/src/java/voldemort/store/metadata/MetadataStore.java @@ -74,7 +74,7 @@ public class MetadataStore implements StorageEngine { public static final String CLUSTER_KEY = "cluster.xml"; public static final String STORES_KEY = "stores.xml"; - public static final String SYSTEM_STORES_KEY = "systemStores"; + public static final String SYSTEM_STORES_KEY = "system.stores"; public static final String SERVER_STATE_KEY = "server.state"; public static final String NODE_ID_KEY = "node.id"; public static final String REBALANCING_STEAL_INFO = "rebalancing.steal.info.key"; diff --git a/src/java/voldemort/store/routed/PipelineRoutedStore.java b/src/java/voldemort/store/routed/PipelineRoutedStore.java index e6284d2e4b..968ff5a89e 100644 --- a/src/java/voldemort/store/routed/PipelineRoutedStore.java +++ b/src/java/voldemort/store/routed/PipelineRoutedStore.java @@ -157,29 +157,24 @@ public PipelineRoutedStore(String name, } private ConfigureNodesType obtainNodeConfigurationType(Integer zonesRequired) { - // If Zone and local preference required - if(zonesRequired != null - && routingStrategy.getType().equals(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY)) - return ConfigureNodesType.BYZONE_LOCAL; - - // If only local preference required - else if(zonesRequired == null - && routingStrategy.getType().equals(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY)) - return ConfigureNodesType.DEFAULT_LOCAL; - - // If only Zone required - else if(zonesRequired != null - && !routingStrategy.getType() - .equals(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY)) - return ConfigureNodesType.BYZONE; - - // Default case - return ConfigureNodesType.DEFAULT; + if(zonesRequired != null) { + if(routingStrategy.getType().equals(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY)) { + return ConfigureNodesType.BYZONE_LOCAL; + } else { + return ConfigureNodesType.BYZONE; + } + } else { + if(routingStrategy.getType().equals(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY)) { + return ConfigureNodesType.DEFAULT_LOCAL; + } + } + + return ConfigureNodesType.DEFAULT; } - private AbstractConfigureNodes>, BasicPipelineData>>> getNodeConfiguration(BasicPipelineData>> pipelineData, - ByteArray key) { + private AbstractConfigureNodes>, BasicPipelineData>>> makeNodeConfigurationForGet(BasicPipelineData>> pipelineData, + ByteArray key) { switch(obtainNodeConfigurationType(pipelineData.getZonesRequired())) { case DEFAULT: return new ConfigureNodesDefault>, BasicPipelineData>>>(pipelineData, @@ -250,8 +245,8 @@ public List> request(Store store) { // Get the correct type of configure nodes action depending on the store // requirements - AbstractConfigureNodes>, BasicPipelineData>>> configureNodes = getNodeConfiguration(pipelineData, - key); + AbstractConfigureNodes>, BasicPipelineData>>> configureNodes = makeNodeConfigurationForGet(pipelineData, + key); pipeline.addEventAction(Event.STARTED, configureNodes); @@ -675,8 +670,8 @@ public boolean isHintedHandoffEnabled() { return slopStores != null; } - private AbstractConfigureNodes putNodeConfiguration(PutPipelineData pipelineData, - ByteArray key) { + private AbstractConfigureNodes makeNodeConfigurationForPut(PutPipelineData pipelineData, + ByteArray key) { switch(obtainNodeConfigurationType(pipelineData.getZonesRequired())) { case DEFAULT: return new ConfigureNodesDefault(pipelineData, @@ -744,8 +739,8 @@ public void put(ByteArray key, Versioned versioned, byte[] transforms) // Get the correct type of configure nodes action depending on the store // requirements - AbstractConfigureNodes configureNodes = putNodeConfiguration(pipelineData, - key); + AbstractConfigureNodes configureNodes = makeNodeConfigurationForPut(pipelineData, + key); if(isHintedHandoffEnabled()) hintedHandoff = new HintedHandoff(failureDetector, diff --git a/src/java/voldemort/store/routed/action/ConfigureNodesByZone.java b/src/java/voldemort/store/routed/action/ConfigureNodesByZone.java index 7a194f649b..6f1d15a1f0 100644 --- a/src/java/voldemort/store/routed/action/ConfigureNodesByZone.java +++ b/src/java/voldemort/store/routed/action/ConfigureNodesByZone.java @@ -34,7 +34,7 @@ import voldemort.utils.ByteArray; import voldemort.utils.ByteUtils; -/* +/** * Configure the Nodes obtained via the routing strategy based on the zone * information. Local zone nodes first, followed by the corresponding nodes from * each of the other zones, ordered by proximity. diff --git a/src/java/voldemort/store/routed/action/ConfigureNodesDefault.java b/src/java/voldemort/store/routed/action/ConfigureNodesDefault.java index b05379d74f..0df936339b 100644 --- a/src/java/voldemort/store/routed/action/ConfigureNodesDefault.java +++ b/src/java/voldemort/store/routed/action/ConfigureNodesDefault.java @@ -1,3 +1,19 @@ +/* + * 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.store.routed.action; import java.util.List; @@ -12,7 +28,7 @@ import voldemort.utils.ByteArray; import voldemort.utils.ByteUtils; -/* +/** * Default Configure Nodes that does not reorder the list of nodes obtained via * the routing strategy */ diff --git a/src/java/voldemort/store/routed/action/ConfigureNodesLocalHost.java b/src/java/voldemort/store/routed/action/ConfigureNodesLocalHost.java index 443a538b25..f3c88b962b 100644 --- a/src/java/voldemort/store/routed/action/ConfigureNodesLocalHost.java +++ b/src/java/voldemort/store/routed/action/ConfigureNodesLocalHost.java @@ -1,3 +1,19 @@ +/* + * 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.store.routed.action; import java.net.InetAddress; @@ -15,7 +31,7 @@ import voldemort.store.routed.Pipeline.Event; import voldemort.utils.ByteArray; -/* +/** * Use the default node list returned via the routing strategy. However give * preference to the current node, if it is part of the preflist returned from * the routing strategy. diff --git a/src/java/voldemort/store/routed/action/ConfigureNodesLocalHostByZone.java b/src/java/voldemort/store/routed/action/ConfigureNodesLocalHostByZone.java index ceb5e688eb..8d34795f31 100644 --- a/src/java/voldemort/store/routed/action/ConfigureNodesLocalHostByZone.java +++ b/src/java/voldemort/store/routed/action/ConfigureNodesLocalHostByZone.java @@ -1,3 +1,19 @@ +/* + * 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.store.routed.action; import java.net.InetAddress; @@ -15,7 +31,7 @@ import voldemort.store.routed.Pipeline.Operation; import voldemort.utils.ByteArray; -/* +/** * Use the zone aware node list returned via the routing strategy. However give * preference to the current node, if it is part of the preflist returned from * the routing strategy. diff --git a/src/java/voldemort/store/system/SystemStoreConstants.java b/src/java/voldemort/store/system/SystemStoreConstants.java index f46cc779c2..0013b47d7a 100644 --- a/src/java/voldemort/store/system/SystemStoreConstants.java +++ b/src/java/voldemort/store/system/SystemStoreConstants.java @@ -34,7 +34,6 @@ public class SystemStoreConstants { public static enum SystemStoreName { voldsys$_client_registry, - voldsys$_metadata_version, voldsys$_metadata_version_persistence; } @@ -61,28 +60,11 @@ public static enum SystemStoreName { + " 7" + " " - + " " - + " voldsys$_metadata_version" - + " local-pref-all-routing" - + " proximity-handoff" - + " memory" - + " client" - + " 1" - + " 1" - + " 1" - + " " - + " string" - + " " - + " " - + " string" - + " " - + " " - + " " + " voldsys$_metadata_version_persistence" + " local-pref-all-routing" + " proximity-handoff" - + " file" + + " file-backed-cache" + " client" + " 1" + " 1" diff --git a/src/java/voldemort/utils/MetadataVersionStoreUtils.java b/src/java/voldemort/utils/MetadataVersionStoreUtils.java index dc6d917052..e320692d27 100644 --- a/src/java/voldemort/utils/MetadataVersionStoreUtils.java +++ b/src/java/voldemort/utils/MetadataVersionStoreUtils.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.utils; import java.io.ByteArrayInputStream; @@ -7,6 +23,13 @@ import voldemort.client.SystemStore; +/** + * A Utils class that facilitates conversion between the string containing + * metadata versions and the corresponding Properties object. + * + * @author csoman + * + */ public class MetadataVersionStoreUtils { public static final String VERSIONS_METADATA_KEY = "metadata-versions"; diff --git a/test/unit/voldemort/client/ClientJmxTest.java b/test/unit/voldemort/client/ClientJmxTest.java index 1e5529c09e..57f65d22c5 100644 --- a/test/unit/voldemort/client/ClientJmxTest.java +++ b/test/unit/voldemort/client/ClientJmxTest.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.lang.management.ManagementFactory; diff --git a/test/unit/voldemort/client/ClientRegistryTest.java b/test/unit/voldemort/client/ClientRegistryTest.java index 7ab2c479e1..87cb8b8512 100644 --- a/test/unit/voldemort/client/ClientRegistryTest.java +++ b/test/unit/voldemort/client/ClientRegistryTest.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.io.ByteArrayInputStream; @@ -39,7 +55,7 @@ public class ClientRegistryTest extends TestCase { public static final String STORES_XML_FILE = "test/common/voldemort/config/stores.xml"; public static final String CLIENT_CONTEXT_NAME = "testClientRegistryHappyPath"; public static final String CLIENT_CONTEXT_NAME2 = "testClientRegistryUnhappyPath"; - public static final int CLIENT_REGISTRY_REFRSH_INTERVAL = 1; + public static final int CLIENT_REGISTRY_REFRESH_INTERVAL = 1; public static final int TOTAL_SERVERS = 2; private SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(TOTAL_SERVERS, @@ -87,6 +103,10 @@ public void tearDown() throws Exception { this.clearRegistryContent(); } + /* + * Tests that the client registry is populated correctly and that we can + * query using Admin Tool. + */ @Test public void testHappyPath() { List emptyPartitionList = Lists.newArrayList(); @@ -96,7 +116,7 @@ public void testHappyPath() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[0]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(clientConfig); StoreClient client1 = socketFactory.getStoreClient(TEST_STORE_NAME); @@ -131,7 +151,7 @@ public void testHappyPath() { assertEquals(1, infoList.size()); try { - Thread.sleep(CLIENT_REGISTRY_REFRSH_INTERVAL * 1000 * 5); + Thread.sleep(CLIENT_REGISTRY_REFRESH_INTERVAL * 1000 * 5); } catch(InterruptedException e) {} // now the periodical update has gone through, it shall be higher than // the bootstrap time @@ -149,6 +169,10 @@ public void testHappyPath() { socketFactory.close(); } + /* + * Test happy path for 2 clients created by the same factory, pointing to + * the same store + */ @Test public void testTwoClients() { List emptyPartitionList = Lists.newArrayList(); @@ -158,7 +182,7 @@ public void testTwoClients() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[0]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(clientConfig); StoreClient client1 = socketFactory.getStoreClient(TEST_STORE_NAME); @@ -215,7 +239,7 @@ public void testTwoClients() { assertEquals(infoList.size(), 2); try { - Thread.sleep(CLIENT_REGISTRY_REFRSH_INTERVAL * 1000 * 5); + Thread.sleep(CLIENT_REGISTRY_REFRESH_INTERVAL * 1000 * 5); } catch(InterruptedException e) {} // now the periodical update has gone through, it shall be higher than // the bootstrap time @@ -233,6 +257,10 @@ public void testTwoClients() { socketFactory.close(); } + /* + * Tests client registry for 2 clients created using the same factory, + * pointing to different stores + */ @Test public void testTwoStores() { List emptyPartitionList = Lists.newArrayList(); @@ -242,7 +270,7 @@ public void testTwoStores() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[0]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(clientConfig); StoreClient client1 = socketFactory.getStoreClient(TEST_STORE_NAME); @@ -316,7 +344,7 @@ public void testTwoStores() { } try { - Thread.sleep(CLIENT_REGISTRY_REFRSH_INTERVAL * 1000 * 5); + Thread.sleep(CLIENT_REGISTRY_REFRESH_INTERVAL * 1000 * 5); } catch(InterruptedException e) {} // now the periodical update has gone through, it shall be higher than // the bootstrap time @@ -334,6 +362,10 @@ public void testTwoStores() { socketFactory.close(); } + /* + * Tests client registry for 2 clients created using the different + * factories, pointing to different stores + */ @Test public void testTwoFactories() { List emptyPartitionList = Lists.newArrayList(); @@ -343,7 +375,7 @@ public void testTwoFactories() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[0]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory1 = new SocketStoreClientFactory(clientConfig); @@ -353,7 +385,7 @@ public void testTwoFactories() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[0]) .setClientContextName(CLIENT_CONTEXT_NAME2) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory2 = new SocketStoreClientFactory(clientConfig2); @@ -448,7 +480,7 @@ public void testTwoFactories() { } try { - Thread.sleep(CLIENT_REGISTRY_REFRSH_INTERVAL * 1000 * 5); + Thread.sleep(CLIENT_REGISTRY_REFRESH_INTERVAL * 1000 * 5); } catch(InterruptedException e) {} // now the periodical update has gone through, it shall be higher than // the bootstrap time @@ -467,6 +499,9 @@ public void testTwoFactories() { socketFactory2.close(); } + /* + * Tests client registry for in the presence of 1 server failure. + */ @Test public void testOneServerFailure() { // bring down one server before starting up the clients @@ -479,7 +514,7 @@ public void testOneServerFailure() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[1]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory1 = new SocketStoreClientFactory(clientConfig); @@ -489,7 +524,7 @@ public void testOneServerFailure() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[1]) .setClientContextName(CLIENT_CONTEXT_NAME2) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory2 = new SocketStoreClientFactory(clientConfig2); @@ -542,7 +577,7 @@ public void testOneServerFailure() { } try { - Thread.sleep(CLIENT_REGISTRY_REFRSH_INTERVAL * 1000 * 5); + Thread.sleep(CLIENT_REGISTRY_REFRESH_INTERVAL * 1000 * 5); } catch(InterruptedException e) {} // now the periodical update has gone through, it shall be higher than // the bootstrap time @@ -561,6 +596,9 @@ public void testOneServerFailure() { socketFactory2.close(); } + /* + * Test repeated client-registry setup due to client bounce. + */ @Test public void testRepeatRegistrationSameFactory() { @@ -571,7 +609,7 @@ public void testRepeatRegistrationSameFactory() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[1]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory1 = new SocketStoreClientFactory(clientConfig); @@ -581,7 +619,7 @@ public void testRepeatRegistrationSameFactory() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[1]) .setClientContextName(CLIENT_CONTEXT_NAME2) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory2 = new SocketStoreClientFactory(clientConfig2); @@ -607,6 +645,10 @@ public void testRepeatRegistrationSameFactory() { socketFactory2.close(); } + /* + * Test repeated client-registry setup due to client bounce and via a + * different factory. + */ @Test public void testRepeatRegistrationDifferentFactories() { long client1LastBootstrapTime = 0; @@ -620,7 +662,7 @@ public void testRepeatRegistrationDifferentFactories() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[1]) .setClientContextName(CLIENT_CONTEXT_NAME) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory1 = new SocketStoreClientFactory(clientConfig); @@ -630,7 +672,7 @@ public void testRepeatRegistrationDifferentFactories() { .setBootstrapUrls(SERVER_LOCAL_URL + serverPorts[1]) .setClientContextName(CLIENT_CONTEXT_NAME2) - .setClientRegistryUpdateInSecs(CLIENT_REGISTRY_REFRSH_INTERVAL) + .setClientRegistryUpdateIntervalInSecs(CLIENT_REGISTRY_REFRESH_INTERVAL) .setEnableLazy(false); SocketStoreClientFactory socketFactory2 = new SocketStoreClientFactory(clientConfig2); @@ -685,7 +727,7 @@ public void testRepeatRegistrationDifferentFactories() { } try { - Thread.sleep(CLIENT_REGISTRY_REFRSH_INTERVAL * 1000 * 5); + Thread.sleep(CLIENT_REGISTRY_REFRESH_INTERVAL * 1000 * 5); } catch(InterruptedException e) {} // now the periodical update has gone through, it shall be higher // than diff --git a/test/unit/voldemort/client/EndToEndRebootstrapTest.java b/test/unit/voldemort/client/EndToEndRebootstrapTest.java index 2202bfb41e..a2ee510627 100644 --- a/test/unit/voldemort/client/EndToEndRebootstrapTest.java +++ b/test/unit/voldemort/client/EndToEndRebootstrapTest.java @@ -1,10 +1,30 @@ +/* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.util.Properties; -import junit.framework.TestCase; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -25,7 +45,14 @@ import voldemort.utils.SystemTime; import voldemort.xml.ClusterMapper; -public class EndToEndRebootstrapTest extends TestCase { +/** + * Test class to verify that the Zenstore client rebootstraps when needed (on + * change of cluster.xml) + * + * @author csoman + * + */ +public class EndToEndRebootstrapTest { private static final String STORE_NAME = "test-replication-persistent"; private static final String CLUSTER_KEY = "cluster.xml"; @@ -44,7 +71,6 @@ public class EndToEndRebootstrapTest extends TestCase { public static String socketUrl = ""; protected final int CLIENT_ZONE_ID = 0; - @Override @Before public void setUp() throws Exception { cluster = ServerTestUtils.getLocalCluster(2, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } }); @@ -75,7 +101,7 @@ public void setUp() throws Exception { Node node = cluster.getNodeById(0); String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort(); ClientConfig clientConfig = new ClientConfig(); - clientConfig.setClientRegistryUpdateInSecs(5); + clientConfig.setClientRegistryUpdateIntervalInSecs(5); clientConfig.setAsyncMetadataRefreshInMs(5000); clientConfig.setBootstrapUrls(bootstrapUrl); SocketStoreClientFactory storeClientFactory = new SocketStoreClientFactory(clientConfig); @@ -100,13 +126,22 @@ public void setUp() throws Exception { } - @Override @After public void tearDown() throws Exception { servers[0].stop(); servers[1].stop(); } + /* + * Test to validate that the client bootstraps on metadata change. First do + * some operations to validate that the client is correctly initialized. + * Then update the cluster.xml using the Admin Tool (which should update the + * metadata version as well). Verify that the client bootstraps after this + * update. + * + * Whether the client has automatically bootstrapped is verified by checking + * the new bootstrap time in the client registry. + */ @Test public void testEndToEndRebootstrap() { try { diff --git a/test/unit/voldemort/store/configuration/FileBackedCachingStorageEngineTest.java b/test/unit/voldemort/store/configuration/FileBackedCachingStorageEngineTest.java index 46186d28fa..27eff256dc 100644 --- a/test/unit/voldemort/store/configuration/FileBackedCachingStorageEngineTest.java +++ b/test/unit/voldemort/store/configuration/FileBackedCachingStorageEngineTest.java @@ -1,3 +1,19 @@ +/* + * 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.store.configuration; import static voldemort.TestUtils.getClock; @@ -19,6 +35,12 @@ import voldemort.versioning.VectorClock; import voldemort.versioning.Versioned; +/** + * A testclass for verifying the FileBackedCachingStorageEngine + * + * @author csoman + * + */ public class FileBackedCachingStorageEngineTest extends AbstractStoreTest { diff --git a/test/unit/voldemort/store/routed/action/ConfigureNodesLocalHostTest.java b/test/unit/voldemort/store/routed/action/ConfigureNodesLocalHostTest.java index 97ceff026b..7e3eb11157 100644 --- a/test/unit/voldemort/store/routed/action/ConfigureNodesLocalHostTest.java +++ b/test/unit/voldemort/store/routed/action/ConfigureNodesLocalHostTest.java @@ -1,3 +1,19 @@ +/* + * 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.store.routed.action; import static org.junit.Assert.assertEquals; @@ -26,6 +42,12 @@ import com.google.common.collect.ImmutableList; +/** + * Test class to verify the ConfigureNodesLocalHost strategy + * + * @author csoman + * + */ public class ConfigureNodesLocalHostTest { protected final ByteArray aKey = TestUtils.toByteArray("vold"); @@ -35,7 +57,6 @@ private List getTestNodes() { try { currentHost = InetAddress.getLocalHost().getHostName(); } catch(UnknownHostException e) { - // TODO Auto-generated catch block e.printStackTrace(); } return ImmutableList.of(node(0, "some-node-1", 2, 7, 14), @@ -53,6 +74,10 @@ private Node node(int id, String hostName, int... tags) { return new Node(id, hostName, 8080, 6666, 6667, list); } + /* + * Checks to see that the local host is obtained as the first node in the + * list returned by ConfigureNodesLocalHost + */ @Test public void testConfigureNodesLocalHost() throws Exception { List nodes = getTestNodes(); diff --git a/test/unit/voldemort/store/system/AsyncMetadataVersionManagerTest.java b/test/unit/voldemort/store/system/AsyncMetadataVersionManagerTest.java index c28f9f518e..1972254411 100644 --- a/test/unit/voldemort/store/system/AsyncMetadataVersionManagerTest.java +++ b/test/unit/voldemort/store/system/AsyncMetadataVersionManagerTest.java @@ -1,3 +1,19 @@ +/* + * 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.store.system; import static org.junit.Assert.assertEquals; @@ -23,6 +39,12 @@ import voldemort.store.socket.clientrequest.ClientRequestExecutorPool; import voldemort.utils.SystemTime; +/** + * Test class to verify the AsyncMetadataVersionManager + * + * @author csoman + * + */ public class AsyncMetadataVersionManagerTest { private static String storesXmlfile = "test/common/voldemort/config/stores.xml"; @@ -88,6 +110,13 @@ public void tearDown() throws Exception { servers[1].stop(); } + /* + * Validates that the AsyncMetadataVersionManager correctly identifies the + * version update. This is done by initializing the base metadata version + * (for cluster.xml), starting the AsyncMetadataVersionManager and then + * updating the version to a new value. For the test to succeed the callback + * has to be invoked correctly by the asynchronous manager. + */ @Test public void testBasicAsyncBehaviour() { String storeVersionKey = "cluster.xml"; diff --git a/test/unit/voldemort/store/system/SystemStoreTest.java b/test/unit/voldemort/store/system/SystemStoreTest.java index 4f6b12ffbf..a2ca3eef0b 100644 --- a/test/unit/voldemort/store/system/SystemStoreTest.java +++ b/test/unit/voldemort/store/system/SystemStoreTest.java @@ -1,3 +1,19 @@ +/* + * 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.store.system; import static org.junit.Assert.assertEquals; @@ -21,6 +37,13 @@ import voldemort.store.socket.SocketStoreFactory; import voldemort.store.socket.clientrequest.ClientRequestExecutorPool; +/** + * Test class to verify the SystemStore (used to interact with the system + * metadata stores managed by the cluster). + * + * @author csoman + * + */ public class SystemStoreTest { private static String storesXmlfile = "test/common/voldemort/config/stores.xml";