Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-39339: [C++] Add ForceCachedHierarchicalNamespaceSupport to help with testing #39340

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions cpp/src/arrow/filesystem/azurefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -934,14 +934,38 @@ class AzureFileSystem::Impl {
break;
}
ARROW_ASSIGN_OR_RAISE(
cached_hns_support_,
auto hns_support,
internal::CheckIfHierarchicalNamespaceIsEnabled(adlfs_client, options_));
DCHECK_NE(cached_hns_support_, HNSSupport::kUnknown);
// Caller should handle kContainerNotFound case appropriately.
return cached_hns_support_;
DCHECK_NE(hns_support, HNSSupport::kUnknown);
if (hns_support == HNSSupport::kContainerNotFound) {
// Caller should handle kContainerNotFound case appropriately as it knows the
// container this refers to, but the cached value in that case should remain
// kUnknown before we get a CheckIfHierarchicalNamespaceIsEnabled result that
// is not kContainerNotFound.
cached_hns_support_ = HNSSupport::kUnknown;
} else {
cached_hns_support_ = hns_support;
}
return hns_support;
}

public:
/// This is used from unit tests to ensure we perform operations on all the
/// possible states of cached_hns_support_.
void ForceCachedHierarchicalNamespaceSupport(int support) {
auto hns_support = static_cast<HNSSupport>(support);
switch (hns_support) {
case HNSSupport::kUnknown:
case HNSSupport::kContainerNotFound:
case HNSSupport::kDisabled:
case HNSSupport::kEnabled:
cached_hns_support_ = hns_support;
return;
}
// This is reachable if an invalid int is cast to enum class HNSSupport.
DCHECK(false) << "Invalid enum HierarchicalNamespaceSupport value.";
}

Result<FileInfo> GetFileInfo(const AzureLocation& location) {
if (location.container.empty()) {
DCHECK(location.path.empty());
Expand Down Expand Up @@ -1553,6 +1577,12 @@ AzureFileSystem::AzureFileSystem(std::unique_ptr<Impl>&& impl)
default_async_is_sync_ = false;
}

AzureFileSystem* AzureFileSystem::ForceCachedHierarchicalNamespaceSupport(
int hns_support) {
impl_->ForceCachedHierarchicalNamespaceSupport(hns_support);
return this;
}

Result<std::shared_ptr<AzureFileSystem>> AzureFileSystem::Make(
const AzureOptions& options, const io::IOContext& io_context) {
ARROW_ASSIGN_OR_RAISE(auto impl, AzureFileSystem::Impl::Make(options, io_context));
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/filesystem/azurefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class ARROW_EXPORT AzureFileSystem : public FileSystem {

explicit AzureFileSystem(std::unique_ptr<Impl>&& impl);

protected:
AzureFileSystem* ForceCachedHierarchicalNamespaceSupport(int hns_support);

public:
~AzureFileSystem() override = default;

Expand Down
Loading
Loading