This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQdbCluster.c
More file actions
144 lines (116 loc) · 3.83 KB
/
Copy pathQdbCluster.c
File metadata and controls
144 lines (116 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (c) 2009-2021, quasardb SAS. All rights reserved.
// All rights reserved.
#include "QdbBatch.h"
#include "QdbBatchResult.h"
#include "QdbBlob.h"
#include "QdbCluster.h"
#include "QdbEntryFactory.h"
#include "QdbInteger.h"
#include "QdbQuery.h"
#include "QdbTag.h"
#include "QdbTsBatchTable.h"
#include "QdbTsBatchColumnInfo.h"
#include "class_definition.h"
#include "connection.h"
#include <qdb/client.h>
#define class_name QdbCluster
#define class_storage _cluster_t
typedef struct
{
qdb_handle_t handle;
} _cluster_t;
CLASS_METHOD_1(__construct, STRING_ARG(uri))
{
this->handle = connection_open(uri);
}
CLASS_METHOD_0(__destruct)
{
connection_close(this->handle);
}
CLASS_METHOD_2(setUserCredentials, STRING_ARG(userName), STRING_ARG(secretKey))
{
qdb_error_t err = qdb_option_set_user_credentials(this->handle, Z_STRVAL_P(userName), Z_STRVAL_P(secretKey));
if (err) throw_qdb_error(err);
}
CLASS_METHOD_1(setClusterPublicKey, STRING_ARG(publicKey))
{
qdb_error_t err = qdb_option_set_cluster_public_key(this->handle, Z_STRVAL_P(publicKey));
if (err) throw_qdb_error(err);
}
CLASS_METHOD_1(makeBatchTable, ARRAY_ARG(columns_info))
{
HashTable* range = Z_ARR_P(columns_info);
long columns_cnt = zend_hash_num_elements(range);
if (columns_cnt <= 0) throw_invalid_argument
("cluster.make_batch_table(columns_info) must get at least one column info");
// Guard against the stack allocation.
else if (columns_cnt > 10000) throw_invalid_argument
("cluster.make_batch_table(columns_info) cannot use more than 10000 one column info");
// Allocate data on stack on free the memory automatically when exceptions are occuring.
qdb_ts_batch_column_info_t* info_copy = alloca(columns_cnt * sizeof(qdb_ts_batch_column_info_t));
QdbTsBatchColumnInfo_make_native_array(range, info_copy);
QdbTsBatchTable_createInstance(return_value, this->handle, info_copy, columns_cnt);
}
CLASS_METHOD_1(makeQuery, STRING_ARG(query))
{
QdbQuery_createInstance(return_value, this->handle, Z_STRVAL_P(query));
}
CLASS_METHOD_1(blob, STRING_ARG(alias))
{
QdbBlob_createInstance(return_value, this->handle, alias);
}
CLASS_METHOD_1(entry, STRING_ARG(alias))
{
qdb_error_t err = QdbEntryFactory_createFromAlias(return_value, this->handle, Z_STRVAL_P(alias));
if (err) throw_qdb_error(err);
}
CLASS_METHOD_1(integer, STRING_ARG(alias))
{
QdbInteger_createInstance(return_value, this->handle, alias);
}
CLASS_METHOD_0_1(purgeAll, LONG_ARG(timeout))
{
int timeout_value = timeout ? Z_LVAL_P(timeout) : 300;
if (timeout_value <= 0)
{
throw_invalid_argument("Argument timeout must be a positive (non-zero) integer");
return;
}
qdb_error_t err = qdb_purge_all(this->handle, timeout_value);
if (err) throw_qdb_error(err);
}
CLASS_METHOD_1(runBatch, OBJECT_ARG(QdbBatch, batch))
{
qdb_operation_t* ops;
size_t ops_count;
QdbBatch_copyOperations(batch, &ops, &ops_count);
qdb_run_batch(this->handle, ops, ops_count);
QdbBatchResult_createInstance(return_value, this->handle, ops, ops_count);
}
CLASS_METHOD_1(tag, STRING_ARG(alias))
{
QdbTag_createInstance(return_value, this->handle, alias);
}
CLASS_METHOD_0(lastError)
{
qdb_string_t message;
qdb_error_t error = qdb_get_last_error(this->handle, NULL, &message);
if (QDB_FAILURE(error)) throw_qdb_error(error);
RETVAL_STRINGL(message.data, message.length);
}
BEGIN_CLASS_MEMBERS()
ADD_CONSTRUCTOR(__construct)
ADD_DESTRUCTOR(__destruct)
ADD_METHOD(setUserCredentials)
ADD_METHOD(setClusterPublicKey)
ADD_METHOD(makeBatchTable)
ADD_METHOD(makeQuery)
ADD_METHOD(blob)
ADD_METHOD(entry)
ADD_METHOD(integer)
ADD_METHOD(purgeAll)
ADD_METHOD(runBatch)
ADD_METHOD(tag)
ADD_METHOD(lastError)
END_CLASS_MEMBERS()
#include "class_definition.i"