rasdaman client API 10.5.1
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
31#include "rasnet/messages/rasmgr_client_service.grpc.pb.h"
32#include "rasnet/messages/client_rassrvr_service.grpc.pb.h"
33#include "common/grpc/messages/health_service.grpc.pb.h"
34
35#include <memory>
36#include <mutex>
37#include <condition_variable>
38#include <thread>
39
40#include <google/protobuf/service.h>
41#include <google/protobuf/stubs/common.h>
42
43class r_Ref_Any;
44template <typename T>
45class r_Ref;
46class r_GMarray;
47
48// rpcif.h
49struct RPCMarray;
50struct GetMDDRes;
51struct GetTileRes;
52struct GetElementRes;
53
55{
56public:
57 explicit RasnetClientComm(const std::string &rasmgrHost, int rasmgrPort = DEFAULT_PORT);
58 virtual ~RasnetClientComm() noexcept;
59
60 int connectClient(const std::string &userName, const std::string &passwordHash);
62
63 int openDB(const char *database) override;
64 int closeDB() override;
65 int createDB(const char *name) override;
66 int destroyDB(const char *name) override;
67
68 int openTA(unsigned short readOnly) override;
69 int commitTA() override;
70 int abortTA() override;
71
72 void insertMDD(const char *collName, r_GMarray *mar) override;
73 r_Ref_Any getMDDByOId(const r_OId &oid) override;
74
75 void insertColl(const char *collName, const char *typeName, const r_OId &oid) override;
76 void deleteCollByName(const char *collName) override;
77 void deleteObjByOId(const r_OId &oid) override;
78 void removeObjFromColl(const char *name, const r_OId &oid) override;
79 r_Ref_Any getCollByName(const char *name) override;
80 r_Ref_Any getCollByOId(const r_OId &oid) override;
81 r_Ref_Any getCollOIdsByName(const char *name) override;
82 r_Ref_Any getCollOIdsByOId(const r_OId &oid) override;
83
84 void executeQuery(const r_OQL_Query &query, r_Set<r_Ref_Any> &result) override;
85 void executeQuery(const r_OQL_Query &query) override;
86 void executeQuery(const r_OQL_Query &query, r_Set<r_Ref_Any> &result, int dummy) override;
87
88 r_OId getNewOId(unsigned short objType) override;
89 unsigned short getObjectType(const r_OId &oid) override;
90
91 char *getTypeStructure(const char *typeName, r_Type_Type typeType) override;
92
93 int setTransferFormat(r_Data_Format format, const char *formatParams = NULL) override;
94 int setStorageFormat(r_Data_Format format, const char *formatParams = NULL) override;
95
96 void setUserIdentification(const char *userName, const char *plainTextPassword) override;
97 void setMaxRetry(unsigned int newMaxRetry) override;
98 unsigned int getMaxRetry() override;
99 void setTimeoutInterval(int seconds) override;
100 int getTimeoutInterval() override;
101
102private:
103 // -------------------------------------------------------------------------
104 // rasmgr service
105 std::shared_ptr<rasnet::service::RasmgrClientService::Stub> rasmgrService;
106 bool initializedRasMgrService{false};
107 std::mutex rasMgrServiceMtx;
108 std::shared_ptr<common::HealthService::Stub> rasmgrHealthService;
109 //
110 std::shared_ptr<rasnet::service::RasmgrClientService::Stub> getRasMgrService(bool throwIfConnectionFailed = true);
111 void initRasserverService();
112 void closeRasserverService();
113
114 // -------------------------------------------------------------------------
115 // rasserver service
116 std::shared_ptr<rasnet::service::ClientRassrvrService::Stub> rasserverService;
117 bool initializedRasServerService{false};
118 std::mutex rasServerServiceMtx;
119 std::shared_ptr<common::HealthService::Stub> rasserverHealthService;
120 //
121 std::shared_ptr<rasnet::service::ClientRassrvrService::Stub> getRasServerService(bool throwIfConnectionFailed = true);
122 void initRasmgrService();
123 void closeRasmgrService();
124
125 // -------------------------------------------------------------------------
126 // START: KEEP ALIVE THREADS
127 int64_t keepAliveTimeout{};
128
129 // rasmgr
130 std::unique_ptr<std::thread> rasMgrKeepAliveManagementThread;
131 std::mutex rasmgrKeepAliveMutex;
132 bool isRasmgrKeepAliveRunning{false};
133 std::condition_variable isRasmgrKeepAliveRunningCondition;
134 //
135 void startRasMgrKeepAlive();
136 void stopRasMgrKeepAlive();
137 void clientRasMgrKeepAliveRunner();
138
139 // rasserver
140 std::unique_ptr<std::thread> rasServerKeepAliveManagementThread;
141 std::mutex rasserverKeepAliveMutex;
142 bool isRasserverKeepAliveRunning{false};
143 std::condition_variable isRasserverKeepAliveRunningCondition;
144 //
145 void startRasServerKeepAlive();
146 void stopRasServerKeepAlive();
147 void clientRasServerKeepAliveRunner();
148 // END: KEEP ALIVE
149
150 // -------------------------------------------------------------------------
151 // various identifiers
153 std::uint32_t clientId{};
158 std::uint32_t remoteClientId;
159 std::uint32_t sessionId;
160
161 // -------------------------------------------------------------------------
162 // authentication
163 char capability[100];
164
165 // -------------------------------------------------------------------------
166 // connection details
168 std::string rasmgrHost;
170 std::string rasmgrHostname;
172 std::string rasServerHost;
174 int rasServerPort;
176 r_Data_Format transferFormat{r_Array};
178 r_Data_Format storageFormat{r_Array};
180 char *transferFormatParams{nullptr};
182 char *storageFormatParams{nullptr};
185 size_t timeoutMs{};
187 r_Parse_Params clientParams;
188
189 // -------------------------------------------------------------------------
190 // error handlers
191 static void handleError(const std::string &error);
192 static void handleStatusCode(int status, const std::string &method);
193
194 // -------------------------------------------------------------------------
195 // utility methods
196 int executeStartInsertPersMDD(const char *collName, r_GMarray *mar);
197 int executeInsertTile(bool persistent, RPCMarray *tile);
198 void executeEndInsertMDD(bool persistent);
199 int executeEndTransfer();
200 r_Ref_Any executeGetCollByNameOrOId(const char *collName, const r_OId &oid);
201 r_Ref_Any executeGetCollOIdsByNameOrOId(const char *collName, const r_OId &oid);
202 int executeStartInsertTransMDD(r_GMarray *mdd);
203 int executeInitUpdate();
204 GetMDDRes *executeGetNextMDD();
205 GetTileRes *executeGetNextTile();
206 int executeExecuteQuery(const char *query, r_Set<r_Ref_Any> &result);
207 GetElementRes *executeGetNextElement();
208 int executeExecuteUpdateQuery(const char *query);
209 int executeExecuteUpdateQuery(const char *query, r_Set<r_Ref_Any> &result);
210 int executeSetFormat(bool lTransferFormat, r_Data_Format format, const char *formatParams);
211
212 void getMDDCollection(r_Set<r_Ref_Any> &mddColl, unsigned int isQuery);
213 unsigned short getMDDCore(r_Ref<r_GMarray> &mdd, GetMDDRes *thisResult, unsigned int isQuery);
214 void sendMDDConstants(const r_OQL_Query &query);
215 void getElementCollection(r_Set<r_Ref_Any> &resultColl);
216
217 int concatArrayData(const char *source, unsigned long srcSize, char *&dest,
218 unsigned long &destSize, unsigned long &destLevel);
219 void freeGetTileRes(GetTileRes *ptr);
220
221 void freeMarRpcRepresentation(const r_GMarray *mar, RPCMarray *rpcMarray);
222 void getMarRpcRepresentation(
223 const r_GMarray *mar, RPCMarray *&rpcMarray, r_Data_Format initStorageFormat, const r_Base_Type *baseType);
224 void checkForRwTransaction();
225};
226
227#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:55
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 setStorageFormat(r_Data_Format format, const char *formatParams=NULL) override
set the preferred storage format
void insertColl(const char *collName, const char *typeName, const r_OId &oid) override
Collection methods.
virtual ~RasnetClientComm() noexcept
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 setTransferFormat(r_Data_Format format, const char *formatParams=NULL) override
Configuration methods.
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