use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class MultiUfsMountIntegrationTest method createFile.
@Test
public void createFile() throws Exception {
CreateFilePOptions writeBoth = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).build();
AlluxioURI file1 = mMountPoint1.join("file1");
AlluxioURI file2 = mMountPoint2.join("file2");
mFileSystem.createFile(file1, writeBoth).close();
mFileSystem.createFile(file2, writeBoth).close();
Assert.assertTrue(mLocalUfs.isFile(PathUtils.concatPath(mUfsUri1, "file1")));
Assert.assertTrue(mLocalUfs.isFile(PathUtils.concatPath(mUfsUri2, "file2")));
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class CapacityUsageIntegrationTest method createAndWriteFile.
private void createAndWriteFile(AlluxioURI filePath, WritePType writeType, int len) throws IOException, AlluxioException {
ByteBuffer buf = ByteBuffer.allocate(len);
buf.order(ByteOrder.nativeOrder());
for (int k = 0; k < len; k++) {
buf.put((byte) k);
}
CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(writeType).build();
FileOutStream os = mFileSystem.createFile(filePath, options);
os.write(buf.array());
os.close();
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class SpecificTierWriteIntegrationTest method writeFileAndCheckUsage.
/**
* Writes a file into a specified tier, and then verifies the expected bytes on each tier.
*
* @param writeTier the specific tier to write the file to
* @param writeSize number of bytes to write
* @param memBytes the expected number of bytes used in the MEM tier
* @param ssdBytes the expected number of bytes used in the SSD tier
* @param hddBytes the expected number of bytes used in the HDD tier
*/
private void writeFileAndCheckUsage(int writeTier, int writeSize, long memBytes, long ssdBytes, long hddBytes) throws Exception {
CreateFilePOptions createOptions = CreateFilePOptions.newBuilder().setWriteTier(writeTier).setWriteType(WritePType.MUST_CACHE).build();
FileOutStream os = mFileSystem.createFile(new AlluxioURI("/tier-" + writeTier + "_" + CommonUtils.randomAlphaNumString(5)), createOptions);
os.write(BufferUtils.getIncreasingByteArray(writeSize));
os.close();
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
long totalBytes = memBytes + ssdBytes + hddBytes;
Assert.assertEquals("Total bytes used", totalBytes, mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class).getUsedBytes());
Map<String, Long> bytesOnTiers = mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class).getUsedBytesOnTiers();
Assert.assertEquals("MEM tier usage", memBytes, bytesOnTiers.get(Constants.MEDIUM_MEM).longValue());
Assert.assertEquals("SSD tier usage", ssdBytes, bytesOnTiers.get(Constants.MEDIUM_SSD).longValue());
Assert.assertEquals("HDD tier usage", hddBytes, bytesOnTiers.get(Constants.MEDIUM_HDD).longValue());
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class AbstractFileSystem method create.
/**
* Attempts to create a file. Overwrite will not succeed if the path exists and is a folder.
*
* @param path path to create
* @param permission permissions of the created file/folder
* @param overwrite overwrite if file exists
* @param bufferSize the size in bytes of the buffer to be used
* @param replication under filesystem replication factor, this is ignored
* @param blockSize block size in bytes
* @param progress queryable progress
* @return an {@link FSDataOutputStream} created at the indicated path of a file
*/
@Override
public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException {
LOG.debug("create({}, {}, {}, {}, {}, {}, {})", path, permission, overwrite, bufferSize, replication, blockSize, progress);
if (mStatistics != null) {
mStatistics.incrementWriteOps(1);
}
AlluxioURI uri = getAlluxioPath(path);
CreateFilePOptions options = CreateFilePOptions.newBuilder().setBlockSizeBytes(blockSize).setMode(new Mode(permission.toShort()).toProto()).setRecursive(true).build();
FileOutStream outStream;
try {
outStream = mFileSystem.createFile(uri, options);
} catch (AlluxioException e) {
// now we should consider the override parameter
try {
if (mFileSystem.exists(uri)) {
if (!overwrite) {
throw new IOException("Not allowed to create() (overwrite=false) for existing Alluxio path: " + uri);
}
if (mFileSystem.getStatus(uri).isFolder()) {
throw new IOException(ExceptionMessage.FILE_CREATE_IS_DIRECTORY.getMessage(uri));
}
mFileSystem.delete(uri);
}
outStream = mFileSystem.createFile(uri, options);
} catch (AlluxioException e2) {
throw new IOException(e2);
}
}
return new FSDataOutputStream(outStream, mStatistics);
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readTest2.
/**
* Tests {@link FileInStream#read(byte[])}.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_STREAMING_READER_CHUNK_SIZE_BYTES, "64KB" })
public void readTest2() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
Aggregations