use of voldemort.server.VoldemortServer in project voldemort by voldemort.
the class VoldemortServletContextListener method contextDestroyed.
public void contextDestroyed(ServletContextEvent event) {
logger.info("Calling application shutdown...");
VoldemortServer server = (VoldemortServer) event.getServletContext().getAttribute(SERVER_KEY);
if (server != null)
server.stop();
logger.info("Destroying application...");
event.getServletContext().removeAttribute(SERVER_KEY);
event.getServletContext().removeAttribute(SERVER_CONFIG_KEY);
event.getServletContext().removeAttribute(VELOCITY_ENGINE_KEY);
}
use of voldemort.server.VoldemortServer in project voldemort by voldemort.
the class StoreSwapperTest method tearDown.
@After
public void tearDown() throws IOException {
adminClient.close();
for (VoldemortServer server : servers) {
ServerTestUtils.stopVoldemortServer(server);
}
socketStoreFactory.close();
}
use of voldemort.server.VoldemortServer in project voldemort by voldemort.
the class AbstractZoneAffinityTest method setup.
@Before
public void setup() throws IOException {
byte[] v1_bytes = { (byte) 'V', (byte) '1' };
byte[] v2_bytes = { (byte) 'V', (byte) '2' };
byte[] k1_bytes = { (byte) 'K', (byte) '1' };
byte[] k2_bytes = { (byte) 'K', (byte) '2' };
byte[] k3_bytes = { (byte) 'K', (byte) '3' };
clientConfig = new ClientConfig();
clientConfig.setBootstrapUrls(cluster.getNodes().iterator().next().getSocketUrl().toString());
clientConfig.setClientZoneId(clientZoneId);
setupZoneAffinitySettings();
SocketStoreClientFactory socketStoreClientFactory = new SocketStoreClientFactory(clientConfig);
for (Integer nodeId : cluster.getNodeIds()) {
SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, stores, new Properties());
VoldemortServer vs = ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster);
vservers.put(nodeId, vs);
socketStoreFactories.put(nodeId, socketStoreFactory);
Store<ByteArray, byte[], byte[]> store = vs.getStoreRepository().getLocalStore(storeDef.getName());
Node node = cluster.getNodeById(nodeId);
VectorClock version1 = new VectorClock();
version1.incrementVersion(0, System.currentTimeMillis());
VectorClock version2 = version1.incremented(0, System.currentTimeMillis());
if (node.getZoneId() == clientZoneId) {
// local zone
store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
} else {
// remote zone
store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v2_bytes, version2), null);
store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
store.put(new ByteArray(k3_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
}
}
client = socketStoreClientFactory.getRawStore(storeDef.getName(), null);
}
use of voldemort.server.VoldemortServer in project voldemort by voldemort.
the class AbstractZoneAffinityTest method tearDown.
@After
public void tearDown() throws IOException {
client.close();
for (VoldemortServer vs : this.vservers.values()) {
ServerTestUtils.stopVoldemortServer(vs);
}
for (SocketStoreFactory ssf : this.socketStoreFactories.values()) {
ssf.close();
}
ClusterTestUtils.reset();
}
use of voldemort.server.VoldemortServer in project voldemort by voldemort.
the class ServerTestUtils method startVoldemortServer.
/**
* Starts a Voldemort server for testing purposes.
*
* Unless the ports passed in via cluster are guaranteed to be available,
* this method is susceptible to BindExceptions in VoldemortServer.start().
* (And, there is no good way of guaranteeing that ports will be available,
* so...)
*
* The method {@link ServerTestUtils#startVoldemortCluster} should be used
* in preference to this method.}
*
* @param socketStoreFactory
* @param config
* @param cluster
* @param testConnection
* @return
*/
public static VoldemortServer startVoldemortServer(SocketStoreFactory socketStoreFactory, VoldemortConfig config, Cluster cluster, boolean testConnection) throws BindException {
// TODO: Some tests that use this method fail intermittently with the
// following output:
//
// A successor version version() to this version() exists for key
// cluster.xml
// voldemort.versioning.ObsoleteVersionException: A successor version
// version() to this version() exists for key cluster.xml"
//
// Need to trace through the constructor VoldemortServer(VoldemortConfig
// config, Cluster cluster) to understand how this error is possible,
// and why it only happens intermittently.
final int MAX_NUMBER_OF_ATTEMPTS = 120;
// 5 minutes
final long MAX_RETRY_TIME_IN_MS = 5 * Time.MS_PER_MINUTE;
VoldemortException lastVE = null;
long startTime = System.currentTimeMillis(), currentTime = System.currentTimeMillis();
for (int i = 1; (i <= MAX_NUMBER_OF_ATTEMPTS) && (currentTime - startTime < MAX_RETRY_TIME_IN_MS); i++, currentTime = System.currentTimeMillis()) {
VoldemortServer server = null;
boolean success = false;
try {
if (cluster != null) {
server = new VoldemortServer(config, cluster);
} else {
server = new VoldemortServer(config);
}
server.start();
if (testConnection)
ServerTestUtils.waitForServerStart(socketStoreFactory, server.getIdentityNode());
// wait till server starts or throw exception
success = true;
return server;
} catch (VoldemortException ve) {
if (ve.getCause() instanceof BindException) {
ve.printStackTrace();
trySleep(Math.min(100 * i, 1000));
lastVE = ve;
} else {
throw ve;
}
} finally {
if (!success && server != null) {
// This is in case new VoldemortServer() worked but ServerTestUtils.waitForServerStart() failed.
try {
server.stop();
} catch (Exception e) {
logger.error("Got an exception while trying to close a VoldemortServer", e);
}
}
}
}
throw new BindException(lastVE.getMessage());
}
Aggregations