@@ -526,7 +526,6 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
526
526
throw InternalException (" Cached file not initialized properly" );
527
527
}
528
528
memcpy (buffer, hfh.cached_file_handle ->GetData () + location, nr_bytes);
529
- hfh.file_offset = location + nr_bytes;
530
529
return ;
531
530
}
532
531
@@ -537,22 +536,30 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
537
536
bool skip_buffer = hfh.flags .DirectIO () || hfh.flags .RequireParallelAccess ();
538
537
if (skip_buffer && to_read > 0 ) {
539
538
GetRangeRequest (hfh, hfh.path , {}, location, (char *)buffer, to_read);
539
+
540
+ // Update handle status within critical section for parallel access.
541
+ if (hfh.flags .RequireParallelAccess ()) {
542
+ std::lock_guard<std::mutex> lck (hfh.mu );
543
+ hfh.buffer_available = 0 ;
544
+ hfh.buffer_idx = 0 ;
545
+ return ;
546
+ }
547
+
540
548
hfh.buffer_available = 0 ;
541
549
hfh.buffer_idx = 0 ;
542
- hfh.file_offset = location + nr_bytes;
543
550
return ;
544
551
}
545
552
546
553
if (location >= hfh.buffer_start && location < hfh.buffer_end ) {
547
- hfh.file_offset = location;
548
554
hfh.buffer_idx = location - hfh.buffer_start ;
549
555
hfh.buffer_available = (hfh.buffer_end - hfh.buffer_start ) - hfh.buffer_idx ;
550
556
} else {
551
557
// reset buffer
552
558
hfh.buffer_available = 0 ;
553
559
hfh.buffer_idx = 0 ;
554
- hfh.file_offset = location;
555
560
}
561
+
562
+ idx_t start_offset = location; // Start file offset to read from.
556
563
while (to_read > 0 ) {
557
564
auto buffer_read_len = MinValue<idx_t >(hfh.buffer_available , to_read);
558
565
if (buffer_read_len > 0 ) {
@@ -564,36 +571,37 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
564
571
565
572
hfh.buffer_idx += buffer_read_len;
566
573
hfh.buffer_available -= buffer_read_len;
567
- hfh. file_offset += buffer_read_len;
574
+ start_offset += buffer_read_len;
568
575
}
569
576
570
577
if (to_read > 0 && hfh.buffer_available == 0 ) {
571
- auto new_buffer_available = MinValue<idx_t >(hfh.READ_BUFFER_LEN , hfh.length - hfh. file_offset );
578
+ auto new_buffer_available = MinValue<idx_t >(hfh.READ_BUFFER_LEN , hfh.length - start_offset );
572
579
573
580
// Bypass buffer if we read more than buffer size
574
581
if (to_read > new_buffer_available) {
575
582
GetRangeRequest (hfh, hfh.path , {}, location + buffer_offset, (char *)buffer + buffer_offset, to_read);
576
583
hfh.buffer_available = 0 ;
577
584
hfh.buffer_idx = 0 ;
578
- hfh. file_offset += to_read;
585
+ start_offset += to_read;
579
586
break ;
580
587
} else {
581
- GetRangeRequest (hfh, hfh.path , {}, hfh. file_offset , (char *)hfh.read_buffer .get (),
588
+ GetRangeRequest (hfh, hfh.path , {}, start_offset , (char *)hfh.read_buffer .get (),
582
589
new_buffer_available);
583
590
hfh.buffer_available = new_buffer_available;
584
591
hfh.buffer_idx = 0 ;
585
- hfh.buffer_start = hfh. file_offset ;
592
+ hfh.buffer_start = start_offset ;
586
593
hfh.buffer_end = hfh.buffer_start + new_buffer_available;
587
594
}
588
595
}
589
596
}
590
597
}
591
598
592
599
int64_t HTTPFileSystem::Read (FileHandle &handle, void *buffer, int64_t nr_bytes) {
593
- auto &hfh = ( HTTPFileHandle &)handle ;
600
+ auto &hfh = handle. Cast < HTTPFileHandle>() ;
594
601
idx_t max_read = hfh.length - hfh.file_offset ;
595
602
nr_bytes = MinValue<idx_t >(max_read, nr_bytes);
596
603
Read (handle, buffer, nr_bytes, hfh.file_offset );
604
+ hfh.file_offset += nr_bytes;
597
605
return nr_bytes;
598
606
}
599
607
@@ -602,7 +610,7 @@ void HTTPFileSystem::Write(FileHandle &handle, void *buffer, int64_t nr_bytes, i
602
610
}
603
611
604
612
int64_t HTTPFileSystem::Write (FileHandle &handle, void *buffer, int64_t nr_bytes) {
605
- auto &hfh = ( HTTPFileHandle &)handle ;
613
+ auto &hfh = handle. Cast < HTTPFileHandle>() ;
606
614
Write (handle, buffer, nr_bytes, hfh.file_offset );
607
615
return nr_bytes;
608
616
}
0 commit comments