} else {
removeIndexConfig(name);
}
//clone is meaningless if properties are NULL
if(clone && properties != null){
IndexMetadata tmp = properties;
properties = new IndexMetadata();
properties.putAll(tmp);
}
Map<String,IndexMetadata> toAdd,toRemove;
IndexMetadata oldMetadata = null;
synchronized (inMemoryModelLock ) {
ManagedIndexState currentState = getState(name);
if(currentState != null){
toRemove = managed.get(currentState);
} else {
toRemove = null;
}
if(properties == null){
toAdd = null; //remove
} else {
ManagedIndexState newState = properties.getState();
toAdd = managed.get(newState);
}
//now update in-memory state
if(toRemove != null){
oldMetadata = toRemove.remove(name);
}
if(toAdd != null){
toAdd.put(name, properties);
}
//now update the archive name to core name mappings
if(oldMetadata != null){
for(String indexArchive : oldMetadata.getIndexArchives()){
Collection<String> indexes = archiveName2CoreName.get(indexArchive);
if(indexes.remove(name) && indexes.isEmpty()){
archiveName2CoreName.remove(indexArchive);
}
}