Skip to content

Commit

Permalink
add version and update time to client registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Gao committed Jun 27, 2012
1 parent 7b3c8e2 commit dbc2f54
Show file tree
Hide file tree
Showing 11 changed files with 872 additions and 96 deletions.
7 changes: 7 additions & 0 deletions META-INF/MANIFEST.MF
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 20.8-b03-424 (Apple Inc.)
Implementation-Title: Voldemort
Implementation-Version: 0.90.1
Implementation-Vendor: LinkedIn

11 changes: 10 additions & 1 deletion build.xml
Expand Up @@ -5,7 +5,7 @@

<property name="name" value="voldemort" />
<property name="display.name" value="Voldemort" />
<property name="author" value="Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao" />
<property name="author" value="Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu" />
<property environment="env" />

<path id="main-classpath">
Expand Down Expand Up @@ -76,6 +76,12 @@
<exclude name="**/log4j.properties" />
</fileset>
</copy>
<replace-dir dir="META-INF" />
<manifest file="META-INF/MANIFEST.MF">
<attribute name="Implementation-Title" value="Voldemort" />
<attribute name="Implementation-Version" value="${curr.release}" />
<attribute name="Implementation-Vendor" value="LinkedIn" />
</manifest>
<!-- place to put log4j.properties -->
<replace-dir dir="${resources.dir}"/>
<copy file="${java.dir}/log4j.properties" todir="${resources.dir}"/>
Expand Down Expand Up @@ -141,6 +147,9 @@
<fileset dir="${java.dir}">
<include name="**/*.xsd" />
</fileset>
<fileset dir=".">
<include name="META-INF/MANIFEST.MF" />
</fileset>
</jar>
</target>

