* Decoder constructor. * * Due to the large amount of memory needed to buffer log statements, the * decoder is intended to be constructed once and then re-used via open(). */
| 589 | * decoder is intended to be constructed once and then re-used via open(). |
| 590 | */ |
| 591 | Log::Decoder::Decoder() |
| 592 | : filename() |
| 593 | , inputFd(nullptr) |
| 594 | , logMsgsPrinted(0) |
| 595 | , bufferFragment(nullptr) |
| 596 | , good(false) |
| 597 | , checkpoint() |
| 598 | , freeBuffers() |
| 599 | , fmtId2metadata() |
| 600 | , fmtId2fmtString() |
| 601 | , rawMetadata(nullptr) |
| 602 | , endOfRawMetadata(nullptr) |
| 603 | , numBufferFragmentsRead(0) |
| 604 | , numCheckpointsRead(0) |
| 605 | { |
| 606 | // Take advantage of virtual memory an allocate an insanely large (1GB) |
| 607 | // buffer to store log metadata read from the logFile. Such a large buffer |
| 608 | // is used so that we don't have to explicitly manage the buffer and instead |
| 609 | // leave it up to the virtual memory system. |
| 610 | rawMetadata = static_cast<char*>(malloc(1024*1024*1024)); |
| 611 | |
| 612 | if (rawMetadata == nullptr) { |
| 613 | fprintf(stderr, "Could not allocate an internal 1GB buffer to store log" |
| 614 | " metadata"); |
| 615 | exit(-1); |
| 616 | } |
| 617 | |
| 618 | endOfRawMetadata = rawMetadata; |
| 619 | fmtId2metadata.reserve(1000); |
| 620 | fmtId2fmtString.reserve(1000); |
| 621 | bufferFragment = allocateBufferFragment(); |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Reads the metadata necessary to decompress log messsages from a log file. |