Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started reading the Zk configurations

  • Loading branch information...
commit 1f030097a78b49adbf001b309e773c9dabdc85ec 1 parent 6cd77d9
@rsumbaly authored
View
17 src/java/voldemort/server/VoldemortConfig.java
@@ -171,6 +171,8 @@
private int rebalancingServicePeriod;
private int maxParallelStoresRebalancing;
+ private String zkConnect;
+
public VoldemortConfig(Properties props) {
this(new Props(props));
}
@@ -182,6 +184,7 @@ public VoldemortConfig(Props props) {
this.nodeId = getIntEnvVariable(VOLDEMORT_NODE_ID_VAR_NAME);
}
this.voldemortHome = props.getString("voldemort.home");
+ this.zkConnect = props.getString("zk.connect", "");
this.dataDirectory = props.getString("data.directory", this.voldemortHome + File.separator
+ "data");
this.metadataDirectory = props.getString("metadata.directory", voldemortHome
@@ -417,6 +420,20 @@ public static VoldemortConfig loadFromVoldemortHome(String voldemortHome) {
return new VoldemortConfig(properties);
}
+ public String getZkConnect() {
+ return zkConnect;
+ }
+
+ public void setZkConnect(String zkConnect) {
+ this.zkConnect = zkConnect;
+ }
+
+ public boolean hasZkConnect() {
+ if(this.zkConnect.length() > 0)
+ return true;
+ return false;
+ }
+
/**
* The interval at which gossip is run to exchange metadata
*/
View
4 src/java/voldemort/server/VoldemortServer.java
@@ -78,7 +78,7 @@ public VoldemortServer(VoldemortConfig config) {
this.voldemortConfig = config;
this.storeRepository = new StoreRepository();
this.metadata = MetadataStore.readFromDirectory(new File(this.voldemortConfig.getMetadataDirectory()),
- voldemortConfig.getNodeId());
+ voldemortConfig);
this.identityNode = metadata.getCluster().getNodeById(voldemortConfig.getNodeId());
this.services = createServices();
}
@@ -103,7 +103,7 @@ public VoldemortServer(VoldemortConfig config, Cluster cluster) {
metadataInnerEngine.put(MetadataStore.CLUSTER_KEY,
new Versioned<String>(new ClusterMapper().writeCluster(cluster)),
null);
- this.metadata = new MetadataStore(metadataInnerEngine, voldemortConfig.getNodeId());
+ this.metadata = new MetadataStore(metadataInnerEngine, voldemortConfig);
this.services = createServices();
}
View
33 src/java/voldemort/store/metadata/MetadataStore.java
@@ -41,6 +41,7 @@
import voldemort.routing.RouteToAllStrategy;
import voldemort.routing.RoutingStrategy;
import voldemort.routing.RoutingStrategyFactory;
+import voldemort.server.VoldemortConfig;
import voldemort.server.rebalance.RebalancerState;
import voldemort.store.StorageEngine;
import voldemort.store.Store;
@@ -76,6 +77,7 @@
public static final String STORES_KEY = "stores.xml";
public static final String SERVER_STATE_KEY = "server.state";
public static final String NODE_ID_KEY = "node.id";
+ public static final String ZOOKEEPER_CONNECTION_STRING_KEY = "zk.connect";
public static final String REBALANCING_STEAL_INFO = "rebalancing.steal.info.key";
public static final String GRANDFATHERING_INFO = "grandfathering.info.key";
@@ -86,7 +88,8 @@
public static final Set<String> OPTIONAL_KEYS = ImmutableSet.of(SERVER_STATE_KEY,
NODE_ID_KEY,
REBALANCING_STEAL_INFO,
- GRANDFATHERING_INFO);
+ GRANDFATHERING_INFO,
+ ZOOKEEPER_CONNECTION_STRING_KEY);
public static final Set<Object> METADATA_KEYS = ImmutableSet.builder()
.addAll(REQUIRED_KEYS)
@@ -109,6 +112,7 @@
private final Store<String, String, String> innerStore;
private final Map<String, Versioned<Object>> metadataCache;
+ private final VoldemortConfig voldemortConfig;
private static final ClusterMapper clusterMapper = new ClusterMapper();
private static final StoreDefinitionsMapper storeMapper = new StoreDefinitionsMapper();
@@ -124,12 +128,13 @@
private static final Logger logger = Logger.getLogger(MetadataStore.class);
- public MetadataStore(Store<String, String, String> innerStore, int nodeId) {
+ public MetadataStore(Store<String, String, String> innerStore, VoldemortConfig voldemortConfig) {
this.innerStore = innerStore;
this.metadataCache = new HashMap<String, Versioned<Object>>();
this.storeNameTolisteners = new ConcurrentHashMap<String, MetadataStoreListener>();
+ this.voldemortConfig = voldemortConfig;
- init(nodeId);
+ init();
}
public void addMetadataStoreListener(String storeName, MetadataStoreListener listener) {
@@ -146,7 +151,7 @@ public void remoteMetadataStoreListener(String storeName) {
this.storeNameTolisteners.remove(storeName);
}
- public static MetadataStore readFromDirectory(File dir, int nodeId) {
+ public static MetadataStore readFromDirectory(File dir, VoldemortConfig voldemortConfig) {
if(!Utils.isReadableDir(dir))
throw new IllegalArgumentException("Metadata directory " + dir.getAbsolutePath()
+ " does not exist or can not be read.");
@@ -155,7 +160,7 @@ public static MetadataStore readFromDirectory(File dir, int nodeId) {
+ ".");
Store<String, String, String> innerStore = new ConfigurationStorageEngine(MetadataStore.METADATA_STORE_NAME,
dir.getAbsolutePath());
- return new MetadataStore(innerStore, nodeId);
+ return new MetadataStore(innerStore, voldemortConfig);
}
public String getName() {
@@ -285,7 +290,7 @@ public synchronized void cleanAllRebalancingState() {
getVersions(new ByteArray(ByteUtils.getBytes(key, "UTF-8"))).get(0));
}
- init(getNodeId());
+ init();
}
public void cleanRebalancingState(RebalancePartitionsInfo stealInfo) {
@@ -421,19 +426,22 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
/**
* Initializes the metadataCache for MetadataStore
*/
- private void init(int nodeId) {
+ private void init() {
logger.info("metadata init().");
+ // Initialize the Zk Connection
+ initCache(ZOOKEEPER_CONNECTION_STRING_KEY, voldemortConfig.getZkConnect());
+
// Required keys
initCache(CLUSTER_KEY);
initCache(STORES_KEY);
- initCache(NODE_ID_KEY, nodeId);
- if(getNodeId() != nodeId)
+ initCache(NODE_ID_KEY, voldemortConfig.getNodeId());
+ if(getNodeId() != voldemortConfig.getNodeId())
throw new RuntimeException("Attempt to start previous node:"
+ getNodeId()
+ " as node:"
- + nodeId
+ + voldemortConfig.getNodeId()
+ " (Did you copy config directory ? try deleting .temp .version in config dir to force clean) aborting ...");
// Initialize with default if not present
@@ -498,7 +506,8 @@ private void initCache(String key, Object defaultValue) {
} else if(GRANDFATHERING_INFO.equals(key)) {
GrandfatherState grandfatherState = (GrandfatherState) value.getValue();
valueStr = grandfatherState.toJsonString();
- } else if(SERVER_STATE_KEY.equals(key) || NODE_ID_KEY.equals(key)) {
+ } else if(SERVER_STATE_KEY.equals(key) || NODE_ID_KEY.equals(key)
+ || ZOOKEEPER_CONNECTION_STRING_KEY.equals(key)) {
valueStr = value.getValue().toString();
} else {
throw new VoldemortException("Unhandled key:'" + key
@@ -543,6 +552,8 @@ private void initCache(String key, Object defaultValue) {
} else {
valueObject = new GrandfatherState(Arrays.asList(RebalancePartitionsInfo.create(valueString)));
}
+ } else if(ZOOKEEPER_CONNECTION_STRING_KEY.equals(key)) {
+ valueObject = value.getValue();
} else {
throw new VoldemortException("Unhandled key:'" + key
+ "' for String to Object serialization.");
View
2  test/common/voldemort/ServerTestUtils.java
@@ -379,7 +379,7 @@ public static MetadataStore createMetadataStore(Cluster cluster, List<StoreDefin
new Versioned<String>(new StoreDefinitionsMapper().writeStoreList(storeDefs)),
null);
- return new MetadataStore(innerStore, 0);
+ return new MetadataStore(innerStore, getVoldemortConfig());
}
public static List<StoreDefinition> getStoreDefs(int numStores) {
Please sign in to comment.
Something went wrong with that request. Please try again.