Source:
<code>protected StorageDomain electNewMaster(boolean duringReconstruct, boolean selectInactiveWhenNoActiveUnknownDomains, boolean canChooseCurrentMasterAsNewMaster) { if (getStoragePool() == null) { log.warn("Cannot elect new master: storage pool not found"); return null; } List<StorageDomain> storageDomains = getStorageDomainDao().getAllForStoragePool(getStoragePool().getId()); if (storageDomains.isEmpty()) { log.warn("Cannot elect new master, no storage domains found for pool {}", getStoragePool().getName()); return null; } Collections.sort(storageDomains, Comparator.comparing(StorageDomain::getLastTimeUsedAsMaster) <START> .thenComparing(Comparator.comparing(StorageDomain::isShared))); <END> StorageDomain newMaster = null; StorageDomain storageDomain = getStorageDomain(); for (StorageDomain dbStorageDomain : storageDomains) { if (hostedEngineHelper.isHostedEngineStorageDomain(dbStorageDomain)) { continue; } if ((storageDomain == null || (duringReconstruct || !dbStorageDomain.getId() .equals(storageDomain.getId()))) && ((dbStorageDomain.getStorageDomainType() == StorageDomainType.Data) || (canChooseCurrentMasterAsNewMaster && dbStorageDomain.getStorageDomainType() == StorageDomainType.Master))) { if (dbStorageDomain.getStatus() == StorageDomainStatus.Active || dbStorageDomain.getStatus() == StorageDomainStatus.Unknown) { newMaster = dbStorageDomain; break; } else if (selectInactiveWhenNoActiveUnknownDomains && newMaster == null && dbStorageDomain.getStatus() == StorageDomainStatus.Inactive) { newMaster = dbStorageDomain; } } } return newMaster; }</code><technical_language>natural ordering of booleans is false true. This patch prefer local domains shared domains, is of want. StorageDomain::isLocal instead</technical_language>

Target:
protected StorageDomain electNewMaster(boolean duringReconstruct, boolean selectInactiveWhenNoActiveUnknownDomains, boolean canChooseCurrentMasterAsNewMaster) { if (getStoragePool() == null) { log.warn("Cannot elect new master: storage pool not found"); return null; } List<StorageDomain> storageDomains = getStorageDomainDao().getAllForStoragePool(getStoragePool().getId()); if (storageDomains.isEmpty()) { log.warn("Cannot elect new master, no storage domains found for pool {}", getStoragePool().getName()); return null; } Collections.sort(storageDomains, Comparator.comparing(StorageDomain::getLastTimeUsedAsMaster) .thenComparing(Comparator.comparing(StorageDomain::isLocal))); StorageDomain newMaster = null; StorageDomain storageDomain = getStorageDomain(); for (StorageDomain dbStorageDomain : storageDomains) { if (hostedEngineHelper.isHostedEngineStorageDomain(dbStorageDomain)) { continue; } if ((storageDomain == null || (duringReconstruct || !dbStorageDomain.getId() .equals(storageDomain.getId()))) && ((dbStorageDomain.getStorageDomainType() == StorageDomainType.Data) || (canChooseCurrentMasterAsNewMaster && dbStorageDomain.getStorageDomainType() == StorageDomainType.Master))) { if (dbStorageDomain.getStatus() == StorageDomainStatus.Active || dbStorageDomain.getStatus() == StorageDomainStatus.Unknown) { newMaster = dbStorageDomain; break; } else if (selectInactiveWhenNoActiveUnknownDomains && newMaster == null && dbStorageDomain.getStatus() == StorageDomainStatus.Inactive) { newMaster = dbStorageDomain; } } } return newMaster; }