88#include " duckdb/common/thread.hpp"
99#include " duckdb/common/types/hash.hpp"
1010#include " duckdb/function/scalar/strftime_format.hpp"
11- #include " duckdb/logging/http_logger .hpp"
11+ #include " duckdb/logging/file_system_logger .hpp"
1212#include " duckdb/main/client_context.hpp"
1313#include " duckdb/main/database.hpp"
1414#include " duckdb/main/secret/secret_manager.hpp"
@@ -32,7 +32,8 @@ shared_ptr<HTTPUtil> HTTPFSUtil::GetHTTPUtil(optional_ptr<FileOpener> opener) {
3232 return make_shared_ptr<HTTPFSUtil>();
3333}
3434
35- unique_ptr<HTTPParams> HTTPFSUtil::InitializeParameters (optional_ptr<FileOpener> opener, optional_ptr<FileOpenerInfo> info) {
35+ unique_ptr<HTTPParams> HTTPFSUtil::InitializeParameters (optional_ptr<FileOpener> opener,
36+ optional_ptr<FileOpenerInfo> info) {
3637 auto result = make_uniq<HTTPFSParams>(*this );
3738 result->Initialize (opener);
3839
@@ -277,8 +278,8 @@ void TimestampToTimeT(timestamp_t timestamp, time_t &result) {
277278
278279HTTPFileHandle::HTTPFileHandle (FileSystem &fs, const OpenFileInfo &file, FileOpenFlags flags,
279280 unique_ptr<HTTPParams> params_p)
280- : FileHandle(fs, file.path, flags), params(std::move(params_p)), http_params(params->Cast<HTTPFSParams>()), flags(flags), length( 0 ),
281- buffer_available (0 ), buffer_idx(0 ), file_offset(0 ), buffer_start(0 ), buffer_end(0 ) {
281+ : FileHandle(fs, file.path, flags), params(std::move(params_p)), http_params(params->Cast<HTTPFSParams>()),
282+ flags (flags), length( 0 ), buffer_available(0 ), buffer_idx(0 ), file_offset(0 ), buffer_start(0 ), buffer_end(0 ) {
282283 // check if the handle has extended properties that can be set directly in the handle
283284 // if we have these properties we don't need to do a head request to obtain them later
284285 if (file.extended_info ) {
@@ -342,6 +343,9 @@ unique_ptr<FileHandle> HTTPFileSystem::OpenFileExtended(const OpenFileInfo &file
342343
343344 auto handle = CreateHandle (file, flags, opener);
344345 handle->Initialize (opener);
346+
347+ DUCKDB_LOG_FILE_SYSTEM_OPEN ((*handle));
348+
345349 return std::move (handle);
346350}
347351
@@ -356,6 +360,8 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
356360 throw InternalException (" Cached file not initialized properly" );
357361 }
358362 memcpy (buffer, hfh.cached_file_handle ->GetData () + location, nr_bytes);
363+ DUCKDB_LOG_FILE_SYSTEM_READ (handle, nr_bytes, location);
364+ hfh.file_offset = location + nr_bytes;
359365 return ;
360366 }
361367
@@ -366,17 +372,19 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
366372 bool skip_buffer = hfh.flags .DirectIO () || hfh.flags .RequireParallelAccess ();
367373 if (skip_buffer && to_read > 0 ) {
368374 GetRangeRequest (hfh, hfh.path , {}, location, (char *)buffer, to_read);
369-
375+ DUCKDB_LOG_FILE_SYSTEM_READ (handle, nr_bytes, location);
370376 // Update handle status within critical section for parallel access.
371377 if (hfh.flags .RequireParallelAccess ()) {
372378 std::lock_guard<std::mutex> lck (hfh.mu );
373379 hfh.buffer_available = 0 ;
374380 hfh.buffer_idx = 0 ;
381+ hfh.file_offset = location + nr_bytes;
375382 return ;
376383 }
377384
378385 hfh.buffer_available = 0 ;
379386 hfh.buffer_idx = 0 ;
387+ hfh.file_offset = location + nr_bytes;
380388 return ;
381389 }
382390
@@ -423,14 +431,15 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
423431 }
424432 }
425433 }
434+ hfh.file_offset = location + nr_bytes;
435+ DUCKDB_LOG_FILE_SYSTEM_READ (handle, nr_bytes, location);
426436}
427437
428438int64_t HTTPFileSystem::Read (FileHandle &handle, void *buffer, int64_t nr_bytes) {
429439 auto &hfh = handle.Cast <HTTPFileHandle>();
430440 idx_t max_read = hfh.length - hfh.file_offset ;
431441 nr_bytes = MinValue<idx_t >(max_read, nr_bytes);
432442 Read (handle, buffer, nr_bytes, hfh.file_offset );
433- hfh.file_offset += nr_bytes;
434443 return nr_bytes;
435444}
436445
@@ -642,6 +651,10 @@ void HTTPFileHandle::Initialize(optional_ptr<FileOpener> opener) {
642651 http_params.state = make_shared_ptr<HTTPState>();
643652 }
644653
654+ if (opener) {
655+ TryAddLogger (*opener);
656+ }
657+
645658 auto current_cache = TryGetMetadataCache (opener, hfs);
646659
647660 bool should_write_cache = false ;
@@ -711,5 +724,7 @@ void HTTPFileHandle::StoreClient(unique_ptr<HTTPClient> client) {
711724 client_cache.StoreClient (std::move (client));
712725}
713726
714- HTTPFileHandle::~HTTPFileHandle () = default ;
727+ HTTPFileHandle::~HTTPFileHandle () {
728+ DUCKDB_LOG_FILE_SYSTEM_CLOSE ((*this ));
729+ };
715730} // namespace duckdb
0 commit comments