Class AnalyticsIndexTypeMigrationService
keyword
type of the fields the index template types so. An index template types
the indices created after it only, so an index created while the template
typed a field as a number keeps that type once the template types it
keyword, and the engine then answers a grouping on the field from
the indices of one type only and counts a value once per type among its
distinct values, with no error. The type of a field cannot be changed in an
index that holds documents: the index is copied into one created with the
expected types, which takes its place behind the alias and then its name.
One index at a time, in five steps: the copy is created under a name the index template does not match, so that it stays out of the alias while it fills; the documents are copied by the engine and counted; the copy takes the place of the original behind the alias, in the request that deletes the original; the copy is cloned under the original's name; the clone takes the place of the copy behind the alias, in the request that deletes the copy. An index is deleted only once the one that replaces it holds as many documents, and each exchange behind the alias is one request, so a search reads a week once. One case reads it twice for a moment: a new weekly index created between the clone and the last exchange, since the storage then gives the alias to every index named after the prefix, the clone included. The last exchange ends it; a clone that is not available or does not hold every document is deleted at once, and the copy keeps the alias.
A copy that carries the alias says that its original is deleted: this is what a new run reads to resume. A copy without the alias is an unfinished one, deleted and made again; a copy with the alias is cloned again.
One run at a time: a run holds a lock document the engine creates for one caller only, renews it while it works and releases it when it ends, each time for the version of the document it last wrote. A run that finds the lock held does nothing, unless the lock was not renewed for 600000L ms, which a run that was stopped leaves behind, and is told after how long such a lock can be taken over; a run whose lock was taken over learns it at its next renewal and stops. The lock is renewed right before each request that deletes an index, so a run that lost it stops before that request and leaves the week in progress to the other run. A second run in the same server is refused before it reads the lock, whose state this service keeps for one run. Each deletion of an index that is not part of an exchange first reads whether the copy carries the alias: the copy is then the one that holds the week.
The lock relies on two things. Its age is the time of the node that reads it minus the time of the node that wrote it: the nodes of a cluster keep their clocks synchronised, as the clustered job store already requires, to well within the expiry. And a run that is paused for longer than the expiry between a renewal and the request that follows it still sends that request after another run took the lock over: the two then work on the same week, and the reading of the alias before a deletion narrows that case without closing it.
Only a field the index template types keyword, and that the newest
index holds as such, is changed: any value can be held as a keyword. A
field the template does not name keeps its type, whatever the newest index
gives it, and the difference is reported.
What stays open while an index is migrated: a field the storage maps on the alias during the copy is not mapped on the migrated index, which holds no document with it since only the newest index is written; the retention, which deletes the oldest weekly indices at each start and at each new weekly index, can delete the clone before the last exchange, which then fails and leaves the alias to the copy: the next run clones it again, and the retention deletes that week at its next pass; and a last exchange the engine refuses leaves the clone under the weekly name, where the next weekly index gives it the alias beside the copy, until the next run, which deletes it and clones the copy again.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longA lock that was not renewed for that long was left by a stopped runstatic final StringStarts the name of an index being copied. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThe newest index is the one written.migrate()Lists the weekly indices that hold, as another type, a field the index template typeskeywordand the newest index holds as such, then migrates them, oldest first.
-
Field Details
-
MIGRATION_INDEX_PREFIX
Starts the name of an index being copied. The index template matches the names starting with the index prefix: a copy named otherwise receives neither its alias nor its mappings.- See Also:
-
LOCK_EXPIRY_MS
public static final long LOCK_EXPIRY_MSA lock that was not renewed for that long was left by a stopped run- See Also:
-
-
Constructor Details
-
AnalyticsIndexTypeMigrationService
public AnalyticsIndexTypeMigrationService()
-
-
Method Details
-
migrate
Lists the weekly indices that hold, as another type, a field the index template typeskeywordand the newest index holds as such, then migrates them, oldest first. The mappings of an index and of the newest one are read again at its turn, which can come long after the list was made: an index the retention deleted meanwhile, or that has the expected types by then, is skipped. An index that cannot be migrated, whether the engine refuses a request or does not answer it, is left as it is behind the alias, and the next ones are still handled.- Returns:
- the indices that could not be migrated, empty when none is left to migrate
- Throws:
AnalyticsMigrationRunningException- when another run is in progress in this server or holds the lock, and nothing was read nor changed (the exception then tells after how long a lock left by a stopped run can be taken over), or took the lock over, and this run stopped at its next renewal
-
isNewestIndexTypedAsTheTemplate
public boolean isNewestIndexTypedAsTheTemplate()The newest index is the one written. While it holds, as numbers, the fields the index template typeskeyword, nothing is migrated: this is the state of a platform at its first start on a version whose template changed these types, where the index of the current week was created by the former template. The migration is complete only once the newest index has the template's types, which the first index created by the new template brings.- Returns:
- true when the newest weekly index types
keywordevery field the index template types so, or when there is no weekly index
-