[ 
https://issues.apache.org/jira/browse/HADOOP-558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12486705
 ] 

David Bowen commented on HADOOP-558:
------------------------------------


A couple more points:

(1) VersionMapWritable interface extends Writable, so implementing classes need 
to implement readFields without the VersionMap argument.  A possible way to 
handle this is with a ThreadLocal.  E.g. have a static method 
VersionMap.setThreadLocal(VersionMap v) which attaches a VersionMap to the 
current thread for use in subsequent deserialization of VersionMapWritables.

(2) The use of DataInput and DataOutput implies that the external format of 
VersionMaps is binary. It might be preferable to have it be human-readable.  
E.g. they could be Properties files with lines of the form <class name>=<int>.







> Adding versioning to Writable classes
> -------------------------------------
>
>                 Key: HADOOP-558
>                 URL: https://issues.apache.org/jira/browse/HADOOP-558
>             Project: Hadoop
>          Issue Type: Improvement
>          Components: io
>    Affects Versions: 0.6.2
>            Reporter: Owen O'Malley
>         Assigned To: David Bowen
>
> We currently don't have a way to support versioned Writables, which among 
> other problems means that it is very difficult to change the serialization of 
> any types. (A recent example is that we can't change any of the Writables 
> that currently use UTF8.writeString to use Text.writeString with out breaking 
> everything.) Just changing the file version doesn't work because you can't 
> read the old versions.
> Therefore, I propose adding a new interface:
> public interface VersionMapWritable extends Writable {
>   /**
>    * Destructively read into this object from in based on the version map.
>    * @param versionMap a map from each class to its version in the DataInput 
> (version 0 classes are omitted)
>    */
>   public void readFields(DataInput in, Map<Class<VersionMapWritable>, int> 
> versionMap) throws IOException;
>   /**
>    * Classes with non-zero versions should register themselves in static 
> blocks.
>    */
>   public static void registerCurrentVersion(Class<VersionMapWritable> class, 
> int version) {...}
>   /**
>    * If a version map includes the parent type, always include the child type 
> as well.
>    */
>   public static void addDependence(Class<VersionMapWritable> parent, 
> Class<VersionMapWritable> child) { ... }
>   /**
>    * Build a version map for a given list of classes, including any dependent 
> types.
>    */
>   public static Map<Class<VersionMapWritable>, int> 
>               buildVersionMap(Set<Class<VersionMapWritable>> classes) {...}
>   /**
>    * Add the types in the parameter/result types to the list of classes.
>    * Recursively adds the field types for any new types that are added to the 
> set.
>    */
>   public static void addMethodTypes(Set<Class<VersionMapWritable>> result, 
>                      Class<VersionedProtocol> protocol) {...}
>   /**
>    * Add the non-transient fields to the list of classes.
>    */
>   public static void addFieldTypes(Set<Class<VersionMapWritable>> result, 
> Class<Writable> writable) {...}
>   public static Map<Class<VersionMapWritable>, int> readVersionMap(DataInput 
> in) throws IOException { ... }
>   public static void writeVersionMap(DataOutput out, 
>                   Map<Class<VersionMapWritable> versionMap) throws 
> IOException {...}
> }
> VersionedWritable, which stored a version byte within each object, will be 
> depriciated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to