Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Transitioning From Equivalent Indexes to Index Replicas

DZone's Guide to

Transitioning From Equivalent Indexes to Index Replicas

Consider a scenario where you have a couple of equivalent indexes spread across three nodes and you want to migrate these equivalent indexes to index replicas.

· Database Zone ·
Free Resource

New whitepaper: Database DevOps – 6 Tips for Achieving Continuous Delivery. Discover 6 tips for continuous delivery with Database DevOps in this new whitepaper from Redgate. In 9 pages, it covers version control for databases and configurations, branching and testing, automation, using NuGet packages, and advice for how to start a pioneering Database DevOps project. Also includes further research on the industry-wide state of Database DevOps, how application and database development compare, plus practical steps for bringing DevOps to your database. Read it now free.

In the previous post, we saw the benefits of using index replicas over equivalent indexes. Let’s say you are on Couchbase Server 4.x and have the following three equivalent indexes spread across three nodes; and with Couchbase 5.0 Beta available, you want to migrate these equivalent indexes to index replicas.

//old 4.x equivalent indexes
create index eq_index1 on bucket(field1); 
create index eq_index2 on bucket(field1); 
create index eq_index3 on bucket(field1);

Note: If you want to use the same nodes to create the replicas, do make sure that they have the required memory and compute resources for the both the index replicas and equivalent indexes to coexist.

Step 1

Fire the following query with the num_replica parameter being 2, as we earlier had three copies of the index and want to maintain the same topology of indexes.

create index eq_index on bucket(field1) with {“num_replica”:2}

If you are bringing in a new set of three index nodes, then you might as well specify the create index statement with the "nodes" parameter set. For example:

create index eq_index on bucket(field1) with {“nodes” [“10.10.10.1:9001", "10.10.10.2:9002", "10.10.10.3:9003”]}

Step 2

Once Step 1 is complete and all the index replicas are created and online (i.e. index build completed), drop the old 4.x equivalent indexes present:

drop index eq_index1; 
drop index eq_index2;
drop index eq_index3;

Voila! Your N1QL queries are all set to use the index replicas, and there was no application downtime during the process as well. If you had used USE INDEX directive in your N1QL query, then the same needs to be updated with the new index name.

Equivalent indexes are still supported in Couchbase Server 5.0 and a mix of equivalent and replica indexes also works, i.e., N1QL queries would load balance between equivalent and replica indexes; but for efficient manageability, index replicas are recommended over equivalent indexes.

If you haven’t already, click here to download Couchbase Server 5.0 and play around with Index Replicas. 

New whitepaper: Database DevOps – 6 Tips for Achieving Continuous Delivery. Discover 6 tips for continuous delivery with Database DevOps in this new whitepaper from Redgate. In 9 pages, it covers version control for databases and configurations, branching and testing, automation, using NuGet packages, and advice for how to start a pioneering Database DevOps project. Also includes further research on the industry-wide state of Database DevOps, how application and database development compare, plus practical steps for bringing DevOps to your database. Read it now free.

Topics:
database ,couchbase ,distributed computing ,index replica ,equivalent index ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}