-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
FileSystemMasterClientServiceHandler.java
434 lines (390 loc) · 14.1 KB
/
FileSystemMasterClientServiceHandler.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.master.file;
import alluxio.AlluxioURI;
import alluxio.Constants;
import alluxio.RpcUtils;
import alluxio.RpcUtils.RpcCallable;
import alluxio.RpcUtils.RpcCallableThrowsIOException;
import alluxio.exception.AlluxioException;
import alluxio.master.file.options.CheckConsistencyOptions;
import alluxio.master.file.options.CompleteFileOptions;
import alluxio.master.file.options.CreateDirectoryOptions;
import alluxio.master.file.options.CreateFileOptions;
import alluxio.master.file.options.DeleteOptions;
import alluxio.master.file.options.FreeOptions;
import alluxio.master.file.options.ListStatusOptions;
import alluxio.master.file.options.LoadMetadataOptions;
import alluxio.master.file.options.MountOptions;
import alluxio.master.file.options.RenameOptions;
import alluxio.master.file.options.SetAttributeOptions;
import alluxio.thrift.AlluxioTException;
import alluxio.thrift.CheckConsistencyTOptions;
import alluxio.thrift.CompleteFileTOptions;
import alluxio.thrift.CreateDirectoryTOptions;
import alluxio.thrift.CreateFileTOptions;
import alluxio.thrift.DeleteTOptions;
import alluxio.thrift.FileBlockInfo;
import alluxio.thrift.FileInfo;
import alluxio.thrift.FileSystemMasterClientService;
import alluxio.thrift.FreeTOptions;
import alluxio.thrift.ListStatusTOptions;
import alluxio.thrift.MountTOptions;
import alluxio.thrift.SetAttributeTOptions;
import alluxio.wire.ThriftUtils;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.concurrent.NotThreadSafe;
/**
* This class is a Thrift handler for file system master RPCs invoked by an Alluxio client.
*/
@NotThreadSafe // TODO(jiri): make thread-safe (c.f. ALLUXIO-1664)
public final class FileSystemMasterClientServiceHandler implements
FileSystemMasterClientService.Iface {
private static final Logger LOG =
LoggerFactory.getLogger(FileSystemMasterClientServiceHandler.class);
private final FileSystemMaster mFileSystemMaster;
/**
* Creates a new instance of {@link FileSystemMasterClientServiceHandler}.
*
* @param fileSystemMaster the {@link FileSystemMaster} the handler uses internally
*/
public FileSystemMasterClientServiceHandler(FileSystemMaster fileSystemMaster) {
Preconditions.checkNotNull(fileSystemMaster);
mFileSystemMaster = fileSystemMaster;
}
@Override
public long getServiceVersion() {
return Constants.FILE_SYSTEM_MASTER_CLIENT_SERVICE_VERSION;
}
@Override
public List<String> checkConsistency(final String path, final CheckConsistencyTOptions options)
throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<List<String>>() {
@Override
public List<String> call() throws AlluxioException, IOException {
List<AlluxioURI> inconsistentUris = mFileSystemMaster.checkConsistency(
new AlluxioURI(path), new CheckConsistencyOptions(options));
List<String> uris = new ArrayList<>(inconsistentUris.size());
for (AlluxioURI uri : inconsistentUris) {
uris.add(uri.getPath());
}
return uris;
}
@Override
public String toString() {
return String.format("CheckConsistency: path=%s, options=%s", path, options);
}
});
}
@Override
public void completeFile(final String path, final CompleteFileTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallable<Void>() {
@Override
public Void call() throws AlluxioException {
mFileSystemMaster.completeFile(new AlluxioURI(path), new CompleteFileOptions(options));
return null;
}
@Override
public String toString() {
return String.format("CompleteFile: path=%s, options=%s", path, options);
}
});
}
@Override
public void createDirectory(final String path, final CreateDirectoryTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Void>() {
@Override
public Void call() throws AlluxioException, IOException {
mFileSystemMaster.createDirectory(new AlluxioURI(path),
new CreateDirectoryOptions(options));
return null;
}
@Override
public String toString() {
return String.format("CreateDirectory: path=%s, options=%s", path, options);
}
});
}
@Override
public void createFile(final String path, final CreateFileTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Void>() {
@Override
public Void call() throws AlluxioException, IOException {
mFileSystemMaster.createFile(new AlluxioURI(path), new CreateFileOptions(options));
return null;
}
@Override
public String toString() {
return String.format("CreateFile: path=%s, options=%s", path, options);
}
});
}
@Override
public void free(final String path, final boolean recursive, final FreeTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallable<Void>() {
@Override
public Void call() throws AlluxioException {
if (options == null) {
// For Alluxio client v1.4 or earlier.
// NOTE, we try to be conservative here so early Alluxio clients will not be able to force
// freeing pinned items but see the error thrown.
mFileSystemMaster.free(new AlluxioURI(path),
FreeOptions.defaults().setRecursive(recursive));
} else {
mFileSystemMaster.free(new AlluxioURI(path), new FreeOptions(options));
}
return null;
}
@Override
public String toString() {
return String.format("Free: path=%s, recursive=%s, options=%s", path, recursive, options);
}
});
}
/**
* {@inheritDoc}
*
* @deprecated since version 1.1 and will be removed in version 2.0
* @see #getStatus(String)
*/
@Override
@Deprecated
public List<FileBlockInfo> getFileBlockInfoList(final String path) throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallable<List<FileBlockInfo>>() {
@Override
public List<FileBlockInfo> call() throws AlluxioException {
List<FileBlockInfo> result = new ArrayList<>();
for (alluxio.wire.FileBlockInfo fileBlockInfo :
mFileSystemMaster.getFileBlockInfoList(new AlluxioURI(path))) {
result.add(ThriftUtils.toThrift(fileBlockInfo));
}
return result;
}
@Override
public String toString() {
return String.format("GetFileBlockInfoList: path=%s", path);
}
});
}
@Override
public long getNewBlockIdForFile(final String path) throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallable<Long>() {
@Override
public Long call() throws AlluxioException {
return mFileSystemMaster.getNewBlockIdForFile(new AlluxioURI(path));
}
@Override
public String toString() {
return String.format("GetNewBlockIdForFile: path=%s", path);
}
});
}
@Override
public FileInfo getStatus(final String path) throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallable<FileInfo>() {
@Override
public FileInfo call() throws AlluxioException {
return ThriftUtils.toThrift(mFileSystemMaster.getFileInfo(new AlluxioURI(path)));
}
@Override
public String toString() {
return String.format("GetStatus: path=%s", path);
}
});
}
/**
* {@inheritDoc}
*
* @deprecated since version 1.1 and will be removed in version 2.0
*/
@Override
@Deprecated
public FileInfo getStatusInternal(final long fileId) throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallable<FileInfo>() {
@Override
public FileInfo call() throws AlluxioException {
return ThriftUtils.toThrift(mFileSystemMaster.getFileInfo(fileId));
}
@Override
public String toString() {
return String.format("GetStatusInternal: fileId=%s", fileId);
}
});
}
/**
* {@inheritDoc}
*
* @deprecated since version 1.1 and will be removed in version 2.0
*/
@Override
@Deprecated
public String getUfsAddress() throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallable<String>() {
@Override
public String call() throws AlluxioException {
return mFileSystemMaster.getUfsAddress();
}
@Override
public String toString() {
return String.format("GetUfsAddress");
}
});
}
@Override
public List<FileInfo> listStatus(final String path, final ListStatusTOptions options)
throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallable<List<FileInfo>>() {
@Override
public List<FileInfo> call() throws AlluxioException {
List<FileInfo> result = new ArrayList<>();
for (alluxio.wire.FileInfo fileInfo : mFileSystemMaster
.listStatus(new AlluxioURI(path), new ListStatusOptions(options))) {
result.add(ThriftUtils.toThrift(fileInfo));
}
return result;
}
@Override
public String toString() {
return String.format("ListStatus: path=%s, options=%s", path, options);
}
});
}
/**
* {@inheritDoc}
*
* @deprecated since version 1.1 and will be removed in version 2.0
*/
@Override
@Deprecated
public long loadMetadata(final String alluxioPath, final boolean recursive)
throws AlluxioTException {
return RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Long>() {
@Override
public Long call() throws AlluxioException, IOException {
return mFileSystemMaster.loadMetadata(new AlluxioURI(alluxioPath),
LoadMetadataOptions.defaults().setCreateAncestors(true).setLoadDirectChildren(true));
}
@Override
public String toString() {
return String.format("LoadMetadata: alluxioPath=%s, recursive=%s", alluxioPath, recursive);
}
});
}
@Override
public void mount(final String alluxioPath, final String ufsPath, final MountTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Void>() {
@Override
public Void call() throws AlluxioException, IOException {
mFileSystemMaster.mount(new AlluxioURI(alluxioPath), new AlluxioURI(ufsPath),
new MountOptions(options));
return null;
}
@Override
public String toString() {
return String.format("Mount: alluxioPath=%s, ufsPath=%s, options=%s", alluxioPath, ufsPath,
options);
}
});
}
@Override
public void remove(final String path, final boolean recursive, final DeleteTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Void>() {
@Override
public Void call() throws AlluxioException, IOException {
if (options == null) {
// For Alluxio client v1.4 or earlier.
// NOTE, we try to be conservative here so early Alluxio clients will not be able to
// delete files in Alluxio only.
mFileSystemMaster.delete(new AlluxioURI(path), DeleteOptions.defaults()
.setRecursive(recursive).setUnchecked(options.isSkipConsistencyCheck()));
} else {
mFileSystemMaster.delete(new AlluxioURI(path), new DeleteOptions(options));
}
return null;
}
@Override
public String toString() {
return String.format("Remove: path=%s, recursive=%s", path, recursive);
}
});
}
@Override
public void rename(final String srcPath, final String dstPath)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Void>() {
@Override
public Void call() throws AlluxioException, IOException {
mFileSystemMaster
.rename(new AlluxioURI(srcPath), new AlluxioURI(dstPath), RenameOptions.defaults());
return null;
}
@Override
public String toString() {
return String.format("Rename: srcPath=%s, dstPath=%s", srcPath, dstPath);
}
});
}
@Override
public void scheduleAsyncPersist(final String path) throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallable<Void>() {
@Override
public Void call() throws AlluxioException {
mFileSystemMaster.scheduleAsyncPersistence(new AlluxioURI(path));
return null;
}
@Override
public String toString() {
return String.format("ScheduleAsyncPersist: path=%s", path);
}
});
}
// TODO(calvin): Do not rely on client side options
@Override
public void setAttribute(final String path, final SetAttributeTOptions options)
throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallable<Void>() {
@Override
public Void call() throws AlluxioException {
mFileSystemMaster.setAttribute(new AlluxioURI(path), new SetAttributeOptions(options));
return null;
}
@Override
public String toString() {
return String.format("SetAttribute: path=%s, options=%s", path, options);
}
});
}
@Override
public void unmount(final String alluxioPath) throws AlluxioTException {
RpcUtils.callAndLog(LOG, new RpcCallableThrowsIOException<Void>() {
@Override
public Void call() throws AlluxioException, IOException {
mFileSystemMaster.unmount(new AlluxioURI(alluxioPath));
return null;
}
@Override
public String toString() {
return String.format("Unmount: alluxioPath=%s", alluxioPath);
}
});
}
}