KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > virtualdatabase > protocol > ReplicateLogEntries


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
4  * Copyright (C) 2005-2006 Continuent, Inc.
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Olivier Fambon.
20  * Contributor(s): Emmanuel Cecchet.
21  */

22
23 package org.continuent.sequoia.controller.virtualdatabase.protocol;
24
25 import java.io.Serializable JavaDoc;
26 import java.sql.SQLException JavaDoc;
27
28 import org.continuent.hedera.common.Member;
29 import org.continuent.sequoia.common.exceptions.ControllerException;
30 import org.continuent.sequoia.common.exceptions.VirtualDatabaseException;
31 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
32
33 /**
34  * This message is used both to prepare the sending of a set of log entries to a
35  * remote controller's vdb recovery log (intialization) and to terminate it
36  * (termination). Initialization is the second step of the process to rebuild
37  * the remote recovery log from a live one, termination is the final step of the
38  * process. The process is as such so that eventually the remote vdb backends
39  * can be restored from dumps. Upon reception of this message for the
40  * initialisation phase (identified by a null dumpCheckpointName), the remote
41  * recovery log is cleared from the beginning upto the 'now' checkpoint.
42  * Subsequently, CopyLogEntry messages are sent and log entries are inserted 'as
43  * are' into the remote recovery log. Then, upon reception of this message for
44  * the termination phase (non-null dumpCheckpointName), the remote recovery log
45  * makes the dumpCheckpointName available for restore operations.
46  *
47  * @see CopyLogEntry
48  * @author <a HREF="mailto:Olivier.Fambon@emicnetworks.com>Olivier Fambon </a>
49  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
50  * @version 1.0
51  */

52 public class ReplicateLogEntries extends DistributedVirtualDatabaseMessage
53 {
54   private static final long serialVersionUID = -2813776509468770586L;
55
56   private String JavaDoc checkpointName;
57   private String JavaDoc dumpCheckpointName;
58   private long checkpointId;
59   private String JavaDoc dumpName;
60
61   /**
62    * Creates a new <code>ReplicateLogEntries</code> message
63    *
64    * @param checkpointName The checkpoint (aka now checkpoint) before wich
65    * entries are to be replaced.
66    * @param dumpCheckpointName The dump checkoint from which entries are to be
67    * replaced. If this one is null, the recovery log is reset.
68    * @param dumpName the name of the dump associated to dumpCheckpointName.
69    * @param checkpointId The id associated to checkpoint THIS ID SHOULD BE
70    * HIDDEN
71    */

72   public ReplicateLogEntries(String JavaDoc checkpointName, String JavaDoc dumpCheckpointName,
73       String JavaDoc dumpName, long checkpointId)
74   {
75     this.dumpCheckpointName = dumpCheckpointName;
76     this.checkpointName = checkpointName;
77     this.checkpointId = checkpointId;
78     this.dumpName = dumpName;
79   }
80
81   /**
82    * Returns the checkpointName value.
83    *
84    * @return Returns the 'now' checkpointName.
85    */

86   public String JavaDoc getCheckpointName()
87   {
88     return checkpointName;
89   }
90
91   /**
92    * Returns the dump checkpoint name .
93    *
94    * @return Returns the dump CheckpointName.
95    */

96   public String JavaDoc getDumpCheckpointName()
97   {
98     return dumpCheckpointName;
99   }
100
101   /**
102    * Returns the Checkpoint id.
103    *
104    * @return the Checkpoint id
105    */

106   public long getCheckpointId()
107   {
108     return checkpointId;
109   }
110
111   void performSanityChecks(DistributedVirtualDatabase dvdb)
112       throws VirtualDatabaseException, SQLException JavaDoc
113   {
114     if (!dvdb.hasRecoveryLog())
115     {
116       String JavaDoc errorMessage = "Tentative handleReplicateLogEntries on vdb with no recovery log";
117       throw new VirtualDatabaseException(errorMessage);
118     }
119
120     if (dvdb.getRecoveryLog().getDumpInfo(dumpName) == null)
121       throw new VirtualDatabaseException("Invalid dump name: " + dumpName);
122   }
123
124   void performInitializationPhase(DistributedVirtualDatabase dvdb)
125       throws SQLException JavaDoc
126   {
127     dvdb.getRequestManager().getRecoveryLog()
128         .resetLogTableIdAndDeleteRecoveryLog(checkpointName, checkpointId);
129   }
130
131   void performTerminationPhase(DistributedVirtualDatabase dvdb)
132       throws SQLException JavaDoc, VirtualDatabaseException
133   {
134     // 1: store dump checkpoint name in the checkpoints table
135
dvdb.getRequestManager().getRecoveryLog().storeDumpCheckpointName(
136         dumpCheckpointName, checkpointId);
137     // (should this one be synchronous ?)
138

139     // 2: update the dump table with it, and make the dump valid for restore
140
dvdb.getRecoveryLog().updateDumpCheckpoint(dumpName, dumpCheckpointName);
141
142     // 3: update global counters based on new log
143
dvdb.initGlobalCounters(dvdb.getControllerId());
144   }
145
146   /**
147    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
148    * org.continuent.hedera.common.Member)
149    */

150   public Object JavaDoc handleMessageSingleThreaded(DistributedVirtualDatabase dvdb,
151       Member sender)
152   {
153     try
154     {
155       // Note: with this test placed here, the check is performed both at
156
// initialization and at completion.
157
performSanityChecks(dvdb);
158
159       if (dumpCheckpointName == null)
160         performInitializationPhase(dvdb);
161       else
162         performTerminationPhase(dvdb);
163
164     }
165     catch (Exception JavaDoc e)
166     {
167       dvdb.getLogger().warn(e);
168       return new ControllerException(e);
169     }
170
171     return null;
172   }
173
174   /**
175    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
176    * org.continuent.hedera.common.Member, java.lang.Object)
177    */

178   public Serializable JavaDoc handleMessageMultiThreaded(
179       DistributedVirtualDatabase dvdb, Member sender,
180       Object JavaDoc handleMessageSingleThreadedResult)
181   {
182     return (Serializable JavaDoc) handleMessageSingleThreadedResult;
183   }
184 }
Popular Tags