Set Index Lock Mode Operation
-
The lock mode controls the behavior of index modifications.
UseSetIndexesLockOperation
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 the Studio indexes list view.
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
LOCKED_IGNORE
:- 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
LOCKED_ERROR
:- 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 isUNLOCK
, 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:
- Run your application
- Modify the index definition on the server (from Studio, or from another application),
and then set this index lock mode toLOCKED_IGNORE
. - A side-by-side replacement index is created on the server.
It will index your dataset according to the new definition. - 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 isLOCKED
. - 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
set_lock_mode_op = SetIndexesLockOperation(IndexLockMode.LOCKED_IGNORE, "Orders/Totals")
# Execute the operation by passing it to maintenance.send
# An exception will be thrown if index does not exist
store.maintenance.send(set_lock_mode_op)
# Lock mode is now set to 'LockedIgnore'
# Any modification done now to the index will Not be applied, and will Not throw
Set lock mode - multiple indexes
# Define the set lock mode operation, pass the parameters
set_lock_mode_op = SetIndexesLockOperation(IndexLockMode.LOCKED_ERROR, "Orders/Totals", "Orders/ByCompany")
# Execute the operation by passing it to maintenance.send
# An exception will be thrown if any of the specified indexes does not exist
store.maintenance.send(set_lock_mode_op)
# Lock mode is now set to 'LockedError' on both indexes
# Any modifications done now to either index will throw
Syntax
class SetIndexesLockOperation(VoidMaintenanceOperation):
def __init__(self, mode: IndexLockMode, *index_names: str): ...
Parameters | Type | Description |
---|---|---|
mode | IndexLockMode |
Lock mode to set |
*index_names | str |
Index names to set lock mode for |
class IndexLockMode(Enum):
UNLOCK = "Unlock"
LOCKED_IGNORE = "LockedIgnore"
LOCKED_ERROR = "LockedError"
def __str__(self):
return self.value