Skip to content

Commit

Permalink
Merge branch 'server-transforms' into server-transforms-network
Browse files Browse the repository at this point in the history
  • Loading branch information
afeinberg committed Jun 24, 2010
2 parents 4dd8512 + 313e0da commit 51b7dc2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/java/voldemort/client/MockStoreClientFactory.java
Expand Up @@ -31,6 +31,7 @@
import voldemort.store.serialized.SerializingStore;
import voldemort.store.versioned.InconsistencyResolvingStore;
import voldemort.store.versioned.VersionIncrementingStore;
import voldemort.store.views.ViewStorageConfiguration;
import voldemort.store.views.ViewStorageEngine;
import voldemort.utils.SystemTime;
import voldemort.utils.Time;
Expand Down Expand Up @@ -184,7 +185,7 @@ private <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName) {
this.valueSerializer != null ? this.valueSerializer
: serializerFactory.getSerializer(targetDef.getValueSerializer()),
null,
storeDef.getValueTransformation());
ViewStorageConfiguration.loadTransformation(storeDef.getValueTransformation()));
}

Store store = new VersionIncrementingStore(engine, nodeId, time);
Expand Down
7 changes: 3 additions & 4 deletions src/java/voldemort/store/StoreDefinition.java
Expand Up @@ -20,7 +20,6 @@

import voldemort.client.RoutingTier;
import voldemort.serialization.SerializerDefinition;
import voldemort.store.views.View;
import voldemort.utils.Utils;

