1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.partition; |
20 | |
|
21 | |
import java.io.DataInput; |
22 | |
import java.io.DataOutput; |
23 | |
import java.io.IOException; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfigurable; |
27 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
28 | |
import org.apache.giraph.worker.WorkerInfo; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class BasicPartitionOwner implements PartitionOwner, |
35 | |
ImmutableClassesGiraphConfigurable { |
36 | |
|
37 | |
private ImmutableClassesGiraphConfiguration conf; |
38 | |
|
39 | 0 | private int partitionId = -1; |
40 | |
|
41 | |
private WorkerInfo workerInfo; |
42 | |
|
43 | |
private WorkerInfo previousWorkerInfo; |
44 | |
|
45 | |
private String checkpointFilesPrefix; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public BasicPartitionOwner() { } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public BasicPartitionOwner(int partitionId, WorkerInfo workerInfo) { |
59 | 0 | this(partitionId, workerInfo, null, null); |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public BasicPartitionOwner(int partitionId, |
71 | |
WorkerInfo workerInfo, |
72 | |
WorkerInfo previousWorkerInfo, |
73 | 0 | String checkpointFilesPrefix) { |
74 | 0 | this.partitionId = partitionId; |
75 | 0 | this.workerInfo = workerInfo; |
76 | 0 | this.previousWorkerInfo = previousWorkerInfo; |
77 | 0 | this.checkpointFilesPrefix = checkpointFilesPrefix; |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
public int getPartitionId() { |
82 | 0 | return partitionId; |
83 | |
} |
84 | |
|
85 | |
@Override |
86 | |
public WorkerInfo getWorkerInfo() { |
87 | 0 | return workerInfo; |
88 | |
} |
89 | |
|
90 | |
@Override |
91 | |
public void setWorkerInfo(WorkerInfo workerInfo) { |
92 | 0 | this.workerInfo = workerInfo; |
93 | 0 | } |
94 | |
|
95 | |
@Override |
96 | |
public WorkerInfo getPreviousWorkerInfo() { |
97 | 0 | return previousWorkerInfo; |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public void setPreviousWorkerInfo(WorkerInfo workerInfo) { |
102 | 0 | this.previousWorkerInfo = workerInfo; |
103 | 0 | } |
104 | |
|
105 | |
@Override |
106 | |
public void writeWithWorkerIds(DataOutput output) throws IOException { |
107 | 0 | output.writeInt(partitionId); |
108 | 0 | output.writeInt(workerInfo.getTaskId()); |
109 | 0 | if (previousWorkerInfo != null) { |
110 | 0 | output.writeInt(previousWorkerInfo.getTaskId()); |
111 | |
} else { |
112 | 0 | output.writeInt(-1); |
113 | |
} |
114 | 0 | if (checkpointFilesPrefix != null) { |
115 | 0 | output.writeBoolean(true); |
116 | 0 | output.writeUTF(checkpointFilesPrefix); |
117 | |
} else { |
118 | 0 | output.writeBoolean(false); |
119 | |
} |
120 | 0 | } |
121 | |
|
122 | |
@Override |
123 | |
public void readFieldsWithWorkerIds(DataInput input, |
124 | |
Map<Integer, WorkerInfo> workerInfoMap) throws IOException { |
125 | 0 | partitionId = input.readInt(); |
126 | 0 | int workerId = input.readInt(); |
127 | 0 | workerInfo = workerInfoMap.get(workerId); |
128 | 0 | int previousWorkerId = input.readInt(); |
129 | 0 | if (previousWorkerId != -1) { |
130 | 0 | previousWorkerInfo = workerInfoMap.get(previousWorkerId); |
131 | |
} |
132 | 0 | boolean hasCheckpointFilePrefix = input.readBoolean(); |
133 | 0 | if (hasCheckpointFilePrefix) { |
134 | 0 | checkpointFilesPrefix = input.readUTF(); |
135 | |
} |
136 | 0 | } |
137 | |
|
138 | |
@Override |
139 | |
public void readFields(DataInput input) throws IOException { |
140 | 0 | partitionId = input.readInt(); |
141 | 0 | workerInfo = new WorkerInfo(); |
142 | 0 | workerInfo.readFields(input); |
143 | 0 | boolean hasPreviousWorkerInfo = input.readBoolean(); |
144 | 0 | if (hasPreviousWorkerInfo) { |
145 | 0 | previousWorkerInfo = new WorkerInfo(); |
146 | 0 | previousWorkerInfo.readFields(input); |
147 | |
} |
148 | 0 | boolean hasCheckpointFilePrefix = input.readBoolean(); |
149 | 0 | if (hasCheckpointFilePrefix) { |
150 | 0 | checkpointFilesPrefix = input.readUTF(); |
151 | |
} |
152 | 0 | } |
153 | |
|
154 | |
@Override |
155 | |
public void write(DataOutput output) throws IOException { |
156 | 0 | output.writeInt(partitionId); |
157 | 0 | workerInfo.write(output); |
158 | 0 | if (previousWorkerInfo != null) { |
159 | 0 | output.writeBoolean(true); |
160 | 0 | previousWorkerInfo.write(output); |
161 | |
} else { |
162 | 0 | output.writeBoolean(false); |
163 | |
} |
164 | 0 | if (checkpointFilesPrefix != null) { |
165 | 0 | output.writeBoolean(true); |
166 | 0 | output.writeUTF(checkpointFilesPrefix); |
167 | |
} else { |
168 | 0 | output.writeBoolean(false); |
169 | |
} |
170 | 0 | } |
171 | |
|
172 | |
@Override |
173 | |
public ImmutableClassesGiraphConfiguration getConf() { |
174 | 0 | return conf; |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public void setConf(ImmutableClassesGiraphConfiguration conf) { |
179 | 0 | this.conf = conf; |
180 | 0 | } |
181 | |
|
182 | |
@Override |
183 | |
public String toString() { |
184 | 0 | return "(id=" + partitionId + ",cur=" + workerInfo + ",prev=" + |
185 | |
previousWorkerInfo + ",ckpt_file=" + checkpointFilesPrefix + ")"; |
186 | |
} |
187 | |
} |