Skip to content

Commit cecd6ec

Browse files
committed
DOCSP-35922: csot - gridfs (#683)
* DOCSP-35922: csot - gridfs * cross links * JS small fix (cherry picked from commit 5c9b19a)
1 parent 14670dc commit cecd6ec

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

source/connection/specify-connection-options/csot.txt

+31
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,36 @@ and prints the ``name`` field value for each document:
303303
:dedent:
304304
:emphasize-lines: 3
305305

306+
.. _java-csot-gridfs:
307+
308+
GridFS
309+
------
310+
311+
You can set a timeout option for :ref:`GridFS <java-crud-gridfs>`
312+
operations when instantiating a ``GridFSBucket`` by using the
313+
``withTimeout()`` method. This timeout applies to all operations
314+
performed on the bucket, such as uploading and downloading data. If you
315+
do not set a timeout, the ``GridFSBucket`` instance inherits the timeout
316+
setting from the ``MongoDatabase`` it is created with.
317+
318+
The following code demonstrates how to set a timeout when instantiating
319+
a ``GridFSBucket``:
320+
321+
.. literalinclude:: /includes/connect/CsotExample.java
322+
:language: java
323+
:start-after: start-gridfsbucket-timeout
324+
:end-before: end-gridfsbucket-timeout
325+
:dedent:
326+
:emphasize-lines: 3
327+
328+
.. important:: InputStream Timeout Support
329+
330+
When you call the ``uploadFromStream()`` method on a ``GridFSBucket``
331+
that has an operation timeout, timeout breaches might occur because
332+
the ``InputStream`` class lacks inherent read timeout support. This might
333+
extend the operation beyond the specified timeout limit, causing a
334+
timeout exception.
335+
306336
API Documentation
307337
-----------------
308338

@@ -317,3 +347,4 @@ API documentation:
317347
- `ClientEncryptionSettings.Builder.timeout() <{+core-api+}/ClientEncryptionSettings.Builder.html#timeout(long,java.util.concurrent.TimeUnit)>`__
318348
- `FindIterable.timeoutMode() <{+driver-api+}/FindIterable.html#timeoutMode(com.mongodb.client.cursor.TimeoutMode)>`__
319349
- `TimeoutMode <{+core-api+}/client/cursor/TimeoutMode.html>`__
350+
- `GridFSBucket.withTimeout() <{+driver-api+}/gridfs/GridFSBucket.html#withTimeout(long,java.util.concurrent.TimeUnit)>`__

source/crud/gridfs.txt

+29-21
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,35 @@ Overview
2222
--------
2323

2424
In this guide, you can learn how to store and retrieve large files in
25-
MongoDB using **GridFS**. GridFS is a specification implemented by the
26-
driver that describes how to split files into chunks when storing them
25+
MongoDB by using **GridFS**. GridFS is a specification implemented by the
26+
{+driver-short+} that describes how to split files into chunks when storing them
2727
and reassemble them when retrieving them. The driver implementation of
2828
GridFS is an abstraction that manages the operations and organization of
29-
the file storage.
29+
the file storage in your Java application.
3030

31-
You should use GridFS if the size of your files exceed the BSON document
32-
size limit of 16MB. For more detailed information on whether GridFS is
33-
suitable for your use case, see the :manual:`GridFS server manual page </core/gridfs>`.
31+
Use GridFS if the size of your files exceed the BSON document
32+
size limit of 16MB. To learn more about whether GridFS is
33+
suitable for your use case, see the :manual:`GridFS </core/gridfs>`
34+
reference in the {+mdb-server+} manual.
3435

35-
See the following sections that describe GridFS operations and how to
36-
perform them:
36+
The following sections describe GridFS operations and demonstrate how to
37+
perform these actions with the driver:
3738

38-
- :ref:`Create a GridFS bucket <gridfs-create-bucket>`
39-
- :ref:`Store Files <gridfs-store-files>`
40-
- :ref:`Retrieve File Information <gridfs-retrieve-file-info>`
41-
- :ref:`Download Files <gridfs-download-files>`
42-
- :ref:`Rename Files <gridfs-rename-files>`
43-
- :ref:`Delete Files <gridfs-delete-files>`
44-
- :ref:`Delete a GridFS bucket <gridfs-delete-bucket>`
39+
- :ref:`gridfs-create-bucket`
40+
- :ref:`gridfs-store-files`
41+
- :ref:`gridfs-retrieve-file-info`
42+
- :ref:`gridfs-download-files`
43+
- :ref:`gridfs-rename-files`
44+
- :ref:`gridfs-delete-files`
45+
- :ref:`gridfs-delete-bucket`
46+
47+
.. tip:: Timeout Setting
48+
49+
You can use the client-side operation timeout (CSOT) setting to limit
50+
the amount of time in which the server can finish GridFS operations.
51+
To learn more about using this setting with GridFS, see the
52+
:ref:`java-csot-gridfs` section of the Limit Server Execution Time
53+
guide.
4554

4655
How GridFS Works
4756
----------------
@@ -419,11 +428,10 @@ For more information about this method, see the
419428
`drop() <{+driver-api+}/gridfs/GridFSBucket.html#drop()>`__
420429
API Documentation.
421430

422-
Additional Resources
423-
--------------------
431+
Additional Information
432+
----------------------
424433

425434
- `MongoDB GridFS specification <https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst>`__
426-
- Runnable example
427-
`GridFSTour.java <https://github.com/mongodb/mongo-java-driver/blob/master/driver-sync/src/examples/gridfs/GridFSTour.java>`__
428-
from the MongoDB Java Driver repository.
429-
435+
- Runnable file `GridFSTour.java
436+
<https://github.com/mongodb/mongo-java-driver/blob/master/driver-sync/src/examples/gridfs/GridFSTour.java>`__
437+
from the driver source repository

source/includes/connect/CsotExample.java

+18
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,22 @@ private void cursorTimeout(){
133133
}
134134

135135
}
136+
137+
private void gridFSTimeout(){
138+
MongoClientSettings settings = MongoClientSettings.builder()
139+
.applyConnectionString(new ConnectionString("<connection string>"))
140+
.build();
141+
142+
try (MongoClient mongoClient = MongoClients.create(settings)) {
143+
MongoDatabase database = mongoClient.getDatabase("db");
144+
145+
// start-gridfsbucket-timeout
146+
GridFSBucket gridFSBucket = GridFSBuckets
147+
.create(database)
148+
.withTimeout(200L, MILLISECONDS);
149+
// end-gridfsbucket-timeout
150+
}
151+
152+
}
153+
136154
}

0 commit comments

Comments
 (0)