Skip to content

Commit

Permalink
undo changes to mbean registration names - don't use client context a…
Browse files Browse the repository at this point in the history
…s part of the name
  • Loading branch information
Lei Gao committed Jul 30, 2012
1 parent fd1f9fb commit e77ee0f
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 222 deletions.
65 changes: 12 additions & 53 deletions src/java/voldemort/client/AbstractStoreClientFactory.java
Expand Up @@ -24,7 +24,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -104,7 +103,7 @@ public abstract class AbstractStoreClientFactory implements StoreClientFactory {
private final RoutedStoreFactory routedStoreFactory;
private final int clientZoneId;
private final String clientContextName;
private final AtomicInteger sequencer;
private final AtomicInteger clientSequencer;
private final HashSet<SchedulerService> clientAsyncServiceRepo;

public AbstractStoreClientFactory(ClientConfig config) {
Expand All @@ -120,26 +119,22 @@ public AbstractStoreClientFactory(ClientConfig config) {
this.maxBootstrapRetries = config.getMaxBootstrapRetries();
this.stats = new StoreStats();
this.clientZoneId = config.getClientZoneId();
this.clientContextName = (null == config.getClientContextName() ? ""
: config.getClientContextName());
this.clientContextName = config.getClientContextName();
this.routedStoreFactory = new RoutedStoreFactory(config.isPipelineRoutedStoreEnabled(),
threadPool,
config.getTimeoutConfig());

this.sequencer = new AtomicInteger(0);
this.clientSequencer = new AtomicInteger(0);
this.clientAsyncServiceRepo = new HashSet<SchedulerService>();

if(this.isJmxEnabled) {
JmxUtils.registerMbean(threadPool,
JmxUtils.createObjectName(JmxUtils.getPackageName(threadPool.getClass()),
JmxUtils.getClassName(threadPool.getClass())
+ "."
+ clientContextName
+ jmxId()));
JmxUtils.registerMbean(new StoreStatsJmx(stats),
JmxUtils.createObjectName("voldemort.store.stats.aggregate",
clientContextName + ".aggregate-perf"
+ jmxId()));
"aggregate-perf" + jmxId()));
}
}

Expand Down Expand Up @@ -167,22 +162,20 @@ public <K, V> StoreClient<K, V> getStoreClient(String storeName,
this,
3,
clientContextName,
sequencer.getAndIncrement(),
clientSequencer.getAndIncrement(),
config,
service);
}

@SuppressWarnings("unchecked")
public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId) {
return getRawStore(storeName, resolver, clientId, null, null);
InconsistencyResolver<Versioned<V>> resolver) {
return getRawStore(storeName, resolver, null, null);
}

@SuppressWarnings("unchecked")
public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId,
String customStoresXml,
String clusterXmlString) {

Expand Down Expand Up @@ -279,13 +272,7 @@ public <K, V, T> Store<K, V, T> getRawStore(String storeName,
store = statStore;
JmxUtils.registerMbean(new StoreStatsJmx(statStore.getStats()),
JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()),
clientContextName
+ "."
+ store.getName()
+ jmxId()
+ (null == clientId ? ""
: "."
+ clientId.toString())));
store.getName() + jmxId()));
}

if(storeDef.getKeySerializer().hasCompression()
Expand Down Expand Up @@ -319,11 +306,6 @@ public <K, V, T> Store<K, V, T> getRawStore(String storeName,
return serializedStore;
}

public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver) {
return getRawStore(storeName, resolver, null);
}

protected ClientConfig getConfig() {
return config;
}
Expand Down Expand Up @@ -481,36 +463,13 @@ private void stopClientAsyncSchedulers() {
clientAsyncServiceRepo.clear();
}

protected String getClientContext() {
return clientContextName;
}

/* Give a unique id to avoid jmx clashes */
public String jmxId() {
return jmxId == 0 ? "" : Integer.toString(jmxId);
}

/**
* Generate a unique client ID based on: 0. clientContext, if specified; 1.
* storeName; 2. deployment path; 3. client sequence
*
* @param storeName the name of the store the client is created for
* @param contextName the name of the client context
* @param clientSequence the client sequence number
* @return unique client ID
*/
public static UUID generateClientId(ClientInfo clientInfo) {
String contextName = clientInfo.getContext();
int clientSequence = clientInfo.getClientSequence();

String newLine = System.getProperty("line.separator");
StringBuilder context = new StringBuilder(contextName == null ? "" : contextName);
context.append(0 == clientSequence ? "" : ("." + clientSequence));
context.append(".").append(clientInfo.getStoreName());
context.append("@").append(clientInfo.getLocalHostName()).append(":");
context.append(clientInfo.getDeploymentPath()).append(newLine);

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

return UUID.nameUUIDFromBytes(context.toString().getBytes());
}

}
12 changes: 2 additions & 10 deletions src/java/voldemort/client/CachingStoreClientFactory.java
Expand Up @@ -17,7 +17,6 @@
package voldemort.client;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -76,13 +75,7 @@ public <K, V> StoreClient<K, V> getStoreClient(String storeName,

public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver) {
return getRawStore(storeName, resolver, null);
}

