Navigation Menu

Skip to content

Commit

Permalink
Refactored checkcompatibility into Validator class as a static method
Browse files Browse the repository at this point in the history
  • Loading branch information
abh1nay committed Oct 11, 2012
1 parent 46f42fe commit f66c20d
Show file tree
Hide file tree
Showing 4 changed files with 781 additions and 828 deletions.
3 changes: 2 additions & 1 deletion config/single_node_cluster/config/stores.xml
Expand Up @@ -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>
62 changes: 2 additions & 60 deletions src/java/voldemort/VoldemortAdminTool.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

}
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f66c20d

Please sign in to comment.