1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.ooc.command; |
20 | |
|
21 | |
import org.apache.giraph.ooc.OutOfCoreEngine; |
22 | |
import org.apache.giraph.ooc.data.DiskBackedEdgeStore; |
23 | |
import org.apache.giraph.ooc.data.DiskBackedMessageStore; |
24 | |
import org.apache.giraph.ooc.data.DiskBackedPartitionStore; |
25 | |
|
26 | |
import java.io.IOException; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class StoreDataBufferIOCommand extends IOCommand { |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public enum DataBufferType { PARTITION, MESSAGE }; |
37 | |
|
38 | |
|
39 | |
|
40 | |
private final DataBufferType type; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public StoreDataBufferIOCommand(OutOfCoreEngine oocEngine, |
50 | |
int partitionId, |
51 | |
DataBufferType type) { |
52 | 0 | super(oocEngine, partitionId); |
53 | 0 | this.type = type; |
54 | 0 | } |
55 | |
|
56 | |
@Override |
57 | |
public boolean execute() throws IOException { |
58 | 0 | boolean executed = false; |
59 | 0 | if (oocEngine.getMetaPartitionManager() |
60 | 0 | .startOffloadingBuffer(partitionId)) { |
61 | 0 | switch (type) { |
62 | |
case PARTITION: |
63 | 0 | DiskBackedPartitionStore partitionStore = |
64 | |
(DiskBackedPartitionStore) |
65 | 0 | oocEngine.getServerData().getPartitionStore(); |
66 | 0 | numBytesTransferred += |
67 | 0 | partitionStore.offloadBuffers(partitionId); |
68 | 0 | DiskBackedEdgeStore edgeStore = |
69 | 0 | (DiskBackedEdgeStore) oocEngine.getServerData().getEdgeStore(); |
70 | 0 | numBytesTransferred += edgeStore.offloadBuffers(partitionId); |
71 | 0 | break; |
72 | |
case MESSAGE: |
73 | 0 | DiskBackedMessageStore messageStore = |
74 | |
(DiskBackedMessageStore) |
75 | 0 | oocEngine.getServerData().getIncomingMessageStore(); |
76 | 0 | numBytesTransferred += |
77 | 0 | messageStore.offloadBuffers(partitionId); |
78 | 0 | break; |
79 | |
default: |
80 | 0 | throw new IllegalStateException("execute: requested data buffer type " + |
81 | |
"does not exist!"); |
82 | |
} |
83 | 0 | oocEngine.getMetaPartitionManager().doneOffloadingBuffer(partitionId); |
84 | 0 | executed = true; |
85 | |
} |
86 | 0 | return executed; |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public IOCommandType getType() { |
91 | 0 | return IOCommandType.STORE_BUFFER; |
92 | |
} |
93 | |
|
94 | |
@Override |
95 | |
public String toString() { |
96 | 0 | return "StoreDataBufferIOCommand: (partitionId = " + partitionId + ", " + |
97 | 0 | "type = " + type.name() + ")"; |
98 | |
} |
99 | |
} |