You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Scott Carey (JIRA)" <ji...@apache.org> on 2010/01/27 02:26:34 UTC

[jira] Created: (AVRO-380) Avro Container File format change: add block size to block descriptor

Avro Container File format change:  add block size to block descriptor
----------------------------------------------------------------------

                 Key: AVRO-380
                 URL: https://issues.apache.org/jira/browse/AVRO-380
             Project: Avro
          Issue Type: Improvement
          Components: doc, java, spec
    Affects Versions: 1.3.0
            Reporter: Scott Carey
             Fix For: 1.3.0


The new file format in AVRO-160 limits a few use cases that I have found to be important.

A block currently contains a count of the number of records, the block data, and a sync marker.  
This change would add the block size, in bytes, along side the number of records.   

This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Scott Carey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12805310#action_12805310 ] 

Scott Carey commented on AVRO-380:
----------------------------------

I will work on this patch later this week.  However, I can only contribute the Java and documentation changes.

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Updated: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Scott Carey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Scott Carey updated AVRO-380:
-----------------------------

    Attachment: AVRO-380.patch

Updated patch:

* Block size and block record count are longs in both the format and the code.   This reader implementation will throw an exception if a block size is larger than Integer.MAX_VALUE.
* When a block is read from the underlying stream, the reader checks that the number of bytes read is equal to the block size (that it is not truncated).
* When a block is finished (blockCount records read), the reader checks that all bytes have been read.  This is done by forcing an EOFException -- which is ugly and I plan to change at a later time as an optimization along with other planned changes.
* DeflateCodec now writes and reads RFC-1951 'raw' deflate, in line with the documentation.


> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch, AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Updated: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Philip Zeyliger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philip Zeyliger updated AVRO-380:
---------------------------------

      Resolution: Fixed
        Assignee: Scott Carey
    Hadoop Flags: [Incompatible change, Reviewed]
          Status: Resolved  (was: Patch Available)

I've committed this.  Thanks, Scott!  (I think this is your first code contribution to Avro; excellent!)

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>            Assignee: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch, AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Doug Cutting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806078#action_12806078 ] 

Doug Cutting commented on AVRO-380:
-----------------------------------

I am okay with the implementation not working for blocks larger than 2GB, but the format should permit larger blocks.

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Scott Carey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806067#action_12806067 ] 

Scott Carey commented on AVRO-380:
----------------------------------

bq. If you set syncInterval to Integer.MAX_VALUE, I bet things will break, because we allocate a ByteArrayOutputStream of 2*Integer.MAX_VALUE, which is going to overflow.

We probably will want to allocate ByteArrayOutputStream to MIN( estimated_need, Integer.MAX_VALUE).  Java can't create arrays with length larger than Integer.MAX_VALUE anyway.  

In order to support uncompressed blocks larger than that, we would need significant changed -- outside the scope of this and perhaps never needed.

I think we might want to limit syncInterval to 1GB though.  If someone tried to set it to near 2GB, and a value was big enough to take the block from just under this size to over 2GB it would break.

Since this format requires both the size of the block and the count of items before writing, it is probably not the best format for very large blocks.  One would want to stream that volume of data to disk and not buffer it, which means the count and size are unknown when first written.  This can only be done if the count and size is removed, or if the count and size is a fixed size field and the file supports random writes so that those fields can be written after the block.

bq. I think it's your responsibility here to check that block.length bytes were actually read. I used LenghtLimitedInputStream for that. You could certainly also read into the buffer until you've read the number of bytes you expect to. I think this also introduces an extra copy for the null codec, but, as you say, there are more things that could be done for performance here.

Yeah, I was trying to not copy too much, but the best way to do that is to complete the buffering performance and api changes to BinaryEncoder/BinaryDecoder.  I'll add the extra checks.


> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Doug Cutting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806039#action_12806039 ] 

Doug Cutting commented on AVRO-380:
-----------------------------------

I would prefer we use longs instead of ints for both the count and the block size to better future-proof the format.  2GB isn't as big as it used to be and it's only getting smaller.  I don't think there are significant performance benefits to using int over long here.

Other than that, +1.


> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Updated: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Scott Carey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Scott Carey updated AVRO-380:
-----------------------------

    Attachment: AVRO-380.patch

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Philip Zeyliger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806025#action_12806025 ] 

Philip Zeyliger commented on AVRO-380:
--------------------------------------

bq. setSyncInterval()

