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 /
18rasdaman 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
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
44class r_Ref_Any;
45template <typename T>
46class r_Ref;
47class r_GMarray;
48
49// rpcif.h
50struct RPCMarray;
51struct GetMDDRes;
52struct GetTileRes;
53struct GetElementRes;
54
56{
57public:
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);
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
104private:
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
The class ClientComm represents one connection between one client entity (for example an object of cl...
Definition clientcomm.hh:51
r_Database * database
reference to the database that created this client communicator
Definition clientcomm.hh:202
r_Type_Type
Definition clientcomm.hh:153
Definition rasnetclientcomm.hh:56
int openTA(unsigned short readOnly) override
Transaction methods.
void deleteCollByName(const char *collName) override
deletes an MDD collection by name
int closeDB() override
close current database
int connectClient(const std::string &userName, const std::string &passwordHash)
r_Ref_Any getMDDByOId(const r_OId &oid) override
gets MDD object by oid
unsigned short getObjectType(const r_OId &oid) override
get oid type
int openDB(const char *database) override
Database methods.
RasnetClientComm(const std::string &rasmgrHost, int rasmgrPort=DEFAULT_PORT)
int setTransferFormat(r_Data_Format format, const char *formatParams=nullptr) override
Configuration methods.
void insertColl(const char *collName, const char *typeName, const r_OId &oid) override
Collection methods.
~RasnetClientComm() noexcept override
unsigned int getMaxRetry() override
get maximum retry to get a server
r_Ref_Any getCollByName(const char *name) override
gets collection by name
void setTimeoutInterval(int seconds) override
set communication timeout interval in seconds.
r_OId getNewOId(unsigned short objType) override
System methods.
void setMaxRetry(unsigned int newMaxRetry) override
set maximum retry to get a server
void removeObjFromColl(const char *name, const r_OId &oid) override
removes an object from a collection
int commitTA() override
commit current transaction
int getTimeoutInterval() override
get communication timeout interval in seconds.
r_Ref_Any getCollOIdsByOId(const r_OId &oid) override
gets collection references by oid
r_Ref_Any getCollOIdsByName(const char *name) override
gets collection references by name
void executeQuery(const r_OQL_Query &query, r_Set< r_Ref_Any > &result) override
Query methods.
char * getTypeStructure(const char *typeName, r_Type_Type typeType) override
get type structure deallocate using delete []
int destroyDB(const char *name) override
destroy a database
r_Ref_Any getCollByOId(const r_OId &oid) override
gets collection by oid
int setStorageFormat(r_Data_Format format, const char *formatParams=nullptr) override
set the preferred storage format
int abortTA() override
abort current transaction
void insertMDD(const char *collName, r_GMarray *mar) override
MDD methods.
void deleteObjByOId(const r_OId &oid) override
deletes an object by oid (right now, objects are collection only)
void setUserIdentification(const char *userName, const char *plainTextPassword) override
user identification for RasMGR
int createDB(const char *name) override
create a database
This class is the superclass of the types r_Structure_Type and r_Primitive_Type in the representation...
Definition basetype.hh:40
The class represents a generic MDD in the sense that it is independent of the cell base type.
Definition gmarray.hh:66
Class r_OId represents an object identifier.
Definition oid.hh:39
The global function r_oql_execute() is used to invoke RasML queries.
Definition oqlquery.hh:71
Class for parsing a string consisting of key=value pairs separated by ",".
Definition parseparams.hh:40
The class r_Ref_Any is defined to support a reference to any type.
Definition ref.hh:65
References of type r_Ref in many respects behave like C++ pointers but provide an additional mechanis...
Definition ref.hh:198
The class implements a set container.
Definition set.hh:42
r_Data_Format
\begin{tabular}{ll} <tt>r_Array</tt> && no compression, row-major memory representation\...
Definition mddtypes.hh:94
@ r_Array
Definition mddtypes.hh:95