changeset 497:6d7e284f22dc

global sequence mode
author one
date Sun, 24 Oct 2010 14:16:40 +0900
parents 280a04224c6c
children 138f3b33aa5e
files Todo rep/handler/Editor.java rep/handler/Forwarder.java
diffstat 3 files changed, 50 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Todo	Sun Oct 24 14:16:27 2010 +0900
+++ b/Todo	Sun Oct 24 14:16:40 2010 +0900
@@ -1,3 +1,13 @@
+Sun Oct 24 13:24:55 JST 2010
+
+gseq + editor-id + lseq の順にソートする
+gseq は、他コマンドが来た時に、それよりも大きく設定する
+gseq をsyncするプロトコルが必要 (heart beat を兼ねて)
+
+    gseq * 1000 + lseq
+で良い? lseq がoverflowしたら gseq が一つ増える。
+自分で遅くする分には問題ない
+
 Sat Oct 23 22:24:31 JST 2010
 
     Editor1    Editor2    Editor3 
@@ -43,6 +53,8 @@
 
 Editor3で、eがa,cを追い越せない理由は?
 
+    なんらかのマークがないと区別できない
+
     c_a
     _ed
     _f_
--- a/rep/handler/Editor.java	Sun Oct 24 14:16:27 2010 +0900
+++ b/rep/handler/Editor.java	Sun Oct 24 14:16:40 2010 +0900
@@ -80,11 +80,11 @@
 	(4) 他のEditorのCommandを受け取ってから、ack が来るまでのCommandをキューに
 		入れておき、ack が来たら、eid とCommandの順序を基にソートする。(other merge (Slow))
 	Direct
-	(5)  他のEditor Command が来た時点で、すぐにmergeする
-	(6)  自分のEditor Command が来て、
-	          未確定の他のEditor Command があれば、それを確定(sentList/unMergedListから削除)
-	          自分のEditor Command はsentListに追加 (unMergedListには既に入っている)
-	(7)  Ackが来たら、そのEditor Command まで確定
+	       seq = gseq*limit + lseq
+	(5)  他のEditor Command が来た時点で、すぐにmergeする。  gseqを他コマンドのgseqよりも
+	  大きくなるように設定。sentListに追加  
+	(6)  自分のEditor Command はsentListに追加
+	(7)  Ackが来たら、そのEditor Command まで確定 (sentList/unMergedListから削除)
 
 		Editor には、ソートした編集結果になるように、それまで行なった編集をUndo
 		して、ソートした編集結果を適用する。Undo が無駄な動作をしないように最適化する。
@@ -192,8 +192,12 @@
 		}
 	}
 
+	
+	/**
+	 * 	エディタからの新たな編集コマンド
+	 * @param command
+	 */
 	private void userEditorCommand(REPCommand command) {
-		//エディタからの新たな編集コマンド
 		if (next==this) return; // singleton case
 		transSendCmd(command);
 		sendEditorCommand(command);
@@ -415,22 +419,11 @@
 	}
 
 	/**
-	 * User Editor Command Fix the command order of
-	 * other editor commands except own command
-	 * truncate sentList and unMergedCmds.
-	 *   mode==false  Don't truncate unMergedCmds after merge mark 
+	 * User Editor Command
+	 *    no truncate here 
 	 */
 	private void truncateSentList(REPCommand commit, boolean mode) {
 		if (mode && blocking) 	return; // merging is not enough except from endMerge()
-		LinkedList<REPCommand>s = new LinkedList<REPCommand>();
-		for(REPCommand command:sentList) {
-			if (command.eid!=eid) {
-				s.clear();
-				continue;
-			}
-			s.addLast(command);
-		}
-		sentList = s;
 	}
 	
 	/**
@@ -642,7 +635,6 @@
 	public boolean merge(REPCommand prev){
 		logger.writeLog("beforeMerge"+eid+":"+sentList);
 		LinkedList<REPCommand> output = new LinkedList<REPCommand>();
-		LinkedList<REPCommand> newSentList = new LinkedList<REPCommand>();
 		// merge queue上にあるコマンドを全部undoコマンドするのと同時に
 		// sort したコマンド列を生成する
 		for( REPCommand cmd0 : sentList) {
@@ -652,25 +644,17 @@
 
 		sortedEditCmds = new TreeSet<REPCommand>(new REPCommandComparator(1));
 		logger.writeLog("sentList"+eid+":"+sentList);
-		boolean flag = true;
 		for( REPCommand cmd0 : sentList ) {
-			if (cmd0.cmd==REP.REPCMD_MERGE_MARK) { 
-				flag = false;
-			}
 			if (cmd0.cmd==REP.REPCMD_INSERT || cmd0.cmd==REP.REPCMD_DELETE) {
-				if (flag)	sortedEditCmds.add(cmd0);
-				else newSentList.add(cmd0);
+				sortedEditCmds.add(cmd0);
 			}
 		}
 		output.addLast(mergeMark);
+		output.addAll(sortedEditCmds);
 		LinkedList<REPCommand> ns = new LinkedList<REPCommand>();
-		output.addAll(sortedEditCmds);
 		ns.addAll(sortedEditCmds);
-		ns.addLast(mergeMark);
-		output.addAll(newSentList);
-		ns.addAll(newSentList);
 		sentList = ns;
-		logger.writeLog("sortedMerge"+eid+":"+sortedEditCmds+newSentList);
+		logger.writeLog("sortedMerge"+eid+":"+sortedEditCmds);
 		// unMerged command のdeleteのundo string は、この時点で使えない。
 		// Editor 側から送り返して来たものを使う必要がある。
 		logger.writeLog("outputMerge"+eid+":"+output);
@@ -753,6 +737,8 @@
 		public int compare(REPCommand o1, REPCommand o2) {
 			int eid1 = o1.eid-base; if (eid1<0) eid1 += Integer.MAX_VALUE;
 			int eid2 = o2.eid-base; if (eid2<0) eid2 += Integer.MAX_VALUE;
+			if ( gSeq(o1)<gSeq(o2) ) return -1;
+			if ( gSeq(o1)>gSeq(o2) ) return 1;
 			if ( eid1<eid2 ) return -1;
 			if ( eid1>eid2 ) return 1;
 			if ( o1.seq<o2.seq ) return -1;
@@ -769,8 +755,25 @@
 	 */
 	public void transReceiveCmd(REPNode nextEditor,REPCommand cmd){
 		assert (cmd.eid != eid);
+		incrementGseq(cmd);
 	}
 
+	final int gseqLimit = 1000;
+	
+	private int gSeq(REPCommand cmd) {
+		return cmd.seq/gseqLimit;
+	}
+	
+	/**
+	 * increment global sequence part 
+	 * @param oseq
+	 */
+	private void incrementGseq( REPCommand cmd) {
+		if (gSeq(cmd) / gseqLimit > seq / gseqLimit) {
+			setSeq((gSeq(cmd)/gseqLimit+1)*gseqLimit);
+		}
+	}
+	
 	public void setEid(int _eid){
 		eid = _eid;
 	}
--- a/rep/handler/Forwarder.java	Sun Oct 24 14:16:27 2010 +0900
+++ b/rep/handler/Forwarder.java	Sun Oct 24 14:16:40 2010 +0900
@@ -35,6 +35,10 @@
 	public int seq() {
 		return seq++;
 	}
+	
+	public void setSeq(int seq) {
+		this.seq = seq;
+	}
 
 	@Override
 	public void send(REPCommand command) {