If you set syncInterval to Integer.MAX_VALUE, I bet things will break, because we allocate a ByteArrayOutputStream of 2*Integer.MAX_VALUE, which is going to overflow.

If there's a goal of supporting individual values larger than 2GB (I don't know that such a goal is useful), then the byte counts need to be a long.  I'm fine with this not being a goal, though.

bq. DataFileStream: in.read(block);

I think it's your responsibility here to check that block.length bytes were actually read.  I used LenghtLimitedInputStream for that.  You could certainly also read into the buffer until you've read the number of bytes you expect to.  I think this also introduces an extra copy for the null codec, but, as you say, there are more things that could be done for performance here.

bq. There is also either a flaw in the Deflate Codec documentation, or the Deflate Codec code.

Hmm.  D'oh, I think you're right.  I think we should do RFC-1951 (for "deflate"; if we called it "zlib"...).  I think this just means changing two 'false''s to 'true''s.  Let's do it in this patch.
Hm.  I think you're right, which is a bit embarassing

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Scott Carey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806072#action_12806072 ] 

Scott Carey commented on AVRO-380:
----------------------------------

bq. I would prefer we use longs instead of ints for both the count and the block size to better future-proof the format. 2GB isn't as big as it used to be and it's only getting smaller. I don't think there are significant performance benefits to using int over long here. 

Sure. I had assumed that we would never support blocks larger than 2GB because the file format is not designed for large blocks (since the size and count have to be known in advance for appends-only writes).  But it is trivial to make it use a long instead just in case, and as you say its not a performance concern.  

The code will break however if the size ever gets larger than an int, and it is not possible for the count to get larger than the size.  Is it worth unit testing those corner conditions?  I don't think it is.  I'll add javadoc that makes it clear that very large blocks are not recommended.


> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Philip Zeyliger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806026#action_12806026 ] 

Philip Zeyliger commented on AVRO-380:
--------------------------------------

Meant to add: overall approach looks good.

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Updated: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Scott Carey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Scott Carey updated AVRO-380:
-----------------------------

    Status: Patch Available  (was: Open)

This patch adds the block size to the block format.  

Each block then has:
blockCount -- the number of records in the block
blockSize -- the size in bytes of the block data, after compression
bytes -- blockSize bytes of data encoded by the file's codec
sync -- 16 byte sync marker

The file will fail to read a block if the block size or count does not match the data, or if a sync marker is wrong.

This worked best by changing the Codec API.  The current deflate and null codecs are not ideal for performance, but this patch focuses on the functionality.  I'll open a performance enhancement ticket later.
The Codec API and the file reader/writer will likely also change later due to performance enhancements on the BinaryDecoder and BinaryEncoder that I plan to work on.  These enhancements are all interdependent.

There is also either a flaw in the Deflate Codec documentation, or the Deflate Codec code.  The document claims that we are using RFC-1951 (unwrapped deflate compression), but the code is writing RFC-1950 (deflate wrapped in a "ZLIB" container).
I am on the fence as to which we should use.  The right answer is probably 'whatever is easiest on all platforms'.  
If we decide on which to do I can add the fix to this patch, or we can defer to another ticket.


> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Doug Cutting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806425#action_12806425 ] 

Doug Cutting commented on AVRO-380:
-----------------------------------

+1 to the patch.

> we may be able to have a Decoder.isEof() function, to avoid the exception mess

Should we file an issue for this?  It's come up in a few contexts already as an awkward point in the API and would be nice to fix.

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch, AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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


[jira] Commented: (AVRO-380) Avro Container File format change: add block size to block descriptor

Posted by "Philip Zeyliger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/AVRO-380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806414#action_12806414 ] 

Philip Zeyliger commented on AVRO-380:
--------------------------------------

+1.

I'll commit this tomorrow, unless there's more discussion.

BTW, I agree that as we do more with the Decoder API, we may be able to have a Decoder.isEof() function, to avoid the exception mess.

> Avro Container File format change:  add block size to block descriptor
> ----------------------------------------------------------------------
>
>                 Key: AVRO-380
>                 URL: https://issues.apache.org/jira/browse/AVRO-380
>             Project: Avro
>          Issue Type: Improvement
>          Components: doc, java, spec
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-380.patch, AVRO-380.patch
>
>
> The new file format in AVRO-160 limits a few use cases that I have found to be important.
> A block currently contains a count of the number of records, the block data, and a sync marker.  
> This change would add the block size, in bytes, along side the number of records.   
> This allows efficient access to a block's data without the need to decode the data into individual Datums, which is useful for various use cases.  

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