@@ -69,6 +69,13 @@ public void shardInitialized(ShardRouting unassignedShard, ShardRouting initiali
69
69
@ Override
70
70
public void shardStarted (ShardRouting initializingShard , ShardRouting startedShard ) {
71
71
addAllocationId (startedShard );
72
+ if (startedShard .primary ()
73
+ // started shard has to have null recoverySource; have to pick up recoverySource from its initializing state
74
+ && (initializingShard .recoverySource () instanceof RecoverySource .ExistingStoreRecoverySource
75
+ || initializingShard .recoverySource () instanceof RecoverySource .SnapshotRecoverySource )) {
76
+ Updates updates = changes (startedShard .shardId ());
77
+ updates .removedAllocationIds .add (RecoverySource .ExistingStoreRecoverySource .FORCED_ALLOCATION_ID );
78
+ }
72
79
}
73
80
74
81
@ Override
@@ -144,7 +151,8 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
144
151
oldInSyncAllocationIds .contains (updates .initializedPrimary .allocationId ().getId ()) == false ) {
145
152
// we're not reusing an existing in-sync allocation id to initialize a primary, which means that we're either force-allocating
146
153
// an empty or a stale primary (see AllocateEmptyPrimaryAllocationCommand or AllocateStalePrimaryAllocationCommand).
147
- RecoverySource .Type recoverySourceType = updates .initializedPrimary .recoverySource ().getType ();
154
+ RecoverySource recoverySource = updates .initializedPrimary .recoverySource ();
155
+ RecoverySource .Type recoverySourceType = recoverySource .getType ();
148
156
boolean emptyPrimary = recoverySourceType == RecoverySource .Type .EMPTY_STORE ;
149
157
assert updates .addedAllocationIds .isEmpty () : (emptyPrimary ? "empty" : "stale" ) +
150
158
" primary is not force-initialized in same allocation round where shards are started" ;
@@ -156,9 +164,12 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
156
164
// forcing an empty primary resets the in-sync allocations to the empty set (ShardRouting.allocatedPostIndexCreate)
157
165
indexMetaDataBuilder .putInSyncAllocationIds (shardId .id (), Collections .emptySet ());
158
166
} else {
167
+ assert recoverySource instanceof RecoverySource .ExistingStoreRecoverySource
168
+ || recoverySource instanceof RecoverySource .SnapshotRecoverySource
169
+ : recoverySource ;
159
170
// forcing a stale primary resets the in-sync allocations to the singleton set with the stale id
160
171
indexMetaDataBuilder .putInSyncAllocationIds (shardId .id (),
161
- Collections .singleton (updates . initializedPrimary . allocationId (). getId () ));
172
+ Collections .singleton (RecoverySource . ExistingStoreRecoverySource . FORCED_ALLOCATION_ID ));
162
173
}
163
174
} else {
164
175
// standard path for updating in-sync ids
@@ -291,7 +302,8 @@ void removeAllocationId(ShardRouting shardRouting) {
291
302
* Add allocation id of this shard to the set of in-sync shard copies
292
303
*/
293
304
private void addAllocationId (ShardRouting shardRouting ) {
294
- changes (shardRouting .shardId ()).addedAllocationIds .add (shardRouting .allocationId ().getId ());
305
+ final Updates changes = changes (shardRouting .shardId ());
306
+ changes .addedAllocationIds .add (shardRouting .allocationId ().getId ());
295
307
}
296
308
297
309
/**
0 commit comments