#include <fsc_DataCollectorStorage.h>


Why buffered: When many objects of this class is used it is not possible to have all files open all the time. The buffer is used to avoid opening and closing the file for each write. When it is full then open file, flush and close operations are performed.
Definition at line 43 of file fsc_DataCollectorStorage.h.
Public Member Functions | |
| fsc_DataCollectorStorage (ivd_MediaKey_t a_mediumKey, ivd_MedVolNum_t a_medVolNum) | |
| virtual | ~fsc_DataCollectorStorage (void) |
| void | CreateFile () |
| void | CheckHeader () |
| void | WriteToBuffer (const UInt8_t *a_buff_p) |
| writes m_recSize bytes from a_buff to the end of the m_buffer | |
| void | ReadContent (ivd_FileLocationData_t_v_t &a_fileLoc_v) |
| bool | GetNextRecord (ivd_FileLocationData_t &a_fileLocationData) |
Public Attributes | |
| log_CLASSID_m | |
Private Member Functions | |
| void | InitBuffer () |
| reserve space for buffer | |
| void | Flush () |
| When buffer getting full a Flush is called. | |
Private Attributes | |
| UInt8_t * | m_buffer |
| UInt8_t * | m_bufPos |
| UInt8_t * | m_bufEnd |
| UInt32_t | m_recSize |
| UInt32_t | m_bufSize |
| const ivd_MediaKey_t | m_mediumKey |
| RMDB medium key. | |
| const ivd_MedVolNum_t | m_medVolNum |
| RMDB volume num. | |
Friends | |
| class | ut_fsc_DataCollectorStorage |
| class | fsc_RedunCopyDataVolStorageWriter |
| class | fsc_ReorgScanReorgVolStorage |
| class | fsc_ReorgScanContentVolStorage |
| fsc_DataCollectorStorage::fsc_DataCollectorStorage | ( | ivd_MediaKey_t | a_mediumKey, | |
| ivd_MedVolNum_t | a_medVolNum | |||
| ) |
Definition at line 49 of file fsc_DataCollectorStorage.cpp.
References dbg_DETAIL, InitBuffer(), log_DBG_m, and log_FUNC_m.
00050 : 00051 m_buffer(NULL), 00052 m_bufPos(NULL), 00053 m_bufEnd(NULL), 00054 00055 m_recSize(sizeof(ivd_FileLocationData_t)), 00056 m_bufSize(fsc_DefBufSize_c), 00057 m_mediumKey(a_mediumKey), 00058 m_medVolNum(a_medVolNum) 00059 { 00060 log_FUNC_m(fsc_DataCollectorStorage); 00061 log_DBG_m(dbg_DETAIL,"a_mediumKey: " << a_mediumKey << 00062 " a_medVolNum: " << a_medVolNum); 00063 00064 InitBuffer(); 00065 } //============================================================================//

