Skip to content

Commit

Permalink
Merge pull request #86 from Mytherin/attach
Browse files Browse the repository at this point in the history
Make ATTACH work over Azure
  • Loading branch information
samansmink authored Oct 22, 2024
2 parents a40ecb7 + 3f83679 commit f4b876f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ concurrency:
jobs:
duckdb-stable-build:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/[email protected].1
uses: duckdb/extension-ci-tools/.github/workflows/[email protected].2
with:
extension_name: azure
duckdb_version: v1.1.1
ci_tools_version: v1.1.1
duckdb_version: v1.1.2
ci_tools_version: v1.1.2
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools'

duckdb-stable-deploy:
name: Deploy extension binaries
needs: duckdb-stable-build
uses: duckdb/extension-ci-tools/.github/workflows/[email protected].1
uses: duckdb/extension-ci-tools/.github/workflows/[email protected].2
secrets: inherit
with:
extension_name: azure
duckdb_version: v1.1.1
duckdb_version: v1.1.2
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools'
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 208 files
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

0 comments on commit f4b876f

Please sign in to comment.