rasdaman client API  10.6.3
The Array Analytics Engine: Datacubes at Your Fingertips
rasnetclientcomm.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 */
23 
24 #ifndef RASNETCLIENTCOMM_HH
25 #define RASNETCLIENTCOMM_HH
26 
27 #include "clientcomm/clientcomm.hh"
28 #include "globals.hh"
29 #include "raslib/parseparams.hh"
30 #include "common/thread/threadutil.hh"
31 
32 #include "common/macros/compilerdefs.hh"
33 #include "rasnet/messages/rasmgr_client_service.grpc.pb.h"
34 #include "rasnet/messages/client_rassrvr_service.grpc.pb.h"
35 #include "common/grpc/messages/health_service.grpc.pb.h"
36 
37 #include <memory>
38 #include <mutex>
39 #include <thread>
40 
41 #include <google/protobuf/service.h>
42 #include <google/protobuf/stubs/common.h>
43 
44 class r_Ref_Any;
45 template <typename T>
46 class r_Ref;
47 class r_GMarray;
48 
49 // rpcif.h
50 struct RPCMarray;
51 struct GetMDDRes;
52 struct GetTileRes;
53 struct GetElementRes;
54 
56 {
57 public:
58  explicit RasnetClientComm(const std::string &rasmgrHost, int rasmgrPort = DEFAULT_PORT);
59  DISABLE_COPY_AND_MOVE(RasnetClientComm)
60  ~RasnetClientComm() noexcept override;
61 
62  int connectClient(const std::string &userName, const std::string &passwordHash);
63  int disconnectClient();
64 
65  int openDB(const char *database) override;
66  int closeDB() override;
67  int createDB(const char *name) override;
68  int destroyDB(const char *name) override;
69 
70  int openTA(unsigned short readOnly) override;
71  int commitTA() override;
72  int abortTA() override;
73 
74  void insertMDD(const char *collName, r_GMarray *mar) override;
75  r_Ref_Any getMDDByOId(const r_OId &oid) override;
76 
77  void insertColl(const char *collName, const char *typeName, const r_OId &oid) override;
78  void deleteCollByName(const char *collName) override;
79  void deleteObjByOId(const r_OId &oid) override;
80  void removeObjFromColl(const char *name, const r_OId &oid) override;
81  r_Ref_Any getCollByName(const char *name) override;
82  r_Ref_Any getCollByOId(const r_OId &oid) override;
83  r_Ref_Any getCollOIdsByName(const char *name) override;
84  r_Ref_Any getCollOIdsByOId(const r_OId &oid) override;
85 
86  void executeQuery(const r_OQL_Query &query, r_Set<r_Ref_Any> &result) override;
87  void executeQuery(const r_OQL_Query &query) override;
88  void executeQuery(const r_OQL_Query &query, r_Set<r_Ref_Any> &result, int dummy) override;
89 
90  r_OId getNewOId(unsigned short objType) override;
91  unsigned short getObjectType(const r_OId &oid) override;
92 
93  char *getTypeStructure(const char *typeName, r_Type_Type typeType) override;
94 
95  int setTransferFormat(r_Data_Format format, const char *formatParams = nullptr) override;
96  int setStorageFormat(r_Data_Format format, const char *formatParams = nullptr) override;
97 
98  void setUserIdentification(const char *userName, const char *plainTextPassword) override;
99  void setMaxRetry(unsigned int newMaxRetry) override;
100  unsigned int getMaxRetry() override;
101  void setTimeoutInterval(int seconds) override;
102  int getTimeoutInterval() override;
103 
104 private:
105  // -------------------------------------------------------------------------
106  // various identifiers
108  std::uint32_t clientId{};
113  std::uint32_t remoteClientId{};
114  std::uint32_t sessionId{};
115 
116  // -------------------------------------------------------------------------
117  // authentication
118  char capability[100];
119 
120  // -------------------------------------------------------------------------
121  // connection details
123  std::string rasmgrHostname;
125  std::string rasmgrHost;
127  std::string rasServerHost;
129  int rasServerPort{};
131  r_Data_Format transferFormat{r_Array};
133  r_Data_Format storageFormat{r_Array};
135  char *transferFormatParams{nullptr};
137  char *storageFormatParams{nullptr};
140  size_t timeoutMs{};
142  r_Parse_Params clientParams{};
143 
144  // -------------------------------------------------------------------------
145  // rasmgr service
146  std::shared_ptr<rasnet::service::RasmgrClientService::Stub> rasmgrService;
147  bool initializedRasMgrService{false};
148  std::mutex rasMgrServiceMtx;
149  std::shared_ptr<common::HealthService::Stub> rasmgrHealthService;
150  //
151  std::shared_ptr<rasnet::service::RasmgrClientService::Stub> getRasMgrService(bool throwIfConnectionFailed = true);
152  void initRasmgrService();
153  void closeRasmgrService();
154 
155  // -------------------------------------------------------------------------
156  // rasserver service
157  std::shared_ptr<rasnet::service::ClientRassrvrService::Stub> rasserverService;
158  bool initializedRasServerService{false};
159  std::mutex rasServerServiceMtx;
160  std::shared_ptr<common::HealthService::Stub> rasserverHealthService;
161  //
162  std::shared_ptr<rasnet::service::ClientRassrvrService::Stub> getRasServerService(bool throwIfConnectionFailed = true);
163  void initRasserverService();
164  void closeRasserverService();
165 
166  // -------------------------------------------------------------------------
167  // START: KEEP ALIVE THREADS
168  int64_t keepAliveTimeout{};
169 
170  // rasmgr
171  std::unique_ptr<common::PeriodicTaskExecutor> rasMgrKeepAlive;
172  void startRasMgrKeepAlive();
174  void clientRasMgrKeepAliveRunner();
175 
176  // rasserver
177  std::unique_ptr<common::PeriodicTaskExecutor> rasSrvKeepAlive;
178  void startRasServerKeepAlive();
180  void clientRasServerKeepAliveRunner();
181  // END: KEEP ALIVE
182 
183  // -------------------------------------------------------------------------
184  // error handlers
186  NORETURN static void handleError(const std::string &error) noexcept(false);
188  static void handleStatusCode(int status, const std::string &method) noexcept(false);
189 
190  // -------------------------------------------------------------------------
191  // utility methods
192  int executeStartInsertPersMDD(const char *collName, r_GMarray *mar);
193  int executeInsertTile(bool persistent, RPCMarray *tile);
194  void executeEndInsertMDD(bool persistent);
195  int executeEndTransfer();
196  r_Ref_Any executeGetCollByNameOrOId(const char *collName, const r_OId &oid);
197  r_Ref_Any executeGetCollOIdsByNameOrOId(const char *collName, const r_OId &oid);
198  int executeStartInsertTransMDD(r_GMarray *mdd);
199  int executeInitUpdate();
200  GetMDDRes *executeGetNextMDD();
201  GetTileRes *executeGetNextTile();
202  int executeExecuteQuery(const char *query, r_Set<r_Ref_Any> &result);
203  GetElementRes *executeGetNextElement();
204  int executeExecuteUpdateQuery(const char *query);
205  int executeExecuteUpdateQuery(const char *query, r_Set<r_Ref_Any> &result);
206  int executeSetFormat(bool lTransferFormat, r_Data_Format format, const char *formatParams);
207 
208  void getMDDCollection(r_Set<r_Ref_Any> &mddColl, unsigned int isQuery);
209  unsigned short getMDDCore(r_Ref<r_GMarray> &mdd, GetMDDRes *thisResult, unsigned int isQuery);
210  void sendMDDConstants(const r_OQL_Query &query);
211  void getElementCollection(r_Set<r_Ref_Any> &resultColl);
212 
213  int concatArrayData(const char *source, unsigned long srcSize, char *&dest,
214  unsigned long &destSize, unsigned long &destLevel);
215  void freeGetTileRes(GetTileRes *ptr);
216 
217  void freeMarRpcRepresentation(const r_GMarray *mar, RPCMarray *rpcMarray);
218  void getMarRpcRepresentation(
219  const r_GMarray *mar, RPCMarray *&rpcMarray, r_Data_Format initStorageFormat, const r_Base_Type *baseType);
220  void checkForRwTransaction();
221 };
222 
223 #endif // RASNETCLIENTCOMM_HH
RasnetClientComm::setUserIdentification
void setUserIdentification(const char *userName, const char *plainTextPassword) override
user identification for RasMGR
ClientComm
The class ClientComm represents one connection between one client entity (for example an object of cl...
Definition: clientcomm.hh:50
RasnetClientComm
Definition: rasnetclientcomm.hh:55
RasnetClientComm::insertColl
void insertColl(const char *collName, const char *typeName, const r_OId &oid) override
Collection methods.
RasnetClientComm::getCollOIdsByName
r_Ref_Any getCollOIdsByName(const char *name) override
gets collection references by name
RasnetClientComm::~RasnetClientComm
~RasnetClientComm() noexcept override
RasnetClientComm::disconnectClient
int disconnectClient()
RasnetClientComm::getObjectType
unsigned short getObjectType(const r_OId &oid) override
get oid type
RasnetClientComm::destroyDB
int destroyDB(const char *name) override
destroy a database
RasnetClientComm::getCollByOId
r_Ref_Any getCollByOId(const r_OId &oid) override
gets collection by oid
RasnetClientComm::commitTA
int commitTA() override
commit current transaction
RasnetClientComm::getNewOId
r_OId getNewOId(unsigned short objType) override
System methods.
r_Ref_Any
The class r_Ref_Any is defined to support a reference to any type.
Definition: ref.hh:64
RasnetClientComm::setMaxRetry
void setMaxRetry(unsigned int newMaxRetry) override
set maximum retry to get a server
r_Base_Type
This class is the superclass of the types r_Structure_Type and r_Primitive_Type in the representation...
Definition: basetype.hh:39
r_Ref
References of type r_Ref in many respects behave like C++ pointers but provide an additional mechanis...
Definition: collection.hh:196
r_Data_Format
r_Data_Format
\begin{tabular}{ll} <tt>r_Array</tt> && no compression, row-major memory representation\...
Definition: mddtypes.hh:93
RasnetClientComm::getCollByName
r_Ref_Any getCollByName(const char *name) override
gets collection by name
RasnetClientComm::RasnetClientComm
RasnetClientComm(const std::string &rasmgrHost, int rasmgrPort=DEFAULT_PORT)
RasnetClientComm::getTypeStructure
char * getTypeStructure(const char *typeName, r_Type_Type typeType) override
get type structure deallocate using delete []
RasnetClientComm::setTimeoutInterval
void setTimeoutInterval(int seconds) override
set communication timeout interval in seconds.
RasnetClientComm::getCollOIdsByOId
r_Ref_Any getCollOIdsByOId(const r_OId &oid) override
gets collection references by oid
r_Array
@ r_Array
Definition: mddtypes.hh:95
RasnetClientComm::deleteCollByName
void deleteCollByName(const char *collName) override
deletes an MDD collection by name
parseparams.hh
r_Set
The class implements a set container.
Definition: oqlquery.hh:31
RasnetClientComm::getMaxRetry
unsigned int getMaxRetry() override
get maximum retry to get a server
RasnetClientComm::createDB
int createDB(const char *name) override
create a database
ClientComm::r_Type_Type
r_Type_Type
Definition: clientcomm.hh:152
RasnetClientComm::setStorageFormat
int setStorageFormat(r_Data_Format format, const char *formatParams=nullptr) override
set the preferred storage format
RasnetClientComm::setTransferFormat
int setTransferFormat(r_Data_Format format, const char *formatParams=nullptr) override
Configuration methods.
RasnetClientComm::deleteObjByOId
void deleteObjByOId(const r_OId &oid) override
deletes an object by oid (right now, objects are collection only)
RasnetClientComm::openDB
int openDB(const char *database) override
Database methods.
RasnetClientComm::insertMDD
void insertMDD(const char *collName, r_GMarray *mar) override
MDD methods.
RasnetClientComm::abortTA
int abortTA() override
abort current transaction
RasnetClientComm::removeObjFromColl
void removeObjFromColl(const char *name, const r_OId &oid) override
removes an object from a collection
RasnetClientComm::closeDB
int closeDB() override
close current database
r_GMarray
The class represents a generic MDD in the sense that it is independent of the cell base type.
Definition: gmarray.hh:65
RasnetClientComm::getMDDByOId
r_Ref_Any getMDDByOId(const r_OId &oid) override
gets MDD object by oid
RasnetClientComm::openTA
int openTA(unsigned short readOnly) override
Transaction methods.
r_Parse_Params
Class for parsing a string consisting of key=value pairs separated by ",".
Definition: parseparams.hh:39
RasnetClientComm::getTimeoutInterval
int getTimeoutInterval() override
get communication timeout interval in seconds.
RasnetClientComm::executeQuery
void executeQuery(const r_OQL_Query &query, r_Set< r_Ref_Any > &result) override
Query methods.
r_OId
Class r_OId represents an object identifier.
Definition: oid.hh:38
clientcomm.hh
ClientComm::database
r_Database * database
reference to the database that created this client communicator
Definition: clientcomm.hh:202
r_OQL_Query
The global function r_oql_execute() is used to invoke RasML queries.
Definition: oqlquery.hh:70
RasnetClientComm::connectClient
int connectClient(const std::string &userName, const std::string &passwordHash)