Set Index Lock Mode Operation


  • The lock mode controls the behavior of index modifications.
    Use SetIndexesLockOperation to modify the lock mode for a single index or multiple indexes.

  • Indexes scope:
    The lock mode can be set only for static-indexes, not for auto-indexes.

  • Nodes scope:
    The lock mode will be updated on all nodes in the database group.

  • Setting the lock mode can also be done from the indexes list view in the Studio.
    Locking an index is not a security measure, the index can be unlocked at any time.

  • In this page:


Lock modes

  • Unlocked - when lock mode is set to Unlock:

    • Any change to the index definition will be applied.
    • If the new index definition differs from the one stored on the server,
      the index will be updated and the data will be re-indexed using the new index definition.
  • Locked (ignore) - when lock mode is set to LockedIgnore:

    • Index definition changes will Not be applied.
    • Modifying the index definition will return successfully and no error will be raised,
      however, no change will be made to the index definition on the server.
  • Locked (error) - when lock mode is set to LockedError:

    • Index definitions changes will Not be applied.
    • An exception will be thrown upon trying to modify the index.

Sample usage flow

Consider the following scenario:

  • Your client application defines and deploys a static-index upon application startup.

  • After the application has started, you make a change to your index definition and re-indexing occurs.
    However, if the index lock mode is 'Unlock', the next time your application will start,
    it will reset the index definition back to the original version.

  • Locking the index allows to make changes to the running index and prevents the application
    from setting it back to the previous definition upon startup. See the following steps:

    1. Run your application
    2. Modify the index definition on the server (from Studio, or from another application),
      and then set this index lock mode to LockedIgnore.
    3. A side-by-side replacement index is created on the server.
      It will index your dataset according to the new definition.
    4. At this point, if any instance of your original application is started,
      the code that defines and deploys the index upon startup will have no effect
      since the index is 'locked'.
    5. Once the replacement index is done indexing, it will replace the original index.

Set lock mode - single index

// Define the set lock mode operation
// Pass index name & lock mode
const setLockModeOp = new SetIndexesLockOperation("Orders/Totals", "LockedIgnore");

// Execute the operation by passing it to maintenance.send
// An exception will be thrown if index does not exist
await store.maintenance.send(setLockModeOp);

// Lock mode is now set to 'LockedIgnore'
// Any modifications done now to the index will Not be applied, and will Not throw

Set lock mode - multiple indexes

// Define the index list and the new lock mode:
const parameters = {
    indexNames: ["Orders/Totals", "Orders/ByCompany"],
    mode: "LockedError"
}

// Define the set lock mode operation, pass the parameters
const setLockModeOp = new SetIndexesLockOperation(parameters);

// Execute the operation by passing it to maintenance.send
// An exception will be thrown if any of the specified indexes do not exist
await store.maintenance.send(setLockModeOp);

// Lock mode is now set to 'LockedError' on both indexes
// Any modifications done now to either index will throw

Syntax

// Available overloads:
const setLockModeOp = new SetIndexesLockOperation(indexName, mode);
const setLockModeOp = new SetIndexesLockOperation(parameters);
Parameters Type Description
indexName string Index name for which to set lock mode
mode "Unlock" /
"LockedIgnore" /
"LockedError"
Lock mode to set
parameters parameters object List of indexes + lock mode to set.
An exception is thrown if any of the specified indexes do not exist.

// parameters object
{
    indexNames, // string[], list of index names
    mode        // Lock mode to set
}