Skip to content

Commit

Permalink
Set ttlaction back to free
Browse files Browse the repository at this point in the history
  • Loading branch information
ssyssy committed Mar 8, 2023
1 parent 73f3ce8 commit 3c9e6af
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 86 deletions.
Expand Up @@ -102,7 +102,7 @@ public void defaults() throws IOException {
assertEquals(ModeUtils.applyFileUMask(Mode.defaults(),
mConf.getString(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)), options.getMode());
assertEquals(Constants.NO_TTL, options.getCommonOptions().getTtl());
assertEquals(TtlAction.DELETE_ALLUXIO, options.getCommonOptions().getTtlAction());
assertEquals(TtlAction.FREE, options.getCommonOptions().getTtlAction());
assertEquals(ufsType, options.getUnderStorageType());
assertEquals(WriteType.CACHE_THROUGH, options.getWriteType());
assertEquals(Constants.LAST_TIER, options.getWriteTier());
Expand Down
4 changes: 2 additions & 2 deletions core/common/src/main/java/alluxio/conf/PropertyKey.java
Expand Up @@ -5715,9 +5715,9 @@ public String toString() {
.build();
public static final PropertyKey USER_FILE_CREATE_TTL_ACTION =
enumBuilder(Name.USER_FILE_CREATE_TTL_ACTION, TtlAction.class)
.setDefaultValue(TtlAction.DELETE_ALLUXIO)
.setDefaultValue(TtlAction.FREE)
.setDescription("When file's ttl is expired, the action performs on it. Options: "
+ "DELETE_ALLUXIO(default), FREE or DELETE")
+ "FREE(default) or DELETE")
.setScope(Scope.CLIENT)
.build();
public static final PropertyKey USER_FILE_UFS_TIER_ENABLED =
Expand Down
Expand Up @@ -32,11 +32,9 @@ private ProtobufUtils() {} // prevent instantiation
*/
public static TtlAction fromProtobuf(PTtlAction pTtlAction) {
if (pTtlAction == null) {
return TtlAction.DELETE_ALLUXIO;
return TtlAction.FREE;
}
switch (pTtlAction) {
case DELETE_ALLUXIO:
return TtlAction.DELETE_ALLUXIO;
case DELETE:
return TtlAction.DELETE;
case FREE:
Expand All @@ -54,11 +52,9 @@ public static TtlAction fromProtobuf(PTtlAction pTtlAction) {
*/
public static PTtlAction toProtobuf(TtlAction ttlAction) {
if (ttlAction == null) {
return PTtlAction.DELETE_ALLUXIO;
return PTtlAction.FREE;
}
switch (ttlAction) {
case DELETE_ALLUXIO:
return PTtlAction.DELETE_ALLUXIO;
case DELETE:
return PTtlAction.DELETE;
case FREE:
Expand Down
Expand Up @@ -84,7 +84,7 @@ public void heartbeat() throws InterruptedException {
TtlAction ttlAction = inode.getTtlAction();
LOG.info("Path {} TTL has expired, performing action {}", path.getPath(), ttlAction);
switch (ttlAction) {
case FREE:
case FREE: // Default: FREE
// public free method will lock the path, and check WRITE permission required at
// parent of file
if (inode.isDirectory()) {
Expand Down Expand Up @@ -114,19 +114,6 @@ public void heartbeat() throws InterruptedException {
mFileSystemMaster.delete(path, DeleteContext.defaults());
}
break;
case DELETE_ALLUXIO: // Default: DELETE_ALLUXIO
// public delete method will lock the path, and check WRITE permission required at
// parent of file
if (inode.isDirectory()) {
mFileSystemMaster.delete(path,
DeleteContext.mergeFrom(DeletePOptions.newBuilder()
.setRecursive(true).setAlluxioOnly(true)));
} else {
mFileSystemMaster.delete(path,
DeleteContext.mergeFrom(DeletePOptions.newBuilder()
.setAlluxioOnly(true)));
}
break;
default:
LOG.error("Unknown ttl action {}", ttlAction);
}
Expand Down
Expand Up @@ -625,7 +625,10 @@ public void ttlDirectoryDelete() throws Exception {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(dirId);
assertEquals(fileInfo.getFileId(), dirId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
// TTL is set to 0, the directory should have been freed during last TTL check.
assertEquals(0,
mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT)
.getInAlluxioPercentage());
mFileSystemMaster.getFileInfo(dirId);
}

Expand All @@ -646,7 +649,10 @@ public void ttlDirectoryDeleteReplay() throws Exception {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(dirId);
assertEquals(fileInfo.getFileId(), dirId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
// TTL is set to 0, the directory should have been freed during last TTL check.
assertEquals(0,
mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT)
.getInAlluxioPercentage());
mFileSystemMaster.getFileInfo(dirId);
}

Expand Down Expand Up @@ -764,8 +770,10 @@ public void setTtlForFileWithNoTtl() throws Exception {
SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder()
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
// TTL is set to 0, the file should have been freed during last TTL check.
assertEquals(0,
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT)
.getInAlluxioPercentage());
mFileSystemMaster.getFileInfo(fileId);
}

Expand All @@ -791,8 +799,10 @@ public void setTtlForDirectoryWithNoTtl() throws Exception {
SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder()
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
// TTL is set to 0, the file should have been freed during last TTL check.
assertEquals(0,
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT)
.getInAlluxioPercentage());
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT);
mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT);
mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT);
Expand All @@ -817,8 +827,10 @@ public void setSmallerTtlForFileWithTtl() throws Exception {
SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder()
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
// TTL is set to 0, the file should have been freed during last TTL check.
assertEquals(0,
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT)
.getInAlluxioPercentage());
mFileSystemMaster.getFileInfo(fileId);
}

Expand All @@ -840,8 +852,10 @@ public void setSmallerTtlForDirectoryWithTtl() throws Exception {
SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder()
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
// TTL is set to 0, the file should have been freed during last TTL check.
assertEquals(0,
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT)
.getInAlluxioPercentage());
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT);
}

Expand Down
1 change: 0 additions & 1 deletion core/transport/src/main/proto/grpc/common.proto
Expand Up @@ -89,7 +89,6 @@ message ConfigProperty {
enum TtlAction {
DELETE = 0; // Delete the file after TTL expires.
FREE = 1; // Free the file after TTL expires.
DELETE_ALLUXIO = 2; // Delete the data and metadata in Alluxio after TTL expires.
}

message Command {
Expand Down
8 changes: 0 additions & 8 deletions core/transport/src/main/proto/proto.lock
Expand Up @@ -1601,10 +1601,6 @@
{
"name": "FREE",
"integer": 1
},
{
"name": "DELETE_ALLUXIO",
"integer": 2
}
]
},
Expand Down Expand Up @@ -8654,10 +8650,6 @@
{
"name": "FREE",
"integer": 1
},
{
"name": "DELETE_ALLUXIO",
"integer": 2
}
]
},
Expand Down
1 change: 0 additions & 1 deletion core/transport/src/main/proto/proto/journal/file.proto
Expand Up @@ -172,7 +172,6 @@ message InodeDirectoryIdGeneratorEntry {
enum PTtlAction {
DELETE = 0;
FREE = 1;
DELETE_ALLUXIO = 2;
}

// next available id: 30
Expand Down
Expand Up @@ -187,7 +187,7 @@ public void clientFileInfoEmptyFile() throws Exception {
assertFalse(fileInfo.isPersisted());
assertFalse(fileInfo.isPinned());
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
Assert.assertEquals(TtlAction.DELETE_ALLUXIO, fileInfo.getTtlAction());
Assert.assertEquals(TtlAction.FREE, fileInfo.getTtlAction());
Assert.assertEquals(TEST_USER, fileInfo.getOwner());
Assert.assertEquals(0644, (short) fileInfo.getMode());
}
Expand Down
45 changes: 3 additions & 42 deletions tests/src/test/java/alluxio/client/fs/TtlIntegrationTest.java
Expand Up @@ -79,45 +79,6 @@ public void before() throws Exception {
Arrays.fill(mBuffer, (byte) 'A');
}

/**
* Tests that when many TTLs expire at the same time, files are deleted from alluxio properly.
*/
@Test
public void expireManyAfterDeleteAlluxio() throws Exception {
int numFiles = 100;
AlluxioURI[] files = new AlluxioURI[numFiles];
for (int i = 0; i < numFiles; i++) {
files[i] = new AlluxioURI("/file" + i);
// Only the even-index files should expire.
long ttl = i % 2 == 0 ? TTL_INTERVAL_MS / 2 : TTL_INTERVAL_MS * 1000;
mOutStream = mFileSystem.createFile(files[i],
CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH)
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl)).build());
mOutStream.write(mBuffer, 0, 10);
mOutStream.close();

