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

Make ATTACH work over Azure #86

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/azure_blob_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ unique_ptr<AzureFileHandle> AzureBlobStorageFileSystem::CreateHandle(const strin

auto handle = make_uniq<AzureBlobStorageFileHandle>(*this, path, flags, storage_context->read_options,
std::move(blob_client));
handle->PostConstruct();
if (!handle->PostConstruct()) {
return nullptr;
}
return std::move(handle);
}

Expand Down
4 changes: 3 additions & 1 deletion src/azure_dfs_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ unique_ptr<AzureFileHandle> AzureDfsStorageFileSystem::CreateHandle(const string

auto handle = make_uniq<AzureDfsStorageFileHandle>(*this, path, flags, storage_context->read_options,
file_system_client.GetFileClient(parsed_url.path));
handle->PostConstruct();
if (!handle->PostConstruct()) {
return nullptr;
}
return std::move(handle);
}

Expand Down
20 changes: 14 additions & 6 deletions src/azure_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@ AzureFileHandle::AzureFileHandle(AzureStorageFileSystem &fs, string path, FileOp
if (flags.OpenForReading()) {
read_buffer = duckdb::unique_ptr<data_t[]>(new data_t[read_options.buffer_size]);
}
if (flags.RequireParallelAccess()) {
// use direct i/o if parallel access is required
flags |= FileOpenFlags(FileOpenFlags::FILE_FLAGS_DIRECT_IO);
}
}

void AzureFileHandle::PostConstruct() {
static_cast<AzureStorageFileSystem &>(file_system).LoadFileInfo(*this);
bool AzureFileHandle::PostConstruct() {
return static_cast<AzureStorageFileSystem &>(file_system).LoadFileInfo(*this);
}

void AzureStorageFileSystem::LoadFileInfo(AzureFileHandle &handle) {
bool AzureStorageFileSystem::LoadFileInfo(AzureFileHandle &handle) {
if (handle.flags.OpenForReading()) {
try {
LoadRemoteFileInfo(handle);
} catch (const Azure::Storage::StorageException &e) {
auto status_code = int(e.StatusCode);
if (status_code == 404 && handle.flags.ReturnNullIfNotExists()) {
return false;
}
throw IOException(
"AzureBlobStorageFileSystem open file '%s' failed with code'%s', Reason Phrase: '%s', Message: '%s'",
handle.path, e.ErrorCode, e.ReasonPhrase, e.Message);
Expand All @@ -52,6 +60,7 @@ void AzureStorageFileSystem::LoadFileInfo(AzureFileHandle &handle) {
handle.path, e.what());
}
}
return true;
}

unique_ptr<FileHandle> AzureStorageFileSystem::OpenFile(const string &path, FileOpenFlags flags,
Expand Down Expand Up @@ -162,11 +171,10 @@ shared_ptr<AzureContextState> AzureStorageFileSystem::GetOrCreateStorageContext(
if (FileOpener::TryGetCurrentSetting(opener, "azure_context_caching", value)) {
azure_context_caching = value.GetValue<bool>();
}
auto client_context = FileOpener::TryGetClientContext(opener);

shared_ptr<AzureContextState> result;
if (azure_context_caching) {
auto client_context = FileOpener::TryGetClientContext(opener);

if (azure_context_caching && client_context) {
auto context_key = GetContextPrefix() + parsed_url.storage_account_name;

auto &registered_state = client_context->registered_state;
Expand Down
8 changes: 4 additions & 4 deletions src/azure_storage_account_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ static Azure::Storage::Blobs::BlobServiceClient GetBlobStorageAccountClient(opti
}

const SecretMatch LookupSecret(optional_ptr<FileOpener> opener, const std::string &path) {
auto context = opener->TryGetClientContext();
auto secret_manager = FileOpener::TryGetSecretManager(opener);
auto transaction = FileOpener::TryGetCatalogTransaction(opener);

if (context) {
auto transaction = CatalogTransaction::GetSystemCatalogTransaction(*context);
return context->db->config.secret_manager->LookupSecret(transaction, path, "azure");
if (secret_manager && transaction) {
return secret_manager->LookupSecret(*transaction, path, "azure");
}

return {};
Expand Down
6 changes: 3 additions & 3 deletions src/include/azure_filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class AzureStorageFileSystem;

class AzureFileHandle : public FileHandle {
public:
virtual void PostConstruct();
virtual bool PostConstruct();
void Close() override {
}

protected:
AzureFileHandle(AzureStorageFileSystem &fs, string path, FileOpenFlags flags, const AzureReadOptions &read_options);

public:
const FileOpenFlags flags;
FileOpenFlags flags;

// File info
idx_t length;
Expand Down Expand Up @@ -96,7 +96,7 @@ class AzureStorageFileSystem : public FileSystem {
void Seek(FileHandle &handle, idx_t location) override;
void FileSync(FileHandle &handle) override;

void LoadFileInfo(AzureFileHandle &handle);
bool LoadFileInfo(AzureFileHandle &handle);

protected:
virtual duckdb::unique_ptr<AzureFileHandle> CreateHandle(const string &path, FileOpenFlags flags,
Expand Down
Loading