Returns amount of times when index was rebuilt since storage was opened.
It is used to support so called "live index rebuild" feature.
Value of this version is increased every time when index is going to be rebuild.
So if two sequential calls of this method return different numbers it means that index at least started to rebuild
itself.
If you use indexes to increase speed of fetching data from database you should follow following workflow:
- Read index rebuild version.
- Check index rebuild flag
#isRebuilding(), if it is true, do not use index and fetch data directly from
database clusters.
- Fetch data from index.
- Read index rebuild version again, if it is not equal to version which was read at first time, go to step 2.
It is VERY important do not reorder steps 1 and 2.
Such recording may lead to situation when index is rebuilding but we miss this state.
This approach works well ONLY if you do not use methods which return
OIndexCursor instance.
In case of you work with cursors index rebuild may cause data inconsistency issues in both:
- Code which calls index methods to create cursor (can be avoided using steps are listed above)
- During iteration over the cursor itself
To detect last data inconsistency issue please use cursor wrapper
OIndexChangesWrapper which throws
com.orientechnologies.orient.core.exception.OIndexIsRebuildingExceptionin case of index rebuild.
Both of these approaches are used in implementation of support of "live index rebuild" for SELECT
SQL queries.
- In case of index which we are going to use to speed up
SELECT
query is rebuilding
we skip this index.
- If index is rebuilding at the moment when we iterate over the cursor
we catch
com.orientechnologies.orient.core.exception.OIndexIsRebuildingException exception
and retry whole query again.