Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-5744

Cleanup AbstractType/TypeSerializer classes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Low
    • Resolution: Fixed
    • 2.0 beta 2
    • None
    • None

    Description

      This is somewhat a followup to CASSANDRA-4495. I'm attaching 3 patches that do the following:

      1. It inverse the serialize and deserialize method in TypeSerializer. Sorry I didn't saw that earlier, but calling serialize the method that takes a byte array to produce an object feels wrong to me (and wikipedia seems to agree with me that this should the other way around: http://en.wikipedia.org/wiki/Serialization )
      2. For historical reasons (which imo were somewhat of a mistake in the first place but that's another story), we accept an empty byte buffer as a valid value for any type. When I say "valid", I mean that validate() never throw (except for InetAddressType as it happens, but that's more of an inconsistency that the patch fixes). However, for some reason most deserialize methods were just throwing a random exception if an empty byte buffer. So I think we should be coherent here, if validate() pass, you should be able to deserialize the value alright, and the 2nd patch make sure of that (return null when there was nothing else making sense).
      3. The patch removes a bunch of code duplication. Namely, AbstracType has a getSerializer() method that return the corresponding TypeSerializer, but despite that, every AbstractType subclass was redefining its compose, decompose and validate that were just calling the corresponding method in their deserializer. So the patch makes those method concrete in AbstractType and remove the code duplication all over the place. Furthermore, TypeSerializer had a getString(ByteBuffer) and a toString(T value) methods. But since we also have a deserialize(ByteBuffer), the former getString() is really not useful as it's just toString(deserialize()). So the patch also remove that method.

      Attachments

        1. 0001-Inverse-serialize-deserialize.txt
          36 kB
          Sylvain Lebresne
        2. 0001-Inverse-serialize-deserialize-v2.patch
          37 kB
          Carl Yeksigian
        3. 0002-Make-sure-deseriaze-don-t-throw-on-empty-BB.txt
          9 kB
          Sylvain Lebresne
        4. 0003-Avoid-duplicating-code.txt
          58 kB
          Sylvain Lebresne
        5. 0003-Avoid-duplicating-code-v2.patch
          57 kB
          Carl Yeksigian

        Activity

          People

            slebresne Sylvain Lebresne
            slebresne Sylvain Lebresne
            Sylvain Lebresne
            Carl Yeksigian
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: