Commit ea7e5643 authored by Michael Davis's avatar Michael Davis
Browse files

[os-generic-queues] Refactors Algorithms.hpp, it compiles again

parent d792e6f1
......@@ -94,6 +94,8 @@ struct ContainerTraits
typedef std::list<ElementDescriptor> ElementDescriptorContainer;
typedef std::set<ElementAddress> ElementsToSkipSet;
CTA_GENERATE_EXCEPTION_CLASS(NoSuchContainer);
template<typename Element>
struct OpFailure {
Element *element;
......@@ -107,22 +109,22 @@ struct ContainerTraits
typename OpFailure<InsertedElement>::list failedElements;
};
ContainerSummary getContainerSummary(Container&);
static void trimContainerIfNeeded(Container &cont, ScopedExclusiveLock &contLock,
const ContainerIdentifier &cId, log::LogContext &lc);
CTA_GENERATE_EXCEPTION_CLASS(NoSuchContainer);
template<typename Element>
static ElementAddress getElementAddress(const Element &e);
static void getLockedAndFetched(Container &cont, ScopedExclusiveLock &contLock, AgentReference &agRef, const ContainerIdentifier &cId, log::LogContext &lc);
static void getLockedAndFetchedNoCreate(Container &cont, ScopedExclusiveLock &contLock, const ContainerIdentifier &cId, log::LogContext &lc);
static void addReferencesAndCommit(Container &cont, typename InsertedElement::list &elemMemCont, AgentReference &agentRef, log::LogContext &lc);
static void addReferencesIfNecessaryAndCommit(Container &cont, typename InsertedElement::list &elemMemCont, AgentReference &agentRef, log::LogContext &lc);
void removeReferencesAndCommit(Container &cont, typename OpFailure<InsertedElement>::list &elementsOpFailures);
void removeReferencesAndCommit(Container &cont, std::list<ElementAddress> &elementAddressList);
static ContainerSummary getContainerSummary(Container &cont);
static void trimContainerIfNeeded(Container &cont, ScopedExclusiveLock &contLock,
const ContainerIdentifier &cId, log::LogContext &lc);
static void getLockedAndFetched(Container &cont, ScopedExclusiveLock &contLock, AgentReference &agRef,
const ContainerIdentifier &cId, log::LogContext &lc);
static void getLockedAndFetchedNoCreate(Container &cont, ScopedExclusiveLock &contLock,
const ContainerIdentifier &cId, log::LogContext &lc);
static void addReferencesAndCommit(Container &cont, typename InsertedElement::list &elemMemCont,
AgentReference &agentRef, log::LogContext &lc);
static void addReferencesIfNecessaryAndCommit(Container &cont, typename InsertedElement::list &elemMemCont,
AgentReference &agentRef, log::LogContext &lc);
static void removeReferencesAndCommit(Container &cont, typename OpFailure<InsertedElement>::list &elementsOpFailures);
static void removeReferencesAndCommit(Container &cont, std::list<ElementAddress> &elementAddressList);
static typename OpFailure<InsertedElement>::list
switchElementsOwnership(typename InsertedElement::list &elemMemCont, const ContainerAddress &contAddress,
......
/*
/**
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
* Copyright © 2018 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,6 +22,48 @@
namespace cta { namespace objectstore {
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsSummary::
addDeltaToLog(const PoppedElementsSummary &previous, log::ScopedParamContainer &params) {
params.add("filesAdded", files - previous.files)
.add("bytesAdded", bytes - previous.bytes)
.add("filesBefore", previous.files)
.add("bytesBefore", previous.bytes)
.add("filesAfter", files)
.add("bytesAfter", bytes);
}
void ContainerTraitsTypes<ArchiveQueue>::ContainerSummary::
addDeltaToLog(ContainerSummary& previous, log::ScopedParamContainer& params) {
params.add("queueJobsBefore", previous.jobs)
.add("queueBytesBefore", previous.bytes)
.add("queueJobsAfter", jobs)
.add("queueBytesAfter", bytes);
}
auto ContainerTraits<ArchiveQueue>::PopCriteria::
operator-=(const PoppedElementsSummary &pes) -> PopCriteria & {
bytes -= pes.bytes;
files -= pes.files;
return *this;
}
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsList::
insertBack(PoppedElementsList &&insertedList) {
for (auto &e: insertedList) {
std::list<PoppedElement>::emplace_back(std::move(e));
}
}
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsList::insertBack(PoppedElement &&e) {
std::list<PoppedElement>::emplace_back(std::move(e));
}
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsBatch::
addToLog(log::ScopedParamContainer &params) {
params.add("bytes", summary.bytes)
.add("files", summary.files);
}
template<>
const std::string ContainerTraits<ArchiveQueue>::c_containerTypeName = "ArchiveQueue";
......
......@@ -79,49 +79,12 @@ struct ContainerTraitsTypes<ArchiveQueue>
};
};
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsSummary::
addDeltaToLog(const PoppedElementsSummary &previous, log::ScopedParamContainer &params)
{
params.add("filesAdded", files - previous.files)
.add("bytesAdded", bytes - previous.bytes)
.add("filesBefore", previous.files)
.add("bytesBefore", previous.bytes)
.add("filesAfter", files)
.add("bytesAfter", bytes);
}
void ContainerTraitsTypes<ArchiveQueue>::ContainerSummary::
addDeltaToLog(ContainerSummary& previous, log::ScopedParamContainer& params)
{
params.add("queueJobsBefore", previous.jobs)
.add("queueBytesBefore", previous.bytes)
.add("queueJobsAfter", jobs)
.add("queueBytesAfter", bytes);
}
auto ContainerTraits<ArchiveQueue>::PopCriteria::
operator-=(const PoppedElementsSummary &pes) -> PopCriteria & {
bytes -= pes.bytes;
files -= pes.files;
return *this;
}
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsList::
insertBack(PoppedElementsList &&insertedList) {
for (auto &e: insertedList) {
std::list<PoppedElement>::emplace_back(std::move(e));
}
}
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsList::insertBack(PoppedElement &&e) {
std::list<PoppedElement>::emplace_back(std::move(e));
}
void ContainerTraitsTypes<ArchiveQueue>::PoppedElementsBatch::
addToLog(log::ScopedParamContainer &params) {
params.add("bytes", summary.bytes)
.add("files", summary.files);
template<>
template<typename Element>
ContainerTraits<ArchiveQueue>::ElementAddress ContainerTraits<ArchiveQueue>::
getElementAddress(const Element &e) {
return e.archiveRequest->getAddressIfSet();
}
......@@ -139,8 +102,6 @@ public:
static const std::string c_containerTypeName; //= "ArchiveQueue";
static const std::string c_identifyerType; // = "tapepool";
static ContainerSummary getContainerSummary(Container &cont);
template <class Element>
struct OpFailure {
Element * element;
......@@ -150,9 +111,6 @@ public:
typedef std::list<ElementDescriptor> ElementDescriptorContainer;
template <class Element>
static ElementAddress getElementAddress(const Element & e) { return e.archiveRequest->getAddressIfSet(); }
static void getLockedAndFetched(Container & cont, ScopedExclusiveLock & aqL, AgentReference & agRef, const ContainerIdentifier & contId,
log::LogContext & lc);
......@@ -165,10 +123,6 @@ public:
static void addReferencesIfNecessaryAndCommit(Container & cont, InsertedElement::list & elemMemCont,
AgentReference & agentRef, log::LogContext & lc);
static void removeReferencesAndCommit(Container & cont, OpFailure<InsertedElement>::list & elementsOpFailures);
static void removeReferencesAndCommit(Container & cont, std::list<ElementAddress>& elementAddressList);
class OwnershipSwitchFailure: public cta::exception::Exception {
public:
OwnershipSwitchFailure(const std::string & message): cta::exception::Exception(message) {};
......
......@@ -63,6 +63,7 @@ add_library (ctaobjectstore SHARED
ArchiveQueueAlgorithms.cpp
RetrieveQueue.cpp
RetrieveQueueShard.cpp
RetrieveQueueAlgorithms.cpp
ArchiveRequest.cpp
RetrieveRequest.cpp
DriveRegister.cpp
......
......@@ -22,13 +22,13 @@
namespace cta { namespace objectstore {
template <>
class ContainerTraits<RetrieveQueue> {
public:
typedef RetrieveQueue Container;
typedef std::string ContainerAddress;
typedef std::string ElementAddress;
typedef std::string ContainerIdentifyer;
template<>
struct ContainerTraitsTypes<RetrieveQueue>
{
struct ContainerSummary {
void addDeltaToLog(const ContainerSummary&, log::ScopedParamContainer&);
};
struct InsertedElement {
std::unique_ptr<RetrieveRequest> retrieveRequest;
uint16_t copyNb;
......@@ -38,6 +38,49 @@ public:
serializers::RetrieveJobStatus status;
typedef std::list<InsertedElement> list;
};
struct ElementDescriptor {};
struct PoppedElement {};
struct PoppedElementsSummary;
struct PopCriteria {
PopCriteria();
PopCriteria& operator-= (const PoppedElementsSummary &);
};
struct PoppedElementsSummary {
bool operator<(const PopCriteria&);
PoppedElementsSummary& operator+=(const PoppedElementsSummary&);
PoppedElementsSummary(const PoppedElementsSummary&);
void addDeltaToLog(const PoppedElementsSummary&, log::ScopedParamContainer&);
};
struct PoppedElementsList {
PoppedElementsList();
void insertBack(PoppedElementsList&&);
};
struct PoppedElementsBatch {
PoppedElementsList elements;
PoppedElementsSummary summary;
void addToLog(log::ScopedParamContainer&);
};
};
template<>
template<typename Element>
ContainerTraits<RetrieveQueue>::ElementAddress ContainerTraits<RetrieveQueue>::
getElementAddress(const Element &e) {
return e.retrieveRequest->getAddressIfSet();
}
#if 0
template <>
class ContainerTraits<RetrieveQueue> {
public:
typedef RetrieveQueue Container;
typedef std::string ContainerAddress;
typedef std::string ElementAddress;
typedef std::string ContainerIdentifyer;
template <class Element>
struct OpFailure {
......@@ -48,8 +91,6 @@ public:
typedef RetrieveRequest::JobDump ElementDescriptor;
typedef std::list<ElementDescriptor> ElementDescriptorContainer;
template <class Element>
static ElementAddress getElementAddress(const Element & e) { return e.retrieveRequest->getAddressIfSet(); }
static void getLockedAndFetched(Container & cont, ScopedExclusiveLock & aqL, AgentReference & agRef, const ContainerIdentifyer & contId,
log::LogContext & lc) {
......@@ -133,5 +174,6 @@ public:
CTA_GENERATE_EXCEPTION_CLASS(NoSuchContainer);
};
#endif
}} // namespace cta::objectstore
\ No newline at end of file
}} // namespace cta::objectstore
Supports Markdown
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