-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
LineageMaster.java
194 lines (170 loc) · 6.58 KB
/
LineageMaster.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Licensed to the University of California, Berkeley under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package tachyon.master.lineage;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.apache.thrift.TProcessor;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import tachyon.Constants;
import tachyon.HeartbeatThread;
import tachyon.TachyonURI;
import tachyon.client.file.TachyonFile;
import tachyon.conf.TachyonConf;
import tachyon.job.Job;
import tachyon.master.MasterBase;
import tachyon.master.file.FileSystemMaster;
import tachyon.master.journal.Journal;
import tachyon.master.journal.JournalEntry;
import tachyon.master.journal.JournalOutputStream;
import tachyon.master.lineage.checkpoint.CheckpointPlanningExecutor;
import tachyon.master.lineage.meta.Lineage;
import tachyon.master.lineage.meta.LineageFile;
import tachyon.master.lineage.meta.LineageStore;
import tachyon.master.lineage.recompute.RecomputeExecutor;
import tachyon.master.lineage.recompute.RecomputeLauncher;
import tachyon.master.lineage.recompute.RecomputePlanner;
import tachyon.thrift.BlockInfoException;
import tachyon.thrift.FileAlreadyExistException;
import tachyon.thrift.InvalidPathException;
import tachyon.thrift.LineageCommand;
import tachyon.thrift.LineageMasterService;
import tachyon.util.ThreadFactoryUtils;
/**
* The lineage master stores the lineage metadata in Tachyon, and it contains the components that
* manage all lineage-related activities.
*/
public final class LineageMaster extends MasterBase {
private final TachyonConf mTachyonConf;
private final LineageStore mLineageStore;
private final FileSystemMaster mFileSystemMaster;
/** The service that checkpoints lineages. */
private Future<?> mCheckpointExecutionService;
/** The service that recomputes lineages. */
private Future<?> mRecomputeExecutionService;
public LineageMaster(TachyonConf conf, Journal journal, FileSystemMaster fileSystemMaster) {
super(journal,
Executors.newFixedThreadPool(2, ThreadFactoryUtils.build("file-system-master-%d", true)));
mTachyonConf = Preconditions.checkNotNull(conf);
mFileSystemMaster = Preconditions.checkNotNull(fileSystemMaster);
mLineageStore = new LineageStore();
}
@Override
public TProcessor getProcessor() {
return new LineageMasterService.Processor<LineageMasterServiceHandler>(
new LineageMasterServiceHandler(this));
}
@Override
public String getServiceName() {
return Constants.LINEAGE_MASTER_SERVICE_NAME;
}
@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
// TODO add journal support
}
@Override
public void start(boolean isLeader) throws IOException {
super.start(isLeader);
if (isLeader) {
mCheckpointExecutionService =
getExecutorService().submit(new HeartbeatThread("Checkpoint planning service",
new CheckpointPlanningExecutor(mTachyonConf, mLineageStore),
mTachyonConf.getInt(Constants.MASTER_CHECKPOINT_INTERVAL_MS)));
mRecomputeExecutionService =
getExecutorService().submit(new HeartbeatThread("Recomupte service",
new RecomputeExecutor(new RecomputePlanner(mLineageStore),
new RecomputeLauncher(mTachyonConf, mLineageStore)),
mTachyonConf.getInt(Constants.MASTER_RECOMPUTE_INTERVAL_MS)));
}
}
@Override
public void stop() throws IOException {
super.stop();
if (mCheckpointExecutionService != null) {
mCheckpointExecutionService.cancel(true);
}
if (mRecomputeExecutionService != null) {
mRecomputeExecutionService.cancel(true);
}
}
@Override
public void streamToJournalCheckpoint(JournalOutputStream outputStream) throws IOException {
// TODO add journal support
}
public long createLineage(List<TachyonURI> inputFiles, List<TachyonURI> outputFiles, Job job) {
// validate input files exist
List<TachyonFile> inputTachyonFiles = Lists.newArrayList();
for (TachyonURI inputFile : inputFiles) {
long fileId;
try {
fileId = mFileSystemMaster.getFileId(inputFile);
inputTachyonFiles.add(new TachyonFile(fileId));
} catch (InvalidPathException e) {
// TODO error handling
}
}
// create output files
List<LineageFile> outputTachyonFiles = Lists.newArrayList();
for (TachyonURI outputFile : outputFiles) {
long fileId;
try {
fileId = mFileSystemMaster.createFile(outputFile, 0, true);
outputTachyonFiles.add(new LineageFile(fileId));
} catch (InvalidPathException e) {
// TODO error handling
} catch (FileAlreadyExistException e) {
// TODO error handling
} catch (BlockInfoException e) {
// TODO error handling
}
}
return mLineageStore.addLineage(inputTachyonFiles, outputTachyonFiles, job);
}
public boolean deleteLineage(long lineageId, boolean cascade) {
Lineage lineage = mLineageStore.getLineage(lineageId);
if (lineage == null) {
// TODO error handling
}
// there should not be child lineage if cascade
if (!cascade && !mLineageStore.getChildren(lineage).isEmpty()) {
// TODO error handling
}
mLineageStore.deleteLineage(lineageId);
return true;
}
public long recreateFile(String path, long blockSizeBytes) {
try {
return mFileSystemMaster.resetBlockSize(new TachyonURI(path), blockSizeBytes);
} catch (InvalidPathException e) {
// TODO(yupeng): error handling
return -1;
}
}
public void asyncCompleteFile(long fileId, String filePath) {
// TODO
}
/**
* Instructs a worker to persist the files for checkpoint.
*
* @param workerId the id of the worker that heartbeats
* @return the command for checkpointing the blocks of a file.
*/
public LineageCommand lineageWorkerHeartbeat(long workerId) {
// TODO
return null;
}
}