Permalink
Browse files

Refactored checkcompatibility into Validator class as a static method

  • Loading branch information...
1 parent 46f42fe commit f66c20d8fd072e04b8de6708969f6ada0bb53f0c @abh1nay abh1nay committed Oct 1, 2012
@@ -35,4 +35,5 @@
<schema-info version="1">{"type": "record", "name": "myrec","fields": [{ "name": "original", "type": "string" }, { "name": "new-field", "type": "string", "default":"" }]}</schema-info>
</value-serializer>
</store>
- </stores>
+
+</stores>
@@ -49,9 +49,7 @@
import joptsimple.OptionParser;
import joptsimple.OptionSet;
-import org.apache.avro.Schema;
import org.apache.commons.io.FileUtils;
-import org.apache.log4j.Level;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;
@@ -66,7 +64,6 @@
import voldemort.serialization.SerializerFactory;
import voldemort.serialization.StringSerializer;
import voldemort.serialization.avro.versioned.SchemaEvolutionValidator;
-import voldemort.serialization.avro.versioned.SchemaEvolutionValidator.Message;
import voldemort.server.rebalance.RebalancerState;
import voldemort.store.StoreDefinition;
import voldemort.store.compress.CompressionStrategy;
@@ -493,13 +490,13 @@ public static void main(String[] args) throws Exception {
if(keySerDef.getName().equals(AVRO_GENERIC_VERSIONED_TYPE_NAME)) {
- checkSchemaCompatibility(keySerDef);
+ SchemaEvolutionValidator.checkSchemaCompatibility(keySerDef);
}
if(valueSerDef.getName().equals(AVRO_GENERIC_VERSIONED_TYPE_NAME)) {
- checkSchemaCompatibility(valueSerDef);
+ SchemaEvolutionValidator.checkSchemaCompatibility(valueSerDef);
}
}
@@ -661,61 +658,6 @@ private static void synchronizeMetadataVersion(AdminClient adminClient, int base
}
- public static void checkSchemaCompatibility(SerializerDefinition serDef) throws Exception {
-
- Map<Integer, String> schemaVersions = serDef.getAllSchemaInfoVersions();
-
- Iterator schemaIterator = schemaVersions.entrySet().iterator();
-
- Schema firstSchema = null;
- Schema secondSchema = null;
-
- String firstSchemaStr;
- String secondSchemaStr;
-
- if(!schemaIterator.hasNext())
- throw new VoldemortException("No schema specified");
-
- Map.Entry schemaPair = (Map.Entry) schemaIterator.next();
-
- firstSchemaStr = (String) schemaPair.getValue();
-
- while(schemaIterator.hasNext()) {
-
- schemaPair = (Map.Entry) schemaIterator.next();
-
- secondSchemaStr = (String) schemaPair.getValue();
- Schema oldSchema = Schema.parse(firstSchemaStr);
- Schema newSchema = Schema.parse(secondSchemaStr);
- List<Message> messages = SchemaEvolutionValidator.checkBackwardCompatability(oldSchema,
- newSchema,
- oldSchema.getName());
- Level maxLevel = Level.ALL;
- for(Message message: messages) {
- System.out.println(message.getLevel() + ": " + message.getMessage());
- if(message.getLevel().isGreaterOrEqual(maxLevel)) {
- maxLevel = message.getLevel();
- }
- }
-
- if(maxLevel.isGreaterOrEqual(Level.ERROR)) {
- System.out.println(Level.ERROR
- + ": The schema is not backward compatible. New clients will not be able to read existing data.");
- throw new VoldemortException(" The schema is not backward compatible. New clients will not be able to read existing data.");
- } else if(maxLevel.isGreaterOrEqual(Level.WARN)) {
- System.out.println(Level.WARN
- + ": The schema is partially backward compatible, but old clients will not be able to read data serialized in the new format.");
- throw new VoldemortException("The schema is partially backward compatible, but old clients will not be able to read data serialized in the new format.");
- } else {
- System.out.println(Level.INFO
- + ": The schema is backward compatible. Old and new clients will be able to read records serialized by one another.");
- }
-
- firstSchemaStr = secondSchemaStr;
-
- }
- }
-
private static void executeRollback(Integer nodeId,
String storeName,
long pushVersion,
Oops, something went wrong.

0 comments on commit f66c20d

Please sign in to comment.