MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / getSegment

Method getSegment

src/jrd/replication/ChangeLog.cpp:1034–1089  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1032}
1033
1034ChangeLog::Segment* ChangeLog::getSegment(ULONG length)
1035{
1036 Segment* activeSegment = NULL;
1037 Segment* freeSegment = NULL;
1038
1039 FB_UINT64 minSequence = MAX_UINT64;
1040
1041 for (const auto segment : m_segments)
1042 {
1043 const auto segmentState = segment->getState();
1044 const auto segmentSequence = segment->getSequence();
1045
1046 if (segmentState == SEGMENT_STATE_USED)
1047 {
1048 if (activeSegment)
1049 raiseError("Multiple active journal segments found");
1050
1051 activeSegment = segment;
1052 }
1053 else if (segmentState == SEGMENT_STATE_FREE)
1054 {
1055 if (!freeSegment || segmentSequence < minSequence)
1056 {
1057 freeSegment = segment;
1058 minSequence = segmentSequence;
1059 }
1060 }
1061 }
1062
1063 const auto state = m_sharedMemory->getHeader();
1064
1065 if (activeSegment && activeSegment->hasData() && m_config->archiveTimeout)
1066 {
1067 const size_t deltaTimestamp = time(NULL) - state->timestamp;
1068
1069 if (deltaTimestamp > m_config->archiveTimeout)
1070 {
1071 activeSegment->setState(SEGMENT_STATE_FULL);
1072 activeSegment = NULL;
1073 m_workingSemaphore.release();
1074 }
1075 }
1076
1077 if (activeSegment)
1078 return activeSegment;
1079
1080 if (freeSegment)
1081 return reuseSegment(freeSegment);
1082
1083 // Allocate one more segment if configuration allows that
1084
1085 if (!m_config->segmentCount || m_segments.getCount() < m_config->segmentCount)
1086 return createSegment();
1087
1088 return NULL;
1089}

Callers 2

storeBlobMethod · 0.45
readMethod · 0.45

Calls 8

raiseErrorFunction · 0.70
getStateMethod · 0.45
getSequenceMethod · 0.45
getHeaderMethod · 0.45
hasDataMethod · 0.45
setStateMethod · 0.45
releaseMethod · 0.45
getCountMethod · 0.45

Tested by

no test coverage detected