// Delete some of the even files to make sure this doesn't trip up the TTL checker.
if (i % 20 == 0) {
mFileSystem.delete(files[i]);
}
}
CommonUtils.sleepMs(2 * TTL_INTERVAL_MS);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
for (int i = 0; i < numFiles; i++) {
if (i % 2 == 0) {
assertFalse(mFileSystem.exists(files[i]));
// Check Ufs file existence
if (i % 20 != 0) {
String fileName = "file" + i;
// Check Ufs file existence
assertTrue(Arrays.stream(mUfs.list()).anyMatch(s -> s.equals(fileName)));
}
} else {
assertTrue(mFileSystem.exists(files[i]));
}
}
}

/**
* Tests that when many TTLs expire at the same time, files are freed properly.
*/
Expand All @@ -130,9 +91,9 @@ public void expireManyAfterFree() throws Exception {
// Only the even-index files should expire.
long ttl = i % 2 == 0 ? TTL_INTERVAL_MS / 2 : TTL_INTERVAL_MS * 1000;
mOutStream = mFileSystem.createFile(files[i],
CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH)
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl)
.setTtlAction(TtlAction.FREE)).build());
CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH)
.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl))
.build());
mOutStream.write(mBuffer, 0, 10);
mOutStream.close();

Expand Down

0 comments on commit 3c9e6af

Please sign in to comment.