storage: Making use of SkipList-based index
Change-Id: I360af97ae794da383fe00aaad8ab3c417c5167d3
Refs: #1695, #1434
diff --git a/src/handles/base-handle.hpp b/src/handles/base-handle.hpp
index 3223940..3048856 100644
--- a/src/handles/base-handle.hpp
+++ b/src/handles/base-handle.hpp
@@ -22,7 +22,7 @@
#include "common.hpp"
-#include "storage/storage-handle.hpp"
+#include "storage/repo-storage.hpp"
#include "repo-command-response.hpp"
#include "repo-command-parameter.hpp"
@@ -30,7 +30,6 @@
class BaseHandle : noncopyable
{
-
public:
class Error : std::runtime_error
{
@@ -43,11 +42,13 @@
};
public:
- BaseHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain, Scheduler& scheduler)
+ BaseHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
+ Scheduler& scheduler)
: m_face(face)
, m_storageHandle(storageHandle)
, m_keyChain(keyChain)
, m_scheduler(scheduler)
+ // , m_storeindex(storeindex)
{
}
@@ -62,7 +63,7 @@
return m_face;
}
- inline StorageHandle&
+ inline RepoStorage&
getStorageHandle()
{
return m_storageHandle;
@@ -73,7 +74,13 @@
{
return m_scheduler;
}
-
+/*
+ inline RepoStorage&
+ getStoreIndex()
+ {
+ return m_storeindex;
+ }
+*/
uint64_t
generateProcessId();
@@ -94,9 +101,10 @@
private:
Face& m_face;
- StorageHandle& m_storageHandle;
+ RepoStorage& m_storageHandle;
KeyChain& m_keyChain;
Scheduler& m_scheduler;
+ // RepoStorage& m_storeindex;
};
inline void
diff --git a/src/handles/delete-handle.cpp b/src/handles/delete-handle.cpp
index ad4a474..c6ad7c5 100644
--- a/src/handles/delete-handle.cpp
+++ b/src/handles/delete-handle.cpp
@@ -21,8 +21,9 @@
namespace repo {
-DeleteHandle::DeleteHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain,
- Scheduler& scheduler, ValidatorConfig& validator)
+DeleteHandle::DeleteHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
+ Scheduler& scheduler,// RepoStorage& storeindex,
+ ValidatorConfig& validator)
: BaseHandle(face, storageHandle, keyChain, scheduler)
, m_validator(validator)
{
@@ -35,11 +36,6 @@
bind(&DeleteHandle::onValidationFailed, this, _1, _2));
}
-void
-DeleteHandle::onRegisterSuccess(const Name& prefix)
-{
- std::cerr << "Successfully registered prefix " << prefix << std::endl;
-}
void
DeleteHandle::onRegisterFailed(const Name& prefix, const std::string& reason)
@@ -101,13 +97,14 @@
std::cerr << reason << std::endl;
negativeReply(*interest, 401);
}
-
+//listen change the setinterestfilter
void
DeleteHandle::listen(const Name& prefix)
{
- getFace().setInterestFilter(Name(prefix).append("delete"),
+ ndn::Name deleteprefix = Name(prefix).append("delete");
+ ndn::InterestFilter filter(deleteprefix);
+ getFace().setInterestFilter(filter,
bind(&DeleteHandle::onInterest, this, _1, _2),
- bind(&DeleteHandle::onRegisterSuccess, this, _1),
bind(&DeleteHandle::onRegisterFailed, this, _1, _2));
}
@@ -139,31 +136,28 @@
DeleteHandle::processSingleDeleteCommand(const Interest& interest,
RepoCommandParameter& parameter)
{
- uint64_t nDeletedDatas = 0;
- if (getStorageHandle().deleteData(parameter.getName())) {
- nDeletedDatas++;
+ int64_t nDeletedDatas = getStorageHandle().deleteData(parameter.getName());
+ if (nDeletedDatas == -1) {
+ std::cerr << "Deletion Failed!" <<std::endl;
+ negativeReply(interest, 405); //405 means deletion fail
}
- positiveReply(interest, parameter, 200, nDeletedDatas);
+ else
+ positiveReply(interest, parameter, 200, nDeletedDatas);
}
void
DeleteHandle::processSelectorDeleteCommand(const Interest& interest,
RepoCommandParameter& parameter)
{
- uint64_t nDeletedDatas = 0;
- Name name = parameter.getName();
- Selectors selectors = parameter.getSelectors();
- vector<Name> names;
- getStorageHandle().readNameAny(name, selectors, names);
-
- for (vector<Name>::iterator it = names.begin(); it != names.end(); ++it) {
- if (getStorageHandle().deleteData(*it)) {
- nDeletedDatas++;
- }
+ int64_t nDeletedDatas = getStorageHandle()
+ .deleteData(Interest(parameter.getName())
+ .setSelectors(parameter.getSelectors()));
+ if (nDeletedDatas == -1) {
+ std::cerr << "Deletion Failed!" <<std::endl;
+ negativeReply(interest, 405); //405 means deletion fail
}
-
- //All data has been deleted, return 200
- positiveReply(interest, parameter, 200, nDeletedDatas);
+ else
+ positiveReply(interest, parameter, 200, nDeletedDatas);
}
void
diff --git a/src/handles/delete-handle.hpp b/src/handles/delete-handle.hpp
index 5a3b33a..4b0ac85 100644
--- a/src/handles/delete-handle.hpp
+++ b/src/handles/delete-handle.hpp
@@ -21,7 +21,7 @@
#define REPO_HANDLES_DELETE_HANDLE_HPP
#include "base-handle.hpp"
-
+#include <ndn-cxx/security/validator-config.hpp>
namespace repo {
using std::vector;
@@ -41,7 +41,7 @@
};
public:
- DeleteHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain,
+ DeleteHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
Scheduler& scheduler, ValidatorConfig& validator);
virtual void
@@ -52,9 +52,6 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onRegisterSuccess(const Name& prefix);
-
- void
onRegisterFailed(const Name& prefix, const std::string& reason);
void
diff --git a/src/handles/read-handle.cpp b/src/handles/read-handle.cpp
index e13a85c..83133e2 100644
--- a/src/handles/read-handle.cpp
+++ b/src/handles/read-handle.cpp
@@ -24,16 +24,11 @@
void
ReadHandle::onInterest(const Name& prefix, const Interest& interest)
{
- Data data;
- if (getStorageHandle().readData(interest, data)) {
- getFace().put(data);
- }
-}
-void
-ReadHandle::onRegisterSuccess(const Name& prefix)
-{
- std::cerr << "Successfully registered prefix " << prefix << std::endl;
+ shared_ptr<ndn::Data> data = getStorageHandle().readData(interest);
+ if (data != NULL) {
+ getFace().put(*data);
+ }
}
void
@@ -46,9 +41,9 @@
void
ReadHandle::listen(const Name& prefix)
{
- getFace().setInterestFilter(prefix,
+ ndn::InterestFilter filter(prefix);
+ getFace().setInterestFilter(filter,
bind(&ReadHandle::onInterest, this, _1, _2),
- bind(&ReadHandle::onRegisterSuccess, this, _1),
bind(&ReadHandle::onRegisterFailed, this, _1, _2));
}
diff --git a/src/handles/read-handle.hpp b/src/handles/read-handle.hpp
index 7bf0484..19d2034 100644
--- a/src/handles/read-handle.hpp
+++ b/src/handles/read-handle.hpp
@@ -22,13 +22,15 @@
#include "base-handle.hpp"
+
namespace repo {
class ReadHandle : public BaseHandle
{
public:
- ReadHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain, Scheduler& scheduler)
+ ReadHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
+ Scheduler& scheduler)
: BaseHandle(face, storageHandle, keyChain, scheduler)
{
}
@@ -44,9 +46,6 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onRegisterSuccess(const Name& prefix);
-
- void
onRegisterFailed(const Name& prefix, const std::string& reason);
};
diff --git a/src/handles/tcp-bulk-insert-handle.cpp b/src/handles/tcp-bulk-insert-handle.cpp
index a69dfe2..d7802ed 100644
--- a/src/handles/tcp-bulk-insert-handle.cpp
+++ b/src/handles/tcp-bulk-insert-handle.cpp
@@ -66,7 +66,7 @@
} // namespace detail
TcpBulkInsertHandle::TcpBulkInsertHandle(boost::asio::io_service& ioService,
- StorageHandle& storageHandle)
+ RepoStorage& storageHandle)
: m_acceptor(ioService)
, m_storageHandle(storageHandle)
{
diff --git a/src/handles/tcp-bulk-insert-handle.hpp b/src/handles/tcp-bulk-insert-handle.hpp
index 17233f4..ef1cbdd 100644
--- a/src/handles/tcp-bulk-insert-handle.hpp
+++ b/src/handles/tcp-bulk-insert-handle.hpp
@@ -21,7 +21,7 @@
#define REPO_HANDLES_TCP_BULK_INSERT_HANDLE_HPP
#include "common.hpp"
-#include "storage/storage-handle.hpp"
+#include "storage/repo-storage.hpp"
#include <boost/asio.hpp>
@@ -42,7 +42,7 @@
public:
TcpBulkInsertHandle(boost::asio::io_service& ioService,
- StorageHandle& storageHandle);
+ RepoStorage& storageHandle);
void
listen(const std::string& host, const std::string& port);
@@ -50,7 +50,7 @@
void
stop();
- StorageHandle&
+ RepoStorage&
getStorageHandle()
{
return m_storageHandle;
@@ -64,7 +64,7 @@
private:
boost::asio::ip::tcp::acceptor m_acceptor;
boost::asio::ip::tcp::endpoint m_localEndpoint;
- StorageHandle& m_storageHandle;
+ RepoStorage& m_storageHandle;
};
} // namespace repo
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index 07a5664..65098bf 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.cpp
@@ -26,8 +26,9 @@
static const ndn::time::milliseconds NOEND_TIMEOUT(10000);
static const ndn::time::milliseconds PROCESS_DELETE_TIME(10000);
-WriteHandle::WriteHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain,
- Scheduler& scheduler, ValidatorConfig& validator)
+WriteHandle::WriteHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
+ Scheduler& scheduler,// RepoStorage& storeindex,
+ ValidatorConfig& validator)
: BaseHandle(face, storageHandle, keyChain, scheduler)
, m_validator(validator)
, m_retryTime(RETRY_TIMEOUT)
@@ -51,12 +52,6 @@
bind(&WriteHandle::onValidationFailed, this, _1, _2));
}
-void
-WriteHandle::onRegisterSuccess(const Name& prefix)
-{
- std::cerr << "Successfully registered prefix " << prefix << std::endl;
-}
-
// onRegisterFailed.
void
WriteHandle::onRegisterFailed(const Name& prefix, const std::string& reason)
@@ -127,6 +122,8 @@
if (response.getInsertNum() == 0) {
getStorageHandle().insertData(*data);
+ // getStorageHandle().insertEntry(*data);
+ // getStoreIndex().insert(*data);
response.setInsertNum(1);
}
@@ -200,15 +197,15 @@
{
Name insertPrefix;
insertPrefix.append(prefix).append("insert");
- getFace().setInterestFilter(insertPrefix,
+ ndn::InterestFilter filter_insert(insertPrefix);
+ getFace().setInterestFilter(filter_insert,
bind(&WriteHandle::onInterest, this, _1, _2),
- bind(&WriteHandle::onRegisterSuccess, this, _1),
bind(&WriteHandle::onRegisterFailed, this, _1, _2));
Name insertCheckPrefix;
insertCheckPrefix.append(prefix).append("insert check");
- getFace().setInterestFilter(insertCheckPrefix,
+ ndn::InterestFilter filter_insertCheck(insertCheckPrefix);
+ getFace().setInterestFilter(filter_insertCheck,
bind(&WriteHandle::onCheckInterest, this, _1, _2),
- bind(&WriteHandle::onRegisterSuccess, this, _1),
bind(&WriteHandle::onRegisterFailed, this, _1, _2));
}
diff --git a/src/handles/write-handle.hpp b/src/handles/write-handle.hpp
index 8638a23..6d42630 100644
--- a/src/handles/write-handle.hpp
+++ b/src/handles/write-handle.hpp
@@ -21,7 +21,9 @@
#define REPO_HANDLES_WRITE_HANDLE_HPP
#include "base-handle.hpp"
-
+//#include <ndn-cxx/security/signature-sha256.hpp>
+#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
#include <queue>
namespace repo {
@@ -67,7 +69,7 @@
public:
- WriteHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain,
+ WriteHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
Scheduler& scheduler, ValidatorConfig& validator);
virtual void
@@ -112,9 +114,6 @@
void
onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason);
- void
- onRegisterSuccess(const Name& prefix);
-
/**
* @brief insert command prefix register failed
*/