InMemoryStorage » History » Revision 9
Revision 7 (Yingdi Yu, 09/12/2014 11:34 PM) → Revision 9/28 (Yingdi Yu, 09/13/2014 10:54 PM)
# Per-application in-memory storage Many NDN applications need to publish data packets. A data packet may have a FreshnessPeriod which indicates how long a node (local fowarders and routers) should wait after the arrival of this data before marking it as stale. As stated in NDN-TLV spec: > Note that the stale data is still valid data; the expiration of FreshnessPeriod only means that the producer may have produced newer data. The inconsistency between the actually validity of a data packet and its FreshnessPeriod comes from the unpredictability of the future. In some cases, the data producer cannot predict when a data packet will be replaced by a new version of data packet. One extreme solution is to set FreshnessPeriod of the unpredictable data packet to 0, so that whenever the data is request, the interest will be forwarded to the original producer to check whether a new version of data packet has been generated or not. Fortunately, some data packets are relatively static (i.e., it occasionally changes) and can benefit from network caching. The FreshnessPeriod becomes a tradeoff between network caching and data freshness. As a result, during the FreshnessPeriod, the producer will not be bothered by interests for the same data packet. However, after the FreshnessPeriod, when all the cached copies become stale, the producer should be prepared to receive the interests again. If, at that time, the data is still valid, the producer should return the same data packet to refresh the cached copies. It seems that it is beneficial to keep a copy of the valid data packet at the producer side, otherwise the producer has to generate/sign the data packet again and again. The copy of the valid data packet cannot be stored in the ContentStore of local nfd, because current ContentStore can only tell fresh or stale data, but cannot tell valid or invalid data. Instead, it is better to provide the storage inside the app, i.e., in-memory storage. We list several use cases of the in-memory storage. ## Use cases ### PIB Service PIB provides the public information about identities, keys, and certificates. For example, one may ask PIB for the system default key. And PIB's reply should be valid until the system default key is changed. Since PIB cannot predict when the system default key will be changed, it is more reasonable to set a relatively short FreshnessPeriod for the reply. As a result, after every FreshnessPeriod, PIB may receive an interest for the system default key, because the cached copy in ContentStore is marked as stale. In this case, PIB can benefit from the in-memory storage. By putting the reply into the in-memory storage, PIB can avoid repeatedly generating the same data packet. ### Nack When the producer want to explicitly tell consumer some data does not exist for now, it may use the nack data. However, the producer may not know when the requested data will be generated. With the same logic, the producer can generate a nack data with short FreshnessPeriod, and put it into the in-memory storage to avoid repeatedly generating the same nack. When the requested data has been generated, the producer can replace the nack with the new data in the in-memory storage. ### ChronoChat For chatroom discovery, each chatroom needs to publish the chatroom-info data. Chatroom-info must have finite FreshnessPeriod, so that after FreshnessPeriod, the chatroom-refresh interest will reach one of the chatroom participants. If the chatroom-info has not changed yet, it is not necessary to generate a new chatroom-info data. The FreshnessPeriod of a chat message can be set to infinite. However, ContentStore may not guarantee to keep all the chat messages even if they are fresh. An in-memory storage can help here as a guaranteed storage as long as the process is running. ### NLSR NLSR LSA is the same as ChronoChat chat message. ## Design Goal The goal of InMemoryStorage is to allow an application instance to keep a copy of valid data packets in its own memory. The InMemoryStorage is useful in two general cases: * when data packets have been generated without incoming interest; * when the lifetime of a data packet is longer than the FreshnessPeriod of the data packet. For an application that may run into either of the two cases, it can create an InMemoryStorage instance within itself and insert the data packets into the InMemoryStorage. When the app receives an incoming interest, the app may first look up matched data packet in the InMemoryStorage to avoid generating the same data packet again. Data packets in an InMemoryStorage is explicitly managed by the app. A data packet can be either inserted into or erased from the InMemoryStorage. In other words, the only way to change a data packet in an InMemoryStorage is to erase the data packet from the InMemoryStorage. Ideally, Although ideally, the InMemoryStorage should find a data packet that can match the incoming interest, that is, besides longest name prefix matching, the actual matching procedure can be simpler, i.e., the InMemoryStorage should also process selectors. However, some selectors are may not meaningful need to the data producer (e.g., MustBeFresh). handle selectors. Moreover, The reason behind this is that the variety of app, as the data packets at the producer side producer, should know what is much less than the one in the cache intermediate routers, most appropriate data packet to return. so Therefore, among five types of selectors that have been defined for interest packet, some selectors (e.g., ChilderSelector, Min/MaxSuffixComponents, PublisherPublicKeyLocator) may not of them can be necessary. Therefore, longest name prefix matching alone ignored * **MustBeFresh**: the app, as the end of the interest forwarding path, should be sufficient for InMemoryStorage in most cases. always return the data packet that is currently valid. And InMemoryStorage provides two types * **ChildSelector**: rightmost child selector is usually used to retrieve the latest version of the data look up interfaces: one is by-name while packet, so if the other one app can guarantee that only the latest version of the data packet exists in the InMemoryStorage, rightmost child selector is by-interest. not needed. The by-name method will return default behavior of InMemoryStorage is to find the leftmost child. * : Looking up a data packet that can match the interest name. in InMemoryStorage is done by pure longest name prefix matching. If When there are more than one matched data packet, packets, the lower bound (the first one in canonical order) order will be returned. Note that an An InMemoryStorage instance is created within an application instance, and is destroyed when the application instance ends. Therefore, the lifetime of the InMemoryStorage instance is no longer than the lifetime of the application instance. The data packets stored in the InMemoryStorage will also be eliminated if the data packets are not backed up in some persistent storage (e.g., hard disk, repo, etc.) before the InMemoryStorage is destroyed. Also note that data in the InMemoryStorage cannot be modified unless erased. This implies that a data packet is uniquely identified by its name and implicit digest, so that a data packet in InMemoryStorage cannot be overwritten by another data packet with the same name. Whether selectors should be processed is still in discussion. For now, among the five selectors, four are not needed ## Interface ### Core Methods The interfaces core methods of InMemoryStorage is defined as: class InMemoryStorage { ... // required methods void insert(const Data& data); void erase(const Name& prefix); shared_ptr<const Data> find(const Name& name); // not supported for now // shared_ptr<const Data> // find(const Interest& interest); // optional methods void save(const std::string& filename); // save data packets to }; #### `insert` Once a file in default format void load(const std::string& filename); // load data packets from a file is inserted into InMemoryStorage, it will stay in default format ... }; the storage #### `erase` #### `find` ### Helper Methods ## Reference There is another type of local storage, which is different from in-memory storage, called [Managed ContentStore](http://redmine.named-data.net/projects/nfd/wiki/ManagedContentStore)