| 348 | // ChangeLog class implementation |
| 349 | |
| 350 | ChangeLog::ChangeLog(MemoryPool& pool, |
| 351 | const string& dbId, |
| 352 | const Guid& guid, |
| 353 | const FB_UINT64 sequence, |
| 354 | const Replication::Config* config) |
| 355 | : PermanentStorage(pool), |
| 356 | m_dbId(dbId), m_config(config), m_segments(pool), |
| 357 | m_sequence(sequence), m_generation(0), m_shutdown(false) |
| 358 | { |
| 359 | memcpy(&m_guid, &guid, sizeof(Guid)); |
| 360 | |
| 361 | initSharedFile(); |
| 362 | |
| 363 | { // scope |
| 364 | LockGuard guard(this); |
| 365 | |
| 366 | // If the server crashes while archiving, segments may remain in the ARCH state forever. |
| 367 | // This code allows to recover their state and retry archiving them. |
| 368 | |
| 369 | const auto state = m_sharedMemory->getHeader(); |
| 370 | |
| 371 | if (!state->pidUpper) |
| 372 | { |
| 373 | fb_assert(!state->pidLower); |
| 374 | |
| 375 | for (const auto segment : m_segments) |
| 376 | { |
| 377 | if (segment->getState() == SEGMENT_STATE_ARCH) |
| 378 | segment->setState(SEGMENT_STATE_FULL); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | linkSelf(); |
| 383 | } |
| 384 | |
| 385 | Thread::start(archiver_thread, this, THREAD_medium); |
| 386 | m_startupSemaphore.enter(); |
| 387 | m_workingSemaphore.release(); |
| 388 | } |
| 389 | |
| 390 | ChangeLog::~ChangeLog() |
| 391 | { |