public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId) {
return inner.getRawStore(storeName, resolver, clientId);
return getRawStore(storeName, resolver);
}

public void close() {
Expand Down Expand Up @@ -126,9 +119,8 @@ else if(client instanceof LazyStoreClient<?, ?>) {

public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId,
String storesXml,
String clusterXml) {
return inner.getRawStore(storeName, resolver, clientId, storesXml, clusterXml);
return inner.getRawStore(storeName, resolver, storesXml, clusterXml);
}
}
2 changes: 1 addition & 1 deletion src/java/voldemort/client/ClientConfig.java
Expand Up @@ -78,7 +78,7 @@ public class ClientConfig {
private long failureDetectorRequestLengthThreshold = socketTimeoutMs;

private volatile int maxBootstrapRetries = 2;
private volatile String clientContextName = "default";
private volatile String clientContextName = "";

/* 5 second check interval, in ms */
private volatile long asyncCheckMetadataInterval = 5000;
Expand Down
49 changes: 37 additions & 12 deletions src/java/voldemort/client/DefaultStoreClient.java
Expand Up @@ -21,7 +21,6 @@
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -77,7 +76,7 @@ public class DefaultStoreClient<K, V> implements StoreClient<K, V> {
private final String storeName;
private final InconsistencyResolver<Versioned<V>> resolver;
private final SystemStoreRepository sysRepository;
private final UUID clientId;
private final String clientId;
private volatile Store<K, V, Object> store;
private final SchedulerService scheduler;
private ClientInfo clientInfo;
Expand Down Expand Up @@ -109,17 +108,15 @@ public DefaultStoreClient(String storeName,
clientSequence,
System.currentTimeMillis(),
ManifestFileReader.getReleaseVersion());
this.clientId = AbstractStoreClientFactory.generateClientId(clientInfo);
this.clientId = generateClientId(clientInfo);
this.config = config;
this.sysRepository = new SystemStoreRepository();
this.scheduler = scheduler;
// Registering self to be able to bootstrap client dynamically via JMX
JmxUtils.registerMbean(this,
JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()),
JmxUtils.getClassName(this.getClass())
+ "." + clientContext + "."
+ storeName + "."
+ clientId.toString()));
+ "." + storeName));

// Bootstrap this client
bootStrap();
Expand All @@ -130,17 +127,17 @@ public DefaultStoreClient(String storeName,
config.getAsyncCheckMetadataInterval());
}

registerClient(clientId.toString(), config.getClientRegistryRefreshInterval());
logger.info("Voldemort client created: " + clientId.toString() + "\n" + clientInfo);
registerClient(clientId, config.getClientRegistryRefreshInterval());
logger.info("Voldemort client created: " + clientId + "\n" + clientInfo);
}

