use of voldemort.store.views.ViewStorageEngine in project voldemort by voldemort.
the class Benchmark method initializeStore.
@SuppressWarnings("unchecked")
public void initializeStore(Props benchmarkProps) throws Exception {
this.numThreads = benchmarkProps.getInt(THREADS, MAX_WORKERS);
this.numConnectionsPerNode = benchmarkProps.getInt(NUM_CONNECTIONS_PER_NODE, MAX_CONNECTIONS_PER_NODE);
this.numIterations = benchmarkProps.getInt(ITERATIONS, 1);
this.statusIntervalSec = benchmarkProps.getInt(INTERVAL, 0);
this.verbose = benchmarkProps.getBoolean(VERBOSE, false);
this.verifyRead = benchmarkProps.getBoolean(VERIFY, false);
this.ignoreNulls = benchmarkProps.getBoolean(IGNORE_NULLS, false);
int clientZoneId = benchmarkProps.getInt(CLIENT_ZONE_ID, -1);
if (benchmarkProps.containsKey(URL)) {
// Remote benchmark
if (!benchmarkProps.containsKey(STORE_NAME)) {
throw new VoldemortException("Missing storename");
}
String socketUrl = benchmarkProps.getString(URL);
String storeName = benchmarkProps.getString(STORE_NAME);
ClientConfig clientConfig = new ClientConfig().setMaxThreads(numThreads).setMaxTotalConnections(numThreads).setMaxConnectionsPerNode(numConnectionsPerNode).setRoutingTimeout(1500, TimeUnit.MILLISECONDS).setSocketTimeout(1500, TimeUnit.MILLISECONDS).setConnectionTimeout(500, TimeUnit.MILLISECONDS).setRequestFormatType(RequestFormatType.VOLDEMORT_V3).setBootstrapUrls(socketUrl);
if (clientZoneId >= 0) {
clientConfig.setClientZoneId(clientZoneId);
}
SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(clientConfig);
this.storeClient = socketFactory.getStoreClient(storeName);
StoreDefinition storeDef = getStoreDefinition(socketFactory, storeName);
this.keyType = findKeyType(storeDef);
benchmarkProps.put(Benchmark.KEY_TYPE, this.keyType);
this.factory = socketFactory;
} else {
// Local benchmark
localMode = true;
String storageEngineClass = benchmarkProps.getString(STORAGE_CONFIGURATION_CLASS);
this.keyType = benchmarkProps.getString(KEY_TYPE, STRING_KEY_TYPE);
Serializer serializer = findKeyType(this.keyType);
Store<Object, Object, Object> store = null;
VoldemortConfig voldemortConfig;
if (benchmarkProps.containsKey(LOCAL_SERVER_PROPERTIES)) {
File homeDir = TestUtils.createTempDir();
File configDir = new File(homeDir, "config");
configDir.mkdir();
FileUtils.copyFile(new File(benchmarkProps.get(LOCAL_SERVER_PROPERTIES)), new File(configDir, "server.properties"));
voldemortConfig = VoldemortConfig.loadFromVoldemortHome(homeDir.getAbsolutePath());
} else {
voldemortConfig = ServerTestUtils.getVoldemortConfig();
}
StorageConfiguration conf = (StorageConfiguration) ReflectUtils.callConstructor(ReflectUtils.loadClass(storageEngineClass), new Object[] { voldemortConfig });
StorageEngine<ByteArray, byte[], byte[]> engine = conf.getStore(TestUtils.makeStoreDefinition(DUMMY_DB), TestUtils.makeSingleNodeRoutingStrategy());
if (conf.getType().compareTo(ViewStorageConfiguration.TYPE_NAME) == 0) {
engine = new ViewStorageEngine(STORE_NAME, engine, new StringSerializer(), new StringSerializer(), serializer, new StringSerializer(), null, BenchmarkViews.loadTransformation(benchmarkProps.getString(VIEW_CLASS).trim()));
}
store = SerializingStore.wrap(engine, serializer, new StringSerializer(), new IdentitySerializer());
this.factory = new StaticStoreClientFactory(store);
this.storeClient = factory.getStoreClient(store.getName());
}
this.storeInitialized = true;
}
use of voldemort.store.views.ViewStorageEngine in project voldemort by voldemort.
the class MockStoreClientFactory method getRawStore.
private <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName) {
List<StoreDefinition> storeDefs = storeMapper.readStoreList(new StringReader(storesXml));
StoreDefinition storeDef = null;
for (StoreDefinition d : storeDefs) if (d.getName().equals(storeName))
storeDef = d;
if (storeDef == null)
throw new BootstrapFailureException("Unknown store '" + storeName + "'.");
DefaultSerializerFactory serializerFactory = new DefaultSerializerFactory();
Serializer<K1> keySerializer = (Serializer<K1>) serializerFactory.getSerializer(storeDef.getKeySerializer());
Serializer<V1> valueSerializer = (Serializer<V1>) serializerFactory.getSerializer(storeDef.getValueSerializer());
Serializer<T1> transformsSerializer = null;
if (storeDef.isView())
transformsSerializer = (Serializer<T1>) serializerFactory.getSerializer(storeDef.getTransformsSerializer());
// Add inconsistency resolving decorator, using their inconsistency
// resolver (if they gave us one)
InconsistencyResolver<Versioned<V1>> secondaryResolver = new TimeBasedInconsistencyResolver();
StorageEngine engine;
if (storeDef.isView())
engine = new InMemoryStorageEngine(storeDef.getViewTargetStoreName());
else
engine = new InMemoryStorageEngine(storeDef.getName());
if (storeDef.isView()) {
// instantiate view
String targetName = storeDef.getViewTargetStoreName();
StoreDefinition targetDef = StoreUtils.getStoreDef(storeDefs, targetName);
engine = new ViewStorageEngine(storeName, engine, this.viewValueSerializer != null ? this.viewValueSerializer : serializerFactory.getSerializer(storeDef.getValueSerializer()), this.transformsSerializer != null ? this.transformsSerializer : serializerFactory.getSerializer(storeDef.getTransformsSerializer()), this.keySerializer != null ? this.keySerializer : serializerFactory.getSerializer(targetDef.getKeySerializer()), this.valueSerializer != null ? this.valueSerializer : serializerFactory.getSerializer(targetDef.getValueSerializer()), null, ViewStorageConfiguration.loadTransformation(storeDef.getValueTransformation()));
}
Store store = new VersionIncrementingStore(engine, nodeId, time);
store = new SerializingStore(store, this.keySerializer != null ? this.keySerializer : keySerializer, this.valueSerializer != null ? this.valueSerializer : valueSerializer, this.transformsSerializer != null ? this.transformsSerializer : transformsSerializer);
Store<K1, V1, T1> consistentStore = new InconsistencyResolvingStore<K1, V1, T1>(store, new ChainedResolver<Versioned<V1>>(new VectorClockInconsistencyResolver(), secondaryResolver));
return consistentStore;
}
Aggregations