[JAVA-1094] GridFS can update file metadata incorrectly. Created: 24/Jan/14  Updated: 02/Sep/15  Resolved: 02/Sep/15

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ross Lawley Assignee: Ross Lawley
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

When using GridFS without a write concern you can set a file which fails but the metadata updates - meaning its out of sync with the chunks.

This can lead other tools to return the incorrect sized fields.

public class Java1094Test extends TestCase {
 
    @Test
    public void testOutputStream() throws Exception {
 
        String name = "JAVA-1094";
        DB db = new MongoClient().getDB(name);
        db.dropDatabase();
        db.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
        GridFS fs = new GridFS(db);
 
 
        GridFSInputFile created = fs.createFile(name);
        created.setId(name);
 
        OutputStream writeStream = created.getOutputStream();
        writeStream.write("MongoDB".getBytes());
        writeStream.close();
 
        GridFSDBFile out = fs.findOne(name);
        assertEquals(out.getLength(), 7);
 
        GridFSInputFile update = fs.createFile(name);
        
        // This will trigger a Duplicate Key error but we don't acknowledge the write.
        update.setId(name);
        OutputStream updatedWriteStream = update.getOutputStream();
        updatedWriteStream.write("MongoDB Rules".getBytes());
        updatedWriteStream.close();
 
        GridFSDBFile out1 = fs.findOne(name);
        assertEquals(out1.getLength(), 7);
    }
 
}



 Comments   
Comment by Ross Lawley [ 02/Sep/15 ]

There is a new GridFS implementation JAVA-1713 that follows the new specification and doesn't allow the setting of file_id as in the example.

Using without an acknowledged write concern - carries the same risk as ordinary operations and is well known and documented behaviour.

Comment by Jeffrey Yemin [ 14/Feb/14 ]

May not make the 2.12.0 train, so removing the fix version for now.

Generated at Thu Feb 08 08:53:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.