Expand Down
11 changes: 11 additions & 0 deletions src/java/voldemort/client/ClientConfig.java
Expand Up @@ -80,6 +80,8 @@ public class ClientConfig {
private volatile int maxBootstrapRetries = 2;
private volatile String clientContextName = "default";
private volatile long asyncCheckMetadataInterval = 5000;
/* 12 hr refresh internval */
private volatile long clientRegistryRefreshInterval = 3600 * 1000 * 12;

public ClientConfig() {}

Expand Down Expand Up @@ -721,4 +723,13 @@ public ClientConfig setAsyncCheckMetadataInterval(long asyncCheckMetadataInterva
this.asyncCheckMetadataInterval = asyncCheckMetadataInterval;
return this;
}

public long getClientRegistryRefreshInterval() {
return this.clientRegistryRefreshInterval;
}

public ClientConfig setClientRegistryRefreshInterval(long clientRegistryRefrshInterval) {
this.clientRegistryRefreshInterval = clientRegistryRefrshInterval;
return this;
}
}
66 changes: 64 additions & 2 deletions src/java/voldemort/client/ClientInfo.java
Expand Up @@ -23,14 +23,26 @@ public class ClientInfo implements Serializable {
private int sequence;
private String localHostName;
private String deploymentPath;

public ClientInfo(String storeName, String clientContext, int clientSequence, long bootstrapTime) {
private long updateTime;
private String releaseVersion;

public ClientInfo(String storeName,
String clientContext,
int clientSequence,
long bootstrapTime,
String version) {
this.bootstrapTime = bootstrapTime;
this.storeName = storeName;
this.context = clientContext;
this.sequence = clientSequence;
this.localHostName = createHostName();
this.deploymentPath = createDeploymentPath();
this.updateTime = bootstrapTime;
this.releaseVersion = version;

if(logger.isDebugEnabled()) {
logger.debug(this.toString());
}
}

private String createDeploymentPath() {
Expand Down Expand Up @@ -103,4 +115,54 @@ public void setLocalHostName(String localHostName) {
public String getLocalHostName() {
return localHostName;
}

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

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

public void setReleaseVersion(String version) {
this.releaseVersion = version;
}

public String getReleaseVersion() {
return this.releaseVersion;
}

@Override
public boolean equals(Object object) {
if(this == object)
return true;
if(object == null)
return false;
if(!object.getClass().equals(ClientInfo.class))
return false;
ClientInfo clientInfo = (ClientInfo) object;
return (this.bootstrapTime == clientInfo.bootstrapTime)
&& (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.releaseVersion == clientInfo.releaseVersion);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("boostrapTime[").append(bootstrapTime).append("], ");
builder.append("context[").append(context).append("], ");
builder.append("deploymentPath[").append(deploymentPath).append("], ");
builder.append("localHostName[").append(localHostName).append("], ");
builder.append("sequence[").append(sequence).append("], ");
builder.append("storeName[").append(storeName).append("], ");
builder.append("updateTime[").append(updateTime).append("], ");
builder.append("releaseVersion[").append(releaseVersion).append("]");
return builder.toString();
}

}
7 changes: 4 additions & 3 deletions src/java/voldemort/client/DefaultStoreClient.java
Expand Up @@ -37,6 +37,7 @@
import voldemort.store.Store;
import voldemort.store.StoreCapabilityType;
import voldemort.utils.JmxUtils;
import voldemort.utils.ManifestFileReader;
import voldemort.utils.Utils;
import voldemort.versioning.InconsistencyResolver;
import voldemort.versioning.InconsistentDataException;
Expand Down Expand Up @@ -98,7 +99,8 @@ public DefaultStoreClient(String storeName,
this.clientInfo = new ClientInfo(storeName,
clientContext,
clientSequence,
System.currentTimeMillis());
System.currentTimeMillis(),
ManifestFileReader.getReleaseVersion());
this.clientId = AbstractStoreClientFactory.generateClientId(clientInfo);
this.config = config;

Expand All @@ -120,8 +122,7 @@ public DefaultStoreClient(String storeName,
}

registerClient();
logger.info("Voldemort client created: clientContext=" + clientContext + " clientSequence="
+ clientSequence + " clientId=" + clientId.toString());
logger.info("Voldemort client created: " + clientId.toString() + "\n" + clientInfo);
}

private void registerClient() {
Expand Down
77 changes: 0 additions & 77 deletions src/java/voldemort/server/SystemStoreConstants.java

This file was deleted.

11 changes: 3 additions & 8 deletions src/java/voldemort/store/system/SystemStoreConstants.java
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import voldemort.store.StoreDefinition;
import voldemort.utils.RebalanceUtils;
import voldemort.xml.StoreDefinitionsMapper;

/**
Expand All @@ -22,7 +23,7 @@ public static enum SystemStoreName {
public static final String SYSTEM_STORE_SCHEMA = "<stores>"
+ " <store>"
+ " <name>voldsys$_client_registry</name>"
+ " <routing-strategy>zone-routing</routing-strategy>"
+ " <routing-strategy>all-routing</routing-strategy>"
+ " <hinted-handoff-strategy>proximity-handoff</hinted-handoff-strategy>"
+ " <persistence>memory</persistence>"
+ " <routing>client</routing>"
Expand Down Expand Up @@ -92,13 +93,7 @@ public static List<StoreDefinition> getAllSystemStoreDefs() {
}

public static StoreDefinition getSystemStoreDef(String name) {
StoreDefinition storeDef = null;
List<StoreDefinition> allDefs = getAllSystemStoreDefs();
for(StoreDefinition def: allDefs) {
if(name.equals(def.getName())) {
storeDef = def;
}
}
return storeDef;
return RebalanceUtils.getStoreDefinitionWithName(allDefs, name);
}
}
27 changes: 27 additions & 0 deletions src/java/voldemort/utils/ManifestFileReader.java
@@ -0,0 +1,27 @@
package voldemort.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ManifestFileReader {

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

private static String MANIFEST_FILE = "META-INF/MANIFEST.MF";
private static String RELEASE_VERSION_KEY = "Implementation-Version";

public static String getReleaseVersion() {
String version = null;
Properties properties = new Properties();
try {
properties.load(new FileInputStream(MANIFEST_FILE));
version = properties.getProperty(RELEASE_VERSION_KEY);
} catch(IOException e) {
logger.warn("Unable to load voldemort release version due to the following error:", e);
}
return version;
}
}
22 changes: 17 additions & 5 deletions src/java/voldemort/utils/RebalanceUtils.java
Expand Up @@ -50,6 +50,7 @@
import voldemort.cluster.Node;
import voldemort.routing.RoutingStrategy;
import voldemort.routing.RoutingStrategyFactory;
import voldemort.routing.RoutingStrategyType;
import voldemort.server.VoldemortConfig;
import voldemort.server.rebalance.VoldemortRebalancingException;
import voldemort.store.StoreDefinition;
Expand Down Expand Up @@ -486,11 +487,21 @@ public static boolean checkKeyBelongsToPartition(int nodeId,
HashMap<Integer, List<Integer>> replicaToPartitionList,
Cluster cluster,
StoreDefinition storeDef) {
List<Integer> keyPartitions = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
cluster)
.getPartitionList(key);
List<Integer> nodePartitions = cluster.getNodeById(nodeId).getPartitionIds();
return checkKeyBelongsToPartition(keyPartitions, nodePartitions, replicaToPartitionList);
boolean checkResult = false;
if(storeDef.getRoutingStrategyType().equals(RoutingStrategyType.TO_ALL_STRATEGY)
|| storeDef.getRoutingStrategyType()
.equals(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY)) {
checkResult = true;
} else {
List<Integer> keyPartitions = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
cluster)
.getPartitionList(key);
List<Integer> nodePartitions = cluster.getNodeById(nodeId).getPartitionIds();
checkResult = checkKeyBelongsToPartition(keyPartitions,
nodePartitions,
replicaToPartitionList);
}
return checkResult;
}

/**
Expand Down Expand Up @@ -1395,6 +1406,7 @@ public static StoreDefinition getStoreDefinitionWithName(List<StoreDefinition> s
for(StoreDefinition storeDef: storeDefs) {
if(storeDef.getName().compareTo(storeName) == 0) {
def = storeDef;
break;
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/common/voldemort/config/stores.xml
Expand Up @@ -185,4 +185,34 @@
<hinted-handoff-strategy>all-handoff</hinted-handoff-strategy>
<hint-preflist-size>10</hint-preflist-size>
</store>
<store>
<name>test-store-eventual-1</name>
<persistence>bdb</persistence>
<routing>client</routing>
<replication-factor>2</replication-factor>
<required-reads>1</required-reads>
<required-writes>1</required-writes>
<key-serializer>
<type>string</type>
<schema-info>UTF-8</schema-info>
</key-serializer>
<value-serializer>
<type>java-serialization</type>
</value-serializer>
</store>
<store>
<name>test-store-eventual-2</name>
<persistence>bdb</persistence>
<routing>client</routing>
<replication-factor>2</replication-factor>
<required-reads>1</required-reads>
<required-writes>1</required-writes>
<key-serializer>
<type>string</type>
<schema-info>UTF-8</schema-info>
</key-serializer>
<value-serializer>
<type>java-serialization</type>
</value-serializer>
</store>
</stores>

0 comments on commit dbc2f54

Please sign in to comment.