Skip to content

Commit 150e08e

Browse files
trnljyemin
authored andcommitted
JAVA-851: disable check for upper bound on chunkSize in GridFS
1 parent 09b38d9 commit 150e08e

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/main/com/mongodb/gridfs/GridFS.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ public class GridFS {
5454

5555
/**
5656
* file's max chunk size
57+
*
58+
* @deprecated You can calculate max chunkSize with
59+
* a similar formula {@link com.mongodb.MongoClient#getMaxBsonObjectSize()} - 500*1000.
60+
* Please ensure that you left enough space for metadata (500kb is enough).
5761
*/
58-
public static final long MAX_CHUNKSIZE = (long)(3.5 * 1000 * 1000);
62+
@Deprecated
63+
public static final long MAX_CHUNKSIZE = (long) (3.5 * 1000 * 1000);
5964

6065
/**
6166
* bucket to use for the collection namespaces

src/main/com/mongodb/gridfs/GridFSInputFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ public int saveChunks( long chunkSize ) throws IOException {
215215
if ( _savedChunks )
216216
throw new MongoException( "chunks already saved!" );
217217

218-
if ( chunkSize <= 0 || chunkSize > GridFS.MAX_CHUNKSIZE ) {
219-
throw new MongoException( "chunkSize must be greater than zero and less than or equal to GridFS.MAX_CHUNKSIZE");
218+
if ( chunkSize <= 0) {
219+
throw new MongoException("chunkSize must be greater than zero");
220220
}
221221

222222
if ( _chunkSize != chunkSize ) {

src/test/com/mongodb/gridfs/GridFSTest.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.InputStream;
2929
import java.io.OutputStream;
3030
import java.util.List;
31+
import java.util.Random;
3132

3233
public class GridFSTest extends TestCase {
3334

@@ -146,7 +147,7 @@ public void testMetadata()
146147

147148
@Test(groups = {"basic"})
148149
public void testBadChunkSize() throws Exception {
149-
int fileSize = (int)(2 * GridFS.MAX_CHUNKSIZE);
150+
int fileSize = 2 * _db.getMongo().getMaxBsonObjectSize();
150151
if (fileSize > 1024 * 1024 * 1024)
151152
//If this is the case, GridFS is probably obsolete...
152153
fileSize = 10 * 1024 * 1024;
@@ -165,16 +166,8 @@ public void testBadChunkSize() throws Exception {
165166
assertTrue(mongoExc.toString().contains("chunkSize must be greater than zero"));
166167
}
167168

168-
try{
169-
inputFile.save(GridFS.MAX_CHUNKSIZE + 10);
170-
fail("should have received an exception about a chunk size being too big");
171-
}catch(MongoException mongoExc) {
172-
//also expecting it to complain about the chunkSize
173-
assertTrue(mongoExc.toString().contains("and less than or equal to GridFS.MAX_CHUNKSIZE"));
174-
}
175-
176169
//For good measure let's save and restore the bytes
177-
inputFile.save(GridFS.MAX_CHUNKSIZE / 2);
170+
inputFile.save(_db.getMongo().getMaxBsonObjectSize() - 500 * 1000);
178171
GridFSDBFile savedFile = _fs.findOne(new BasicDBObject("_id", inputFile.getId()));
179172
ByteArrayOutputStream savedFileByteStream = new ByteArrayOutputStream();
180173
savedFile.writeTo(savedFileByteStream);

0 commit comments

Comments
 (0)