Commit 1b73d478 authored by Georgios Bitzes's avatar Georgios Bitzes

FST: More widespread use of unique_ptr for CheckSum objects

parent af098550
Pipeline #704454 passed with stages
in 62 minutes and 47 seconds
......@@ -903,15 +903,14 @@ FmdDbMapHandler::ResyncDisk(const char* path,
int checksumtype = LayoutId::GetChecksumFromEnv(env);
LayoutId::layoutid_t layoutid =
LayoutId::GetId(LayoutId::kPlain, checksumtype);
eos::fst::CheckSum* checksum =
eos::fst::ChecksumPlugins::GetChecksumObject(layoutid, false);
std::unique_ptr<CheckSum> checksum =
eos::fst::ChecksumPlugins::GetChecksumObjectPtr(layoutid, false);
if (checksum) {
if (checksum->SetBinChecksum(checksumVal, checksumLen)) {
diskchecksum = checksum->GetHexChecksum();
}
delete checksum;
}
}
......
......@@ -790,17 +790,17 @@ ScanDir::ScanFileLoadAware(const std::unique_ptr<eos::fst::FileIo>& io,
struct timezone tz;
struct timeval opentime;
struct timeval currenttime;
eos::fst::CheckSum* normalXS, *blockXS;
eos::fst::CheckSum* blockXS;
scansize = 0;
scantime = 0;
filePath = io->GetPath();
fileXSPath = filePath + ".xsmap";
normalXS = eos::fst::ChecksumPlugins::GetChecksumObject(layoutid);
std::unique_ptr<eos::fst::CheckSum> normalXS =
eos::fst::ChecksumPlugins::GetChecksumObjectPtr(layoutid);
gettimeofday(&opentime, &tz);
struct stat current_stat;
if (io->fileStat(&current_stat)) {
delete normalXS;
return false;
}
......@@ -828,10 +828,6 @@ ScanDir::ScanFileLoadAware(const std::unique_ptr<eos::fst::FileIo>& io,
delete blockXS;
}
if (normalXS) {
delete normalXS;
}
return false;
}
......@@ -948,9 +944,7 @@ ScanDir::ScanFileLoadAware(const std::unique_ptr<eos::fst::FileIo>& io,
delete blockXS;
}
if (normalXS) {
delete normalXS;
}
normalXS.reset();
if (bgThread) {
XrdSysThread::CancelPoint();
......
......@@ -1661,13 +1661,12 @@ XrdFstOfs::GetKeytabChecksum(const std::string& kt_path) const
size_t nread = ::read(fd, buffer, sizeof(buffer));
if (nread > 0) {
CheckSum* KeyCKS = ChecksumPlugins::GetChecksumObject(
eos::common::LayoutId::kAdler);
std::unique_ptr<CheckSum> KeyCKS =
ChecksumPlugins::GetChecksumObjectPtr(eos::common::LayoutId::kAdler);
if (KeyCKS) {
KeyCKS->Add(buffer, nread, 0);
kt_cks = KeyCKS->GetHexChecksum();
delete KeyCKS;
}
}
......
......@@ -63,7 +63,7 @@ XrdFstOfsFile::XrdFstOfsFile(const char* user, int MonID) :
commitReconstruction(false), mEventOnClose(false), mEventWorkflow(""),
mSyncEventOnClose(false),
mIsOCchunk(false), writeErrorFlag(false), mTpcFlag(kTpcNone),
fMd(nullptr), mCheckSum(nullptr), layOut(nullptr), maxOffsetWritten(0),
fMd(nullptr), layOut(nullptr), maxOffsetWritten(0),
openSize(0), closeSize(0),
mTpcThreadStatus(EINVAL), mTpcState(kTpcIdle), mTpcRetc(0)
{
......@@ -2937,7 +2937,7 @@ XrdFstOfsFile::ProcessMixedOpaque()
// Call the checksum factory function with the selected layout
if (opaqueCheckSum != "ignore") {
mCheckSum.reset(eos::fst::ChecksumPlugins::GetChecksumObject(mLid));
mCheckSum = eos::fst::ChecksumPlugins::GetChecksumObjectPtr(mLid);
eos_debug("checksum requested %d %u", mCheckSum.get(), mLid);
}
......
......@@ -98,6 +98,13 @@ public:
return 0;
}
static std::unique_ptr<CheckSum>
GetChecksumObjectPtr(unsigned int layoutid, bool blockchecksum = false)
{
return std::unique_ptr<CheckSum>(GetChecksumObject(layoutid, blockchecksum));
}
};
EOSFSTNAMESPACE_END
......
......@@ -167,8 +167,9 @@ Storage::Verify()
fMd->mProtoFmd.set_size(statinfo.st_size);
fMd->mProtoFmd.set_lid(verifyfile->lId);
fMd->mProtoFmd.set_cid(verifyfile->cId);
CheckSum* checksummer = ChecksumPlugins::GetChecksumObject(
fMd->mProtoFmd.lid());
std::unique_ptr<CheckSum> checksummer =
ChecksumPlugins::GetChecksumObjectPtr(fMd->mProtoFmd.lid());
unsigned long long scansize = 0;
float scantime = 0; // is ms
eos::fst::CheckSum::ReadCallBack::callback_data_t cbd;
......@@ -315,10 +316,6 @@ Storage::Verify()
}
}
if (checksummer) {
delete checksummer;
}
if (fMd) {
delete fMd;
}
......
......@@ -34,8 +34,8 @@ main (int argc, char* argv[])
exit(-1);
}
eos::fst::CheckSum *normalXS;
normalXS = eos::fst::ChecksumPlugins::GetChecksumObject(eos::common::LayoutId::kAdler);
std::unique_ptr<eos::fst::CheckSum> normalXS =
eos::fst::ChecksumPlugins::GetChecksumObjectPtr(eos::common::LayoutId::kAdler);
if (normalXS)
{
XrdOucString path = (argv[1]) ? argv[1] : "";
......@@ -45,8 +45,8 @@ main (int argc, char* argv[])
{
fprintf(stderr,"error: unable to scan file path=%s\n", argv[1]);
exit(-1);
}
else
}
else
{
fprintf(stdout, "path=%s size=%llu time=%.02f adler32=%s\n", argv[1], scansize, scantime, normalXS->GetHexChecksum());
exit(0);
......
......@@ -79,9 +79,9 @@ main(int argc, const char* argv[])
eos::common::LayoutId::GetId(eos::common::LayoutId::kPlain,
eos::common::LayoutId::kNone, 0,
blockSizeSymbol, checksumType);
eos::fst::CheckSum* checksum = eos::fst::ChecksumPlugins::GetChecksumObject(
layoutid, true);
std::unique_ptr<eos::fst::CheckSum> checksum =
eos::fst::ChecksumPlugins::GetChecksumObjectPtr(layoutid, true);
if (!checksum) {
fprintf(stderr, "error: failed to get checksum object for file %s",
path.c_str());
......
......@@ -80,8 +80,8 @@ main(int argc, const char* argv[])
eos::common::LayoutId::GetId(eos::common::LayoutId::kPlain,
eos::common::LayoutId::kNone, 0,
blockSizeSymbol, checksumType);
eos::fst::CheckSum* checksum = eos::fst::ChecksumPlugins::GetChecksumObject(
layoutid, true);
std::unique_ptr<eos::fst::CheckSum> checksum =
eos::fst::ChecksumPlugins::GetChecksumObjectPtr(layoutid, true);
if (!checksum) {
fprintf(stderr, "error: failed to get checksum object for file %s",
......
......@@ -145,7 +145,7 @@ int kXS = 0;
off_t offsetXS = 0;
bool computeXS = false;
std::string xsString = "";
eos::fst::CheckSum* xsObj = NULL;
std::unique_ptr<eos::fst::CheckSum> xsObj;
//..............................................................................
......@@ -617,7 +617,7 @@ main(int argc, char* argv[])
layoutId = LayoutId::GetId(layout, LayoutId::kCRC32C);
}
xsObj = eos::fst::ChecksumPlugins::GetChecksumObject(layoutId);
xsObj = eos::fst::ChecksumPlugins::GetChecksumObjectPtr(layoutId);
if (xsObj) {
xsObj->Reset();
......@@ -2249,10 +2249,6 @@ main(int argc, char* argv[])
print_summary(src_location, dst_location, totalbytes);
}
if (computeXS && xsObj) {
delete xsObj;
}
//............................................................................
// Close all files
//............................................................................
......
......@@ -110,8 +110,8 @@ int main(int argc, char* argv[])
for (size_t bs = 0; bs < blocksize.size(); bs++) {
for (size_t i = 0; i < checksumnames.size(); i++) {
eos_static_info("benchmarking checksum algorithm %s", checksumnames[i].c_str());
eos::fst::CheckSum* checksum = eos::fst::ChecksumPlugins::GetChecksumObject(
checksumids[i]);
std::unique_ptr<eos::fst::CheckSum> checksum =
eos::fst::ChecksumPlugins::GetChecksumObjectPtr(checksumids[i]);
if (!checksum) {
eos_static_err("failed to get checksum algorithm %s", checksumnames[i].c_str());
......@@ -135,7 +135,6 @@ int main(int argc, char* argv[])
eos_static_info("checksum( %-10s ) = %s realtime=%.02f [ms] blocksize=%s rate=%.02f",
checksumnames[i].c_str(), checksum->GetHexChecksum(), tm.RealTime(),
sizestring.c_str(), MEMORYBUFFERSIZE / tm.RealTime() / 1000.0);
delete checksum;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment