Skip to content

Commit

Permalink
Add support for TTL in directories (facebookincubator#11498)
Browse files Browse the repository at this point in the history
Summary:

Support TTL for directories

Differential Revision: D65734798
  • Loading branch information
yuandagits authored and facebook-github-bot committed Nov 11, 2024
1 parent cc48ac9 commit 047d7e5
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 10 deletions.
6 changes: 5 additions & 1 deletion velox/common/file/FileSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ class LocalFileSystem : public FileSystem {
return filePaths;
}

void mkdir(std::string_view path) override {
void mkdir(std::string_view path, const DirectoryOptions& options) override {
if (FOLLY_UNLIKELY(options.expirationTimeMs.has_value())) {
VELOX_UNSUPPORTED(
"Expiration time is not supported for LocalFileSystem.");
}
std::error_code ec;
std::filesystem::create_directories(path, ec);
VELOX_CHECK_EQ(
Expand Down
10 changes: 9 additions & 1 deletion velox/common/file/FileSystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ struct FileOptions {
bool bufferWrite{true};
};

/// Dfines operations on a per driectory basis
struct DirectoryOptions : FileOptions {
/// Specifies the expiration time for the directory.
std::optional<int64_t> expirationTimeMs{std::nullopt};
};

/// An abstract FileSystem
class FileSystem {
public:
Expand Down Expand Up @@ -113,7 +119,9 @@ class FileSystem {
virtual std::vector<std::string> list(std::string_view path) = 0;

/// Create a directory (recursively). Throws velox exception on failure.
virtual void mkdir(std::string_view path) = 0;
virtual void mkdir(
std::string_view path,
const DirectoryOptions& options = {}) = 0;

/// Remove a directory (all the files and sub-directories underneath
/// recursively). Throws velox exception on failure.
Expand Down
6 changes: 4 additions & 2 deletions velox/common/file/tests/FaultyFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ std::vector<std::string> FaultyFileSystem::list(std::string_view path) {
return files;
}

void FaultyFileSystem::mkdir(std::string_view path) {
void FaultyFileSystem::mkdir(
std::string_view path,
const DirectoryOptions& options) {
const auto delegatedDirPath = extractPath(path);
getFileSystem(delegatedDirPath, config_)->mkdir(delegatedDirPath);
getFileSystem(delegatedDirPath, config_)->mkdir(delegatedDirPath, options);
}

void FaultyFileSystem::rmdir(std::string_view path) {
Expand Down
2 changes: 1 addition & 1 deletion velox/common/file/tests/FaultyFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FaultyFileSystem : public FileSystem {

std::vector<std::string> list(std::string_view path) override;

void mkdir(std::string_view path) override;
void mkdir(std::string_view path, const DirectoryOptions& options) override;

void rmdir(std::string_view path) override;

Expand Down
4 changes: 3 additions & 1 deletion velox/connectors/hive/storage_adapters/abfs/AbfsFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class AbfsFileSystem : public FileSystem {
VELOX_UNSUPPORTED("list for abfs not implemented");
}

void mkdir(std::string_view path) override {
void mkdir(
std::string_view path,
const filesystems::DirectoryOptions& options = {}) override {
VELOX_UNSUPPORTED("mkdir for abfs not implemented");
}

Expand Down
4 changes: 3 additions & 1 deletion velox/connectors/hive/storage_adapters/gcs/GCSFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ void GCSFileSystem::rename(std::string_view, std::string_view, bool) {
VELOX_UNSUPPORTED("rename for GCS not implemented");
}

void GCSFileSystem::mkdir(std::string_view path) {
void GCSFileSystem::mkdir(
std::string_view path,
const DirectoryOptions& options) {
VELOX_UNSUPPORTED("mkdir for GCS not implemented");
}

Expand Down
3 changes: 2 additions & 1 deletion velox/connectors/hive/storage_adapters/gcs/GCSFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class GCSFileSystem : public FileSystem {
void rename(std::string_view, std::string_view, bool) override;

/// Unsupported
void mkdir(std::string_view path) override;
void mkdir(std::string_view path, const DirectoryOptions& options = {})
override;

/// Unsupported
void rmdir(std::string_view path) override;
Expand Down
3 changes: 2 additions & 1 deletion velox/connectors/hive/storage_adapters/hdfs/HdfsFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class HdfsFileSystem : public FileSystem {
VELOX_UNSUPPORTED("list for HDFS not implemented");
}

void mkdir(std::string_view path) override {
void mkdir(std::string_view path, const DirectoryOptions& options = {})
override {
VELOX_UNSUPPORTED("mkdir for HDFS not implemented");
}

Expand Down
3 changes: 2 additions & 1 deletion velox/connectors/hive/storage_adapters/s3fs/S3FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class S3FileSystem : public FileSystem {
VELOX_UNSUPPORTED("list for S3 not implemented");
}

void mkdir(std::string_view path) override {
void mkdir(std::string_view path, const DirectoryOptions& options = {})
override {
VELOX_UNSUPPORTED("mkdir for S3 not implemented");
}

Expand Down

0 comments on commit 047d7e5

Please sign in to comment.