1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CONTRIB_IGNITE_KERNELS_DATASET_IGNITE_DATASET_ITERATOR_H_ 17 #define TENSORFLOW_CONTRIB_IGNITE_KERNELS_DATASET_IGNITE_DATASET_ITERATOR_H_ 18 19 #include "tensorflow/contrib/ignite/kernels/client/ignite_client.h" 20 #include "tensorflow/contrib/ignite/kernels/dataset/ignite_binary_object_parser.h" 21 #include "tensorflow/contrib/ignite/kernels/dataset/ignite_dataset.h" 22 #include "tensorflow/core/platform/mutex.h" 23 24 namespace tensorflow { 25 26 class IgniteDatasetIterator : public DatasetIterator<IgniteDataset> { 27 public: 28 IgniteDatasetIterator(const Params& params, string host, int32 port, 29 string cache_name, bool local, int32 part, 30 int32 page_size, string username, string password, 31 string certfile, string keyfile, string cert_password, 32 std::vector<int32> schema, 33 std::vector<int32> permutation); 34 ~IgniteDatasetIterator(); 35 Status GetNextInternal(IteratorContext* ctx, std::vector<Tensor>* out_tensors, 36 bool* end_of_sequence) override; 37 38 protected: 39 Status SaveInternal(IteratorStateWriter* writer) override; 40 Status RestoreInternal(IteratorContext* ctx, 41 IteratorStateReader* reader) override; 42 43 private: 44 Status GetNextInternalWithValidState(IteratorContext* ctx, 45 std::vector<Tensor>* out_tensors, 46 bool* end_of_sequence); 47 48 Status EstablishConnection(); 49 Status CloseConnection(); 50 Status Handshake(); 51 Status ScanQuery(); 52 Status LoadNextPage(); 53 Status ReceivePage(int32_t page_size); 54 Status CheckTypes(const std::vector<int32_t>& types); 55 int32_t JavaHashCode(string str) const; 56 57 std::unique_ptr<Client> client_; 58 BinaryObjectParser parser_; 59 60 const string cache_name_; 61 const bool local_; 62 const int32 part_; 63 const int32 page_size_; 64 const string username_; 65 const string password_; 66 const std::vector<int32> schema_; 67 const std::vector<int32> permutation_; 68 69 int32_t remainder_; 70 int64_t cursor_id_; 71 bool last_page_; 72 73 bool valid_state_; 74 75 mutex mutex_; 76 77 std::unique_ptr<uint8_t> page_; 78 uint8_t* ptr_; 79 }; 80 81 constexpr uint8_t kNullVal = 101; 82 constexpr uint8_t kStringVal = 9; 83 constexpr uint8_t kProtocolMajorVersion = 1; 84 constexpr uint8_t kProtocolMinorVersion = 1; 85 constexpr uint8_t kProtocolPatchVersion = 0; 86 constexpr int16_t kScanQueryOpcode = 2000; 87 constexpr int16_t kLoadNextPageOpcode = 2001; 88 constexpr int16_t kCloseConnectionOpcode = 0; 89 constexpr int32_t kScanQueryReqLength = 25; 90 constexpr int32_t kScanQueryResHeaderLength = 25; 91 constexpr int32_t kLoadNextPageReqLength = 18; 92 constexpr int32_t kLoadNextPageResHeaderLength = 17; 93 constexpr int32_t kCloseConnectionReqLength = 18; 94 constexpr int32_t kHandshakeReqDefaultLength = 8; 95 constexpr int32_t kMinResLength = 12; 96 97 } // namespace tensorflow 98 99 #endif // TENSORFLOW_CONTRIB_IGNITE_KERNELS_DATASET_IGNITE_DATASET_ITERATOR_H_ 100