# HG changeset patch # User sugi # Date 1420314231 -32400 # Node ID e59c8e99a5c14bc32e1943a0445b40f125a45c53 # Parent cacc83aea5391ed50825598b4f4d1cbeba5ba313 modify chapter4 diff -r cacc83aea539 -r e59c8e99a5c1 paper/chapter1.tex --- a/paper/chapter1.tex Thu Jan 01 12:27:53 2015 +0900 +++ b/paper/chapter1.tex Sun Jan 04 04:43:51 2015 +0900 @@ -33,10 +33,10 @@ \subsection{Data Segment API} 以下が用意されているData Segment APIである。これらを用いてデータの送受信を行う。 \begin{itemize} -\item {\ttfamily void put(String key, Object val)} -\item {\ttfamily void update(String key, Object val)} -\item {\ttfamily void peek(Receiver receiver, String key)} -\item {\ttfamily void take(Receiver receiver, String key)} +\item \verb+void put(String key, Value val)+ +\item \verb+void update(String key, Value val)+ +\item \verb+void peek(Receiver receiver, String key)+ +\item \verb+void take(Receiver receiver, String key)+ \end{itemize} \subsubsection{put} putはデータをQueueに追加するためのAPIである。Lindaのout()に相当する。(図 \ref{fig:put}) @@ -100,7 +100,7 @@ \begin{figure}[htbp] \begin{center} -\includegraphics[width=110mm]{images/dsandcs.pdf} +\includegraphics[width=100mm]{images/dsandcs.pdf} \end{center} \caption{Code SegmentはInput Data Segment とOutput Data Segmentが存在する} \label{fig:dsandcs} @@ -115,7 +115,7 @@ \begin{figure}[htbp] \begin{center} -\includegraphics[width=120mm]{images/dsandcs2.pdf} +\includegraphics[width=110mm]{images/dsandcs2.pdf} \end{center} \caption{Input Data Segment とOut put Data SegmentがCode Segment間の依存関係を自動的に記述する} \label{fig:dsandcs2} @@ -123,6 +123,43 @@ 現在、Inputの場合はsetKeyを呼ぶ際、Outputはput(またはupdate)の際にノードとkeyの指定を行っている。 しかし、どの時点でノードとkeyの指定を行えばよいか、どのようなAPIを用意するべきかは、議論の余地がある。 +\subsection{Code Segmentの実行方法} +Alice には、Start Code Segment (ソースコード \ref{src:StartCodeSegment})というC の main に相当するような最初に実行される Code Segment がある。 +\begin{table}[html] +\lstinputlisting[label=src:StartCodeSegment, caption=StartCodeSegmentの例]{source/StartCodeSegment.java} +\end{table} + +Start Code SegmentはどのData Segmentにも依存しない。つまりInput Data Segmentを持たない。 +このCode Segmentをmainメソッド内でnewし、executeメソッドを呼ぶことで実行を開始させることができる。 + +\subsection{Code Segmentの記述方法} +Code Segmentをユーザーが記述する際にはCode Segmentを継承して記述する(ソースコード \ref{src:CodeSegment})。 +Code SegmentはInput/Output Data Segment Managerを利用することができる。 + +Input DSM はCode Segmentの{\tt ids}というフィールドを用いてアクセスする。 + +\begin{table}[html] +\lstinputlisting[label=src:CodeSegment, caption=CodeSegmentの例]{source/TestCodeSegment.java} +\end{table} + +\begin{itemize} +\item {\ttfamily Receiver create(CommandType type)} +\end{itemize} +createでコマンドが実行された際に取得されるData Segmentが格納される受け皿を作る。引数にはCommandTypeが取られ、指定できるCommandTypeは{\tt PEEK}または{\tt TAKE}である。 +\begin{itemize} +\item \verb+void setKey(String managerKey, String key)+ +\end{itemize} +setKeyメソッドにより、どこのData Segmentのあるkeyに対してpeekまたはtakeコマンドを実行させるかを指定することができる。 +コマンドの結果がレスポンスとして届き次第Code Segmentは実行される。 + +Output DSMはCode Segmentの{\tt ods}というフィールドを用いてアクセスする。 +Output DSMは{\tt put}または{\tt update}を実行することができる。 +\begin{itemize} +\item \verb+void put(String managerKey, String key, Object val)+ +\item \verb+void update(String managerKey, String key, Object val)+ +\end{itemize} + + \section{Meta Data Segment} Meta Data SegmentはData Segmentの一種である。Data Segmentは、ユーザーがput(またはupdate)したデータを管理するData Baseであるのに対して、Meta Data Segmentは、分散フレームワークAliceがputしたデータを管理するData Baseである。管理されているデータは、主にTopology Nodeの状態を表すメタデータである。ユーザーがメタデータを扱うこともできる。 @@ -134,7 +171,12 @@ 現在のAliceでは、メタデータはデータと同じ領域にputされているため、データと同じAPIを用いて取得できる。 \section{Meta Code Segment} -Meta Code SegmentはAlice内部で動いているCode Segmentである。つまり、daemonのことである。 +Meta Code SegmentはAliceを構成するCode Segmentである。 + + + +Alice自身が全てCode Segmentで記述されているため、AliceをMeta Code Segmentのかたまりと考える事ができる。 + \section{Topology Manager} Aliceは複数のノードで構成され、相互に接続される。通信するノードはURLにより直接指定するのではなくTopology Managerで管理する。 @@ -193,4 +235,5 @@ \caption{Topology ManagerとTopology Node間の通信} \label{fig:topologymanagerandnode} \end{figure} + \section{Aliceによるプログラミング手法} \ No newline at end of file diff -r cacc83aea539 -r e59c8e99a5c1 paper/chapter3.tex --- a/paper/chapter3.tex Thu Jan 01 12:27:53 2015 +0900 +++ b/paper/chapter3.tex Sun Jan 04 04:43:51 2015 +0900 @@ -17,9 +17,9 @@ 現在は、TreeVNCのTopologyである木構造のみ指定可能である。引数Childの後に子供の数を指定することで2分木だけではなく3分木などのTopologyを作ることができる。デフォルトでは2分木になっている。 \subsection{Dynamic Topology Managerの参加表明処理} -トポロジーファイルを指定して起動した場合は、図 \ref{fig:topologymanagerandnode}で示したように、アプリケーションが起動する前に全ての接続すべきTopology Nodeの情報がTopology Nodeにputされ,、接続処理が行われる。 +トポロジーファイルを指定して起動した場合は、図 \ref{fig:topologymanagerandnode}で示したように、アプリケーションが起動する前に全ての接続すべきTopology Nodeの情報がTopology Nodeにputされ、接続処理が行われる。 -Dynamic Topologyの場合は、新しくTopology Nodeがアプリケーションに参加するたびにTopology ManagerからTopology Nodeに対して、接続すべきTopology Nodeの情報がputされ、接続処理が行われる。(図 \ref{fig:DynamicTopology}) +Dynamic Topologyの場合は、新しくTopology Nodeがアプリケーションに参加するたびにTopology ManagerからTopology Nodeに対して、接続すべきTopology Nodeの情報がputされ、接続処理が行われる。(図 \ref{fig:DynamicTopology})。 Dynamic Topologyへの参加表明の方法は、従来の方法と同じく、Topology Nodeの起動時にコマンドライン引数からTopology ManagerのIPアドレスとポート番号を指定するだけでよい。 @@ -27,28 +27,69 @@ \begin{center} \includegraphics[width=100mm]{images/DynamicTopologymanagerandnode.pdf} \end{center} -\caption{Topology Nodeが参加する毎に接続すべき情報がTopology Nodeに伝えられる} +\caption{Dynamic Topology ManagerとTopology Node間の通信} \label{fig:DynamicTopology} \end{figure} \section{Keep Alive} ノード間の通信は、Remote Data Segmentに対してputやpeekを行うことでのみ発生する。従って、Code Segmentの実装次第では、長時間通信が行われない可能性がある。通信が行われない間にRemote Data Segmentとの接続が切れた場合、次の通信が行われるまで切断を発見することができない。また、接続状態ではあるが問題が発生し、応答に時間がかかる場合も考えられる。 -以上の問題を検知するために分散アプリケーションではKeep Aliveという、定期的にheart beatを送り生存確認を行う機能を持つことが望ましい。 -そこで、Alice自体にKeep Aliveの機能を実装した。 + +以上の問題を検知するためにアプリケーションではKeep Aliveという、定期的にheart beatを送り生存確認を行う機能を持つことが望ましい。そこで、Alice自体にKeep Aliveの機能を実装した。 一定時間内にノードから応答がない場合、Keep Aliveにより、そのノードのRemote Data Segmentが切断される。 + +図 \ref{fig:keepAlive}は、keepAliveの処理をコミュニケーションダイアグラムで示したものである。 +keepAliveは、タスクとタスクを実行するTaskExecuterと実行順序を管理するSchedulerによって実装されている。 +タスクの種類には、{\tt PING}、{\tt CLOSE}、{\tt CREATE}があり、TaskExecuterは、タスクの種類に従って処理を行なう。 +{\tt PING}は、指定されたRemote Data Segmentに対してheartbeatを送信する。 +{\tt CLOSE}は、指定されたRemote Data Segmentを削除する。 +{\tt CREATE}は{\tt PING}のタスクを作成し、Schedulerに登録する。 + +タスクを作成する際に実行時間の指定をする。Schedulerにタスクを登録すると、Schedulerはタスクの実行時間に従って、タスクを実行順に並び替える。 +\begin{figure}[htbp] +\begin{center} +\includegraphics{images/keepAlive.pdf} +\end{center} +\caption{keepAliveの仕組み} +\label{fig:keepAlive} +\end{figure} + +\subsubsection{処理の流れ} +\begin{enumerate} +\item CreateTask(Code Segment)により{\tt PING}タスクが投入される。\label{enum:putPingTask} +\item TaskExecuterはSchedulerから次に実行すべき{\tt PING}タスクを受け取る。 +\item 指定された時間が訪れるとheartbeatがRemote Data Segment(Node B)に送信される。\label{enum:send} +\item \ref{enum:send}と同時にheartbeatを送信したRemote Data Segmentとの接続を切断する{\tt CLOSE}タスクが投入される。\label{enum:putCloseTask} +\item \ref{enum:putCloseTask}で投入された{\tt CLOSE}タスクが実行されるまでに、Remote Data Segment(Node B)からのレスポンスがあった場合、RemoveTask(Code Segment)により{\tt CLOSE}タスクが削除される。 +\end{enumerate} + +\ref{enum:putPingTask}で作られる{\tt PING}タスクは、接続しているRemote Data Segmentの数だけ投入される。 +"\_CLSIT"というkeyには、アクセス可能なRemote Data Segmentのkeyの一覧が保存されている。 +CreateTaskは、この一欄により動的にタスクを作成している。 + +以上で説明した処理の流れは、接続状態に問題がない場合である。 +接続状態に問題があり、{\tt CLOSE}タスクの実行されるまでにレスポンスがない場合は、{\tt CLOSE}タスクによりRemote Data Segmentが削除される。 +%Singleton Code Segmentの注意点 ids.initが必要とその理由の記述 + \section{切断時の処理} DataBaseではデータ更新の際にトランザクション処理に障害が起こった場合、DataBase側でトランザクション処理開始前に戻すロールバックという処理が行われる。 同様にTreeVNCでは切断を検知した場合、LostParentというメッセージがトップノードに対して送信される。 + 以上の例のように、アプリケーションはノードの切断に対する処理を用意したい場合がある。 しかし、Aliceを用いたアプリケーションの場合、アプリケーション側で検知するのは難しい。 切断自体は、Remote Data Segmentに対してwriteまたはreadを行った際に出るExceptionにより判断することができる。 -だが、I/O の処理はCode Segmentを実行するThreadで行われず、専用のI/O Threadによって行われるためCode SegmentでExceptionを捕まえられない。 -そこで、Aliceが切断を検知、管理する機能 (ClosedEventManager)を追加した。 -アプリケーション側でClosedEventManagerにCode Segmentを登録することで切断時に任意のCode Segmentを実行することができる。 -また、切断したRemote Data Segmentの情報を利用したい場合は、Code Segmentをextends する代わりにClosed Event Code Segmentをextendsし、用意されているMethodを使うことで取得可能である。 +だが、I/O の処理はCode Segmentを実行するThreadで行われない。専用のI/O Threadによって行われるため、Code Segment内でExceptionを捕まえられず、例外として処理することができない。 + +そこで、Aliceが切断を検知した際に、任意のCode Segmentを実行できる機能 (ClosedEventManager)を追加した。 +ユーザはClosedEventManagerにCode Segmentを登録することで、切断時に例外処理として実行するCode Segmentを指定できる。 +また、切断したRemote Data Segmentの情報を利用したい場合は、Code Segmentをextends する代わりにClosed Event Code Segmentをextendsし、用意されているMethodを使うことで取得可能である(ソースコード \ref{src:CatchClosedEvent})。 +\begin{table}[htbp] +\lstinputlisting[label=src:CatchClosedEvent, caption=CloseEventCodeSegmentを継承したCodeSegment]{source/CatchClosedEvent.java} +\end{table} +ClosedEventCodeSegmentを継承したCode Segmentに、Input Data Segmentを追加記述する事ができる。 +その際は、もちろんInput Data Segmentが全て揃うまでCode Segmentは実行されない。 \section{再接続の処理} diff -r cacc83aea539 -r e59c8e99a5c1 paper/images/DynamicTopologymanagerandnode.graffle --- a/paper/images/DynamicTopologymanagerandnode.graffle Thu Jan 01 12:27:53 2015 +0900 +++ b/paper/images/DynamicTopologymanagerandnode.graffle Sun Jan 04 04:43:51 2015 +0900 @@ -417,7 +417,7 @@ Bounds - {{373.10604510875214, 463.76953125}, {57, 28}} + {{409.16854510875214, 459.4375}, {57, 28}} Class ShapedGraphic FitText @@ -466,7 +466,7 @@ Bounds - {{245.125, 20.875}, {57, 28}} + {{315.875, 10.125}, {57, 28}} Class ShapedGraphic FitText @@ -515,7 +515,7 @@ Bounds - {{239.5625, 452.37109375}, {105, 28}} + {{275.625, 448.0390625}, {105, 28}} Class ShapedGraphic FitText @@ -583,8 +583,8 @@ 298 Points - {343.5625, 504.38671875000011} - {406.90921393016993, 429.12359109355884} + {379.625, 500.05468750000011} + {442.97171393016993, 424.79155984355884} Rotation 180 @@ -609,7 +609,7 @@ Bounds - {{258.75, 279.4609375}, {57, 28}} + {{311.625, 269.8828125}, {57, 28}} Class ShapedGraphic FitText @@ -677,8 +677,8 @@ 294 Points - {154.28790978249577, 329.9921875} - {378.25, 227.6484375} + {207.16290978249577, 320.4140625} + {431.125, 218.0703125} Rotation 180 @@ -722,8 +722,8 @@ 292 Points - {223.125, 55.250000000000007} - {324.125, 55.249999999999993} + {293.875, 44.500000000000007} + {394.875, 44.499999999999993} Rotation 180 @@ -748,7 +748,7 @@ Bounds - {{279.0625, 552.38671875}, {57, 14}} + {{315.125, 548.0546875}, {57, 14}} Class ShapedGraphic FitText @@ -796,7 +796,7 @@ Bounds - {{267.0625, 504.38671875}, {81, 48}} + {{303.125, 500.0546875}, {81, 48}} Class ShapedGraphic FontInfo @@ -861,8 +861,8 @@ 289 Points - {145.53667400105238, 500.76043356511332} - {196.7133259989476, 428.76300393488668} + {181.59917400105238, 496.42840231511332} + {232.7758259989476, 424.43097268488668} Style @@ -888,7 +888,7 @@ Bounds - {{363.5625, 380.35546875}, {96, 48}} + {{399.625, 376.0234375}, {96, 48}} Class ShapedGraphic FontInfo @@ -929,7 +929,7 @@ Bounds - {{99.6875, 549.16796875}, {57, 14}} + {{135.75, 544.8359375}, {57, 14}} Class ShapedGraphic FitText @@ -977,7 +977,7 @@ Bounds - {{87.6875, 501.16796875}, {81, 48}} + {{123.75, 496.8359375}, {81, 48}} Class ShapedGraphic FontInfo @@ -1018,7 +1018,7 @@ Bounds - {{185.5625, 428.35546875}, {57, 14}} + {{221.625, 424.0234375}, {57, 14}} Class ShapedGraphic FitText @@ -1066,7 +1066,7 @@ Bounds - {{173.5625, 380.35546875}, {81, 48}} + {{209.625, 376.0234375}, {81, 48}} Class ShapedGraphic FontInfo @@ -1107,7 +1107,7 @@ Bounds - {{257.5625, 365.91796875}, {103, 28}} + {{293.625, 361.5859375}, {103, 28}} Class ShapedGraphic FitText @@ -1180,8 +1180,8 @@ 281 Points - {391.11728070500004, 428.73860438156697} - {328.0077192949999, 504.00358311843308} + {427.17978070500004, 424.40657313156697} + {364.0702192949999, 499.67155186843308} Style @@ -1233,8 +1233,8 @@ 280 Points - {363.0625, 404.3554585086867} - {255.0625, 404.3554585086867} + {399.125, 400.0234272586867} + {291.125, 400.0234272586867} Style @@ -1262,7 +1262,7 @@ Bounds - {{346.25, 173.2109375}, {96, 48}} + {{399.625, 162.34624734355896}, {96, 48}} Class ShapedGraphic FontInfo @@ -1303,7 +1303,7 @@ Bounds - {{82.875, 347.5859375}, {57, 14}} + {{135.75, 338.0078125}, {57, 14}} Class ShapedGraphic FitText @@ -1351,7 +1351,7 @@ Bounds - {{70.875, 299.5859375}, {81, 48}} + {{123.75, 290.0078125}, {81, 48}} Class ShapedGraphic FontInfo @@ -1392,7 +1392,7 @@ Bounds - {{154.25, 221.2421875}, {57, 14}} + {{221.625, 209.578125}, {57, 14}} Class ShapedGraphic FitText @@ -1440,7 +1440,7 @@ Bounds - {{142.25, 173.2421875}, {81, 48}} + {{209.625, 161.578125}, {81, 48}} Class ShapedGraphic FontInfo @@ -1481,7 +1481,7 @@ Bounds - {{116, 252.2421875}, {101, 28}} + {{168.875, 242.6640625}, {101, 28}} Class ShapedGraphic FitText @@ -1530,7 +1530,7 @@ Bounds - {{229.25, 151.2421875}, {103, 28}} + {{293.625, 148.8984375}, {103, 28}} Class ShapedGraphic FitText @@ -1603,8 +1603,8 @@ 241 Points - {345.79348605349213, 218.85898680474884} - {152.33151394625867, 305.28852887611276} + {399.16912903635364, 208.1768803951272} + {205.20589705503198, 295.56237277554931} Style @@ -1656,8 +1656,8 @@ 249 Points - {345.75000000545776, 197.21810354723033} - {223.74999999454201, 197.23612948047321} + {399.12500354020466, 186.16373670070135} + {291.12499522444659, 185.75732118760587} Style @@ -1685,7 +1685,7 @@ Bounds - {{150.875, 92.125}, {57, 14}} + {{221.625, 81.375}, {57, 14}} Class ShapedGraphic FitText @@ -1733,7 +1733,7 @@ Bounds - {{262.375, 78.125}, {27, 28}} + {{333.125, 67.375}, {27, 28}} Class ShapedGraphic FitText @@ -1806,8 +1806,8 @@ 246 Points - {321.375, 68.124990879811577} - {220.375, 68.124990879811577} + {392.125, 57.374990879811577} + {291.125, 57.374990879811577} Style @@ -1835,7 +1835,7 @@ Bounds - {{138.875, 44.125}, {81, 48}} + {{209.625, 33.375}, {81, 48}} Class ShapedGraphic FontInfo @@ -1876,7 +1876,7 @@ Bounds - {{321.875, 44.125}, {96, 48}} + {{392.625, 33.375}, {96, 48}} Class ShapedGraphic FontInfo @@ -1965,7 +1965,7 @@ MasterSheets ModificationDate - 2015-01-01 01:58:44 +0000 + 2015-01-01 12:10:26 +0000 Modifier YuSugimoto NotesVisible @@ -2037,13 +2037,13 @@ WindowInfo BottomSlabHeight - 714 + 669 CurrentSheet 0 Expanded_Canvases Frame - {{5, -0}, {1893, 1058}} + {{-2, 45}, {1239, 1013}} ShowInfo ShowRuler @@ -2053,7 +2053,7 @@ SidebarWidth 230 VisibleRegion - {{-393, -66}, {1346, 916}} + {{-66, -44}, {692, 871}} Zoom 1 ZoomValues diff -r cacc83aea539 -r e59c8e99a5c1 paper/images/DynamicTopologymanagerandnode.pdf Binary file paper/images/DynamicTopologymanagerandnode.pdf has changed diff -r cacc83aea539 -r e59c8e99a5c1 paper/images/keepAlive.pdf Binary file paper/images/keepAlive.pdf has changed diff -r cacc83aea539 -r e59c8e99a5c1 paper/source/CatchClosedEvent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/source/CatchClosedEvent.java Sun Jan 04 04:43:51 2015 +0900 @@ -0,0 +1,12 @@ +import alice.codesegment.CloseEventCodeSegment; +import alice.daemon.ConnectionInfo; + +public class CatchClosedEvent extends CloseEventCodeSegment{ + + @Override + public void run() { + ConnectionInfo e = getConnectionInfo(); + System.out.println("IPAddr "+ e.addr); + System.out.println("port "+ e.port); + } +} diff -r cacc83aea539 -r e59c8e99a5c1 paper/source/StartCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/source/StartCodeSegment.java Sun Jan 04 04:43:51 2015 +0900 @@ -0,0 +1,13 @@ +public class StartCodeSegment extends CodeSegment { + + @Override + public void run() { + System.out.println("run StartCodeSegment"); + + new TestCodeSegment(); + System.out.println("create TestCodeSegment"); + + ods.update("local", "key1", "String data"); + } + +} \ No newline at end of file diff -r cacc83aea539 -r e59c8e99a5c1 paper/source/TestCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/source/TestCodeSegment.java Sun Jan 04 04:43:51 2015 +0900 @@ -0,0 +1,19 @@ +public class TestCodeSegment extends CodeSegment { + private Receiver input1 = ids.create(CommandType.TAKE); + + public TestCodeSegment() { + input1.setKey("local", "key1"); + } + + @Override + public void run() { + int num = input1.asInteger(); + System.out.println("data = " + num); + + if (num == 10) + System.exit(0); + + new TestCodeSegment(); + ods.update("local", "key1", ++num); + } +} \ No newline at end of file