Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1094

GridFS can update file metadata incorrectly.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • 2.11.3
    • GridFS
    • None

    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);
          }
       
      }

      Attachments

        Activity

          People

            ross@mongodb.com Ross Lawley
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: