1 22 23 package org.continuent.sequoia.controller.virtualdatabase.protocol; 24 25 import java.io.Serializable ; 26 import java.sql.SQLException ; 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 52 public class ReplicateLogEntries extends DistributedVirtualDatabaseMessage 53 { 54 private static final long serialVersionUID = -2813776509468770586L; 55 56 private String checkpointName; 57 private String dumpCheckpointName; 58 private long checkpointId; 59 private String dumpName; 60 61 72 public ReplicateLogEntries(String checkpointName, String dumpCheckpointName, 73 String dumpName, long checkpointId) 74 { 75 this.dumpCheckpointName = dumpCheckpointName; 76 this.checkpointName = checkpointName; 77 this.checkpointId = checkpointId; 78 this.dumpName = dumpName; 79 } 80 81 86 public String getCheckpointName() 87 { 88 return checkpointName; 89 } 90 91 96 public String getDumpCheckpointName() 97 { 98 return dumpCheckpointName; 99 } 100 101 106 public long getCheckpointId() 107 { 108 return checkpointId; 109 } 110 111 void performSanityChecks(DistributedVirtualDatabase dvdb) 112 throws VirtualDatabaseException, SQLException 113 { 114 if (!dvdb.hasRecoveryLog()) 115 { 116 String 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 126 { 127 dvdb.getRequestManager().getRecoveryLog() 128 .resetLogTableIdAndDeleteRecoveryLog(checkpointName, checkpointId); 129 } 130 131 void performTerminationPhase(DistributedVirtualDatabase dvdb) 132 throws SQLException , VirtualDatabaseException 133 { 134 dvdb.getRequestManager().getRecoveryLog().storeDumpCheckpointName( 136 dumpCheckpointName, checkpointId); 137 139 dvdb.getRecoveryLog().updateDumpCheckpoint(dumpName, dumpCheckpointName); 141 142 dvdb.initGlobalCounters(dvdb.getControllerId()); 144 } 145 146 150 public Object handleMessageSingleThreaded(DistributedVirtualDatabase dvdb, 151 Member sender) 152 { 153 try 154 { 155 performSanityChecks(dvdb); 158 159 if (dumpCheckpointName == null) 160 performInitializationPhase(dvdb); 161 else 162 performTerminationPhase(dvdb); 163 164 } 165 catch (Exception e) 166 { 167 dvdb.getLogger().warn(e); 168 return new ControllerException(e); 169 } 170 171 return null; 172 } 173 174 178 public Serializable handleMessageMultiThreaded( 179 DistributedVirtualDatabase dvdb, Member sender, 180 Object handleMessageSingleThreadedResult) 181 { 182 return (Serializable ) handleMessageSingleThreadedResult; 183 } 184 } | Popular Tags |