import com.google.common.base.Objects;
Expand Down Expand Up @@ -49,7 +48,7 @@ public class StoreDefinition implements Serializable {
private final Integer retentionScanThrottleRate;
private final String routingStrategyType;
private final String viewOf;
private final View<?, ?, ?, ?> valueTransformation;
private final String valueTransformation;
private final String serializerFactory;

public StoreDefinition(String name,
Expand All @@ -65,7 +64,7 @@ public StoreDefinition(String name,
Integer preferredWrites,
int requiredWrites,
String viewOfStore,
View<?, ?, ?, ?> valTrans,
String valTrans,
Integer retentionDays,
Integer retentionThrottleRate,
String factory) {
Expand Down Expand Up @@ -205,7 +204,7 @@ public boolean hasValueTransformation() {
return this.valueTransformation != null;
}

public View<?, ?, ?, ?> getValueTransformation() {
public String getValueTransformation() {
return valueTransformation;
}

Expand Down
7 changes: 3 additions & 4 deletions src/java/voldemort/store/StoreDefinitionBuilder.java
Expand Up @@ -2,7 +2,6 @@

import voldemort.client.RoutingTier;
import voldemort.serialization.SerializerDefinition;
import voldemort.store.views.View;
import voldemort.utils.Utils;

/**
Expand All @@ -28,7 +27,7 @@ public class StoreDefinitionBuilder {
private Integer retentionScanThrottleRate = null;
private String routingStrategyType = null;
private String viewOf = null;
private View<?, ?, ?, ?> view = null;
private String view = null;
private String serializerFactory = null;

public String getName() {
Expand Down Expand Up @@ -182,11 +181,11 @@ public StoreDefinitionBuilder setViewOf(String viewOf) {
return this;
}

public View<?, ?, ?, ?> getView() {
public String getView() {
return view;
}

public StoreDefinitionBuilder setView(View<?, ?, ?, ?> valueTransformation) {
public StoreDefinitionBuilder setView(String valueTransformation) {
this.view = valueTransformation;
return this;
}
Expand Down
18 changes: 14 additions & 4 deletions src/java/voldemort/store/views/ViewStorageConfiguration.java
Expand Up @@ -55,6 +55,10 @@ public StorageEngine<ByteArray, byte[], byte[]> getStore(String name) {
valueCompressionStrategy = new CompressionStrategyFactory().get(targetDef.getValueSerializer()
.getCompression());
}

/* instantiate the view class */
View<?, ?, ?, ?> view = loadTransformation(def.getValueTransformation());

return new ViewStorageEngine(name,
target,
factory.getSerializer(def.getValueSerializer()),
Expand All @@ -63,18 +67,24 @@ public StorageEngine<ByteArray, byte[], byte[]> getStore(String name) {
factory.getSerializer(targetDef.getKeySerializer()),
factory.getSerializer(targetDef.getValueSerializer()),
valueCompressionStrategy,
def.getValueTransformation());
view);
}

public String getType() {
return TYPE_NAME;
}

private SerializerFactory loadSerializerFactory(String className) {
public static SerializerFactory loadSerializerFactory(String className) {
if(className == null)
return null;
Class<?> transClass = ReflectUtils.loadClass(className.trim());
return (SerializerFactory) ReflectUtils.callConstructor(transClass, new Object[] {});
Class<?> factoryClass = ReflectUtils.loadClass(className.trim());
return (SerializerFactory) ReflectUtils.callConstructor(factoryClass, new Object[] {});
}

public static View<?, ?, ?, ?> loadTransformation(String className) {
if(className == null)
return null;
Class<?> viewClass = ReflectUtils.loadClass(className.trim());
return (View<?, ?, ?, ?>) ReflectUtils.callConstructor(viewClass, new Object[] {});
}
}
19 changes: 4 additions & 15 deletions src/java/voldemort/xml/StoreDefinitionsMapper.java
Expand Up @@ -48,9 +48,7 @@
import voldemort.store.StoreDefinition;
import voldemort.store.StoreDefinitionBuilder;
import voldemort.store.StoreUtils;
import voldemort.store.views.View;
import voldemort.store.views.ViewStorageConfiguration;
import voldemort.utils.ReflectUtils;

/**
* Parses a stores.xml file
Expand Down Expand Up @@ -236,8 +234,8 @@ private StoreDefinition readView(Element store, List<StoreDefinition> stores) {
if(store.getChild(STORE_ROUTING_STRATEGY) != null)
policy = RoutingTier.fromDisplay(store.getChildText(STORE_ROUTING_STRATEGY));

// get transformations
View<?, ?, ?, ?> valTrans = loadTransformation(store.getChildText(VIEW_TRANS_ELMT));
// get view class name
String viewClass = store.getChildText(VIEW_TRANS_ELMT);

return new StoreDefinitionBuilder().setName(name)
.setViewOf(targetName)
Expand All @@ -252,18 +250,11 @@ private StoreDefinition readView(Element store, List<StoreDefinition> stores) {
.setRequiredReads(requiredReads)
.setPreferredWrites(preferredWrites)
.setRequiredWrites(requiredWrites)
.setView(valTrans)
.setView(viewClass)
.setSerializerFactory(viewSerializerFactoryName)
.build();
}

private View<?, ?, ?, ?> loadTransformation(String className) {
if(className == null)
return null;
Class<?> transClass = ReflectUtils.loadClass(className.trim());
return (View<?, ?, ?, ?>) ReflectUtils.callConstructor(transClass, new Object[] {});
}

private SerializerDefinition readSerializer(Element elmt) {
String name = elmt.getChild(STORE_SERIALIZATION_TYPE_ELMT).getText();
boolean hasVersion = true;
Expand Down Expand Up @@ -355,9 +346,7 @@ private Element viewToElement(StoreDefinition storeDefinition) {
if(storeDefinition.getValueTransformation() == null)
throw new MappingException("View " + storeDefinition.getName()
+ " has no defined transformation class.");
store.addContent(new Element(VIEW_TRANS_ELMT).setText(storeDefinition.getValueTransformation()
.getClass()
.getName()));
store.addContent(new Element(VIEW_TRANS_ELMT).setText(storeDefinition.getValueTransformation()));
store.addContent(new Element(STORE_ROUTING_TIER_ELMT).setText(storeDefinition.getRoutingPolicy()
.toDisplay()));
if(storeDefinition.hasPreferredReads())
Expand Down

0 comments on commit 51b7dc2

Please sign in to comment.