| 188 | /* ---------------------------------- MASTER -------------------------------- */ |
| 189 | |
| 190 | bool createDiskBacklog() { |
| 191 | if (g_pserver->repl_backlog_disk != nullptr) |
| 192 | return true; // already exists |
| 193 | // Lets create some disk backed pages and add them here |
| 194 | std::string path = "./repl-backlog-temp" + std::to_string(gettid()); |
| 195 | #if (defined __APPLE__ || defined __FreeBSD__) |
| 196 | int fd = open(path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); |
| 197 | #else |
| 198 | int fd = open(path.c_str(), O_CREAT | O_RDWR | O_LARGEFILE, S_IRUSR | S_IWUSR); |
| 199 | #endif |
| 200 | if (fd < 0) { |
| 201 | return false; |
| 202 | } |
| 203 | size_t alloc = cserver.repl_backlog_disk_size; |
| 204 | int result = truncate(path.c_str(), alloc); |
| 205 | unlink(path.c_str()); // ensure the fd is the only ref |
| 206 | if (result == -1) { |
| 207 | close (fd); |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | g_pserver->repl_backlog_disk = (char*)mmap(nullptr, alloc, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 212 | close(fd); |
| 213 | if (g_pserver->repl_backlog_disk == MAP_FAILED) { |
| 214 | g_pserver->repl_backlog_disk = nullptr; |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | serverLog(LL_VERBOSE, "Disk Backed Replication Allocated"); |
| 219 | return true; |
| 220 | } |
| 221 | |
| 222 | void createReplicationBacklog(void) { |
| 223 | serverAssert(g_pserver->repl_backlog == NULL); |
no test coverage detected