/* This file is part of VoltDB. * Copyright (C) 2008-2010 VoltDB L.L.C. * * VoltDB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VoltDB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VoltDB. If not, see <http://www.gnu.org/licenses/>. */ package org.voltdb.compiler; public class ClusterConfig { public ClusterConfig() { // Nothing... } public ClusterConfig(int hostCount, int sitesPerHost, int replicationFactor, String leaderAddress) { m_hostCount = hostCount; m_sitesPerHost = sitesPerHost; m_leaderAddress = leaderAddress; m_replicationFactor = replicationFactor; m_errorMsg = "Config is unvalidated"; } public int getHostCount() { return m_hostCount; } public int getSitesPerHost() { return m_sitesPerHost; } public int getReplicationFactor() { return m_replicationFactor; } public String getLeaderAddress() { return m_leaderAddress; } public int getPartitionCount() { return (m_hostCount * m_sitesPerHost) / (m_replicationFactor + 1); } public String getErrorMsg() { return m_errorMsg; } public boolean validate() { if (m_hostCount <= 0) { m_errorMsg = "The number of hosts must be > 0."; return false; } if (m_sitesPerHost <= 0) { m_errorMsg = "The number of sites per host must be > 0."; return false; } if (m_hostCount <= m_replicationFactor) { m_errorMsg = String.format("Insufficient hosts (%d) to support K-safety of %d", m_hostCount, m_replicationFactor); return false; } if (getPartitionCount() == 0) { m_errorMsg = String.format("Insufficient execution site count to achieve K-safety of %d", m_replicationFactor); return false; } m_errorMsg = "Cluster config contains no detected errors"; return true; } private int m_hostCount; private int m_sitesPerHost; private int m_replicationFactor; private String m_leaderAddress; private String m_errorMsg; }