|
33 | 33 | #include "compressor.h" |
34 | 34 | #include <atomic> |
35 | 35 | #include <thread> |
| 36 | +#include "photon/thread/thread11.h" |
36 | 37 |
|
37 | 38 | using namespace photon::fs; |
38 | 39 |
|
@@ -938,6 +939,16 @@ class ZFileBuilderMP : public ZFileBuilderBase { |
938 | 939 | UNIMPLEMENTED(int fstat(struct stat *buf) override); |
939 | 940 | }; |
940 | 941 |
|
| 942 | +ssize_t read_chunk(IFile *file, char *buf, off_t offset, size_t length, ssize_t *result) { |
| 943 | + LOG_DEBUG("read zfile index chunk {offset: `, len: `}", offset, length); |
| 944 | + if (file->pread(buf, length, offset) != (ssize_t)length) { |
| 945 | + *result = -1; |
| 946 | + LOG_ERRNO_RETURN(0, -1, "failed to read index chunk {offset: `, len: `}.", offset, length); |
| 947 | + } |
| 948 | + *result = 0; |
| 949 | + return 0; |
| 950 | +} |
| 951 | + |
941 | 952 | bool load_jump_table(IFile *file, CompressionFile::HeaderTrailer *pheader_trailer, |
942 | 953 | CompressionFile::JumpTable &jump_table, bool trailer = true) { |
943 | 954 | char buf[CompressionFile::HeaderTrailer::SPACE]; |
@@ -994,8 +1005,25 @@ bool load_jump_table(IFile *file, CompressionFile::HeaderTrailer *pheader_traile |
994 | 1005 | } |
995 | 1006 | auto ibuf = std::unique_ptr<uint32_t[]>(new uint32_t[pht->index_size]); |
996 | 1007 | LOG_DEBUG("index_offset: `", pht->index_offset); |
997 | | - ret = file->pread((void *)(ibuf.get()), index_bytes, pht->index_offset); |
998 | | - if (ret < (ssize_t)index_bytes) { |
| 1008 | + |
| 1009 | + size_t delta = 1UL<<20; |
| 1010 | + std::vector<photon::join_handle*> ths; |
| 1011 | + ssize_t *r = new ssize_t[index_bytes / delta + 1]{}; |
| 1012 | + DEFER(delete []r); |
| 1013 | + int idx = 0; |
| 1014 | + for (off_t offset = 0; offset < (off_t)index_bytes; offset += delta) { |
| 1015 | + size_t chunk_size = std::min(index_bytes - offset, delta); |
| 1016 | + auto th = photon::thread_create11(&ZFile::read_chunk, file, (char*)ibuf.get() + offset, pht->index_offset + offset, chunk_size, &r[idx++]); |
| 1017 | + ths.push_back(photon::thread_enable_join(th)); |
| 1018 | + } |
| 1019 | + ret = 0; |
| 1020 | + for (int i =0; i<idx; i++){ |
| 1021 | + photon::thread_join(ths[i]); |
| 1022 | + if (r[i]!=0) { |
| 1023 | + ret = -1; |
| 1024 | + } |
| 1025 | + } |
| 1026 | + if (ret != 0) { |
999 | 1027 | LOG_ERRNO_RETURN(0, false, "failed to read index"); |
1000 | 1028 | } |
1001 | 1029 | if (pht->is_digest_enabled()) { |
|
0 commit comments