Skip to content

Commit 789b8ab

Browse files
committed
DOCSP-35922: csot - gridfs (#683)
* DOCSP-35922: csot - gridfs * cross links * JS small fix (cherry picked from commit 5c9b19a) (cherry picked from commit b17d3cc)
1 parent 3b2f2fa commit 789b8ab

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

source/connection/csot.txt

Lines changed: 31 additions & 0 deletions
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/fundamentals/code-snippets/connection/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() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ClientEncryptionSettings.Builder.html#timeout(long,java.util.concurrent.TimeUnit)>`__
318348
- `FindIterable.timeoutMode() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/FindIterable.html#timeoutMode(com.mongodb.client.cursor.TimeoutMode)>`__
319349
- `TimeoutMode <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/cursor/TimeoutMode.html>`__
350+
- `GridFSBucket.withTimeout() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/gridfs/GridFSBucket.html#withTimeout(long,java.util.concurrent.TimeUnit)>`__

source/crud/gridfs.txt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,35 @@ Overview
2323
--------
2424

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

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

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

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

4756
How GridFS Works
4857
----------------
@@ -420,11 +429,10 @@ For more information about this method, see the
420429
`drop() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/gridfs/GridFSBucket.html#drop()>`__
421430
API Documentation.
422431

423-
Additional Resources
424-
--------------------
432+
Additional Information
433+
----------------------
425434

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

source/includes/fundamentals/code-snippets/connection/CsotExample.java

Lines changed: 18 additions & 0 deletions
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)