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: * Copyright (C) 2006 Continuent, Inc.
007: * Contact: sequoia@continuent.org
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: * Initial developer(s): Nicolas Modrzyk.
022: * Contributor(s): Emmanuel Cecchet.
023: */package org.continuent.sequoia.controller.virtualdatabase.protocol;
024:
025: import java.io.Serializable;
026: import java.util.LinkedList;
027:
028: import org.continuent.hedera.common.Member;
029: import org.continuent.sequoia.common.exceptions.VirtualDatabaseException;
030: import org.continuent.sequoia.common.i18n.Translate;
031: import org.continuent.sequoia.common.jmx.management.BackendInfo;
032: import org.continuent.sequoia.common.log.Trace;
033: import org.continuent.sequoia.controller.backend.DatabaseBackend;
034: import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
035:
036: /**
037: * This class defines a BackendTransfer message used to transfer the backend
038: * information and re-enable the backend on the remote controller (checkpoint
039: * transfer have already been taken care of).
040: *
041: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
042: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
043: * @version 1.0
044: */
045: public class BackendTransfer extends DistributedVirtualDatabaseMessage {
046: private static final long serialVersionUID = 520265407391630486L;
047:
048: private BackendInfo info;
049: private String controllerDest;
050: private String checkpointName;
051:
052: private transient LinkedList totalOrderQueue;
053:
054: /**
055: * Creates a new <code>BackendTransfer</code> object
056: *
057: * @param info the info on the backend to transfer
058: * @param controllerDest the JMX name of the target controller
059: * @param checkpointName the name of the ckeckpoint from which to restore
060: */
061: public BackendTransfer(String controllerDest,
062: String checkpointName, BackendInfo info) {
063: this .info = info;
064: this .controllerDest = controllerDest;
065: this .checkpointName = checkpointName;
066: }
067:
068: /**
069: * Returns the controllerDest value.
070: *
071: * @return Returns the controllerDest.
072: */
073: public String getControllerDest() {
074: return controllerDest;
075: }
076:
077: /**
078: * Returns the info value.
079: *
080: * @return Returns the info.
081: */
082: public BackendInfo getInfo() {
083: return info;
084: }
085:
086: /**
087: * Returns the checkpointName value.
088: *
089: * @return Returns the checkpointName.
090: */
091: public String getCheckpointName() {
092: return checkpointName;
093: }
094:
095: /**
096: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
097: * org.continuent.hedera.common.Member)
098: */
099: public Object handleMessageSingleThreaded(
100: DistributedVirtualDatabase dvdb, Member sender) {
101: totalOrderQueue = dvdb.getTotalOrderQueue();
102: if (totalOrderQueue == null)
103: return new VirtualDatabaseException(Translate.get(
104: "virtualdatabase.no.total.order.queue", dvdb
105: .getVirtualDatabaseName()));
106:
107: synchronized (totalOrderQueue) {
108: totalOrderQueue.addLast(this );
109: return this ;
110: }
111: }
112:
113: /**
114: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
115: * org.continuent.hedera.common.Member, java.lang.Object)
116: */
117: public Serializable handleMessageMultiThreaded(
118: DistributedVirtualDatabase dvdb, Member sender,
119: Object handleMessageSingleThreadedResult) {
120: Trace logger = dvdb.getLogger();
121:
122: // Wait for our turn to execute
123: if (!dvdb.waitForTotalOrder(handleMessageSingleThreadedResult,
124: false))
125: logger
126: .error("BackendTransfer was not found in total order queue, posting out of order ("
127: + checkpointName + ")");
128: else
129: synchronized (totalOrderQueue) {
130: totalOrderQueue.removeFirst();
131: totalOrderQueue.notifyAll();
132: }
133:
134: if (logger.isInfoEnabled())
135: logger.info(dvdb.getControllerName()
136: + ": Received transfer command. Checkpoint: "
137: + getCheckpointName());
138: DatabaseBackend backend = new DatabaseBackend(info);
139:
140: try {
141: dvdb.addBackend(backend);
142: } catch (VirtualDatabaseException e) {
143: // No cleanup expected there (if addBackend() behaves). The backend does
144: // not exist here, and still exists (though disabled) on the originating
145: // vdb peer (controller). Just return the exception.
146: return e;
147: }
148:
149: try {
150: if (logger.isInfoEnabled())
151: logger.info(dvdb.getControllerName()
152: + ": Enable backend from " + checkpointName);
153: dvdb.enableBackendFromCheckpoint(backend.getName(),
154: getCheckpointName());
155: } catch (VirtualDatabaseException e) {
156: // The backend was added, but could not be enabled. Remove it from this
157: // vdb peer, since it remains (in a disabled state) on the originating
158: // peer.
159: cleanup(dvdb, backend);
160: return e;
161: }
162: return Boolean.TRUE;
163: }
164:
165: void cleanup(DistributedVirtualDatabase dvdb,
166: DatabaseBackend backend) {
167: try {
168: dvdb.removeBackend(backend);
169: } catch (VirtualDatabaseException e) {
170: dvdb
171: .getLogger()
172: .error(
173: "Could not cleanup vdb after transfer backend failure",
174: e);
175: }
176: }
177: }
|