| 34 | namespace ct |
| 35 | { |
| 36 | Errata |
| 37 | CacheScan::Scan(bool search) |
| 38 | { |
| 39 | int64_t guessed_size = 1048576; // 1M |
| 40 | Errata zret; |
| 41 | std::bitset<65536> dir_bitset; |
| 42 | char *stripe_buff2 = static_cast<char *>(ats_memalign(ats_pagesize(), guessed_size)); |
| 43 | for (int s = 0; s < this->stripe->_segments; s++) { |
| 44 | dir_bitset.reset(); |
| 45 | for (int b = 0; b < this->stripe->_buckets; b++) { |
| 46 | CacheDirEntry *seg = this->stripe->dir_segment(s); |
| 47 | CacheDirEntry *e = dir_bucket(b, seg); |
| 48 | if (dir_offset(e)) { |
| 49 | do { |
| 50 | // loop detected |
| 51 | if (dir_bitset[dir_to_offset(e, seg)]) { |
| 52 | break; |
| 53 | } |
| 54 | int64_t size = dir_approx_size(e); |
| 55 | if (size > guessed_size) { |
| 56 | ats_free(stripe_buff2); |
| 57 | stripe_buff2 = static_cast<char *>(ats_memalign(ats_pagesize(), dir_approx_size(e))); |
| 58 | } |
| 59 | int fd = this->stripe->_span->_fd; |
| 60 | int64_t offset = this->stripe->stripe_offset(e); |
| 61 | ssize_t n = pread(fd, stripe_buff2, size, offset); |
| 62 | if (n < 0) { |
| 63 | std::cout << "Failed to read content from the Stripe. " << strerror(errno) << std::endl; |
| 64 | } else { |
| 65 | Doc *doc = reinterpret_cast<Doc *>(stripe_buff2); |
| 66 | get_alternates(doc->hdr(), doc->hlen, search); |
| 67 | } |
| 68 | dir_bitset[dir_to_offset(e, seg)] = true; |
| 69 | e = next_dir(e, seg); |
| 70 | } while (e); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | ats_free(stripe_buff2); |
| 75 | |
| 76 | return zret; |
| 77 | } |
| 78 | |
| 79 | Errata |
| 80 | CacheScan::unmarshal(HTTPHdrImpl *obj, intptr_t offset) |
no test coverage detected