changeset 407:de4ef4313adc current-release

looks like working...
author one
date Tue, 25 Nov 2008 17:54:54 +0900
parents 8009dd7b2013
children 3f5d5b74ffd6
files Todo rep/handler/Editor.java rep/handler/Translator.java test/Text.java test/sematest/TestEditor.java
diffstat 5 files changed, 33 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Todo	Tue Nov 25 09:07:52 2008 +0900
+++ b/Todo	Tue Nov 25 17:54:54 2008 +0900
@@ -1,3 +1,10 @@
+Tue Nov 25 09:13:42 JST 2008
+
+Todo: 
+だいたい動いたが、たまに爆発するバグが残っているらしい。
+どうも、optimizerのbugっぽいな... いや、違いますね。
+getMergeAgainの問題らしいが、直接の原因は良くわからない。
+
 Mon Nov 24 22:51:45 JST 2008
 
 watingCommandInMerge のqueueを一旦0にしてから、manageを
@@ -12,9 +19,13 @@
 Editor側で、自分が出したINSERT/DELETE commandは無視する必要がある。
 ついでに、Editor側でINSERT_ACK/DELETE_ACKに書き換える方が良いらしい。
 
+Todo:
 INSERT_ACK/DELETE_ACKが出ない場合があるらしい。と言うか、最初の
 一回しか出ていない。
 
+Done:
+   commandInMerge の扱いが変だった。
+
 Wed Nov 19 19:21:47 JST 2008
 
 ACK base に書き換えるのは良いが、途中でjoinして
--- a/rep/handler/Editor.java	Tue Nov 25 09:07:52 2008 +0900
+++ b/rep/handler/Editor.java	Tue Nov 25 17:54:54 2008 +0900
@@ -23,7 +23,7 @@
 	private boolean merging;
 	private REPCommand preMergeCommand;
 	public static boolean noMergeMode=false;
-	static final boolean doOptimize = true;
+	static final boolean doOptimize = false;
 
 	public Editor(SessionManager manager,int editorNo){
 		// no translator case
@@ -131,7 +131,7 @@
 			addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command)));
 			return true;
 		} 
-		ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting");
+		//ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting");
 		return false;
 	}
 
@@ -148,7 +148,7 @@
 	private void sendEditorCommand(REPCommand command) {
 		REPCommand keep = new REPCommand(command);
 		sentList.add(keep);
-		ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
+		//ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
 		assert(sentList.size()<limit);
 		next.send(command);
 	}
@@ -264,7 +264,7 @@
 			default: assert(false);
 			}
 			sentList.add(keep);
-			ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
+			//ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
 			assert(sentList.size()<limit);
 			next.send(keep);
 		} else {
--- a/rep/handler/Translator.java	Tue Nov 25 09:07:52 2008 +0900
+++ b/rep/handler/Translator.java	Tue Nov 25 17:54:54 2008 +0900
@@ -8,6 +8,7 @@
 
 import rep.REP;
 import rep.REPCommand;
+import rep.SessionManager;
 import rep.optimizers.REPCommandOptimizer;
 
 public class Translator {
@@ -194,6 +195,16 @@
 				returnCommand.add(command);
 			}
 		}
+		int count = 0;
+		for(REPCommand command: returnCommand) {
+			switch(command.cmd) {
+			case REPCMD_INSERT: count++; break;
+			case REPCMD_DELETE: count--; break;
+			default: assert false;
+			}
+		}
+		SessionManager.logger.writeLog("MergeAgain ret="+returnCommand.size()+
+				" increment="+count);
 		mergeAgainList.clear();
 		optimizedSend(editor, returnCommand);
 	}
--- a/test/Text.java	Tue Nov 25 09:07:52 2008 +0900
+++ b/test/Text.java	Tue Nov 25 17:54:54 2008 +0900
@@ -23,6 +23,7 @@
 	}
 	
 	public String insert(int i, String str){
+		while (i>size()) add("");
 		assert 0<=i && i<=size();
 		add(i, str);
 		return null;
--- a/test/sematest/TestEditor.java	Tue Nov 25 09:07:52 2008 +0900
+++ b/test/sematest/TestEditor.java	Tue Nov 25 17:54:54 2008 +0900
@@ -8,6 +8,7 @@
 import rep.REP;
 import rep.REPCommand;
 import rep.REPCommandPacker;
+import rep.SessionManager;
 import rep.channel.REPLogger;
 import rep.channel.REPSelectionKey;
 import rep.channel.REPSelector;
@@ -61,8 +62,8 @@
 			this.master=true;
 			text = new Text(txts);
 			cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name+"-file"));
-			//cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0"));
-			//cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0"));
+			cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0"));
+			cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0"));
 			//cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,""));
 		} else {
 			text = new Text(new String[0]);
@@ -150,6 +151,7 @@
 		 * all clients. SYNC is requested by the session manager.
 		 */
 		if (syncCounter>text.size()) {
+			SessionManager.logger.writeLog("Sync Completed.");
 			syncCounter=0;
 		} else {
 			int i=syncCounter-1;
@@ -227,7 +229,7 @@
 
 	private void handle(REPCommand cmd) {
 		if (cmd==null) return;
-		ns.writeLog(name +": read "+cmd);
+		ns.writeLog(name +": read "+cmd + " textsize="+text.size());
 		switch(cmd.cmd) {
 		case REPCMD_INSERT	:
 			if (cmd.eid!=eid) {
@@ -238,7 +240,7 @@
 		case REPCMD_DELETE	:
 			if (cmd.eid!=eid) {
 				String del=""; 
-				if(cmd.lineno>text.size()) {
+				if(cmd.lineno<text.size()) {
 					del = text.delete(cmd.lineno);
 				}
 				cmd.setString(del);