use of voldemort.store.compress.CompressionStrategyFactory in project voldemort by voldemort.
the class ReadOnlyStorageEngineTestInstance method create.
public static ReadOnlyStorageEngineTestInstance create(SearchStrategy strategy, File baseDir, int testSize, int numNodes, int repFactor, SerializerDefinition keySerDef, SerializerDefinition valueSerDef, ReadOnlyStorageFormat type, int[][] partitionMap) throws Exception {
// create some test data
Map<String, String> data = createTestData(testSize);
JsonReader reader = makeTestDataReader(data, baseDir);
// set up definitions for cluster and store
List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < numNodes; i++) {
List<Integer> partitions = new ArrayList<Integer>(partitionMap[i].length);
for (int p : partitionMap[i]) {
partitions.add(p);
}
nodes.add(new Node(i, "localhost", 8080 + i, 6666 + i, 7000 + i, partitions));
}
Cluster cluster = new Cluster("test", nodes);
StoreDefinition storeDef = new StoreDefinitionBuilder().setName("test").setType(ReadOnlyStorageConfiguration.TYPE_NAME).setKeySerializer(keySerDef).setValueSerializer(valueSerDef).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(repFactor).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
RoutingStrategy router = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, cluster);
// build store files in outputDir
File outputDir = TestUtils.createTempDir(baseDir);
JsonStoreBuilder storeBuilder = new JsonStoreBuilder(reader, cluster, storeDef, router, outputDir, null, testSize / 5, 1, 2, 10000, false);
storeBuilder.build(type);
File nodeDir = TestUtils.createTempDir(baseDir);
@SuppressWarnings("unchecked") Serializer<String> keySerializer = (Serializer<String>) new DefaultSerializerFactory().getSerializer(keySerDef);
@SuppressWarnings("unchecked") Serializer<String> valueSerializer = (Serializer<String>) new DefaultSerializerFactory().getSerializer(valueSerDef);
Serializer<String> transSerializer = new StringSerializer();
Map<Integer, Store<String, String, String>> nodeStores = Maps.newHashMap();
Map<Integer, ReadOnlyStorageEngine> readOnlyStores = Maps.newHashMap();
for (int i = 0; i < numNodes; i++) {
File currNode = new File(nodeDir, Integer.toString(i));
currNode.mkdirs();
currNode.deleteOnExit();
Utils.move(new File(outputDir, "node-" + Integer.toString(i)), new File(currNode, "version-0"));
CompressionStrategyFactory compressionStrategyFactory = new CompressionStrategyFactory();
CompressionStrategy keyCompressionStrat = compressionStrategyFactory.get(keySerDef.getCompression());
CompressionStrategy valueCompressionStrat = compressionStrategyFactory.get(valueSerDef.getCompression());
ReadOnlyStorageEngine readOnlyStorageEngine = new ReadOnlyStorageEngine("test", strategy, router, i, currNode, 1);
readOnlyStores.put(i, readOnlyStorageEngine);
Store<ByteArray, byte[], byte[]> innerStore = new CompressingStore(readOnlyStorageEngine, keyCompressionStrat, valueCompressionStrat);
nodeStores.put(i, SerializingStore.wrap(innerStore, keySerializer, valueSerializer, transSerializer));
}
return new ReadOnlyStorageEngineTestInstance(data, baseDir, readOnlyStores, nodeStores, router, keySerializer);
}
use of voldemort.store.compress.CompressionStrategyFactory in project voldemort by voldemort.
the class RESTClientFactory method getRawStore.
@Override
public <K, V, T> Store<K, V, T> getRawStore(String storeName, InconsistencyResolver<Versioned<V>> resolver) {
Store<K, V, T> clientStore = null;
// The lowest layer : Transporting request to coordinator
R2Store r2store = null;
this.d2Client = restClientFactoryConfig.getD2Client();
if (this.d2Client == null) {
logger.info("Using transportclient since d2client is not available");
Map<String, String> properties = new HashMap<String, String>();
properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(this.config.getMaxR2ConnectionPoolSize()));
transportClient = _clientFactory.getClient(properties);
r2store = new R2Store(storeName, this.config.getHttpBootstrapURL(), this.transportClient, this.config);
} else {
logger.info("Using d2client");
r2store = new R2Store(storeName, this.config.getHttpBootstrapURL(), this.d2Client, this.config);
}
this.rawStoreList.add(r2store);
// bootstrap from the coordinator and obtain all the serialization
// information.
String serializerInfoXml = r2store.getSerializerInfoXml();
SerializerDefinition keySerializerDefinition = RestUtils.parseKeySerializerDefinition(serializerInfoXml);
SerializerDefinition valueSerializerDefinition = RestUtils.parseValueSerializerDefinition(serializerInfoXml);
synchronized (this) {
keySerializerMap.put(storeName, keySerializerDefinition);
valueSerializerMap.put(storeName, valueSerializerDefinition);
}
if (logger.isDebugEnabled()) {
logger.debug("Bootstrapping for " + storeName + ": Key serializer " + keySerializerDefinition);
logger.debug("Bootstrapping for " + storeName + ": Value serializer " + valueSerializerDefinition);
}
// Start building the stack..
// First, the transport layer
Store<ByteArray, byte[], byte[]> store = r2store;
// TODO: Add identifierString to the Mbean name
if (this.config.isEnableJmx()) {
StatTrackingStore statStore = new StatTrackingStore(store, this.stats);
store = statStore;
JmxUtils.registerMbean(new StoreStatsJmx(statStore.getStats()), JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()), store.getName()));
}
// Add compression layer
if (keySerializerDefinition.hasCompression() || valueSerializerDefinition.hasCompression()) {
store = new CompressingStore(store, new CompressionStrategyFactory().get(keySerializerDefinition.getCompression()), new CompressionStrategyFactory().get(valueSerializerDefinition.getCompression()));
}
// Add Serialization layer
Serializer<K> keySerializer = (Serializer<K>) serializerFactory.getSerializer(keySerializerDefinition);
Serializer<V> valueSerializer = (Serializer<V>) serializerFactory.getSerializer(valueSerializerDefinition);
clientStore = SerializingStore.wrap(store, keySerializer, valueSerializer, null);
// Add inconsistency Resolving layer
InconsistencyResolver<Versioned<V>> secondaryResolver = resolver == null ? new TimeBasedInconsistencyResolver<V>() : resolver;
clientStore = new InconsistencyResolvingStore<K, V, T>(clientStore, new ChainedResolver<Versioned<V>>(new VectorClockInconsistencyResolver<V>(), secondaryResolver));
return clientStore;
}
use of voldemort.store.compress.CompressionStrategyFactory in project voldemort by voldemort.
the class ViewStorageConfiguration method getStore.
public StorageEngine<ByteArray, byte[], byte[]> getStore(StoreDefinition storeDef, RoutingStrategy strategy) {
String name = storeDef.getName();
StoreDefinition def = StoreUtils.getStoreDef(storeDefs, name);
String targetName = def.getViewTargetStoreName();
StoreDefinition targetDef = StoreUtils.getStoreDef(storeDefs, targetName);
StorageEngine<ByteArray, byte[], byte[]> target = storeRepo.getStorageEngine(targetName);
if (target == null)
throw new VoldemortException("View \"" + name + "\" has a target store \"" + targetName + "\" which does not exist.");
String factoryName = def.getSerializerFactory();
SerializerFactory factory;
if (factoryName == null)
factory = new DefaultSerializerFactory();
else
factory = loadSerializerFactory(factoryName);
CompressionStrategy valueCompressionStrategy = null;
if (targetDef.getValueSerializer().hasCompression()) {
valueCompressionStrategy = new CompressionStrategyFactory().get(targetDef.getValueSerializer().getCompression());
}
View<?, ?, ?, ?> view = loadTransformation(def.getValueTransformation());
return new ViewStorageEngine(name, target, factory.getSerializer(def.getValueSerializer()), def.getTransformsSerializer() != null ? factory.getSerializer(def.getTransformsSerializer()) : null, factory.getSerializer(targetDef.getKeySerializer()), factory.getSerializer(targetDef.getValueSerializer()), valueCompressionStrategy, view);
}
use of voldemort.store.compress.CompressionStrategyFactory in project voldemort by voldemort.
the class StreamingClientTest method verifyKeysExist.
/*
* Checks if each node has the keys it is reponsible for returns false
* otherwise
*/
public boolean verifyKeysExist(int nodeIdToVerifyOn) {
RoutingStrategyFactory factory = new RoutingStrategyFactory();
RoutingStrategy storeRoutingStrategy = factory.updateRoutingStrategy(storeDef, adminClient.getAdminClientCluster());
HashMap<Integer, ArrayList<String>> expectedNodeIdToKeys;
expectedNodeIdToKeys = new HashMap();
Collection<Node> nodesInCluster = adminClient.getAdminClientCluster().getNodes();
for (Node node : nodesInCluster) {
ArrayList<String> keysForNode = new ArrayList();
expectedNodeIdToKeys.put(node.getId(), keysForNode);
}
for (int i = 0; i < NUM_KEYS_1; i++) {
String key = i + "";
String value = key;
List<Node> nodeList = storeRoutingStrategy.routeRequest(key.getBytes());
for (Node node : nodeList) {
ArrayList<String> keysForNode = expectedNodeIdToKeys.get(node.getId());
keysForNode.add(key);
}
}
ArrayList<String> fetchedKeysForNode = new ArrayList();
for (Node node : nodesInCluster) {
List<Integer> partitionIdList = Lists.newArrayList();
partitionIdList.addAll(node.getPartitionIds());
Iterator<ByteArray> keyIteratorRef = null;
keyIteratorRef = adminClient.bulkFetchOps.fetchKeys(node.getId(), TEST_STORE_NAME, partitionIdList, null, false);
final SerializerDefinition serializerDef = storeDef.getKeySerializer();
final SerializerFactory serializerFactory = new DefaultSerializerFactory();
@SuppressWarnings("unchecked") final Serializer<Object> serializer = (Serializer<Object>) serializerFactory.getSerializer(serializerDef);
final CompressionStrategy keysCompressionStrategy;
if (serializerDef != null && serializerDef.hasCompression()) {
keysCompressionStrategy = new CompressionStrategyFactory().get(serializerDef.getCompression());
} else {
keysCompressionStrategy = null;
}
final Iterator<ByteArray> keyIterator = keyIteratorRef;
while (keyIterator.hasNext()) {
byte[] keyBytes = keyIterator.next().get();
try {
Object keyObject = serializer.toObject((null == keysCompressionStrategy) ? keyBytes : keysCompressionStrategy.inflate(keyBytes));
fetchedKeysForNode.add((String) keyObject);
} catch (IOException e) {
e.printStackTrace();
}
}
}
ArrayList<String> keysForNode = expectedNodeIdToKeys.get(nodeIdToVerifyOn);
if (!fetchedKeysForNode.containsAll(keysForNode))
return false;
else
return true;
}
use of voldemort.store.compress.CompressionStrategyFactory in project voldemort by voldemort.
the class BuildAndPushMapper method configure.
@Override
@SuppressWarnings("unchecked")
public void configure(JobConf conf) {
super.configure(conf);
md5er = ByteUtils.getDigest("md5");
keySerializerDefinition = getStoreDef().getKeySerializer();
valueSerializerDefinition = getStoreDef().getValueSerializer();
keyCompressor = new CompressionStrategyFactory().get(keySerializerDefinition.getCompression());
valueCompressor = new CompressionStrategyFactory().get(valueSerializerDefinition.getCompression());
routingStrategy = new ConsistentRoutingStrategy(getCluster(), getStoreDef().getReplicationFactor());
}
Aggregations