Task #3546
closedPIT entry: move away forwarding semantics
Added by Junxiao Shi over 8 years ago. Updated over 8 years ago.
100%
Description
Currently pit::Entry
class has many methods that are unrelated to table structure, but reflect forwarding semantics used by pipelines or strategies.
The semantics of these methods are problematic, and are not general enough for all forwarding strategies.
They should be moved away from pit::Entry
, and placed into forwarding.
The pit::Entry
class shall only contain methods that operate on the table structure, include but are not limited to:
- access to the representative Interest
- insert/delete/get/enumerate in-records
- insert/delete/get/enumerate out-records
Other methods should be moved away, and turned into helper functions in forwarding.
Updated by Junxiao Shi over 8 years ago
Specific design for pit-entry.hpp as of nfd:commit:5e5e44518286e89a0092ea0ad93c22e64128bdd2 :
class Entry : public StrategyInfoHost, noncopyable
{
public:
const Interest& getInterest() const;
const Name& getName() const;
InRecordCollection inRecords;
OutRecordCollection outRecords;
public: // misc
int findNonce(nonce, face) const;
scheduler::EventId unsatisfyTimer;
scheduler::EventId stragglerTimer;
};
class InRecordCollection
{
size_t size() const;
const_iterator begin() const;
const_iterator end() const;
const_iterator find(face) const;
iterator find(face);
iterator add(face, interest);
bool remove(face);
void clear();
};
class OutRecordCollection
{
(same as InRecordCollection)
};
Entry
methods under "misc" are not strictly for structure, but they are used by pipelines and it would be inefficient to turn them intoStrategyInfo
, so they can stay.- Operations on in-records and out-records are entirely through the collection type.
It has been cumbersome to write
outRecord = pitEntry->getOutRecord(inFace); if (outRecord == pitEntry->getOutRecords().end()) ...
(src) becausegetOutRecord
andend
are on different objects; it would look better through the collection type becausefind
andend
are on the same object.
canForwardTo violatesScope hasLocalInRecord hasUnexpiredOutRecords
should be moved to forwarding as free functions, and included by whatever pipeline or strategy that needs them.
A function would look like: bool violatesScope(const pit::Entry& pitEntry, const Face& inFace)
.
Updated by Junxiao Shi over 8 years ago
- Related to Task #3164: Reduce usage of shared_ptr in FIB/PIT/StrategyChoice/Measurements added
Updated by Junxiao Shi over 8 years ago
- Assignee set to Junxiao Shi
20160315 call approves the idea, but the design is changed as:
find add remove
operations for in-record and out-record shall be kept on PIT entry; getters like in_begin() in_end()
may be added for easier access.
Rationale: adding/removing an in-record or out-record not only involves modifications on the collection, but also can change the PIT entry itself.
Updated by Davide Pesavento over 8 years ago
Junxiao Shi wrote:
Rationale: adding/removing an in-record or out-record not only involves modifications on the collection, but also can change the PIT entry itself.
Just for the record, I don't think that kind of reasoning is correct. The fact that adding an in-record changes the pit entry is an implementation detail, and it should not dictate or influence the API in any way.
Updated by Junxiao Shi over 8 years ago
I agree with note-4.
Could @Alex approve the API in note-1 then?
Updated by Alex Afanasyev over 8 years ago
Just for the record, I don't think that kind of reasoning is correct. The fact that adding an in-record changes the pit entry is an implementation detail, and it should not dictate or influence the API in any way.
I disagree with this. The semantics of PIT entry is not just a collection of in and out interests. It is a state that remembers in and out, which is being update whenever you add/remove in/out interests. Yes, it can be separated, but we then we simply moving the logic to somewhere and potentially "violate" PIT entry semantics.
Updated by Davide Pesavento over 8 years ago
Maintaining a class or object invariant is also an implementation detail. Of course the API must not provide a way for its consumer to break the invariant. I wasn't suggesting to do that.
I think the question is whether a pit entry is (from an API point of view) an atomic, stateful entity that appears as a black box, or an aggregate of inRecords + outRecords + some other state. I have no strong opinion on this. All I'm saying is that the rationale in note-3 should not --by itself-- rule out the second definition of pit entry.
Updated by Junxiao Shi over 8 years ago
whether a pit entry is an atomic, stateful entity that appears as a black box, or an aggregate of inRecords + outRecords + some other state
Conceptually, a PIT entry should be an atomic entity, because an in-record or out-record is meaningless without a PIT entry.
However, I'm unsure how this question affects API design.
Updated by Davide Pesavento over 8 years ago
Junxiao Shi wrote:
However, I'm unsure how this question affects API design.
It doesn't have to. What a pit entry conceptually is doesn't necessarily shape every aspect of its API. It can certainly influence it, but some invariants can be maintained even if the "API model" is different from the "conceptual model". That's why I said "from an API point of view" in note-7.
Updated by Junxiao Shi over 8 years ago
It doesn't have to. What a pit entry conceptually is doesn't necessarily shape every aspect of its API.
In this case, I'll stick with note-3 design which has been approved.
Updated by Junxiao Shi over 8 years ago
http://gerrit.named-data.net/2787
patchset1 moves canForwardTo violatesScope findNonce
to forwarding.
I'll do API refactoring (according to note-3) in next patchset.
I'm waiting for a decision on #3545 before moving hasUnexpiredOutRecords
.
This task is easier than expected.
Updated by Junxiao Shi over 8 years ago
- % Done changed from 0 to 50
http://gerrit.named-data.net/2787 patchset2 moves away forwarding semantics.
I plan to refactor pit::Entry
APIs according to note-3 in another commit, to keep this commit small.
Updated by Junxiao Shi over 8 years ago
- Status changed from In Progress to Code review
- % Done changed from 50 to 100
Updated by Junxiao Shi over 8 years ago
http://gerrit.named-data.net/2806
This commit deduplicates Forwarder::LOCALHOST_NAME
and scope_prefix::LOCALHOST
.
Updated by Junxiao Shi over 8 years ago
- Status changed from Code review to In Progress
- % Done changed from 100 to 80
The algorithms should be introduced in NFD devguide "forwarding" section.
Updated by Junxiao Shi over 8 years ago
- Status changed from In Progress to Closed
- % Done changed from 80 to 100
nfd-docs:commit:a3cc734117d558bb0ff76f54827aa2894fad3ba2