| fsc_DataCollectorStorage::~fsc_DataCollectorStorage | ( | void | ) | [virtual] |
| void fsc_DataCollectorStorage::CreateFile | ( | ) |
Definition at line 77 of file fsc_DataCollectorStorage.cpp.
References cmn_File::CloseF(), cmn_CreatePath(), DATACOLLECTOR_FILE_HEADER_SIZE, dbg_DETAIL, fom_CREATE_NEW, fom_WRITE, fsc_ReorgFileHeader(), cmn_File::GetFullPathRef(), log_DBG_m, log_FUNC_m, cmn_File::OpenF(), and cmn_File::WriteF().
Referenced by fsc_RedunCopyDataVolStorageWriter::fsc_RedunCopyDataVolStorageWriter(), fsc_ReorgScanContentVolStorage::fsc_ReorgScanContentVolStorage(), and fsc_ReorgScanReorgVolStorage::fsc_ReorgScanReorgVolStorage().
00077 { 00078 log_FUNC_m(CreateFile); 00079 00080 log_DBG_m(dbg_DETAIL, "Create dir " << GetFullPathRef().UpPath() ); 00081 cmn_CreatePath(GetFullPathRef().UpPath()); 00082 00083 //write file header 00084 OpenF(fom_WRITE | fom_CREATE_NEW); 00085 log_DBG_m(dbg_DETAIL, "Writing Header: " << fsc_ReorgFileHeader << 00086 "size: " << DATACOLLECTOR_FILE_HEADER_SIZE); 00087 WriteF(fsc_ReorgFileHeader, DATACOLLECTOR_FILE_HEADER_SIZE); 00088 CloseF(); 00089 00090 }


| void fsc_DataCollectorStorage::CheckHeader | ( | ) |
Definition at line 94 of file fsc_DataCollectorStorage.cpp.
References cmn_File::CloseF(), DATACOLLECTOR_FILE_HEADER_SIZE, dbg_DETAIL, fsc_ReorgFileHeader(), cmn_File::GetFullPathRef(), ie_DATA_CORRUPTION, ivd_Error, log_DBG_m, log_FUNC_m, cmn_File::OpenF(), and cmn_File::ReadF().
Referenced by fsc_RedunCopyDataVolStorageReader::fsc_RedunCopyDataVolStorageReader(), and i_ReorgJob_i::i_ReorgJob_i().
00094 { 00095 log_FUNC_m(CheckHeader); 00096 00097 OpenF(); 00098 vector<char> buffer; 00099 buffer.resize(DATACOLLECTOR_FILE_HEADER_SIZE+1); 00100 buffer[DATACOLLECTOR_FILE_HEADER_SIZE] = '\0'; 00101 char *buff_p = &buffer[0]; 00102 00103 ivd_FileRetSize_t read = ReadF(buff_p, DATACOLLECTOR_FILE_HEADER_SIZE); 00104 log_DBG_m(dbg_DETAIL,"Data read: " << read << " header: " << buff_p); 00105 00106 // compare fsc_FileHeader_c with fileHeader 00107 if (strcmp(fsc_ReorgFileHeader, buff_p) != 0) { 00108 ostringstream msg; 00109 msg << "File Location Data File (" << GetFullPathRef() << ") is corrupted."; 00110 throw ivd_Error(ie_DATA_CORRUPTION, msg.str() ); 00111 } 00112 CloseF(); 00113 }


| void fsc_DataCollectorStorage::WriteToBuffer | ( | const UInt8_t * | a_buff_p | ) |
writes m_recSize bytes from a_buff to the end of the m_buffer
Definition at line 116 of file fsc_DataCollectorStorage.cpp.
References Flush(), ie_EXCEED_MAX_SIZE, log_FUNC_m, m_bufEnd, m_buffer, m_bufPos, m_bufSize, and m_recSize.
Referenced by fsc_ReorgScanDataVolStorage::Write(), and fsc_RedunCopyDataVolStorage::WriteToBuffer().
00116 { 00117 log_FUNC_m(Write); 00118 // Note buffer size must be multipier of record size. 00119 UInt8_t* pos = m_bufPos + m_recSize; 00120 if (pos > m_bufEnd) { 00121 ostringstream sstr; 00122 sstr << "Buffer possition exceed buffer size. RecSize = " << m_recSize 00123 << " BufSize = " << m_bufSize 00124 << " BufPos = " << hex << m_bufPos 00125 << " BufEnd = " << m_bufEnd 00126 << " buffer = " << m_buffer << dec; 00127 throw ivd_InternalError(ie_EXCEED_MAX_SIZE, sstr.str(), true); 00128 } 00129 memcpy(m_bufPos, a_buff_p, m_recSize); 00130 m_bufPos = pos; 00131 if (pos >= m_bufEnd) { 00132 Flush(); 00133 } 00134 }


| void fsc_DataCollectorStorage::ReadContent | ( | ivd_FileLocationData_t_v_t & | a_fileLoc_v | ) |
Definition at line 194 of file fsc_DataCollectorStorage.cpp.
References cmn_File::CloseF(), DATA_REC_SIZE, DATACOLLECTOR_FILE_HEADER_SIZE, dbg_DETAIL, dbg_LOW, dbg_NORM, ivd_BaseException::GetError(), ie_DATA_CORRUPTION, ie_FILE_ERROR, ivd_Error, log_DBG_m, log_FUNC_m, cmn_File::OpenF(), cmn_File::ReadF(), cmn_File::SeekF(), and cmn_File::StatF().
Referenced by fsc_FLSPerVolume::fsc_FLSPerVolume().
00194 { 00195 log_FUNC_m(ReadContent); 00196 00197 ivd_FileInfo_t info; 00198 ivd_FileSize_t dataFileSize; 00199 try { 00200 StatF(info); 00201 dataFileSize = info.size; 00202 OpenF(); 00203 } 00204 catch (const ivd_SysError &se) { 00205 if (se.GetError() == ie_FILE_ERROR) { 00206 log_DBG_m(dbg_LOW, "File does not exist." << se); 00207 throw ivd_Error(ie_DATA_CORRUPTION, "File Location Data File is missing."); 00208 } 00209 throw; 00210 } 00211 00212 log_DBG_m(dbg_NORM, "Data file size: " << dataFileSize); 00213 00214 UInt32_t fileCountRead = (dataFileSize - DATACOLLECTOR_FILE_HEADER_SIZE)/DATA_REC_SIZE; 00215 if (fileCountRead > 0) { 00216 a_fileLoc_v.resize(fileCountRead); 00217 log_DBG_m(dbg_DETAIL, "Will Read:" << fileCountRead << 00218 ", a_fileLoc_v.size()" << a_fileLoc_v.size()); 00219 00220 SeekF(DATACOLLECTOR_FILE_HEADER_SIZE); 00221 ivd_FileRetSize_t read = ReadF(&a_fileLoc_v[0], dataFileSize - DATACOLLECTOR_FILE_HEADER_SIZE); 00222 00223 log_DBG_m(dbg_DETAIL,"Data read: " << read); 00224 } else { 00225 log_DBG_m(dbg_DETAIL,"no files listed"); 00226 } 00227 CloseF(); 00228 }


| bool fsc_DataCollectorStorage::GetNextRecord | ( | ivd_FileLocationData_t & | a_fileLocationData | ) |
Definition at line 232 of file fsc_DataCollectorStorage.cpp.
References ivd_FileLocationData_t::blockOffset, cmn_File::CloseF(), DATACOLLECTOR_FILE_HEADER_SIZE, dbg_DETAIL, ivd_FileLocationData_t::fileID, cmn_File::IsOpen(), log_DBG_m, log_FUNC_m, ivd_FileLocationData_t::migrationID, cmn_File::OpenF(), cmn_File::ReadF(), cmn_File::SeekF(), and ivd_FileLocationData_t::splitSize.
Referenced by fsc_DataLMgr::Remove().
00232 { 00233 log_FUNC_m(GetNextRecord); 00234 00235 if (!IsOpen()){ 00236 OpenF(); 00237 SeekF(DATACOLLECTOR_FILE_HEADER_SIZE); 00238 } 00239 00240 ivd_FileRetSize_t ret = ReadF(&a_fileLocationData, sizeof(ivd_FileLocationData_t)); 00241 log_DBG_m(dbg_DETAIL, "a_fileLocationData: ret = " << ret 00242 << "\n blockOffset " << a_fileLocationData.blockOffset 00243 << "\n fileID " << a_fileLocationData.fileID 00244 << "\n migrationID " << a_fileLocationData.migrationID 00245 << "\n splitSize " << a_fileLocationData.splitSize); 00246 if (ret < (ivd_FileRetSize_t)sizeof(ivd_FileLocationData_t)) { 00247 CloseF(); 00248 return true; 00249 } else { 00250 return false; 00251 } 00252 }


| void fsc_DataCollectorStorage::InitBuffer | ( | ) | [private] |
reserve space for buffer
Definition at line 137 of file fsc_DataCollectorStorage.cpp.
References assert, cmn_GetEnvVariable(), dbg_DETAIL, fsc_CollectorBufSize_c(), fsc_MaxBufSize_c, cmn_File::GetFullPathRef(), log_DBG_m, log_FUNC_m, log_WRN_m, m_bufEnd, m_buffer, m_bufPos, m_bufSize, and m_recSize.
Referenced by fsc_DataCollectorStorage().
00137 { 00138 log_FUNC_m(InitBuffer); 00139 00140 assert(m_recSize > 0); 00141 assert(m_recSize <= 32768); 00142 00143 string sBuffSize = cmn_GetEnvVariable(fsc_CollectorBufSize_c); 00144 if (!sBuffSize.empty()) { 00145 unsigned int buffSize = atoi(sBuffSize.c_str()); 00146 m_bufSize = buffSize; 00147 } 00148 00149 if (m_bufSize > fsc_MaxBufSize_c) { 00150 log_WRN_m("Buffes size for data collection is greater than allowed. " 00151 << " want size = " << m_bufSize 00152 << " max size will be used = " << fsc_MaxBufSize_c); 00153 m_bufSize = fsc_MaxBufSize_c; 00154 } 00155 if (m_bufSize < m_recSize) { 00156 log_WRN_m("Buffes size for data collection is less than recordSize. " 00157 << " want size = " << m_bufSize 00158 << " record size will be used = " << m_recSize); 00159 m_bufSize = m_recSize; 00160 } 00161 00162 // bufferSize must be multiplier of record size. 00163 m_bufSize /= m_recSize; 00164 m_bufSize *= m_recSize; 00165 00166 m_buffer = new UInt8_t[m_bufSize]; 00167 00168 m_bufPos = m_buffer; 00169 m_bufEnd = m_buffer + m_bufSize; 00170 log_DBG_m(dbg_DETAIL, GetFullPathRef() 00171 << " bufSize =" << m_bufSize 00172 << ", recSize =" << m_recSize 00173 << ", bufPos_p =" << hex << (void*)m_bufPos << dec 00174 << ", bufEnd_p =" << hex << (void*)m_bufEnd << dec); 00175 }


| void fsc_DataCollectorStorage::Flush | ( | ) | [private] |
When buffer getting full a Flush is called.
Definition at line 178 of file fsc_DataCollectorStorage.cpp.
References cmn_File::CloseF(), dbg_DETAIL, fom_OPEN_ALWAYS, fom_WRITE, cmn_File::GetFullPathRef(), log_DBG_m, log_FUNC_m, m_buffer, m_bufPos, cmn_File::OpenF(), cmn_File::SeekEndF(), size, and cmn_File::WriteF().
Referenced by WriteToBuffer(), and ~fsc_DataCollectorStorage().
00178 { 00179 log_FUNC_m(Flush); 00180 00181 UInt32_t size = (char*)m_bufPos - (char*)m_buffer; 00182 if (size > 0) { 00183 OpenF(fom_WRITE | fom_OPEN_ALWAYS); // binary | create | rdwr 00184 ivd_FilePosition_t pos = SeekEndF(); 00185 log_DBG_m(dbg_DETAIL, GetFullPathRef() << " File pos " << pos 00186 << " buff size " << size); 00187 WriteF(m_buffer, size); 00188 CloseF(); 00189 m_bufPos = m_buffer; 00190 } 00191 }


friend class ut_fsc_DataCollectorStorage [friend] |
Definition at line 44 of file fsc_DataCollectorStorage.h.
friend class fsc_RedunCopyDataVolStorageWriter [friend] |
Reimplemented in fsc_RedunCopyDataVolStorage.
Definition at line 45 of file fsc_DataCollectorStorage.h.
friend class fsc_ReorgScanReorgVolStorage [friend] |
Reimplemented in fsc_ReorgScanDataVolStorage.
Definition at line 46 of file fsc_DataCollectorStorage.h.
friend class fsc_ReorgScanContentVolStorage [friend] |
Reimplemented in fsc_ReorgScanDataVolStorage.
Definition at line 47 of file fsc_DataCollectorStorage.h.
Reimplemented from cmn_File.
Reimplemented in fsc_DataCollectorStorageCacheEl, fsc_RedunCopyDataVolStorage, fsc_RedunCopyDataVolStorageWriter, fsc_RedunCopyDataVolStorageReader, fsc_ReorgScanDataVolStorage, fsc_ReorgScanReorgVolStorage, and fsc_ReorgScanContentVolStorage.
Definition at line 69 of file fsc_DataCollectorStorage.h.
UInt8_t* fsc_DataCollectorStorage::m_buffer [private] |
Definition at line 76 of file fsc_DataCollectorStorage.h.
Referenced by Flush(), InitBuffer(), WriteToBuffer(), and ~fsc_DataCollectorStorage().
UInt8_t* fsc_DataCollectorStorage::m_bufPos [private] |
Definition at line 77 of file fsc_DataCollectorStorage.h.
Referenced by Flush(), InitBuffer(), and WriteToBuffer().
UInt8_t* fsc_DataCollectorStorage::m_bufEnd [private] |
Definition at line 78 of file fsc_DataCollectorStorage.h.
Referenced by InitBuffer(), and WriteToBuffer().
UInt32_t fsc_DataCollectorStorage::m_recSize [private] |
Definition at line 80 of file fsc_DataCollectorStorage.h.
Referenced by InitBuffer(), and WriteToBuffer().
UInt32_t fsc_DataCollectorStorage::m_bufSize [private] |
Definition at line 81 of file fsc_DataCollectorStorage.h.
Referenced by InitBuffer(), and WriteToBuffer().
const ivd_MediaKey_t fsc_DataCollectorStorage::m_mediumKey [private] |
RMDB medium key.
Definition at line 84 of file fsc_DataCollectorStorage.h.
Referenced by fsc_RedunCopyDataVolStorageWriter::~fsc_RedunCopyDataVolStorageWriter(), fsc_ReorgScanContentVolStorage::~fsc_ReorgScanContentVolStorage(), and fsc_ReorgScanReorgVolStorage::~fsc_ReorgScanReorgVolStorage().
const ivd_MedVolNum_t fsc_DataCollectorStorage::m_medVolNum [private] |
RMDB volume num.
Definition at line 86 of file fsc_DataCollectorStorage.h.
Referenced by fsc_RedunCopyDataVolStorageWriter::~fsc_RedunCopyDataVolStorageWriter(), fsc_ReorgScanContentVolStorage::~fsc_ReorgScanContentVolStorage(), and fsc_ReorgScanReorgVolStorage::~fsc_ReorgScanReorgVolStorage().
1.5.6