Skip to content

Commit c30c36e

Browse files
DOC-10974: Provide better explanation of "nodes" clause in create index (#590)
* Update Index Replication page * Update Index Partitioning page * Update CREATE INDEX * Update CREATE PRIMARY INDEX --------- Co-authored-by: rakhi-prathap <rakhi.prathap@couchbase.com>
1 parent 36b8b2b commit c30c36e

4 files changed

Lines changed: 93 additions & 56 deletions

File tree

modules/learn/pages/services-and-indexes/indexes/index-replication.adoc

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ You can control the scan consistency for individual queries.
99
// Cross-references
1010
:index-service: xref:services-and-indexes/services/index-service.adoc
1111
:index-partitioning: xref:n1ql:n1ql-language-reference/index-partitioning.adoc
12+
:createindex: xref:n1ql:n1ql-language-reference/createindex.adoc
13+
:createprimaryindex: xref:n1ql:n1ql-language-reference/createprimaryindex.adoc
1214
:failover: xref:learn:clusters-and-availability/failover.adoc
1315
:database-change-protocol: xref:learn:clusters-and-availability/intra-cluster-replication.adoc#database-change-protocol
1416
:index-storage-mode: xref:manage:manage-settings/general-settings.adoc#index-storage-mode
15-
:index-storage-settings-via-cli: xref:manage:manage-settings/general-settings.adoc#index-storage-settings-via-cli
16-
:index-settings-via-rest: xref:manage:manage-settings/general-settings.adoc#index-settings-via-rest
17+
:index-storage-settings-via-cli: xref:cli:cbcli/couchbase-cli-setting-index.adoc
18+
:index-settings-via-rest: xref:rest-api:post-settings-indexes.adoc
1719
:install-sample-buckets: xref:manage:manage-settings/install-sample-buckets.adoc
18-
:query: xref:n1ql:query.adoc
20+
:query: xref:n1ql:n1ql-language-reference/index.adoc
1921
:query-preferences: xref:tools:query-workbench.adoc#query-preferences
2022
:scan_consistency: xref:settings:query-settings.adoc#scan_consistency
2123

@@ -33,20 +35,26 @@ include::ROOT:partial$query-context.adoc[tag=statement]
3335
[#index-replication]
3436
== Index Replication
3537

36-
Secondary indexes can be replicated across cluster-nodes.
37-
This ensures:
38+
[.edition]#{enterprise}#
3839

39-
* _Availability_: If one Index-Service node is lost, the other continues to provide access to replicated indexes.
40-
* _High Performance_: If original and replica copies are available, incoming queries are load-balanced across them.
40+
You can replicate primary and secondary indexes across cluster nodes running the {index-service}[Index Service].
41+
This feature is available only in Couchbase Server Enterprise Edition.
42+
Index replication has the following benefits:
4143

42-
Index-replicas can be created with the {sqlpp} `CREATE INDEX` statement.
43-
Note that whenever a given number of index-replicas is specified for creation, the number must be less than the number of cluster-nodes currently running the {index-service}[Index Service].
44-
If it is not, the index creation fails.
45-
Note also that if, following creation of the maximum number of copies, the number of nodes running the Index Service decreases, Couchbase Server progressively assigns replacement index-replicas to any and all Index-Service nodes subsequently be added to the cluster, until the required number of index-replicas again exists for each replicated index.
44+
* *Availability*: If one Index Service node is lost, the others continues to provide access to replicated indexes.
45+
* *High Performance*: If original and replica copies are available, incoming queries are load-balanced across them.
4646
47-
Index-replicas can be created as follows:
47+
If the number of nodes running the Index Service decreases, and index replicas are lost, Couchbase Server progressively assigns replacement index replicas to all Index Service nodes subsequently added to the cluster, until the required number of index replicas again exists for each replicated index.
4848

49-
* Specifying, by means of the `WITH` clause, the destination nodes.
49+
=== Creating Index Replicas for a Single Index
50+
51+
You can create index replicas using the {sqlpp} {createindex}[CREATE INDEX] and {createprimaryindex}[CREATE PRIMARY INDEX] statements.
52+
53+
To create index replicas for a single index, do one of the following:
54+
55+
* In the `WITH` clause, use the `nodes` attribute to specify the destination nodes.
56+
When you use this attribute by itself, the index is placed on one of the destination nodes, and one replica is placed on each of the others.
57+
+
5058
In the following example, an index with two replicas is created.
5159
The active index is on `node1`, and the replicas are on `node2` and `node3`:
5260
+
@@ -56,44 +64,55 @@ The active index is on `node1`, and the replicas are on `node2` and `node3`:
5664
include::example$services-and-indexes/indexes/replication-nodes.n1ql[]
5765
----
5866

59-
* Specifying _no_ destination nodes; but specifying instead, by means of the `WITH` clause and the `num_replica` attribute, only the _number_ of replicas required.
60-
The replicas are automatically distributed across those nodes of the cluster that are running the Index Service: the distribution-pattern is based on a projection of optimal index-availability, given the number and disposition of Index-Service nodes across defined server-groups.
67+
* In the `WITH` clause, use the `num_replica` attribute to specify the number of replicas required.
68+
When you use this attribute by itself, the index and the required number of replicas are automatically distributed across Index Service nodes.
69+
The distribution pattern is based on a projection of optimal index availability, given the number and disposition of Index Service nodes across defined server groups.
70+
The required number of replicas must be smaller than the number of cluster nodes currently running the Index Service.
71+
If it's not, the index creation fails.
6172
+
6273
In the following example, an index is created with two replicas, with no destination-nodes specified:
6374
+
6475
[source,sqlpp]
6576
----
6677
include::example$services-and-indexes/indexes/replication-num.n1ql[]
6778
----
68-
+
69-
Note that if `nodes` and `num_replica` are both specified in the `WITH` clause, the specified number of nodes must be _one greater_ than `num_replica`.
7079

71-
* Specifying a number of index-replicas to be created by the Index Service whenever `CREATE INDEX` is invoked.
72-
The default is `0`.
73-
If the default is changed to, say, `2`, creation of a single index is henceforth accompanied by the creation of two replicas, which are automatically distributed across the nodes of the cluster running the Index Service.
74-
No explicit specification within the `CREATE INDEX` statement is required.
75-
+
76-
With credentials that provide appropriate authorization, this default can be changed by means of the `curl` command, as follows:
77-
+
80+
* In the `WITH` clause, use the `nodes` and `num_replica` attributes together.
81+
In this case, the Index planner chooses from the set of specified nodes to place the index and the required number of replicas.
82+
The required number of replicas must be smaller than the number of specified nodes.
83+
If it's not, the index creation fails.
84+
85+
For more information on using {sqlpp}, see {query}[].
86+
87+
=== Creating Index Replicas Automatically
88+
89+
The Index Service can create a number of index replicas automatically whenever {createindex}[CREATE INDEX] or {createprimaryindex}[CREATE PRIMARY INDEX] is invoked.
90+
The default number of replicas is `0`.
91+
For example, if you change the number of automatic replicas to `2`, from that point on creation of a single index is accompanied by the creation of two replicas, which are automatically distributed across the nodes of the cluster running the Index Service.
92+
No explicit specification is required within the {sqlpp} statement.
93+
94+
The following example changes the index replication settings using the GSI Settings REST API:
95+
7896
[source,sh]
7997
----
8098
curl -X POST -u 'Administrator:password' \
8199
'http://localhost:8091/settings/indexes' \
82100
-d 'numReplica=2'
83101
----
84-
+
85-
Here, `numReplica` is an integer that establishes the default number of replicas that must be created whenever `CREATE INDEX` is invoked.
86-
Note that this call only succeeds if the cluster contains enough Index Service nodes to host each new index and its replicas: for example, if `2` is specified as the default number of replicas, the Index Service must have been established on at least 3 nodes.
87-
+
88-
Note also that whenever explicit specification of replica-numbers is made within the `CREATE INDEX` statement, this explicit specification takes precedence over any established default.
89102

90-
You can change index replication settings via the {index-storage-mode}[UI] or the {index-settings-via-rest}[REST API].
91-
For further information on using {sqlpp}, refer to {query}[Query Fundamentals].
103+
Here, `numReplica` is an integer that establishes the default number of replicas that must be created whenever an index is created.
104+
This call only succeeds if the cluster contains enough Index Service nodes to host each new index and its replicas: for example, if you specify `2` as the default number of replicas, the Index Service must have been established on at least 3 nodes.
105+
106+
When you explicitly specify the number of replicas with the {createindex}[CREATE INDEX] or {createprimaryindex}[CREATE PRIMARY INDEX] statement, the explicit specification takes precedence over the index replication settings.
107+
108+
You can change the index replication settings using the {index-storage-mode}[UI], the {index-storage-settings-via-cli}[CLI], or the {index-settings-via-rest}[REST API].
92109

93110
[[index-partitioning]]
94111
== Index Partitioning
95112

96-
_Index Partitioning_ increases query performance, by dividing and spreading a large index of documents across multiple nodes. This feature is available only in Couchbase Server Enterprise Edition.
113+
[.edition]#{enterprise}#
114+
115+
Index partitioning increases query performance, by dividing and spreading a large index of documents across multiple nodes. This feature is available only in Couchbase Server Enterprise Edition.
97116

98117
The benefits include:
99118

@@ -105,23 +124,25 @@ The benefits include:
105124

106125
* Provision of a low-latency range query, while allowing indexes to be scaled out as needed.
107126

108-
For detailed information, refer to {index-partitioning}[Index Partitioning].
127+
For more information, see {index-partitioning}[Index Partitioning].
109128

110129
[[index-consistency]]
111130
== Index Consistency
112131

113132
(((scan consistency)))
114133
(((consistency)))
115134
(((consistent)))
116-
Whereas Couchbase Server handles data-mutations with _full consistency_ — all mutations to a given key are applied to the same vBucket, and become immediately available — it maintains indexes with degrees of _eventual consistency_, determined by means of the following query consistency-options, specified per query:
135+
Couchbase Server handles data mutations with full consistency — all mutations to a given key are applied to the same vBucket, and become immediately available.
136+
In contrast, Couchbase Server maintains indexes with degrees of eventual consistency.
137+
For every query, you can specify the following consistency options:
117138

118139
// tag::scan_consistency[]
119140
* `not_bounded`: Executes the query immediately, without requiring any consistency for the query.
120-
If index-maintenance is running behind, out-of-date results may be returned.
141+
If index maintenance is running behind, out-of-date results may be returned.
121142
* `at_plus`: Executes the query, requiring indexes first to be updated to the timestamp of the last update.
122-
If index-maintenance is running behind, the query waits for it to catch up.
123-
* `request_plus`: Executes the query, requiring the indexes first to be updated to the timestamp of the current query-request.
124-
If index-maintenance is running behind, the query waits for it to catch up.
143+
If index maintenance is running behind, the query waits for it to catch up.
144+
* `request_plus`: Executes the query, requiring the indexes first to be updated to the timestamp of the current query request.
145+
If index maintenance is running behind, the query waits for it to catch up.
125146
* `statement_plus`: Executes the query with strong consistency per statement.
126147
Before processing each statement, the service obtains a current vector timestamp and uses it as a lower bound for that statement.
127148

@@ -133,8 +154,8 @@ You can specify the scan consistency via the {query-preferences}[run-time prefer
133154
[[index-snapshots]]
134155
== Index Snapshots
135156

136-
One or more _index snapshots_ are maintained on disk, to permit rapid recovery if node-failures are experienced.
137-
In cases where recovery requires an Index-Service node to be restarted, the nodes indexes are rebuilt from the snapshots retained on disk.
157+
Couchbase Server maintains one or more index snapshots on disk, to permit rapid recovery if nodes fail.
158+
In cases where recovery requires an Index Service node to be restarted, the node's indexes are rebuilt from the snapshots retained on disk.
138159

139160
By default, two index snapshots are stored on disk.
140161
You can change index snapshot settings via the {index-storage-settings-via-cli}[CLI] or the {index-settings-via-rest}[REST API].

modules/n1ql/pages/n1ql-language-reference/createindex.adoc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,25 @@ nodes;;
318318
****
319319
[.edition]#{community}#
320320
321-
In Couchbase Server Community Edition, a single global secondary index can be placed on a single node that runs the indexing service.
322-
The `nodes` property allows you to specify the node that the index is placed on.
323-
(((default index placement)))If `nodes` is not specified, one of the nodes running the indexing service is randomly picked for the index.
321+
In Couchbase Server Community Edition, a single secondary index of type `GSI` can be placed on a single node that runs the Indexing Service.
322+
The `nodes` property enables you to specify the node that the index is placed on.
323+
(((default index placement)))If `nodes` is not specified, the Index planner may place the index on any of the nodes running the Indexing Service.
324324
****
325325
+
326326
****
327327
[.edition]#{enterprise}#
328328
329-
In Couchbase Server Enterprise Edition, you can specify multiple nodes to distribute replicas of an index across nodes running the indexing service: for example, `WITH {"nodes": ["node1:8091", "node2:8091", "node3:8091"]}`.
329+
In Couchbase Server Enterprise Edition, you can specify multiple nodes to distribute replicas of an index across nodes running the Indexing Service: for example, `WITH {"nodes": ["node1:8091", "node2:8091", "node3:8091"]}`.
330330
For details and examples, refer to {index-replication}[Index Replication].
331331
332-
If specifying both [.var]`nodes` and [.var]`num_replica`, the number of nodes in the array must be one greater than the specified number of replicas otherwise the index creation will fail.
333-
334-
(((default index placement)))If [.var]`nodes` is not specified, then the system chooses nodes on which to place the new index and any replicas, in order to achieve the best resource utilization across nodes running the indexing service.
332+
(((default index placement)))If `nodes` is not specified, then the system places the new index and any replicas on any of the nodes running the Indexing Service, in order to achieve the best resource utilization.
335333
This is done by taking into account the current resource usage statistics of index nodes.
334+
335+
If you specify the `nodes` property by itself, the index is placed on one of the destination nodes, and a replica is placed on each of the others.
336+
337+
If you specify both `nodes` and `num_replica`, the Index planner chooses from the set of specified nodes to place the index and its replicas.
338+
In this case, the number of nodes in the array must be greater than the specified number of replicas.
339+
Otherwise, the index creation fails.
336340
****
337341
+
338342
IMPORTANT: A node name passed to the `nodes` property must include the cluster administration port, by default 8091.
@@ -362,7 +366,9 @@ This property is only available in Couchbase Server Enterprise Edition.
362366
The indexer will automatically distribute these replicas amongst index nodes in the cluster for load-balancing and high availability purposes.
363367
The indexer will attempt to distribute the replicas based on the server groups in use in the cluster where possible.
364368
365-
If the value of this property is not less than the number of index nodes in the cluster, then the index creation will fail.
369+
The number of replicas must be lower than the number of index nodes in the cluster.
370+
If `nodes` is specified, the number of replicas must be lower than the number of nodes in the array.
371+
Otherwise, the index creation fails.
366372
****
367373

368374
== Usage

modules/n1ql/pages/n1ql-language-reference/createprimaryindex.adoc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,25 @@ nodes;;
204204
****
205205
[.edition]#{community}#
206206
207-
In Couchbase Server Community Edition, a single primary index of type `GSI` can be placed on a single node that runs the indexing service.
208-
The `nodes` property allows you to specify the node that the index is placed on.
209-
(((default index placement)))If `nodes` is not specified, one of the nodes running the indexing service is randomly picked for the index.
207+
In Couchbase Server Community Edition, a single primary index of type `GSI` can be placed on a single node that runs the Indexing Service.
208+
The `nodes` property enables you to specify the node that the index is placed on.
209+
(((default index placement)))If `nodes` is not specified, the Index planner may place the index on any of the nodes running the Indexing Service.
210210
****
211211
+
212212
****
213213
[.edition]#{enterprise}#
214214
215-
In Couchbase Server Enterprise Edition, you can specify multiple nodes to distribute replicas of an index across nodes running the indexing service: for example, `WITH {"nodes": ["node1:8091", "node2:8091", "node3:8091"]}`.
215+
In Couchbase Server Enterprise Edition, you can specify multiple nodes to distribute replicas of an index across nodes running the Indexing Service: for example, `WITH {"nodes": ["node1:8091", "node2:8091", "node3:8091"]}`.
216216
For details and examples, refer to {index-replication}[Index Replication].
217217
218-
If specifying both [.var]`nodes` and [.var]`num_replica`, the number of nodes in the array must be one greater than the specified number of replicas otherwise the index creation will fail.
219-
220-
(((default index placement)))If [.var]`nodes` is not specified, then the system chooses nodes on which to place the new index and any replicas, in order to achieve the best resource utilization across nodes running the indexing service.
218+
(((default index placement)))If `nodes` is not specified, then the system places the new index and any replicas on any of the nodes running the Indexing Service, in order to achieve the best resource utilization.
221219
This is done by taking into account the current resource usage statistics of index nodes.
220+
221+
If you specify the `nodes` property by itself, the index is placed on one of the destination nodes, and a replica is placed on each of the others.
222+
223+
If you specify both `nodes` and `num_replica`, the Index planner chooses from the set of specified nodes to place the index and its replicas.
224+
In this case, the number of nodes in the array must be greater than the specified number of replicas.
225+
Otherwise, the index creation fails.
222226
****
223227
+
224228
IMPORTANT: A node name passed to the `nodes` property must include the cluster administration port, by default 8091.
@@ -248,7 +252,9 @@ This property is only available in Couchbase Server Enterprise Edition.
248252
The indexer will automatically distribute these replicas amongst index nodes in the cluster for load-balancing and high availability purposes.
249253
The indexer will attempt to distribute the replicas based on the server groups in use in the cluster where possible.
250254
251-
If the value of this property is not less than the number of index nodes in the cluster, then the index creation will fail.
255+
The number of replicas must be lower than the number of index nodes in the cluster.
256+
If `nodes` is specified, the number of replicas must be lower than the number of nodes in the array.
257+
Otherwise, the index creation fails.
252258
****
253259

254260
Partitioned indexes support further options.

modules/n1ql/pages/n1ql-language-reference/index-partitioning.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ CREATE INDEX idx_pe12 ON route
534534
----
535535
====
536536

537+
When you specify a node list for a partitioned index, the Index Service places the partitions according to the available resources on the specified nodes.
538+
For example, if you create an index with 8 partitions and specify a list of 8 nodes, the Index Service does not necessarily place 1 partition on each node.
539+
Rather, the Index Service considers the resource usage on each of the specified nodes, and may choose to place the partitions on 4 of them.
540+
537541
If you create a partitioned index on a specific set of nodes, and then decide that you want to specify a different set of nodes for partition placement, you need to remove the partitioned index and then recreate the partitioned index on a smaller or greater number of nodes.
538542
However, refer also to the section on <<rebalancing,rebalancing a partitioned index>> below.
539543

0 commit comments

Comments
 (0)