MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / write_incremental_file

Function write_incremental_file

tools/comdb2ar/serialise.cpp:1518–1630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1516extern uint32_t myflip(uint32_t in);
1517
1518void write_incremental_file (
1519 const std::string &dbdir,
1520 const std::string &abspath,
1521 const std::string &incrname,
1522 struct stat *st
1523)
1524// Write checksum/LSN information for a database file
1525{
1526 DB_Wrap db(abspath);
1527 int flags = O_RDONLY;
1528 size_t pagesize;
1529 int fd;
1530
1531 RIIA_fd fd_guard(fd);
1532
1533 // TODO: optionally O_DIRECT?
1534 fd = open(abspath.c_str(), flags);
1535 if (fd == -1) {
1536 std::ostringstream ss;
1537 ss << "Can't open" << abspath << " " << strerror(errno) << std::endl;
1538 throw SerialiseError(abspath, ss.str());
1539 }
1540
1541 pagesize = db.get_pagesize();
1542 if (pagesize == 0)
1543 pagesize = 4096;
1544 size_t bufsize = pagesize;
1545 while((bufsize << 1) <= MAX_BUF_SIZE) {
1546 bufsize <<= 1;
1547 }
1548 off_t uptosize = st->st_size;
1549
1550 // st->st_size is going to be the size of the incremental file
1551 // save the size of the real file here
1552 // 12 bytes per page
1553 st->st_size = 12 * (st->st_size / pagesize);
1554
1555 TarHeader head;
1556 head.set_filename(incrname);
1557 head.set_attrs(*st);
1558 head.set_checksum();
1559 tar_block_header hdr = head.get();
1560
1561 // Write tar header
1562 if (writeall(1, &hdr, sizeof(tar_block_header)) != sizeof(tar_block_header)) {
1563 std::ostringstream ss;
1564 ss << "error writing tar block header: " << std::strerror(errno);
1565 throw Error(ss.str());
1566 }
1567
1568 uint8_t *pagebuf = NULL;
1569 off_t bytesleft = uptosize;
1570 unsigned long long pageno = 0;
1571 off_t offset = 0;
1572
1573#if ! defined ( _SUN_SOURCE ) && ! defined ( _HP_SOURCE )
1574 if(posix_memalign((void**) &pagebuf, 512, bufsize))
1575 throw Error("Failed to allocate output buffer");

Callers 1

create_partialsFunction · 0.85

Calls 12

SerialiseErrorClass · 0.85
writeallFunction · 0.85
ErrorClass · 0.85
verify_checksumFunction · 0.85
myflipFunction · 0.85
set_attrsMethod · 0.80
set_checksumMethod · 0.80
get_pagesizeMethod · 0.45
set_filenameMethod · 0.45
getMethod · 0.45
get_cryptoMethod · 0.45
get_swappedMethod · 0.45

Tested by

no test coverage detected