in elastic-db-tools/src/main/java/com/microsoft/azure/elasticdb/shard/recovery/RecoveryManager.java [461:514]
public void rebuildMappingsOnShard(RecoveryToken token,
List<ShardRange> ranges) {
ExceptionUtils.disallowNullArgument(token, "token");
ExceptionUtils.disallowNullArgument(ranges, "ranges");
ShardLocation location = this.getShardLocation(token);
if (!this.getInconsistencies().containsKey(token)) {
throw new IllegalArgumentException(StringUtilsLocal.formatInvariant(Errors._Recovery_InvalidRecoveryToken, token),
new Throwable("token"));
}
StoreShardMap ssmLocal;
ReferenceObjectHelper<StoreShardMap> refSsmLocal = new ReferenceObjectHelper<>(null);
StoreShard dss = this.getStoreShardFromToken("RebuildMappingsOnShard", token, refSsmLocal);
ssmLocal = refSsmLocal.argValue;
List<StoreMapping> mappingsToAdd = new ArrayList<>();
// Determine the ranges we want to keep based on input keeps list.
for (ShardRange range : ranges) {
MappingDifference difference = this.getInconsistencies().get(token).getOrDefault(range, null);
if (difference == null) {
throw new IllegalArgumentException(
StringUtilsLocal.formatInvariant(Errors._Recovery_InvalidRebuildShardSpecification, range, location),
new Throwable("ranges"));
}
// The storeMapping we will use as a template
StoreMapping storeMappingTemplate = difference.getLocation().equals(MappingLocation.MappingInShardMapOnly)
? difference.getMappingForShardMap()
: difference.getMappingForShard();
StoreMapping storeMappingToAdd = new StoreMapping(UUID.randomUUID(), storeMappingTemplate.getShardMapId(), range.getLow().getRawValue(),
range.getHigh().getRawValue(), storeMappingTemplate.getStatus(), null, dss);
mappingsToAdd.add(storeMappingToAdd);
}
try (IStoreOperationLocal op = this.getShardMapManager().getStoreOperationFactory().createReplaceMappingsLocalOperation(
this.getShardMapManager(), location, "RebuildMappingsOnShard", ssmLocal, dss,
new ArrayList<>(this.getInconsistencies().get(token).keySet()), mappingsToAdd)) {
op.doLocal();
}
catch (IOException e) {
e.printStackTrace();
throw (ShardManagementException) e.getCause();
}
this.getStoreShardMaps().remove(token);
this.getLocations().remove(token);
this.getInconsistencies().remove(token);
}