-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.11.3
-
Component/s: GridFS
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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); } }