private void registerClient(String jobId, int interval) {
SystemStore<String, ClientInfo> clientRegistry = this.sysRepository.getClientRegistryStore();
if(null != clientRegistry) {
try {
Version version = clientRegistry.putSysStore(clientId.toString(), clientInfo);
Version version = clientRegistry.putSysStore(clientId, clientInfo);
ClientRegistryRefresher refresher = new ClientRegistryRefresher(clientRegistry,
clientId.toString(),
clientId,
clientInfo,
version);
GregorianCalendar cal = new GregorianCalendar();
Expand Down Expand Up @@ -214,7 +211,7 @@ public void bootStrap() {
*/
clusterXml = ((AbstractStoreClientFactory) storeFactory).bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);

this.store = storeFactory.getRawStore(storeName, resolver, clientId, null, clusterXml);
this.store = storeFactory.getRawStore(storeName, resolver, null, clusterXml);

// Create system stores
logger.info("Creating system stores for store " + this.storeName);
Expand Down Expand Up @@ -498,7 +495,7 @@ else if(versions.size() == 1)

}

public UUID getClientId() {
public String getClientId() {
return clientId;
}

Expand All @@ -515,4 +512,32 @@ public String getClusterMetadataVersion() {
+ this.asyncCheckMetadata.getClusterMetadataVersion();
return result;
}

/**
* Generate a unique client ID based on: 0. clientContext, if specified; 1.
* storeName; 2. deployment path; 3. client sequence
*
* @param storeName the name of the store the client is created for
* @param contextName the name of the client context
* @param clientSequence the client sequence number
* @return unique client ID
*/
public String generateClientId(ClientInfo clientInfo) {
String contextName = clientInfo.getContext();
int clientSequence = clientInfo.getClientSequence();

String newLine = System.getProperty("line.separator");
StringBuilder context = new StringBuilder(contextName == null ? "" : contextName);
context.append(0 == clientSequence ? "" : ("." + clientSequence));
context.append(".").append(clientInfo.getStoreName());
context.append("@").append(clientInfo.getLocalHostName()).append(":");
context.append(clientInfo.getDeploymentPath()).append(newLine);

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

return context.toString();
}

}
10 changes: 1 addition & 9 deletions src/java/voldemort/client/MockStoreClientFactory.java
Expand Up @@ -18,7 +18,6 @@

import java.io.StringReader;
import java.util.List;
import java.util.UUID;

import voldemort.cluster.failuredetector.FailureDetector;
import voldemort.cluster.failuredetector.NoopFailureDetector;
Expand Down Expand Up @@ -107,8 +106,7 @@ public <K, V> StoreClient<K, V> getStoreClient(String storeName,
}

public <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName,
InconsistencyResolver<Versioned<V1>> resolver,
UUID clientId) {
InconsistencyResolver<Versioned<V1>> resolver) {
if(this.storesXml != null)
return getRawStore(storeName);

Expand All @@ -133,11 +131,6 @@ public <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName,
return consistentStore;
}

public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver) {
return getRawStore(storeName, resolver, null);
}

private <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName) {
List<StoreDefinition> storeDefs = storeMapper.readStoreList(new StringReader(storesXml));
StoreDefinition storeDef = null;
Expand Down Expand Up @@ -215,7 +208,6 @@ public FailureDetector getFailureDetector() {

public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId,
String storesXml,
String clusterXml) {
return null;
Expand Down
12 changes: 1 addition & 11 deletions src/java/voldemort/client/SocketStoreClientFactory.java
Expand Up @@ -39,7 +39,6 @@
import voldemort.store.socket.clientrequest.ClientRequestExecutorPool;
import voldemort.store.system.SystemStoreConstants;
import voldemort.utils.ByteArray;
import voldemort.utils.JmxUtils;
import voldemort.versioning.InconsistencyResolver;
import voldemort.versioning.Versioned;

Expand Down Expand Up @@ -70,11 +69,6 @@ public SocketStoreClientFactory(ClientConfig config) {
config.getSocketBufferSize(),
config.getSocketKeepAlive(),
config.isJmxEnabled());
if(config.isJmxEnabled())
JmxUtils.registerMbean(storeFactory,
JmxUtils.createObjectName(JmxUtils.getPackageName(storeFactory.getClass()),
JmxUtils.getClassName(storeFactory.getClass())
+ jmxId()));
}

@Override
Expand Down Expand Up @@ -184,10 +178,6 @@ public void close() {
}

public <K, V, T> Store<K, V, T> getSystemStore(String storeName, String clusterXml) {
return getRawStore(storeName,
null,
null,
SystemStoreConstants.SYSTEM_STORE_SCHEMA,
clusterXml);
return getRawStore(storeName, null, SystemStoreConstants.SYSTEM_STORE_SCHEMA, clusterXml);
}
}
15 changes: 0 additions & 15 deletions src/java/voldemort/client/StoreClientFactory.java
Expand Up @@ -16,8 +16,6 @@

package voldemort.client;

import java.util.UUID;

import voldemort.cluster.failuredetector.FailureDetector;
import voldemort.store.Store;
import voldemort.versioning.InconsistencyResolver;
Expand Down Expand Up @@ -74,18 +72,6 @@ public <K, V> StoreClient<K, V> getStoreClient(String storeName,
<K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver);

/**
* Get the underlying store, not the public StoreClient interface
*
* @param storeName The name of the store
* @param resolver The inconsistency resolver
* @param clientId The unique id of the client
* @return The appropriate store
*/
<K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId);

/**
* Get the underlying store, not the public StoreClient interface
*
Expand All @@ -97,7 +83,6 @@ <K, V, T> Store<K, V, T> getRawStore(String storeName,
*/
<K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
UUID clientId,
String customStoresXml,
String clusterXmlString);

Expand Down

0 comments on commit e77ee0f

Please sign in to comment.