Repository: ignite Updated Branches: refs/heads/master 2c97f7316 -> a3c2ea3bf
IGNITE-9247: CPP Thin: implemented operations on multiple keys This closes #4950 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a3c2ea3b Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a3c2ea3b Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a3c2ea3b Branch: refs/heads/master Commit: a3c2ea3bf5601fa600c92d2f1701372546bc2a7d Parents: 2c97f73 Author: Igor Sapego <[email protected]> Authored: Thu Oct 11 13:26:01 2018 +0300 Committer: Igor Sapego <[email protected]> Committed: Thu Oct 11 13:26:01 2018 +0300 ---------------------------------------------------------------------- .../thin-client-test/src/cache_client_test.cpp | 409 +++++++++++++++++++ .../ignite/impl/thin/cache/cache_client_proxy.h | 59 ++- .../include/ignite/impl/thin/readable.h | 70 +++- .../include/ignite/impl/thin/writable.h | 155 ++++++- .../include/ignite/thin/cache/cache_client.h | 163 +++++++- .../src/impl/cache/cache_client_impl.cpp | 111 +++-- .../src/impl/cache/cache_client_impl.h | 69 +++- .../src/impl/cache/cache_client_proxy.cpp | 33 +- .../cpp/thin-client/src/impl/message.cpp | 20 +- .../cpp/thin-client/src/impl/message.h | 47 ++- 10 files changed, 1056 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client-test/src/cache_client_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client-test/src/cache_client_test.cpp b/modules/platforms/cpp/thin-client-test/src/cache_client_test.cpp index 1bbb0b8..24ff48f 100644 --- a/modules/platforms/cpp/thin-client-test/src/cache_client_test.cpp +++ b/modules/platforms/cpp/thin-client-test/src/cache_client_test.cpp @@ -361,6 +361,56 @@ BOOST_AUTO_TEST_CASE(CacheClientContainsComplexKey) BOOST_CHECK(cache.ContainsKey(key)); } +BOOST_AUTO_TEST_CASE(CacheClientReplaceBasicKey) +{ + IgniteClientConfiguration cfg; + + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = client.GetCache<int32_t, std::string>("local"); + + int32_t key = 42; + std::string valIn = "Lorem ipsum"; + + cache.Put(key, valIn); + + BOOST_REQUIRE(!cache.Replace(1, "Test")); + BOOST_REQUIRE(cache.Replace(42, "Test")); + + BOOST_REQUIRE_EQUAL(cache.Get(1), ""); + BOOST_REQUIRE_EQUAL(cache.Get(42), "Test"); +} + +BOOST_AUTO_TEST_CASE(CacheClientReplaceComplexKey) +{ + IgniteClientConfiguration cfg; + + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<ignite::ComplexType, int32_t> cache = client.GetCache<ignite::ComplexType, int32_t>("local"); + + ignite::ComplexType key; + + key.i32Field = 123; + key.strField = "Test value"; + key.objField.f1 = 42; + key.objField.f2 = "Inner value"; + + int32_t valIn = 42; + + cache.Put(key, valIn); + + BOOST_REQUIRE(!cache.Replace(ignite::ComplexType(), 2)); + BOOST_REQUIRE(cache.Replace(key, 13)); + + BOOST_REQUIRE_EQUAL(cache.Get(key), 13); + BOOST_REQUIRE_EQUAL(cache.Get(ignite::ComplexType()), 0); +} + BOOST_AUTO_TEST_CASE(CacheClientPartitionsInt8) { NumPartitionTest<int8_t>(100); @@ -764,4 +814,363 @@ BOOST_AUTO_TEST_CASE(CacheClientDefaultDynamicCache) } } +BOOST_AUTO_TEST_CASE(CacheClientGetAllContainers) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + std::map<int32_t, std::string> res; + + cache.GetAll(keys, res); + + BOOST_REQUIRE_EQUAL(res.size(), keys.size()); + + for (size_t i = 0; i < keys.size(); ++i) + BOOST_REQUIRE_EQUAL(values[i], res[keys[i]]); +} + +BOOST_AUTO_TEST_CASE(CacheClientGetAllIterators) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + std::map<int32_t, std::string> res; + + cache.GetAll(keys.begin(), keys.end(), std::inserter(res, res.end())); + + BOOST_REQUIRE_EQUAL(res.size(), keys.size()); + + for (size_t i = 0; i < keys.size(); ++i) + BOOST_REQUIRE_EQUAL(values[i], res[keys[i]]); +} + +BOOST_AUTO_TEST_CASE(CacheClientPutAllContainers) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::map<int32_t, std::string> toPut; + + toPut[1] = "first"; + toPut[2] = "second"; + toPut[3] = "third"; + + cache.PutAll(toPut); + + for (std::map<int32_t, std::string>::const_iterator it = toPut.begin(); it != toPut.end(); ++it) + BOOST_REQUIRE_EQUAL(cache.Get(it->first), it->second); +} + +BOOST_AUTO_TEST_CASE(CacheClientPutAllIterators) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::map<int32_t, std::string> toPut; + + toPut[1] = "first"; + toPut[2] = "second"; + toPut[3] = "third"; + + cache.PutAll(toPut.begin(), toPut.end()); + + for (std::map<int32_t, std::string>::const_iterator it = toPut.begin(); it != toPut.end(); ++it) + BOOST_REQUIRE_EQUAL(cache.Get(it->first), it->second); +} + +BOOST_AUTO_TEST_CASE(CacheClientRemoveAllContainers) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 3); + + for (size_t i = 0; i < keys.size(); ++i) + BOOST_REQUIRE_EQUAL(cache.Get(keys[i]), values[i]); + + cache.RemoveAll(keys); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 0); +} + +BOOST_AUTO_TEST_CASE(CacheClientRemoveAllIterators) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 3); + + for (size_t i = 0; i < keys.size(); ++i) + BOOST_REQUIRE_EQUAL(cache.Get(keys[i]), values[i]); + + cache.RemoveAll(keys.begin(), keys.end()); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 0); +} + +BOOST_AUTO_TEST_CASE(CacheClientClearAllContainers) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 3); + + for (size_t i = 0; i < keys.size(); ++i) + BOOST_REQUIRE_EQUAL(cache.Get(keys[i]), values[i]); + + cache.ClearAll(keys); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 0); +} + +BOOST_AUTO_TEST_CASE(CacheClientClearAllIterators) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 3); + + for (size_t i = 0; i < keys.size(); ++i) + BOOST_REQUIRE_EQUAL(cache.Get(keys[i]), values[i]); + + cache.ClearAll(keys.begin(), keys.end()); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 0); +} + +BOOST_AUTO_TEST_CASE(CacheClientContainsKeysContainers) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 3); + + BOOST_REQUIRE(cache.ContainsKeys(keys)); + + std::set<int32_t> check; + + BOOST_REQUIRE(cache.ContainsKeys(check)); + + check.insert(1); + BOOST_REQUIRE(cache.ContainsKeys(check)); + + check.insert(2); + BOOST_REQUIRE(cache.ContainsKeys(check)); + + check.insert(3); + BOOST_REQUIRE(cache.ContainsKeys(check)); + + check.insert(4); + BOOST_REQUIRE(!cache.ContainsKeys(check)); + + check.erase(2); + BOOST_REQUIRE(!cache.ContainsKeys(check)); + + check.erase(4); + BOOST_REQUIRE(cache.ContainsKeys(check)); +} + +BOOST_AUTO_TEST_CASE(CacheClientContainsKeysIterators) +{ + IgniteClientConfiguration cfg; + cfg.SetEndPoints("127.0.0.1:11110"); + + IgniteClient client = IgniteClient::Start(cfg); + + cache::CacheClient<int32_t, std::string> cache = + client.CreateCache<int32_t, std::string>("test"); + + std::vector<int32_t> keys; + + keys.push_back(1); + keys.push_back(2); + keys.push_back(3); + + std::vector<std::string> values; + + values.push_back("first"); + values.push_back("second"); + values.push_back("third"); + + for (size_t i = 0; i < keys.size(); ++i) + cache.Put(keys[i], values[i]); + + BOOST_REQUIRE_EQUAL(cache.GetSize(cache::CachePeekMode::PRIMARY), 3); + + BOOST_REQUIRE(cache.ContainsKeys(keys)); + + std::set<int32_t> check; + + BOOST_REQUIRE(cache.ContainsKeys(check.begin(), check.end())); + + check.insert(1); + BOOST_REQUIRE(cache.ContainsKeys(check.begin(), check.end())); + + check.insert(2); + BOOST_REQUIRE(cache.ContainsKeys(check.begin(), check.end())); + + check.insert(3); + BOOST_REQUIRE(cache.ContainsKeys(check.begin(), check.end())); + + check.insert(4); + BOOST_REQUIRE(!cache.ContainsKeys(check.begin(), check.end())); + + check.erase(2); + BOOST_REQUIRE(!cache.ContainsKeys(check.begin(), check.end())); + + check.erase(4); + BOOST_REQUIRE(cache.ContainsKeys(check.begin(), check.end())); +} + + BOOST_AUTO_TEST_SUITE_END() http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/cache/cache_client_proxy.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/include/ignite/impl/thin/cache/cache_client_proxy.h b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/cache/cache_client_proxy.h index 349a1dc..cda2fae 100644 --- a/modules/platforms/cpp/thin-client/include/ignite/impl/thin/cache/cache_client_proxy.h +++ b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/cache/cache_client_proxy.h @@ -77,6 +77,14 @@ namespace ignite void Put(const WritableKey& key, const Writable& value); /** + * Stores given key-value pairs in cache. + * If write-through is enabled, the stored values will be persisted to store. + * + * @param pairs Writable key-value pair sequence. + */ + void PutAll(const Writable& pairs); + + /** * Get value from cache. * * @param key Key. @@ -85,6 +93,31 @@ namespace ignite void Get(const WritableKey& key, Readable& value); /** + * Retrieves values mapped to the specified keys from cache. + * If some value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * + * @param keys Writable key sequence. + * @param pairs Readable key-value pair sequence. + */ + void GetAll(const Writable& keys, Readable& pairs); + + /** + * Stores given key-value pair in cache only if there is a previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, rom the underlying persistent storage. + * If write-through is enabled, the stored value will be persisted to store. + * + * @param key Key to store in cache. + * @param value Value to be associated with the given key. + * @return True if the value was replaced. + */ + bool Replace(const WritableKey& key, const Writable& value); + + /** * Check if the cache contains a value for the specified key. * * @param key Key whose presence in this cache is to be tested. @@ -93,6 +126,14 @@ namespace ignite bool ContainsKey(const WritableKey& key); /** + * Check if cache contains mapping for these keys. + * + * @param keys Keys. + * @return True if cache contains mapping for all these keys. + */ + bool ContainsKeys(const Writable& keys); + + /** * Gets the number of all entries cached across all nodes. * @note This operation is distributed and will query all participating nodes for their cache sizes. * @@ -125,7 +166,6 @@ namespace ignite * If the returned value is not needed, method removex() should always be used instead of this * one to avoid the overhead associated with returning of the previous value. * If write-through is enabled, the value will be removed from store. - * This method is transactional and will enlist the entry into ongoing transaction if there is one. * * @param key Key whose mapping is to be removed from cache. * @return False if there was no matching key. @@ -133,9 +173,16 @@ namespace ignite bool Remove(const WritableKey& key); /** + * Removes given key mappings from cache. + * If write-through is enabled, the value will be removed from store. + * + * @param keys Keys whose mappings are to be removed from cache. + */ + void RemoveAll(const Writable& keys); + + /** * Removes all mappings from cache. * If write-through is enabled, the value will be removed from store. - * This method is transactional and will enlist the entry into ongoing transaction if there is one. */ void RemoveAll(); @@ -153,6 +200,14 @@ namespace ignite void Clear(); /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param keys Keys to clear. + */ + void ClearAll(const Writable& keys); + + /** * Get from CacheClient. * Use for testing purposes only. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/readable.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/include/ignite/impl/thin/readable.h b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/readable.h index 458da25..87f4cc3 100644 --- a/modules/platforms/cpp/thin-client/include/ignite/impl/thin/readable.h +++ b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/readable.h @@ -18,7 +18,7 @@ #ifndef _IGNITE_IMPL_THIN_READABLE #define _IGNITE_IMPL_THIN_READABLE -#include <ignite/impl/binary/binary_reader_impl.h> +#include <ignite/binary/binary_raw_reader.h> namespace ignite { @@ -91,6 +91,74 @@ namespace ignite /** Data router. */ ValueType& value; }; + + /** + * Implementation of Readable interface for map. + * + * @tparam T1 Type of the first element in the pair. + * @tparam T2 Type of the second element in the pair. + * @tparam I Out iterator. + */ + template<typename T1, typename T2, typename I> + class ReadableMapImpl : public Readable + { + public: + /** Type of the first element in the pair. */ + typedef T1 ElementType1; + + /** Type of the second element in the pair. */ + typedef T2 ElementType2; + + /** Type of the iterator. */ + typedef I IteratorType; + + /** + * Constructor. + * + * @param iter Iterator. + */ + ReadableMapImpl(IteratorType iter) : + iter(iter) + { + // No-op. + } + + /** + * Destructor. + */ + virtual ~ReadableMapImpl() + { + // No-op. + } + + /** + * Read value using reader. + * + * @param reader Reader to use. + */ + virtual void Read(binary::BinaryReaderImpl& reader) + { + using namespace ignite::binary; + + int32_t cnt = reader.ReadInt32(); + + for (int32_t i = 0; i < cnt; ++i) + { + std::pair<ElementType1, ElementType2> pair; + + reader.ReadTopObject<ElementType1>(pair.first); + reader.ReadTopObject<ElementType2>(pair.second); + + iter = pair; + + ++iter; + } + } + + private: + /** Iterator type. */ + IteratorType iter; + }; } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/writable.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/include/ignite/impl/thin/writable.h b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/writable.h index 5d5eefe..d97fc19 100644 --- a/modules/platforms/cpp/thin-client/include/ignite/impl/thin/writable.h +++ b/modules/platforms/cpp/thin-client/include/ignite/impl/thin/writable.h @@ -18,7 +18,7 @@ #ifndef _IGNITE_IMPL_THIN_WRITABLE #define _IGNITE_IMPL_THIN_WRITABLE -#include <ignite/impl/binary/binary_writer_impl.h> +#include <ignite/binary/binary_raw_writer.h> namespace ignite { @@ -50,6 +50,8 @@ namespace ignite /** * Implementation of the Writable class for a concrete type. + * + * @tparam T Value type. */ template<typename T> class WritableImpl : public Writable @@ -91,6 +93,157 @@ namespace ignite /** Value. */ const ValueType& value; }; + + /** + * Implementation of the Writable class for a set of values. + * + * @tparam T Value type. + * @tparam I Iterator type. + */ + template<typename T, typename I> + class WritableSetImpl : public Writable + { + public: + /** Element type. */ + typedef T ElementType; + + /** Iterator type. */ + typedef I IteratorType; + + /** + * Constructor. + * + * @param begin Begin of the sequence. + * @param end Sequence end. + */ + WritableSetImpl(IteratorType begin, IteratorType end) : + begin(begin), + end(end) + { + // No-op. + } + + /** + * Destructor. + */ + virtual ~WritableSetImpl() + { + // No-op. + } + + /** + * Write sequence using writer. + * + * @param writer Writer to use. + */ + virtual void Write(binary::BinaryWriterImpl& writer) const + { + using namespace ignite::binary; + + interop::InteropOutputStream* out = writer.GetStream(); + + int32_t cntPos = out->Reserve(4); + + out->Synchronize(); + + int32_t cnt = 0; + for (IteratorType it = begin; it != end; ++it) + { + writer.WriteObject(*it); + + ++cnt; + } + + out->WriteInt32(cntPos, cnt); + + out->Synchronize(); + } + + private: + /** Sequence begin. */ + IteratorType begin; + + /** Sequence end. */ + IteratorType end; + }; + + /** + * Implementation of the Writable class for a map. + * + * @tparam K Key type. + * @tparam V Value type. + * @tparam I Iterator type. + */ + template<typename K, typename V, typename I> + class WritableMapImpl : public Writable + { + public: + /** Key type. */ + typedef K KeyType; + + /** Value type. */ + typedef V ValueType; + + /** Iterator type. */ + typedef I IteratorType; + + /** + * Constructor. + * + * @param begin Begin of the sequence. + * @param end Sequence end. + */ + WritableMapImpl(IteratorType begin, IteratorType end) : + begin(begin), + end(end) + { + // No-op. + } + + /** + * Destructor. + */ + virtual ~WritableMapImpl() + { + // No-op. + } + + /** + * Write sequence using writer. + * + * @param writer Writer to use. + */ + virtual void Write(binary::BinaryWriterImpl& writer) const + { + using namespace ignite::binary; + + interop::InteropOutputStream* out = writer.GetStream(); + + int32_t cntPos = out->Reserve(4); + + out->Synchronize(); + + int32_t cnt = 0; + for (IteratorType it = begin; it != end; ++it) + { + writer.WriteObject(it->first); + writer.WriteObject(it->second); + + ++cnt; + } + + out->WriteInt32(cntPos, cnt); + + out->Synchronize(); + } + + private: + /** Sequence begin. */ + IteratorType begin; + + /** Sequence end. */ + IteratorType end; + }; } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/include/ignite/thin/cache/cache_client.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/include/ignite/thin/cache/cache_client.h b/modules/platforms/cpp/thin-client/include/ignite/thin/cache/cache_client.h index 39e1269..1fcf4f5 100644 --- a/modules/platforms/cpp/thin-client/include/ignite/thin/cache/cache_client.h +++ b/modules/platforms/cpp/thin-client/include/ignite/thin/cache/cache_client.h @@ -106,6 +106,33 @@ namespace ignite } /** + * Stores given key-value pairs in cache. + * If write-through is enabled, the stored values will be persisted to store. + * + * @param begin Iterator pointing to the beginning of the key-value pair sequence. + * @param end Iterator pointing to the end of the key-value pair sequence. + */ + template<typename InIter> + void PutAll(InIter begin, InIter end) + { + impl::thin::WritableMapImpl<K, V, InIter> wrSeq(begin, end); + + proxy.PutAll(wrSeq); + } + + /** + * Stores given key-value pairs in cache. + * If write-through is enabled, the stored values will be persisted to store. + * + * @param vals Key-value pairs to store in cache. + */ + template<typename Map> + void PutAll(const Map& vals) + { + PutAll(vals.begin(), vals.end()); + } + + /** * Get value from the cache. * * @param key Key. @@ -135,6 +162,60 @@ namespace ignite } /** + * Retrieves values mapped to the specified keys from cache. + * If some value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * + * @param begin Iterator pointing to the beginning of the key sequence. + * @param end Iterator pointing to the end of the key sequence. + * @param dst Output iterator. Should dereference to std::pair or CacheEntry. + */ + template<typename InIter, typename OutIter> + void GetAll(InIter begin, InIter end, OutIter dst) + { + impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end); + impl::thin::ReadableMapImpl<K, V, OutIter> rdSeq(dst); + + proxy.GetAll(wrSeq, rdSeq); + } + + /** + * Retrieves values mapped to the specified keys from cache. + * If some value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * + * @param keys Keys. + * @param res Map of key-value pairs. + */ + template<typename Set, typename Map> + void GetAll(const Set& keys, Map& res) + { + return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end())); + } + + /** + * Stores given key-value pair in cache only if there is a previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, rom the underlying persistent storage. + * If write-through is enabled, the stored value will be persisted to store. + * + * @param key Key to store in cache. + * @param value Value to be associated with the given key. + * @return True if the value was replaced. + */ + bool Replace(const K& key, const V& value) + { + impl::thin::WritableKeyImpl<KeyType> wrKey(key); + impl::thin::WritableImpl<ValueType> wrValue(value); + + return proxy.Replace(wrKey, wrValue); + } + + /** * Check if the cache contains a value for the specified key. * * @param key Key whose presence in this cache is to be tested. @@ -148,6 +229,33 @@ namespace ignite } /** + * Check if cache contains mapping for these keys. + * + * @param keys Keys. + * @return True if cache contains mapping for all these keys. + */ + template<typename Set> + bool ContainsKeys(const Set& keys) + { + return ContainsKeys(keys.begin(), keys.end()); + } + + /** + * Check if cache contains mapping for these keys. + * + * @param begin Iterator pointing to the beginning of the key sequence. + * @param end Iterator pointing to the end of the key sequence. + * @return True if cache contains mapping for all these keys. + */ + template<typename InIter> + bool ContainsKeys(InIter begin, InIter end) + { + impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end); + + return proxy.ContainsKeys(wrSeq); + } + + /** * Gets the number of all entries cached across all nodes. * @note This operation is distributed and will query all participating nodes for their cache sizes. * @@ -169,7 +277,6 @@ namespace ignite * If the returned value is not needed, method removex() should always be used instead of this * one to avoid the overhead associated with returning of the previous value. * If write-through is enabled, the value will be removed from store. - * This method is transactional and will enlist the entry into ongoing transaction if there is one. * * @param key Key whose mapping is to be removed from cache. * @return False if there was no matching key. @@ -182,6 +289,33 @@ namespace ignite } /** + * Removes given key mappings from cache. + * If write-through is enabled, the value will be removed from store. + * + * @param keys Keys whose mappings are to be removed from cache. + */ + template<typename Set> + void RemoveAll(const Set& keys) + { + RemoveAll(keys.begin(), keys.end()); + } + + /** + * Removes given key mappings from cache. + * If write-through is enabled, the value will be removed from store. + * + * @param begin Iterator pointing to the beginning of the key sequence. + * @param end Iterator pointing to the end of the key sequence. + */ + template<typename InIter> + void RemoveAll(InIter begin, InIter end) + { + impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end); + + proxy.RemoveAll(wrSeq); + } + + /** * Removes all mappings from cache. * If write-through is enabled, the value will be removed from store. * This method is transactional and will enlist the entry into ongoing transaction if there is one. @@ -213,6 +347,33 @@ namespace ignite } /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param keys Keys to clear. + */ + template<typename Set> + void ClearAll(const Set& keys) + { + ClearAll(keys.begin(), keys.end()); + } + + /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param begin Iterator pointing to the beginning of the key sequence. + * @param end Iterator pointing to the end of the key sequence. + */ + template<typename InIter> + void ClearAll(InIter begin, InIter end) + { + impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end); + + proxy.ClearAll(wrSeq); + } + + /** * Refresh affinity mapping. * * Retrieves affinity mapping information from remote server. This information uses to send data http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.cpp b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.cpp index fe37a9c..78d0e13 100644 --- a/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.cpp +++ b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.cpp @@ -61,39 +61,78 @@ namespace ignite router.Get()->SyncMessage(req, rsp, endPoints); } + + if (rsp.GetStatus() != ResponseStatus::SUCCESS) + throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + } + + template<typename ReqT, typename RspT> + void CacheClientImpl::SyncMessage(const ReqT& req, RspT& rsp) + { + router.Get()->SyncMessage(req, rsp); + + if (rsp.GetStatus() != ResponseStatus::SUCCESS) + throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); } void CacheClientImpl::Put(const WritableKey& key, const Writable& value) { - CachePutRequest req(id, binary, key, value); + CacheKeyValueRequest<RequestType::CACHE_PUT> req(id, binary, key, value); Response rsp; SyncCacheKeyMessage(key, req, rsp); - - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); } void CacheClientImpl::Get(const WritableKey& key, Readable& value) { - CacheKeyRequest<RequestType::CACHE_GET> req(id, binary, key); - CacheGetResponse rsp(value); + CacheValueRequest<RequestType::CACHE_GET> req(id, binary, key); + CacheValueResponse rsp(value); SyncCacheKeyMessage(key, req, rsp); + } - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + void CacheClientImpl::PutAll(const Writable & pairs) + { + CacheValueRequest<RequestType::CACHE_PUT_ALL> req(id, binary, pairs); + Response rsp; + + SyncMessage(req, rsp); + } + + void CacheClientImpl::GetAll(const Writable& keys, Readable& pairs) + { + CacheValueRequest<RequestType::CACHE_GET_ALL> req(id, binary, keys); + CacheValueResponse rsp(pairs); + + SyncMessage(req, rsp); + } + + bool CacheClientImpl::Replace(const WritableKey& key, const Writable& value) + { + CacheKeyValueRequest<RequestType::CACHE_REPLACE> req(id, binary, key, value); + BoolResponse rsp; + + SyncCacheKeyMessage(key, req, rsp); + + return rsp.GetValue(); } bool CacheClientImpl::ContainsKey(const WritableKey& key) { - CacheKeyRequest<RequestType::CACHE_CONTAINS_KEY> req(id, binary, key); + CacheValueRequest<RequestType::CACHE_CONTAINS_KEY> req(id, binary, key); BoolResponse rsp; SyncCacheKeyMessage(key, req, rsp); - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + return rsp.GetValue(); + } + + bool CacheClientImpl::ContainsKeys(const Writable& keys) + { + CacheValueRequest<RequestType::CACHE_CONTAINS_KEYS> req(id, binary, keys); + BoolResponse rsp; + + SyncMessage(req, rsp); return rsp.GetValue(); } @@ -103,47 +142,43 @@ namespace ignite CacheGetSizeRequest req(id, binary, peekModes); Int64Response rsp; - router.Get()->SyncMessage(req, rsp); - - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + SyncMessage(req, rsp); return rsp.GetValue(); } bool CacheClientImpl::Remove(const WritableKey& key) { - CacheKeyRequest<RequestType::CACHE_REMOVE_KEY> req(id, binary, key); + CacheValueRequest<RequestType::CACHE_REMOVE_KEY> req(id, binary, key); BoolResponse rsp; - router.Get()->SyncMessage(req, rsp); - - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + SyncMessage(req, rsp); return rsp.GetValue(); } + void CacheClientImpl::RemoveAll(const Writable& keys) + { + CacheValueRequest<RequestType::CACHE_REMOVE_KEYS> req(id, binary, keys); + Response rsp; + + SyncMessage(req, rsp); + } + void CacheClientImpl::RemoveAll() { CacheRequest<RequestType::CACHE_REMOVE_ALL> req(id, binary); Response rsp; - router.Get()->SyncMessage(req, rsp); - - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + SyncMessage(req, rsp); } void CacheClientImpl::Clear(const WritableKey& key) { - CacheKeyRequest<RequestType::CACHE_CLEAR_KEY> req(id, binary, key); + CacheValueRequest<RequestType::CACHE_CLEAR_KEY> req(id, binary, key); Response rsp; - router.Get()->SyncMessage(req, rsp); - - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + SyncMessage(req, rsp); } void CacheClientImpl::Clear() @@ -151,21 +186,23 @@ namespace ignite CacheRequest<RequestType::CACHE_CLEAR> req(id, binary); Response rsp; - router.Get()->SyncMessage(req, rsp); + SyncMessage(req, rsp); + } - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); + void CacheClientImpl::ClearAll(const Writable& keys) + { + CacheValueRequest<RequestType::CACHE_CLEAR_KEYS> req(id, binary, keys); + Response rsp; + + SyncMessage(req, rsp); } void CacheClientImpl::LocalPeek(const WritableKey& key, Readable& value) { - CacheKeyRequest<RequestType::CACHE_LOCAL_PEEK> req(id, binary, key); - CacheGetResponse rsp(value); + CacheValueRequest<RequestType::CACHE_LOCAL_PEEK> req(id, binary, key); + CacheValueResponse rsp(value); SyncCacheKeyMessage(key, req, rsp); - - if (rsp.GetStatus() != ResponseStatus::SUCCESS) - throw IgniteError(IgniteError::IGNITE_ERR_CACHE, rsp.GetError().c_str()); } void CacheClientImpl::RefreshAffinityMapping() http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.h b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.h index a28c4dd..f9555a2 100644 --- a/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.h +++ b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_impl.h @@ -75,6 +75,14 @@ namespace ignite void Put(const WritableKey& key, const Writable& value); /** + * Stores given key-value pairs in cache. + * If write-through is enabled, the stored values will be persisted to store. + * + * @param pairs Writable key-value pair sequence. + */ + void PutAll(const Writable& pairs); + + /** * Get value from cache. * * @param key Key. @@ -83,6 +91,31 @@ namespace ignite void Get(const WritableKey& key, Readable& value); /** + * Retrieves values mapped to the specified keys from cache. + * If some value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * + * @param keys Writable key sequence. + * @param pairs Readable key-value pair sequence. + */ + void GetAll(const Writable& keys, Readable& pairs); + + /** + * Stores given key-value pair in cache only if there is a previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, rom the underlying persistent storage. + * If write-through is enabled, the stored value will be persisted to store. + * + * @param key Key to store in cache. + * @param value Value to be associated with the given key. + * @return True if the value was replaced. + */ + bool Replace(const WritableKey& key, const Writable& value); + + /** * Check if the cache contains a value for the specified key. * * @param key Key whose presence in this cache is to be tested. @@ -91,6 +124,14 @@ namespace ignite bool ContainsKey(const WritableKey& key); /** + * Check if cache contains mapping for these keys. + * + * @param keys Keys. + * @return True if cache contains mapping for all these keys. + */ + bool ContainsKeys(const Writable& keys); + + /** * Gets the number of all entries cached across all nodes. * @note This operation is distributed and will query all * participating nodes for their cache sizes. @@ -108,7 +149,6 @@ namespace ignite * If the returned value is not needed, method removex() should always be used instead of this * one to avoid the overhead associated with returning of the previous value. * If write-through is enabled, the value will be removed from store. - * This method is transactional and will enlist the entry into ongoing transaction if there is one. * * @param key Key whose mapping is to be removed from cache. * @return False if there was no matching key. @@ -116,9 +156,16 @@ namespace ignite bool Remove(const WritableKey& key); /** + * Removes given key mappings from cache. + * If write-through is enabled, the value will be removed from store. + * + * @param keys Keys whose mappings are to be removed from cache. + */ + void RemoveAll(const Writable& keys); + + /** * Removes all mappings from cache. * If write-through is enabled, the value will be removed from store. - * This method is transactional and will enlist the entry into ongoing transaction if there is one. */ void RemoveAll(); @@ -136,6 +183,14 @@ namespace ignite void Clear(); /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param keys Keys to clear. + */ + void ClearAll(const Writable& keys); + + /** * Peeks at in-memory cached value using default optional * peek mode. This method will not load value from any * persistent store or from a remote node. @@ -164,6 +219,16 @@ namespace ignite template<typename ReqT, typename RspT> void SyncCacheKeyMessage(const WritableKey& key, const ReqT& req, RspT& rsp); + /** + * Synchronously send message and receive response. + * + * @param req Request message. + * @param rsp Response message. + * @throw IgniteError on error. + */ + template<typename ReqT, typename RspT> + void SyncMessage(const ReqT& req, RspT& rsp); + /** Data router. */ SP_DataRouter router; http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_proxy.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_proxy.cpp b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_proxy.cpp index 1fc8ac9..3d37255 100644 --- a/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_proxy.cpp +++ b/modules/platforms/cpp/thin-client/src/impl/cache/cache_client_proxy.cpp @@ -17,7 +17,8 @@ #include <ignite/impl/thin/cache/cache_client_proxy.h> -#include "impl/cache/cache_client_impl.h" +#include <ignite/impl/thin/cache/cache_client_proxy.h> +#include <impl/cache/cache_client_impl.h> using namespace ignite::impl::thin; using namespace cache; @@ -55,11 +56,31 @@ namespace ignite GetCacheImpl(impl).Get(key, value); } + void CacheClientProxy::PutAll(const Writable& pairs) + { + GetCacheImpl(impl).PutAll(pairs); + } + + void CacheClientProxy::GetAll(const Writable & keys, Readable & pairs) + { + GetCacheImpl(impl).GetAll(keys, pairs); + } + + bool CacheClientProxy::Replace(const WritableKey& key, const Writable& value) + { + return GetCacheImpl(impl).Replace(key, value); + } + bool CacheClientProxy::ContainsKey(const WritableKey & key) { return GetCacheImpl(impl).ContainsKey(key); } + bool CacheClientProxy::ContainsKeys(const Writable & keys) + { + return GetCacheImpl(impl).ContainsKeys(keys); + } + int64_t CacheClientProxy::GetSize(int32_t peekModes) { return GetCacheImpl(impl).GetSize(peekModes); @@ -80,6 +101,11 @@ namespace ignite return GetCacheImpl(impl).Remove(key); } + void CacheClientProxy::RemoveAll(const Writable & keys) + { + return GetCacheImpl(impl).RemoveAll(keys); + } + void CacheClientProxy::RemoveAll() { GetCacheImpl(impl).RemoveAll(); @@ -94,6 +120,11 @@ namespace ignite { GetCacheImpl(impl).Clear(); } + + void CacheClientProxy::ClearAll(const Writable& keys) + { + GetCacheImpl(impl).ClearAll(keys); + } } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/src/impl/message.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/src/impl/message.cpp b/modules/platforms/cpp/thin-client/src/impl/message.cpp index 7a99136..5cf8fb8 100644 --- a/modules/platforms/cpp/thin-client/src/impl/message.cpp +++ b/modules/platforms/cpp/thin-client/src/impl/message.cpp @@ -73,20 +73,6 @@ namespace ignite reader.ReadString(error); } - CachePutRequest::CachePutRequest(int32_t cacheId, bool binary, const Writable& key, const Writable& value) : - CacheKeyRequest<RequestType::CACHE_PUT>(cacheId, binary, key), - value(value) - { - // No-op. - } - - void CachePutRequest::Write(binary::BinaryWriterImpl& writer, const ProtocolVersion& ver) const - { - CacheKeyRequest<RequestType::CACHE_PUT>::Write(writer, ver); - - value.Write(writer); - } - ClientCacheNodePartitionsResponse::ClientCacheNodePartitionsResponse( std::vector<ConnectableNodePartitions>& nodeParts): nodeParts(nodeParts) @@ -111,18 +97,18 @@ namespace ignite nodeParts[i].Read(reader); } - CacheGetResponse::CacheGetResponse(Readable& value) : + CacheValueResponse::CacheValueResponse(Readable& value) : value(value) { // No-op. } - CacheGetResponse::~CacheGetResponse() + CacheValueResponse::~CacheValueResponse() { // No-op. } - void CacheGetResponse::ReadOnSuccess(binary::BinaryReaderImpl& reader, const ProtocolVersion&) + void CacheValueResponse::ReadOnSuccess(binary::BinaryReaderImpl& reader, const ProtocolVersion&) { value.Read(reader); } http://git-wip-us.apache.org/repos/asf/ignite/blob/a3c2ea3b/modules/platforms/cpp/thin-client/src/impl/message.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/thin-client/src/impl/message.h b/modules/platforms/cpp/thin-client/src/impl/message.h index 2f839c0..2d0df6f 100644 --- a/modules/platforms/cpp/thin-client/src/impl/message.h +++ b/modules/platforms/cpp/thin-client/src/impl/message.h @@ -375,12 +375,12 @@ namespace ignite }; /** - * Cache key request. + * Cache value request. * - * Request to cache containing single key. + * Request to cache containing writable value. */ template<int32_t OpCode> - class CacheKeyRequest : public CacheRequest<OpCode> + class CacheValueRequest : public CacheRequest<OpCode> { public: /** @@ -388,11 +388,11 @@ namespace ignite * * @param cacheId Cache ID. * @param binary Binary cache flag. - * @param key Key. + * @param value Value. */ - CacheKeyRequest(int32_t cacheId, bool binary, const Writable& key) : + CacheValueRequest(int32_t cacheId, bool binary, const Writable& value) : CacheRequest<OpCode>(cacheId, binary), - key(key) + value(value) { // No-op. } @@ -400,7 +400,7 @@ namespace ignite /** * Destructor. */ - virtual ~CacheKeyRequest() + virtual ~CacheValueRequest() { // No-op. } @@ -414,18 +414,19 @@ namespace ignite { CacheRequest<OpCode>::Write(writer, ver); - key.Write(writer); + value.Write(writer); } private: /** Key. */ - const Writable& key; + const Writable& value; }; /** - * Cache put request. + * Cache key value request. */ - class CachePutRequest : public CacheKeyRequest<RequestType::CACHE_PUT> + template<int32_t OpCode> + class CacheKeyValueRequest : public CacheValueRequest<OpCode> { public: /** @@ -436,12 +437,17 @@ namespace ignite * @param key Key. * @param value Value. */ - CachePutRequest(int32_t cacheId, bool binary, const Writable& key, const Writable& value); + CacheKeyValueRequest(int32_t cacheId, bool binary, const Writable& key, const Writable& value) : + CacheValueRequest<OpCode>(cacheId, binary, key), + value(value) + { + // No-op. + } /** * Destructor. */ - virtual ~CachePutRequest() + virtual ~CacheKeyValueRequest() { // No-op. } @@ -451,7 +457,12 @@ namespace ignite * @param writer Writer. * @param ver Version. */ - virtual void Write(binary::BinaryWriterImpl& writer, const ProtocolVersion& ver) const; + virtual void Write(binary::BinaryWriterImpl& writer, const ProtocolVersion& ver) const + { + CacheValueRequest<OpCode>::Write(writer, ver); + + value.Write(writer); + } private: /** Value. */ @@ -621,9 +632,9 @@ namespace ignite }; /** - * Cache get response. + * Cache value response. */ - class CacheGetResponse : public Response + class CacheValueResponse : public Response { public: /** @@ -631,12 +642,12 @@ namespace ignite * * @param value Value. */ - CacheGetResponse(Readable& value); + CacheValueResponse(Readable& value); /** * Destructor. */ - virtual ~CacheGetResponse(); + virtual ~CacheValueResponse(); /** * Read data if response status is ResponseStatus::SUCCESS.
