annotate src/alice/datasegment/LocalDataSegmentManager.java @ 225:bc061ee5f31f

bitonic sort work but data is not sorted
author sugi
date Thu, 28 Mar 2013 18:10:24 +0900
parents 409d7679cf7b
children ca1c9c477f54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
1 package alice.datasegment;
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
2
56
17f88fd202ae refactor data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
3 import java.util.concurrent.ConcurrentHashMap;
69
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
4 import java.util.concurrent.LinkedBlockingQueue;
73
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
5 import java.util.concurrent.ThreadPoolExecutor;
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
6 import java.util.concurrent.TimeUnit;
56
17f88fd202ae refactor data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
7
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
8 import org.apache.log4j.Logger;
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
9 import org.msgpack.type.Value;
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
10
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
11 import alice.codesegment.CodeSegment;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
12
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
13 public class LocalDataSegmentManager extends DataSegmentManager {
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
14
56
17f88fd202ae refactor data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
15 private String reverseKey = "local";
17f88fd202ae refactor data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
16 private ConcurrentHashMap<String, DataSegmentKey> dataSegments = new ConcurrentHashMap<String, DataSegmentKey>();
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
17 private Logger logger = Logger.getLogger("local");
69
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
18
73
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
19 private ThreadPoolExecutor dataSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
20 Runtime.getRuntime().availableProcessors(),
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
21 Integer.MAX_VALUE, // keepAliveTime
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
22 TimeUnit.SECONDS,
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
23 new LinkedBlockingQueue<Runnable>());
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
24
172
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
25 public LocalDataSegmentManager() {
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
26 new Thread(replyThread, "LocalDataSegmentManager-replyCommand").start();
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
27 }
69
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
28
172
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
29 private class RunCommand implements Runnable {
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
30
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
31 DataSegmentKey key;
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
32 Command cmd;
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
33
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
34 public RunCommand(DataSegmentKey key, Command cmd) {
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
35 this.key = key;
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
36 this.cmd = cmd;
69
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
37 }
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
38
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
39 @Override
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
40 public void run() {
172
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
41 key.runCommand(cmd);
69
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
42 }
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
43
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
44 }
172
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
45
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
46 public void submitCommand(DataSegmentKey key, Command cmd) {
82a1c25ca0c8 remove unused thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
47 dataSegmentExecutor.execute(new RunCommand(key, cmd));
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
48 }
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
49
13
30f97d776a3e implements Alice daemon
one
parents: 12
diff changeset
50 public DataSegmentKey getDataSegmentKey(String key) {
64
7aaadd08288c add getLocal method to DataSegment
kazz
parents: 63
diff changeset
51 DataSegmentKey dsKey = dataSegments.get(key);
63
498d1d2524d3 change getDataSegmentKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
52 if (dsKey != null)
498d1d2524d3 change getDataSegmentKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
53 return dsKey;
498d1d2524d3 change getDataSegmentKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
54 if (key == null)
16
433e601a8e28 network bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
55 return null;
69
1d4f2b72fb31 delete KeyThread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 68
diff changeset
56 DataSegmentKey newDataSegmentKey = new DataSegmentKey();
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
57 DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey);
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
58 if (dataSegmentKey == null) {
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
59 dataSegmentKey = newDataSegmentKey;
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
60 }
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
61 return dataSegmentKey;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
62 }
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
63
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
64 @Override
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 71
diff changeset
65 public void put(String key, Value val) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
66 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
202
7f47231ef509 add new flip API
sugi
parents: 199
diff changeset
67 Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, reverseKey);
225
bc061ee5f31f bitonic sort work but data is not sorted
sugi
parents: 224
diff changeset
68 submitCommand(dataSegmentKey, cmd);
71
a3a2605e16a2 change checking debug mode of logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
69 if (logger.isDebugEnabled())
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
70 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
71 }
57
7fa9ddb31f64 add comment
one
parents: 56
diff changeset
72
215
1fd7067f0044 remove conversion flag
one
parents: 212
diff changeset
73 public void putObject(String key, Object obj) {
190
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
74 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
202
7f47231ef509 add new flip API
sugi
parents: 199
diff changeset
75 Command cmd = new Command(CommandType.PUT, null, key, obj, 0, 0, null, null, reverseKey);
225
bc061ee5f31f bitonic sort work but data is not sorted
sugi
parents: 224
diff changeset
76 submitCommand(dataSegmentKey, cmd);
190
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
77 if (logger.isDebugEnabled())
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
78 logger.debug(cmd.getCommandString());
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
79 }
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
80
57
7fa9ddb31f64 add comment
one
parents: 56
diff changeset
81 /**
7fa9ddb31f64 add comment
one
parents: 56
diff changeset
82 * Enqueue update command to the queue of each DataSegment key
7fa9ddb31f64 add comment
one
parents: 56
diff changeset
83 */
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
84 @Override
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 71
diff changeset
85 public void update(String key, Value val) {
5
80375ae09a1f add update api
one
parents: 3
diff changeset
86 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
202
7f47231ef509 add new flip API
sugi
parents: 199
diff changeset
87 Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, reverseKey);
225
bc061ee5f31f bitonic sort work but data is not sorted
sugi
parents: 224
diff changeset
88 submitCommand(dataSegmentKey, cmd);
71
a3a2605e16a2 change checking debug mode of logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
89 if (logger.isDebugEnabled())
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
90 logger.debug(cmd.getCommandString());
5
80375ae09a1f add update api
one
parents: 3
diff changeset
91 }
190
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
92
215
1fd7067f0044 remove conversion flag
one
parents: 212
diff changeset
93 public void updateObject(String key, Object val) {
190
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
94 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
202
7f47231ef509 add new flip API
sugi
parents: 199
diff changeset
95 Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, reverseKey);
225
bc061ee5f31f bitonic sort work but data is not sorted
sugi
parents: 224
diff changeset
96 submitCommand(dataSegmentKey, cmd);
190
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
97 if (logger.isDebugEnabled())
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
98 logger.debug(cmd.getCommandString());
a85ff8dc16c1 add Object data
one
parents: 189
diff changeset
99 }
5
80375ae09a1f add update api
one
parents: 3
diff changeset
100
80375ae09a1f add update api
one
parents: 3
diff changeset
101 @Override
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
102 public void take(Receiver receiver, String key, int index, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
103 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
104 int seq = this.seq.getAndIncrement();
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
105 Command cmd = new Command(CommandType.TAKE, receiver, key, null, index, seq, replyQueue, cs, null);
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
106 seqHash.put(seq, cmd);
73
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
107 submitCommand(dataSegmentKey, cmd);
71
a3a2605e16a2 change checking debug mode of logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
108 if (logger.isDebugEnabled())
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
109 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
110 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
111
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
112 @Override
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
113 public void peek(Receiver receiver, String key, int index, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
114 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
115 int seq = this.seq.getAndIncrement();
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
116 Command cmd = new Command(CommandType.PEEK, receiver, key, null, index, seq, replyQueue, cs, null);
58
ebdcab7b9b04 add comment
one
parents: 57
diff changeset
117 seqHash.put(seq, cmd); // waiting for PUT or UPDATE at unique sequence number
73
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
118 submitCommand(dataSegmentKey, cmd);
71
a3a2605e16a2 change checking debug mode of logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
119 if (logger.isDebugEnabled())
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
120 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
121 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
122
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
123 @Override
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
124 public void remove(String key) {
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
125 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
126 Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, replyQueue, null, null);
73
4bfd81352cfa change to concurrent data segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
127 submitCommand(dataSegmentKey, cmd);
71
a3a2605e16a2 change checking debug mode of logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
128 if (logger.isDebugEnabled())
68
d4c7f7b1096b remove copy at OutboundTcpConnection
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 67
diff changeset
129 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
130 }
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
131
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
132 @Override public void finish() {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
133 System.exit(0);
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
134 }
41
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
135
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
136 @Override
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
137 public void close() {
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
138
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
139 }
189
d2f5c885a367 add FLIP API in LocalDataSegmentManager class
e095732
parents: 184
diff changeset
140
209
96110f25adcc add new flip API
sugi
parents: 205
diff changeset
141
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
142 }