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.raidb2;
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.xml.DatabasesXmlTags;
028: import org.continuent.sequoia.controller.backend.result.ControllerResultSet;
029: import org.continuent.sequoia.controller.backend.result.ExecuteResult;
030: import org.continuent.sequoia.controller.cache.metadata.MetadataCache;
031: import org.continuent.sequoia.controller.loadbalancer.WeightedBalancer;
032: import org.continuent.sequoia.controller.loadbalancer.policies.WaitForCompletionPolicy;
033: import org.continuent.sequoia.controller.loadbalancer.policies.createtable.CreateTablePolicy;
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-2 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 RAIDb2ec_WRR extends RAIDb2ec {
051: /*
052: * How the code is organized ? 1. Member variables 2. Constructor(s) 3.
053: * Request handling 4. Debug/Monitoring
054: */
055:
056: private HashMap backends;
057:
058: /*
059: * Constructors
060: */
061:
062: /**
063: * Creates a new RAIDb-2 weighted round robin with error checking request load
064: * balancer.
065: *
066: * @param vdb The virtual database this load balancer belongs to.
067: * @param waitForCompletionPolicy How many backends must complete before
068: * returning the result?
069: * @param createTablePolicy The policy defining how 'create table' statements
070: * should be handled
071: * @param errorCheckingPolicy Policy to apply for error checking.
072: * @param nbOfConcurrentReads Number of concurrent reads allowed
073: * @exception Exception if an error occurs
074: */
075: public RAIDb2ec_WRR(VirtualDatabase vdb,
076: WaitForCompletionPolicy waitForCompletionPolicy,
077: CreateTablePolicy createTablePolicy,
078: ErrorCheckingPolicy errorCheckingPolicy,
079: int nbOfConcurrentReads) throws Exception {
080: super (vdb, waitForCompletionPolicy, createTablePolicy,
081: errorCheckingPolicy, nbOfConcurrentReads);
082: }
083:
084: /*
085: * Request Handling
086: */
087:
088: /**
089: * Performs a read request. It is up to the implementation to choose to which
090: * backend node(s) this request should be sent.
091: *
092: * @param request an <code>SelectRequest</code>
093: * @param metadataCache cached metadata to use to construct the result set
094: * @return the corresponding <code>java.sql.ResultSet</code>
095: * @exception SQLException if an error occurs
096: * @see org.continuent.sequoia.controller.loadbalancer.raidb2.RAIDb2#statementExecuteQuery(SelectRequest,
097: * MetadataCache)
098: */
099: public ControllerResultSet statementExecuteQuery(
100: SelectRequest request, MetadataCache metadataCache)
101: throws SQLException {
102: throw new NotImplementedException(this .getClass().getName()
103: + ":statementExecuteQuery");
104: }
105:
106: /**
107: * Not implemented.
108: *
109: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#readOnlyCallableStatementExecute(StoredProcedure,
110: * MetadataCache)
111: */
112: public ControllerResultSet readOnlyCallableStatementExecuteQuery(
113: StoredProcedure proc, MetadataCache metadataCache)
114: throws SQLException {
115: throw new NotImplementedException(this .getClass().getName()
116: + ":readOnlyCallableStatementExecuteQuery");
117: }
118:
119: /**
120: * Not implemented.
121: *
122: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#readOnlyCallableStatementExecute(StoredProcedure,
123: * MetadataCache)
124: */
125: public ExecuteResult readOnlyCallableStatementExecute(
126: StoredProcedure proc, MetadataCache metadataCache)
127: throws SQLException {
128: throw new NotImplementedException(this .getClass().getName()
129: + ":readOnlyCallableStatementExecute");
130: }
131:
132: /*
133: * Backends management
134: */
135:
136: /**
137: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#setWeight(String,
138: * int)
139: */
140: public void setWeight(String name, int w) throws SQLException {
141: throw new SQLException(
142: "Weight is not supported with this load balancer");
143: }
144:
145: /*
146: * Debug/Monitoring
147: */
148:
149: /**
150: * Gets information about the request load balancer.
151: *
152: * @return <code>String</code> containing information
153: */
154: public String getInformation() {
155: if (backends == null)
156: return "RAIDb-2 Error Checking with Weighted Round Robin Request load balancer: "
157: + "!!!Warning!!! No backend nodes found\n";
158: else
159: return "RAIDb-2 Error Checking with Weighted Round Robin Request load balancer balancing over "
160: + backends.size() + " nodes\n";
161: }
162:
163: /**
164: * @see RAIDb2#getRaidb2Xml()
165: */
166: public String getRaidb2Xml() {
167: return WeightedBalancer.getRaidbXml(backends,
168: DatabasesXmlTags.ELT_RAIDb_2ec_WeightedRoundRobin);
169: }
170: }
|