Skip to content

Commit 025aea2

Browse files
authored
dropIndexes can stop in-progress builds and drop built indexes (#435)
* dropIndexes can stop in progress builds and built indexes * refactor into includes with replacements * fix up includes * updates behavior include * review feedback
1 parent 215d005 commit 025aea2

File tree

6 files changed

+63
-115
lines changed

6 files changed

+63
-115
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Starting in MongoDB 5.2, you can use |drop-index| to drop existing
2+
indexes on the same collection even if there is a build in progress on
3+
another index. In earlier versions, attempting to drop a different
4+
index during an in-progress index build results in a
5+
``BackgroundOperationInProgressForNamespace`` error.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Starting in MongoDB 4.4, if an index specified to |drop-index| is still
2+
building, |drop-index| attempts to stop the in-progress build. Stopping
3+
an index build has the same effect as dropping the built index. In
4+
versions earlier than MongoDB 4.4, |drop-index| returns an error if
5+
there are any index builds in progress on the collection.
6+
7+
For replica sets, run |drop-index| on the :term:`primary`.
8+
The primary stops the index build and creates an associated
9+
"abortIndexBuild" :term:`oplog` entry. Secondaries which replicate
10+
the "abortIndexBuild" oplog entry stop the in-progress index build and
11+
discard the build job. See :ref:`index-build-process` for detailed
12+
documentation on the index build process.
13+
14+
Use :dbcommand:`currentOp` to identify the index builds associated with
15+
a :dbcommand:`createIndexes` or :method:`db.collection.createIndexes()`
16+
operation. See :ref:`currentOp-cmd-index-creation` for an example.

source/reference/command/dropIndexes.txt

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ dropIndexes
7373
Behavior
7474
--------
7575

76+
.. |drop-index| replace:: :dbcommand:`dropIndexes`
77+
78+
.. include:: /includes/fact-drop-index-5.2.rst
79+
7680
Kill related queries only
7781
~~~~~~~~~~~~~~~~~~~~~~~~~
7882

@@ -105,40 +109,12 @@ instead of the index specification document.
105109

106110
.. _dropIndexes-cmd-index-builds:
107111

108-
Abort In-Progress Index Builds
109-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110-
111-
.. versionadded:: 4.4
112-
113-
If an index specified to :dbcommand:`dropIndexes` is still building,
114-
:dbcommand:`dropIndexes` attempts to abort the in-progress build.
115-
Aborting an index build has the same effect as dropping the built
116-
index. Prior to MongoDB 4.4, :dbcommand:`dropIndexes` would return an
117-
error if the collection had any in-progress index builds.
118-
119-
For replica sets, run :dbcommand:`dropIndexes` on the :term:`primary`.
120-
The primary aborts the index build and creates an associated
121-
"abortIndexBuild" oplog entry. Secondaries which replicate the
122-
"abortIndexBuild" oplog entry abort the in-progress index build and
123-
discard the build job. See :ref:`index-build-process` for detailed
124-
documentation on the index build process and the specific timing for
125-
terminating an in-progress index build.
126-
127-
The indexes specified to :dbcommand:`dropIndexes` must be the entire set
128-
of in-progress builds associated to a single :dbcommand:`createIndexes`
129-
or :method:`db.collection.createIndexes()` operation. To drop a specific
130-
index out of a set of related in-progress builds, wait until the index
131-
builds complete and specify that index to :dbcommand:`dropIndexes`.
132-
133-
For example, a :dbcommand:`createIndexes` /
134-
:method:`~db.collection.createIndexes()` operation creates three
135-
indexes. Assuming all three index builds are in-progress,
136-
:dbcommand:`dropIndexes` must specify all three indexes to abort the
137-
index builds.
138-
139-
Use :dbcommand:`currentOp` to identify the index builds associated to a
140-
:dbcommand:`createIndexes` / :method:`~db.collection.createIndexes()`
141-
operation. See :ref:`currentOp-cmd-index-creation` for an example.
112+
Stop In-Progress Index Builds
113+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114+
115+
.. |drop-index| replace:: :dbcommand:`dropIndexes`
116+
117+
.. include:: /includes/fact-stop-in-progress-index-builds.rst
142118

143119
Hidden Indexes
144120
~~~~~~~~~~~~~~

source/reference/method/db.collection.dropIndex.txt

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Definition
6464

6565
If an index specified to
6666
:method:`db.collection.dropIndex()` is still building,
67-
:method:`~db.collection.dropIndex()` attempts to abort the
68-
in-progress build. Aborting an index build has the same
67+
:method:`db.collection.dropIndex()` attempts to stop the
68+
in-progress build. Stopping an index build has the same
6969
effect as dropping the built index. Prior to MongoDB 4.4,
70-
:method:`~db.collection.dropIndex()` returned an error if
70+
:method:`db.collection.dropIndex()` returned an error if
7171
the specified index was still building. See
7272
:ref:`dropIndex-method-index-builds` for more complete
7373
documentation.
@@ -79,7 +79,9 @@ Definition
7979
Behavior
8080
--------
8181

82-
.. include:: /includes/extracts/fact-method-dropIndex-query-behavior.rst
82+
.. |drop-index| replace:: :method:`db.collection.dropIndex()`
83+
84+
.. include:: /includes/fact-drop-index-5.2.rst
8385

8486
Resource Locking
8587
~~~~~~~~~~~~~~~~
@@ -90,43 +92,12 @@ Resource Locking
9092

9193
.. _dropIndex-method-index-builds:
9294

93-
Aborts In-Progress Index Builds
94-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95-
96-
.. versionadded:: 4.4
97-
98-
If an index specified to :method:`db.collection.dropIndex()` is still
99-
being built, :method:`~db.collection.dropIndex()` attempts to abort
100-
the build. Aborting an index build has the same effect as dropping
101-
the built index. Prior to MongoDB 4.4,
102-
:method:`~db.collection.dropIndex()` returned an error if the
103-
specified index was still building.
104-
105-
The index specified to :method:`~db.collection.dropIndex()` must be the
106-
only index associated to the index builder, i.e. the indexes built by a
107-
single :dbcommand:`createIndexes` or
108-
:method:`db.collection.createIndexes()` operation. If the associated
109-
index builder has other in-progress builds, wait until the builds
110-
complete and specify the index to :method:`~db.collection.dropIndex()`.
111-
112-
For example, a :dbcommand:`createIndexes` /
113-
:method:`~db.collection.createIndexes()` operation creates three
114-
indexes. Assuming all three index builds are still in-progress,
115-
:method:`~db.collection.dropIndex()` cannot successfully abort any of
116-
the index builds and therefore cannot drop any of those indexes.
117-
118-
Use :dbcommand:`currentOp` to identify the index builds associated to a
119-
:dbcommand:`createIndexes` / :method:`~db.collection.createIndexes()`
120-
operation. See :ref:`currentOp-cmd-index-creation` for an example.
121-
122-
For replica sets or shard replica sets, aborting an index on the primary
123-
does not simultaneously abort secondary index builds.
124-
:method:`~db.collection.dropIndex()` attempts to abort the in-progress
125-
builds for the specified indexes on the :term:`primary` and if
126-
successful creates an associated "abort" oplog entry. :term:`Secondary
127-
<secondary>` members with replicated in-progress builds wait for a
128-
commit or abort oplog entry from the primary before either committing or
129-
aborting the index build.
95+
Stop In-Progress Index Builds
96+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97+
98+
.. |drop-index| replace:: :method:`db.collection.dropIndex()`
99+
100+
.. include:: /includes/fact-stop-in-progress-index-builds.rst
130101

131102
Hidden Indexes
132103
~~~~~~~~~~~~~~
@@ -151,7 +122,7 @@ Example
151122
-------
152123

153124
Consider a ``pets`` collection. Calling the
154-
:method:`~db.collection.getIndexes()` method on the ``pets`` collection
125+
:method:`db.collection.getIndexes()` method on the ``pets`` collection
155126
returns the following indexes:
156127

157128
.. code-block:: javascript

source/reference/method/db.collection.dropIndexes.txt

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ Definition
109109
Behavior
110110
--------
111111

112-
Cannot Drop ``Ready`` Indexes During In-Progress Index Builds
113-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112+
.. |drop-index| replace:: :method:`db.collection.dropIndexes()`
114113

115-
.. include:: /includes/fact-5.0-dropindexes-inprog.rst
114+
.. include:: /includes/fact-drop-index-5.2.rst
116115

117116
Kill related queries only
118117
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -146,42 +145,12 @@ instead of the index specification document.
146145

147146
.. _dropIndexes-method-index-builds:
148147

149-
Aborts In-Progress Index Builds
150-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151-
152-
.. versionadded:: 4.4
153-
154-
If an index specified to :method:`db.collection.dropIndexes()` is
155-
still building, :method:`~db.collection.dropIndexes()` attempts to
156-
abort the in-progress build. Aborting an index build has the same
157-
effect as dropping the built index. Prior to MongoDB 4.4,
158-
:method:`~db.collection.dropIndexes()` would return an error if the
159-
collection had any in-progress index builds.
160-
161-
For replica sets, run :method:`~db.collection.dropIndexes()` on the
162-
:term:`primary`. The primary aborts the index build and creates an
163-
associated "abortIndexBuild" oplog entry. Secondaries which replicate
164-
the "abortIndexBuild" oplog entry abort the in-progress index build and
165-
discard the build job. See :ref:`index-build-process` for detailed
166-
documentation on the index build process and the specific timing for
167-
terminating an in-progress index build.
168-
169-
The indexes specified to :method:`~db.collection.dropIndexes()` must be
170-
the entire set of in-progress builds associated to a single
171-
:dbcommand:`createIndexes` or :method:`db.collection.createIndexes()`
172-
operation. To drop a specific index out of a set of related in-progress
173-
builds, wait until the index builds complete and specify that index to
174-
:method:`~db.collection.dropIndexes()`
175-
176-
For example, a :dbcommand:`createIndexes` /
177-
:method:`~db.collection.createIndexes()` operation creates three
178-
indexes. Assuming all three index builds are in-progress,
179-
:method:`~db.collection.dropIndexes()` must specify all three indexes to
180-
abort the index builds and drop the indexes.
181-
182-
Use :dbcommand:`currentOp` to identify the index builds associated to a
183-
:dbcommand:`createIndexes` / :method:`~db.collection.createIndexes()`
184-
operation. See :ref:`currentOp-cmd-index-creation` for an example.
148+
Stop In-Progress Index Builds
149+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150+
151+
.. |drop-index| replace:: :method:`db.collection.dropIndexes()`
152+
153+
.. include:: /includes/fact-stop-in-progress-index-builds.rst
185154

186155
Hidden Indexes
187156
~~~~~~~~~~~~~~

source/release-notes/5.2-compatibility.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ Removed :binary:`~bin.mongod` Options
2424
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2525

2626
.. include:: /includes/5.2/removed-mongod-options.rst
27+
28+
29+
Existing Indexes Can Be Dropped During an Index Build
30+
-----------------------------------------------------
31+
32+
Starting in MongoDB 5.2, you can use :dbcommand:`dropIndexes` or
33+
:method:`db.collection.dropIndexes()` to drop existing indexes on the
34+
same collection even if there is an index build in progress. In earlier
35+
versions, attempting to drop a different index during an in-progress
36+
index build results in a ``BackgroundOperationInProgressForNamespace``
37+
error.

0 commit comments

Comments
 (0)