You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Pavel Yaskevich (JIRA)" <ji...@apache.org> on 2011/02/25 19:52:21 UTC

[jira] Created: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
------------------------------------------------------------------------------------

                 Key: CASSANDRA-2250
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
             Project: Cassandra
          Issue Type: Sub-task
            Reporter: Pavel Yaskevich
            Assignee: Jonathan Ellis


Test to reproduce:

{code}
File tempFile = File.createTempFile("braf", null);
tempFile.deleteOnExit();

BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");

byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];

for (int i = 0; i < bigData.length; i++)
     bigData[i] = 'd';

long initialPosition = file.getFilePointer();
file.write(bigData); // writing data
assert file.getFilePointer() == initialPosition + bigData.length;
assert file.length() == initialPosition + bigData.length; // file size should equals to last position

// reading written buffer
file.seek(initialPosition);
data = new byte[bigData.length];
assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
{code}
 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999521#comment-12999521 ] 

Jonathan Ellis commented on CASSANDRA-2250:
-------------------------------------------

That's fine.

I suspect that even RAF.read will return less than requested if the underlying read system call is interrupted, for instance, but I don't care to dig deeper.  Correct code shouldn't rely on read == readFully.

> BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
> ------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2250
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: Core
>            Reporter: Pavel Yaskevich
>
> Test to reproduce:
> {code}
> File tempFile = File.createTempFile("braf", null);
> tempFile.deleteOnExit();
> BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");
> byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];
> for (int i = 0; i < bigData.length; i++)
>      bigData[i] = 'd';
> long initialPosition = file.getFilePointer();
> file.write(bigData); // writing data
> assert file.getFilePointer() == initialPosition + bigData.length;
> assert file.length() == initialPosition + bigData.length; // file size should equals to last position
> // reading written buffer
> file.seek(initialPosition);
> data = new byte[bigData.length];
> assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
> {code}
>  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

Posted by "Pavel Yaskevich (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999478#comment-12999478 ] 

Pavel Yaskevich commented on CASSANDRA-2250:
--------------------------------------------

On my opinion return less than length bytes is acceptable if file does not contain all required length, relying on DEFAULT_BUFFER_SIZE as max length makes bytes(byte[], int, int) and bytes(byte[]) useless

> BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
> ------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2250
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: Core
>            Reporter: Pavel Yaskevich
>
> Test to reproduce:
> {code}
> File tempFile = File.createTempFile("braf", null);
> tempFile.deleteOnExit();
> BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");
> byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];
> for (int i = 0; i < bigData.length; i++)
>      bigData[i] = 'd';
> long initialPosition = file.getFilePointer();
> file.write(bigData); // writing data
> assert file.getFilePointer() == initialPosition + bigData.length;
> assert file.length() == initialPosition + bigData.length; // file size should equals to last position
> // reading written buffer
> file.seek(initialPosition);
> data = new byte[bigData.length];
> assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
> {code}
>  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

Posted by "Pavel Yaskevich (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999491#comment-12999491 ] 

Pavel Yaskevich commented on CASSANDRA-2250:
--------------------------------------------

I just want to point out that in this situation using RAF and BRAF you will get different result as RAF.read(byte[]) will read data.length (expected by developer as you know how match data you wrote) even if it's not guarantied directly by documentation.

> BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
> ------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2250
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: Core
>            Reporter: Pavel Yaskevich
>
> Test to reproduce:
> {code}
> File tempFile = File.createTempFile("braf", null);
> tempFile.deleteOnExit();
> BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");
> byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];
> for (int i = 0; i < bigData.length; i++)
>      bigData[i] = 'd';
> long initialPosition = file.getFilePointer();
> file.write(bigData); // writing data
> assert file.getFilePointer() == initialPosition + bigData.length;
> assert file.length() == initialPosition + bigData.length; // file size should equals to last position
> // reading written buffer
> file.seek(initialPosition);
> data = new byte[bigData.length];
> assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
> {code}
>  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

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

Jonathan Ellis resolved CASSANDRA-2250.
---------------------------------------

       Resolution: Invalid
    Fix Version/s:     (was: 0.7.3)
         Assignee:     (was: Jonathan Ellis)

BRAF's behavior is acceptable.  RAF.read javadoc says "reads *up to* len bytes of data from this file...   returns the total number of bytes read into the buffer."

If you want "keep issuing read() calls until the requested length is satisfied" you need to use readFully().  read() is for "give me whatever you can most efficiently."

> BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
> ------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2250
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: Core
>            Reporter: Pavel Yaskevich
>
> Test to reproduce:
> {code}
> File tempFile = File.createTempFile("braf", null);
> tempFile.deleteOnExit();
> BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");
> byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];
> for (int i = 0; i < bigData.length; i++)
>      bigData[i] = 'd';
> long initialPosition = file.getFilePointer();
> file.write(bigData); // writing data
> assert file.getFilePointer() == initialPosition + bigData.length;
> assert file.length() == initialPosition + bigData.length; // file size should equals to last position
> // reading written buffer
> file.seek(initialPosition);
> data = new byte[bigData.length];
> assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
> {code}
>  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

Posted by "Pavel Yaskevich (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999523#comment-12999523 ] 

Pavel Yaskevich commented on CASSANDRA-2250:
--------------------------------------------

Gotcha, thanks!

> BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
> ------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2250
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: Core
>            Reporter: Pavel Yaskevich
>
> Test to reproduce:
> {code}
> File tempFile = File.createTempFile("braf", null);
> tempFile.deleteOnExit();
> BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");
> byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];
> for (int i = 0; i < bigData.length; i++)
>      bigData[i] = 'd';
> long initialPosition = file.getFilePointer();
> file.write(bigData); // writing data
> assert file.getFilePointer() == initialPosition + bigData.length;
> assert file.length() == initialPosition + bigData.length; // file size should equals to last position
> // reading written buffer
> file.seek(initialPosition);
> data = new byte[bigData.length];
> assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
> {code}
>  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CASSANDRA-2250) BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999482#comment-12999482 ] 

Jonathan Ellis commented on CASSANDRA-2250:
-------------------------------------------

I don't see a point in introducing non-standard differences in the contract BRAF provides vs RAF.

Again, use readFully (the DataInput api) if you want that behavior.  read is deliberately not defined that way.

> BufferedRandomAccessFile.read(byte[], int, int) method reads max DEFAULT_BUFFER_SIZE
> ------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2250
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2250
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: Core
>            Reporter: Pavel Yaskevich
>
> Test to reproduce:
> {code}
> File tempFile = File.createTempFile("braf", null);
> tempFile.deleteOnExit();
> BufferedRandomAccessFile file = new BufferedRandomAccessFile(tempFile, "rw");
> byte[] bigData = new byte[BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE + 10];
> for (int i = 0; i < bigData.length; i++)
>      bigData[i] = 'd';
> long initialPosition = file.getFilePointer();
> file.write(bigData); // writing data
> assert file.getFilePointer() == initialPosition + bigData.length;
> assert file.length() == initialPosition + bigData.length; // file size should equals to last position
> // reading written buffer
> file.seek(initialPosition);
> data = new byte[bigData.length];
> assert file.read(data) == data.length; <-- Fails (returns DEFAULT_BUFFER_SIZE as file.read(..) result)
> {code}
>  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira