1 21 22 package org.continuent.sequoia.controller.virtualdatabase.protocol; 23 24 import java.io.Serializable ; 25 26 import org.continuent.hedera.common.Member; 27 import org.continuent.sequoia.common.exceptions.VirtualDatabaseException; 28 import org.continuent.sequoia.common.i18n.Translate; 29 import org.continuent.sequoia.common.log.Trace; 30 import org.continuent.sequoia.controller.recoverylog.RecoveryLog; 31 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase; 32 33 42 public class InitiateRecoveryLogResync 43 extends DistributedVirtualDatabaseMessage 44 { 45 private static final long serialVersionUID = -6799114439172152L; 46 47 private long originCommonCheckpointId; 48 private String commonCheckpointName; 49 private String nowCheckpointName; 50 private long nbOfEntriesToResync; 51 52 62 public InitiateRecoveryLogResync(String commonCheckpointName, 63 long commonCheckpointId, String nowCheckpointName, 64 long nbOfEntriesToResync) 65 { 66 this.commonCheckpointName = commonCheckpointName; 67 this.originCommonCheckpointId = commonCheckpointId; 68 this.nowCheckpointName = nowCheckpointName; 69 this.nbOfEntriesToResync = nbOfEntriesToResync; 70 } 71 72 77 public final long getOriginCommonCheckpointId() 78 { 79 return originCommonCheckpointId; 80 } 81 82 87 public final String getCommonCheckpointName() 88 { 89 return commonCheckpointName; 90 } 91 92 97 public final long getNbOfEntriesToResync() 98 { 99 return nbOfEntriesToResync; 100 } 101 102 107 public final String getNowCheckpointName() 108 { 109 return nowCheckpointName; 110 } 111 112 116 public Object handleMessageSingleThreaded(DistributedVirtualDatabase dvdb, 117 Member sender) 118 { 119 if (!dvdb.hasRecoveryLog()) 120 return new VirtualDatabaseException(Translate 121 .get("virtualdatabase.no.recovery.log")); 122 123 return this; 124 } 125 126 130 public Serializable handleMessageMultiThreaded( 131 DistributedVirtualDatabase dvdb, Member sender, 132 Object handleMessageSingleThreadedResult) 133 { 134 if (!dvdb.hasRecoveryLog()) 135 return new VirtualDatabaseException(Translate 136 .get("virtualdatabase.no.recovery.log")); 137 138 Trace logger = dvdb.getLogger(); 139 try 140 { 141 RecoveryLog recoveryLog = dvdb.getRequestManager().getRecoveryLog(); 142 long commonCheckpointId = recoveryLog 143 .getCheckpointLogId(getCommonCheckpointName()); 144 long nowCheckpointId = recoveryLog 145 .getCheckpointLogId(getNowCheckpointName()); 146 147 long shift = getNbOfEntriesToResync() 149 - (nowCheckpointId - commonCheckpointId); 150 151 if (shift > 0) 153 recoveryLog.moveEntries(nowCheckpointId, shift); 154 155 recoveryLog.deleteLogEntriesAndCheckpointBetween(commonCheckpointId, 157 nowCheckpointId + shift); 158 159 recoveryLog.removeCheckpoint(nowCheckpointName); 161 recoveryLog.storeCheckpoint(nowCheckpointName, nowCheckpointId + shift); 162 163 return new Long (commonCheckpointId - getOriginCommonCheckpointId()); 164 } 165 catch (Exception e) 166 { 167 logger.error("Unable to initialize recovery log resynchronization", e); 168 return new VirtualDatabaseException( 169 "Unable to initialize recovery log resynchronization", e); 170 } 171 } 172 173 } 174 | Popular Tags |