/** master和slave之间的同步状态 */ public void heartBeat() { ReplicationRequest command = new ReplicationRequest(true); command.setBuckNo(bucket); command.setEnvType(EnvType.HEART_BEAT); packageRequestHeader(command); try { Response rsp = (Response) ioSession.syncSendPacket(command, RMI_TIMEOUT); if (!rsp.isFailure()) { Long maxSeq = (Long) rsp.getContent(); if (log.isInfoEnabled()) { log.info( "{}-bucket master-slave max sequence is [{}, {}].", bucket, maxSeq, pos.curMaxSeq()); } } else { throw new SyncMasterDataException(rsp.getErrorCode()); } } catch (HippoException e) { throw new SyncMasterDataException("Rmi error! " + master + "-" + bucket, e); } }
private Position doBackup(Position pos) { ReplicationRequest command = new ReplicationRequest(); command.setPos(pos); command.setBuckNo(bucket); command.setSize(replication_batch_size); packageRequestHeader(command); Position next = null; try { Response rsp = (Response) ioSession.syncSendPacket(command, RMI_TIMEOUT); if (!rsp.isFailure()) { next = (Position) rsp.getContent(); byte[] d = rsp.getData(); if (d != null) { SyncResult r = storeEngine.set(d, bucket); if (!r.isSuccess()) { // 回滚 pos.pointer(next.pointer()); throw new SyncMasterDataException("save migration data error."); } } // 提交,默认情况下服务端会维护offset,不需要客户端设置 next.pointer(-1); return next; } else { String ec = rsp.getErrorCode(); if (fileNotFound.equals(ec)) { throw new VersionExpiredException("version expire"); } else if (uninited.equals(ec)) { throw new SyncMasterDataException("migrationEngine uninited"); } else { throw new SyncMasterDataException("unknow error = " + ec); } } } catch (HippoException e) { throw new SyncMasterDataException("Rmi error! " + master + "-" + bucket, e); } }