changeset 404:4bb04d5a9bbf

minor fix
author one
date Tue, 25 Nov 2008 03:29:47 +0900
parents e94a3820c13a
children 0b1d52ffb803
files Todo rep/handler/Editor.java
diffstat 2 files changed, 40 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/Todo	Tue Nov 25 03:10:08 2008 +0900
+++ b/Todo	Tue Nov 25 03:29:47 2008 +0900
@@ -6,6 +6,8 @@
 watingCommandInMerge にforwardedCommandManageから入れちゃうと、
 User Editor Command と 一周して来てからのCommandを区別できない...
 
+INSERT_USER/DELETE_USERを入れて回避。Editor側の変更も必要になるが、
+まぁ、仕方がない。
 
 Wed Nov 19 19:21:47 JST 2008
 
--- a/rep/handler/Editor.java	Tue Nov 25 03:10:08 2008 +0900
+++ b/rep/handler/Editor.java	Tue Nov 25 03:29:47 2008 +0900
@@ -63,19 +63,16 @@
 		case REPCMD_DELETE:
 			if (command.eid == REP.MERGE_EID.id){
 				//マージコマンドが返ってきた
-				checkDouble(sentList);
 				if(translator.checkMergeConflict(command)){
 					//マージ中にエディタからの割り込みがあった場合
 					translator.getMergeAgain(this);
 				}
 				checkEndMerge();
-				checkDouble(sentList);
 				return;
 			} else if (command.eid == eid){ 
 				// 編集コマンドが一周して来た
 				if (waitingRequired(command)) return;
 				checkReturnedCommand(command);
-				checkDouble(sentList);
 				return;
 			}
 
@@ -98,44 +95,40 @@
 		if (next==this) return; // singleton case
 		translator.transSendCmd(command);
 		sendEditorCommand(command);
-		checkDouble(sentList);
 		return;
 	}
 	
-	private void checkDouble(List<REPCommand> sentList) {
-		if (sentList.size()==0) return;
-		int count = 0;
-		REPCommand f = sentList.get(0); 
-		for(REPCommand c:sentList) {
-			if (c.eid==f.eid&&c.seq==f.seq) {
-				count++;
-			}
-		}
-		assert(count==1);
-		if (true) return;
-		count = 0;
-		for(PacketSet c:waitingCommandInMerge) {
-			for(REPCommand g:sentList) { 
-				if (c.command.eid==g.eid&&c.command.seq==g.seq) {
-					count++;
-				}
-			}
-		}
-		assert(count==0);
-	}
+//	private void checkDouble(List<REPCommand> sentList) {
+//		if (sentList.size()==0) return;
+//		int count = 0;
+//		REPCommand f = sentList.get(0); 
+//		for(REPCommand c:sentList) {
+//			if (c.eid==f.eid&&c.seq==f.seq) {
+//				count++;
+//			}
+//		}
+//		assert(count==1);
+//		if (true) return;
+//		count = 0;
+//		for(PacketSet c:waitingCommandInMerge) {
+//			for(REPCommand g:sentList) { 
+//				if (c.command.eid==g.eid&&c.command.seq==g.seq) {
+//					count++;
+//				}
+//			}
+//		}
+//		assert(count==0);
+//	}
 
 	private boolean waitingRequired(REPCommand command) {
 		if (hasWaitingCommand()) {
 			// We cannot do this operation before watingCommandQueue.
 			addWaitingCommand(new PacketSet(channel, this, new REPCommand(command)));
-			checkDouble(sentList);
 			return true;
 		} else if (isMerging()) { 
 			addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command)));
-			checkDouble(sentList);
 			return true;
 		} 
-		checkDouble(sentList);
 		ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting");
 		return false;
 	}
@@ -154,7 +147,6 @@
 		REPCommand keep = new REPCommand(command);
 		sentList.add(keep);
 		ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
-		checkDouble(sentList);
 		assert(sentList.size()<limit);
 		next.send(command);
 	}
@@ -166,22 +158,35 @@
 
 	/**
 	 * 一周して来たcommandの処理。
+	 * 
+	 *   INSERT/DELETEを受け取った時に、sentListに登録
+	 *    INSERT_ACK/DELETE_ACKが来たら一周。そこで、Mergeする。
+	 *    
+	 *    自分が出したINSERT/DELETEが戻って来たら、ACKに変更して、Merge。 
+	 * 
+	 * 途中から参加した場合、自分が受けとってないcommandのACKが先に来ることが
+	 * ある。それは、無視して良い。
 	 * @param command
 	 */
 	void checkReturnedCommand(REPCommand command) {
 		assert(!merging);
 		if (sentList.size()==0) {
 			ServerMainLoop.logger.writeLog("Editor eid="+eid+" looped command not registered: "+command);
-			assert(false);
+			assert(command.cmd==REP.REPCMD_DELETE_ACK||
+					command.cmd==REP.REPCMD_INSERT_ACK);
+			return;
 		}
 		REPCommand prev = sentList.remove(0);
-		ServerMainLoop.logger.writeLog("Editor eid="+eid+" remove sentList:"+(prev==null?"null":prev));
+		// ServerMainLoop.logger.writeLog("Editor eid="+eid+" remove sentList:"+(prev==null?"null":prev));
 		if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) {
 			String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+
 				(prev==null?"null":prev)+" sentList=";
 			err += sentList;
 			ServerMainLoop.logger.writeLog(err);
-			assert(false);
+			assert(command.cmd==REP.REPCMD_DELETE_ACK||
+					command.cmd==REP.REPCMD_INSERT_ACK);
+			sentList.add(0,prev);
+			return;
 		}
 		startMerge(command);
 		return;
@@ -190,7 +195,6 @@
 	private void startMerge(REPCommand command) {
 		preMergeCommand = new REPCommand(command);
 		preMergeCommand.string = "";
-		checkDouble(sentList);
 		// merge は必須だが、EditorのCommand実装をテストするには邪魔なので、off に出来るようにする。
 		if (noMergeMode) {
 			endMerge();
@@ -204,7 +208,6 @@
 		// Session Manager 側で、このeditorへの他のeditorからの
 		// 入力を止めて、merge にそなえる。merge は、eidtor 側から
 		// ACKが来てから始まる。
-		checkDouble(sentList);
 		translator.startMerge(cmd);
 	}
 
@@ -255,7 +258,6 @@
 			sentList.add(keep);
 			ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
 			assert(sentList.size()<limit);
-			checkDouble(sentList);
 			next.send(keep);
 		} else {
 			next.send(preMergeCommand);
@@ -347,7 +349,7 @@
 		ServerMainLoop.logger.writeLog("Manager "+manager.getId()+" read : command = " + command 
 				+" from "+manager.editorList.editorByChannel(channel));
 		if (command.cmd==REP.SMCMD_JOIN||command.cmd==REP.SMCMD_PUT) {
-			assert false;
+			// assert false;
 			// 若干問題があるらしい
 			next = new Forwarder(manager,next.channel);
 			REPNode first = new FirstConnector(manager,channel);
@@ -356,9 +358,7 @@
 			return;
 		}
 		if (manager.sessionManage(this, command)) return;
-		checkDouble(sentList);
 		manage(command);
-		checkDouble(sentList);
 	}
 
 	@Override