001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Emmanuel Cecchet.
021: * Contributor(s): Jean-Bernard van Zuylen.
022: */package org.continuent.sequoia.controller.scheduler.raidb1;
023:
024: import java.sql.SQLException;
025: import java.util.HashSet;
026:
027: import org.continuent.sequoia.common.exceptions.RollbackException;
028: import org.continuent.sequoia.common.xml.DatabasesXmlTags;
029: import org.continuent.sequoia.controller.requestmanager.RAIDbLevels;
030: import org.continuent.sequoia.controller.requests.AbstractWriteRequest;
031: import org.continuent.sequoia.controller.requests.ParsingGranularities;
032: import org.continuent.sequoia.controller.requests.SelectRequest;
033: import org.continuent.sequoia.controller.requests.StoredProcedure;
034: import org.continuent.sequoia.controller.scheduler.AbstractScheduler;
035:
036: /**
037: * This scheduler provides optimistic query level scheduling for RAIDb-1
038: * controllers. Reads can execute in parallel of any request. Writes are flagged
039: * as blocking or not based on the completion of a previous write inside the
040: * same transaction.
041: *
042: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
043: * @author <a href="mailto:jbvanzuylen@transwide.com">Jean-Bernard van Zuylen
044: * </a>
045: * @version 1.0
046: * @deprecated since Sequoia 2.2
047: */
048: public class RAIDb1OptimisticQueryLevelScheduler extends
049: AbstractScheduler {
050:
051: //
052: // How the code is organized ?
053: //
054: // 1. Member variables
055: // 2. Constructor
056: // 3. Request handling
057: // 4. Transaction management
058: // 5. Debug/Monitoring
059: //
060:
061: private HashSet completedWrites = new HashSet(); // set of tids
062:
063: //
064: // Constructor
065: //
066:
067: /**
068: * Creates a new Query Level Scheduler
069: */
070: public RAIDb1OptimisticQueryLevelScheduler() {
071: super (RAIDbLevels.RAIDb1, ParsingGranularities.NO_PARSING);
072: }
073:
074: //
075: // Request Handling
076: //
077:
078: /**
079: * Additionally to scheduling the request, this method replaces the SQL Date
080: * macros such as now() with the current date.
081: *
082: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#scheduleNonSuspendedReadRequest(SelectRequest)
083: */
084: public void scheduleNonSuspendedReadRequest(SelectRequest request)
085: throws SQLException {
086: }
087:
088: /**
089: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#readCompletedNotify(SelectRequest)
090: */
091: public final void readCompletedNotify(SelectRequest request) {
092: }
093:
094: /**
095: * Additionally to scheduling the request, this method replaces the SQL Date
096: * macros such as now() with the current date.
097: *
098: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#scheduleWriteRequest(AbstractWriteRequest)
099: */
100: public synchronized void scheduleNonSuspendedWriteRequest(
101: AbstractWriteRequest request) throws SQLException {
102: // if (request.isAutoCommit())
103: // request.setBlocking(true);
104: // else
105: request.setBlocking(completedWrites.contains(new Long(request
106: .getTransactionId())));
107: }
108:
109: /**
110: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#notifyWriteCompleted(AbstractWriteRequest)
111: */
112: public final synchronized void notifyWriteCompleted(
113: AbstractWriteRequest request) {
114: if (!request.isAutoCommit())
115: completedWrites.add(new Long(request.getTransactionId()));
116: }
117:
118: /**
119: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#scheduleNonSuspendedStoredProcedure(org.continuent.sequoia.controller.requests.StoredProcedure)
120: */
121: public final synchronized void scheduleNonSuspendedStoredProcedure(
122: StoredProcedure proc) throws SQLException,
123: RollbackException {
124: proc.setBlocking(completedWrites.contains(new Long(proc
125: .getTransactionId())));
126: }
127:
128: /**
129: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#notifyStoredProcedureCompleted(org.continuent.sequoia.controller.requests.StoredProcedure)
130: */
131: public final synchronized void notifyStoredProcedureCompleted(
132: StoredProcedure proc) {
133: if (!proc.isAutoCommit())
134: completedWrites.add(new Long(proc.getTransactionId()));
135: }
136:
137: //
138: // Transaction Management
139: //
140:
141: /**
142: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#commitTransaction(long)
143: */
144: protected final synchronized void commitTransaction(
145: long transactionId) {
146: completedWrites.remove(new Long(transactionId));
147: }
148:
149: /**
150: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#rollbackTransaction(long)
151: */
152: protected final synchronized void rollbackTransaction(
153: long transactionId) {
154: completedWrites.remove(new Long(transactionId));
155: }
156:
157: /**
158: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#rollbackTransaction(long,
159: * String)
160: */
161: protected final void rollbackTransaction(long transactionId,
162: String savepointName) {
163: }
164:
165: /**
166: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#setSavepointTransaction(long,
167: * String)
168: */
169: protected final void setSavepointTransaction(long transactionId,
170: String name) {
171: }
172:
173: /**
174: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#releaseSavepointTransaction(long,
175: * String)
176: */
177: protected final void releaseSavepointTransaction(
178: long transactionId, String name) {
179: }
180:
181: //
182: // Debug/Monitoring
183: //
184:
185: /**
186: * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler#getXmlImpl()
187: */
188: public String getXmlImpl() {
189: return "<" + DatabasesXmlTags.ELT_RAIDb1Scheduler + " "
190: + DatabasesXmlTags.ATT_level + "=\""
191: + DatabasesXmlTags.VAL_optimisticQuery + "\"/>";
192: }
193: }
|