001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Emmanuel Cecchet.
020: * Contributor(s): Julie Marguerite.
021: */package org.continuent.sequoia.controller.loadbalancer.raidb1;
022:
023: import java.sql.SQLException;
024: import java.util.HashMap;
025:
026: import org.continuent.sequoia.common.exceptions.NotImplementedException;
027: import org.continuent.sequoia.common.i18n.Translate;
028: import org.continuent.sequoia.common.xml.DatabasesXmlTags;
029: import org.continuent.sequoia.controller.backend.result.ControllerResultSet;
030: import org.continuent.sequoia.controller.backend.result.ExecuteResult;
031: import org.continuent.sequoia.controller.cache.metadata.MetadataCache;
032: import org.continuent.sequoia.controller.loadbalancer.WeightedBalancer;
033: import org.continuent.sequoia.controller.loadbalancer.policies.WaitForCompletionPolicy;
034: import org.continuent.sequoia.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy;
035: import org.continuent.sequoia.controller.requests.SelectRequest;
036: import org.continuent.sequoia.controller.requests.StoredProcedure;
037: import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase;
038:
039: /**
040: * RAIDb-1 Weighted Round Robin load balancer with error checking.
041: * <p>
042: * This load balancer tolerates byzantine failures of databases. The read
043: * requests coming from the Request Manager are sent to multiple backend nodes
044: * and the results are compared. Write requests are broadcasted to all backends.
045: *
046: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
047: * @author <a href="mailto:Julie.Marguerite@inria.fr">Julie Marguerite </a>
048: * @version 1.0
049: */
050: public class RAIDb1ec_WRR extends RAIDb1ec {
051: /*
052: * How the code is organized ? 1. Member variables 2. Constructor(s) 3.
053: * Request handling 4. Debug/Monitoring
054: */
055:
056: // private int index; // index in the backend vector the Round-Robin
057: private HashMap weights;
058:
059: /*
060: * Constructors
061: */
062:
063: /**
064: * Creates a new RAIDb-1 Weighted Round Robin with error checking request load
065: * balancer.
066: *
067: * @param vdb the virtual database this load balancer belongs to.
068: * @param waitForCompletionPolicy How many backends must complete before
069: * returning the result?
070: * @param errorCheckingPolicy policy to apply for error checking.
071: * @param nbOfConcurrentReads number of concurrent reads allowed
072: * @exception Exception if an error occurs
073: */
074: public RAIDb1ec_WRR(VirtualDatabase vdb,
075: WaitForCompletionPolicy waitForCompletionPolicy,
076: ErrorCheckingPolicy errorCheckingPolicy,
077: int nbOfConcurrentReads) throws Exception {
078: super (vdb, waitForCompletionPolicy, errorCheckingPolicy,
079: nbOfConcurrentReads);
080: // index = -1;
081: }
082:
083: /*
084: * Request Handling
085: */
086:
087: /**
088: * Not implemented.
089: *
090: * @see org.continuent.sequoia.controller.loadbalancer.raidb1.RAIDb1#statementExecuteQuery(SelectRequest,
091: * MetadataCache)
092: */
093: public ControllerResultSet execSingleBackendReadRequest(
094: SelectRequest request, MetadataCache metadataCache)
095: throws SQLException {
096: throw new NotImplementedException(this .getClass().getName()
097: + ":execSingleBackendReadRequest");
098: }
099:
100: /**
101: * Not implemented.
102: *
103: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#readOnlyCallableStatementExecuteQuery(StoredProcedure,
104: * MetadataCache)
105: */
106: public ControllerResultSet readOnlyCallableStatementExecuteQuery(
107: StoredProcedure proc, MetadataCache metadataCache)
108: throws SQLException {
109: throw new NotImplementedException(this .getClass().getName()
110: + ":readOnlyCallableStatementExecuteQuery");
111: }
112:
113: /**
114: * Not implemented.
115: *
116: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#readOnlyCallableStatementExecute(org.continuent.sequoia.controller.requests.StoredProcedure,
117: * org.continuent.sequoia.controller.cache.metadata.MetadataCache)
118: */
119: public ExecuteResult readOnlyCallableStatementExecute(
120: StoredProcedure proc, MetadataCache metadataCache)
121: throws SQLException {
122: throw new NotImplementedException(this .getClass().getName()
123: + ":readOnlyCallableStatementExecute");
124: }
125:
126: /*
127: * Backends management
128: */
129:
130: /**
131: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#setWeight(String,
132: * int)
133: */
134: public void setWeight(String name, int w) throws SQLException {
135: if (logger.isDebugEnabled())
136: logger.debug(Translate.get("loadbalancer.weight.set",
137: new String[] { String.valueOf(w), name }));
138:
139: weights.put(name, new Integer(w));
140: }
141:
142: /*
143: * Debug/Monitoring
144: */
145:
146: /**
147: * Gets information about the request load balancer.
148: *
149: * @return <code>String</code> containing information
150: */
151: public String getInformation() {
152: // We don't lock since we don't need a top accurate value
153: int size = vdb.getBackends().size();
154:
155: if (size == 0)
156: return "RAIDb-1 Error Checking with Weighted Round-Robin Request load balancer: "
157: + "!!!Warning!!! No backend nodes found\n";
158: else
159: return "RAIDb-1 Error Checking with Weighted Round-Robin Request load balancer ("
160: + size + " backends)\n";
161: }
162:
163: /**
164: * @see org.continuent.sequoia.controller.loadbalancer.raidb1.RAIDb1#getRaidb1Xml
165: */
166: public String getRaidb1Xml() {
167: return WeightedBalancer.getRaidbXml(weights,
168: DatabasesXmlTags.ELT_RAIDb_1ec_WeightedRoundRobin);
169: }
170: }
|