Skip to content

Commit 74c8939

Browse files
committed
holo-clent-c, holo-client-go v1.3.7
1 parent 7a17508 commit 74c8939

62 files changed

Lines changed: 2609 additions & 794 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ Connectors for Hologres
101101
```xml
102102
<dependency>
103103
<groupId>com.alibaba.hologres</groupId>
104-
<artifactId>hologres-connector-flink-1.13</artifactId>
105-
<version>1.4.0</version>
104+
<artifactId>hologres-connector-flink-1.17</artifactId>
105+
<version>1.4.2</version>
106106
<classifier>jar-with-dependencies</classifier>
107107
</dependency>
108108
```

holo-client-c/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.9)
22
project(holo-client VERSION 1.1.0 DESCRIPTION "holo-client")
3-
execute_process(COMMAND git tag --sort=-taggerdate | head -n 1
3+
execute_process(
4+
COMMAND git tag --sort=-taggerdate
5+
COMMAND head -n 1
46
TIMEOUT 10
57
OUTPUT_VARIABLE GIT_VERSION
68
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -27,6 +29,7 @@ set(MY_PUBLIC_HEADERS
2729
include/defs.h
2830
include/holo_client.h
2931
include/holo_config.h
32+
include/logger.h
3033
include/record.h
3134
include/request.h
3235
include/table_schema.h
@@ -48,7 +51,9 @@ add_library(holo-client SHARED
4851
src/get_collector.c
4952
src/holo_client.c
5053
src/holo_config.c
54+
src/keywords.c
5155
src/logger.c
56+
src/logger_log4c.c
5257
src/lp_map.c
5358
src/meta_cache.c
5459
src/metrics.c
@@ -82,7 +87,9 @@ add_library(${STATIC_LIB_NAME} STATIC
8287
src/get_collector.c
8388
src/holo_client.c
8489
src/holo_config.c
90+
src/keywords.c
8591
src/logger.c
92+
src/logger_log4c.c
8693
src/lp_map.c
8794
src/meta_cache.c
8895
src/metrics.c

holo-client-c/Readme.md

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ find_path (LIBPQ_INCLUDE_DIRS NAMES libpq-fe.h HINTS /usr/include/postgresql NO_
5454

5555
### 写入普通表
5656
```c
57-
holo_client_logger_open();
5857
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
5958
HoloConfig config = holo_client_new_config(connInfo);
6059

@@ -76,13 +75,11 @@ holo_client_submit(client, mutation);
7675
holo_client_flush_client(client);
7776

7877
holo_client_close_client(client);
79-
holo_client_logger_close();
8078
```
8179
8280
### 写入分区表
8381
若分区已存在,不论dynamicPartition为何值,写入数据都将插入到正确的分区表中;若分区不存在,dynamicPartition设置为true时,将会自动创建不存在的分区,否则插入失败
8482
```c
85-
holo_client_logger_open();
8683
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
8784
HoloConfig config = holo_client_new_config(connInfo);
8885
config.dynamicPartition = true;
@@ -105,12 +102,10 @@ holo_client_submit(client, mutation);
105102
holo_client_flush_client(client);
106103
107104
holo_client_close_client(client);
108-
holo_client_logger_close();
109105
```
110106

111107
### 写入含主键表
112108
```c
113-
holo_client_logger_open();
114109
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
115110
HoloConfig config = holo_client_new_config(connInfo);
116111
config.writeMode = INSERT_OR_UPDATE;//配置主键冲突时策略
@@ -133,11 +128,9 @@ holo_client_submit(client, mutation);
133128
holo_client_flush_client(client);
134129

135130
holo_client_close_client(client);
136-
holo_client_logger_close();
137131
```
138132
### 根据主键删除
139133
```c
140-
holo_client_logger_open();
141134
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
142135
HoloConfig config = holo_client_new_config(connInfo);
143136
@@ -157,12 +150,10 @@ holo_client_submit(client, mutation);
157150
holo_client_flush_client(client);
158151
159152
holo_client_close_client(client);
160-
holo_client_logger_close();
161153
```
162154

163155
### 写入失败的处理
164156
```c
165-
holo_client_logger_open();
166157
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
167158
HoloConfig config = holo_client_new_config(connInfo);
168159
config.exceptionHandler = handle_failed_record; //每条插入失败的record都会调用这个函数
@@ -180,12 +171,38 @@ holo_client_submit(client, mutation);
180171
holo_client_flush_client(client);
181172

182173
holo_client_close_client(client);
183-
holo_client_logger_close();
174+
```
175+
176+
v1.3.7之后的版本,增加了 holo_client_flush_client_with_errmsg(HoloClient*, char**) 接口,可以获取一次flush中引擎返回的第一个报错的message
177+
```c
178+
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
179+
HoloConfig config = holo_client_new_config(connInfo);
180+
HoloClient* client = holo_client_new_client(config);
181+
182+
HoloTableSchema* schema = holo_client_get_tableschema(client, "schema_name", "table_name", true);
183+
HoloMutation mutation = holo_client_new_mutation_request(schema);
184+
holo_client_set_req_int32_val_by_colindex(mutation, 0, 0);
185+
holo_client_submit(client, mutation);
186+
187+
mutation = holo_client_new_mutation_request(schema);
188+
holo_client_set_req_int32_val_by_colindex(mutation, 0, 1);
189+
holo_client_submit(client, mutation);
190+
191+
char* errMsg = NULL;
192+
int ret = holo_client_flush_client_with_errmsg(client, &errMsg); //传入参数为errMsg的地址,即char**
193+
if (ret != HOLO_CLIENT_RET_OK) {
194+
printf("holo client flush failed!\n");
195+
if (errMsg != NULL) {
196+
printf("errMsg: %s\n", errMsg); //如果flush后errMsg不为NULL,则返回了flush中引擎返回的第一个报错的message
197+
free(errMsg); //message需要用户手动free,否则会发生内存泄漏
198+
}
199+
}
200+
201+
holo_client_close_client(client);
184202
```
185203

186204
### 根据主键点查
187205
```c
188-
holo_client_logger_open();
189206
char* connInfo = "host=xxxx.hologres.aliyuncs.com port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx";
190207
HoloConfig config = holo_client_new_config(connInfo);
191208

@@ -213,7 +230,6 @@ holo_client_destroy_get_request(get); //得到结果后需要手动释放
213230
holo_client_flush_client(client);
214231

215232
holo_client_close_client(client);
216-
holo_client_logger_close();
217233
```
218234
219235
## 附录
@@ -222,14 +238,16 @@ holo_client_logger_close();
222238
| --- | --- | --- |
223239
| connInfo| 无 | 必填, 格式:“host=xxxxxxxxx port=xxx dbname=xxxxx user=xxxxxxxxxx password=xxxxxxxxxx”|
224240
| dynamicPartition | false | 若为true,当分区不存在时自动创建分区 |
241+
| unnestMode | false | 若为true,则会采用unnest模式写入,当batchSize不稳定时,不会产生多个PreparedStatement,节省服务端内存,但是会影响写入速度 |
225242
| useFixedFe | false | 若为true,写入将交给holo的FixedFE执行,会降低写入时的并发连接数 |
226243
| writeMode | INSERT_OR_REPLACE | 当INSERT目标表为有主键的表时采用不同策略<br>INSERT_OR_IGNORE 当主键冲突时,不写入<br>INSERT_OR_UPDATE 当主键冲突时,更新相应列<br>INSERT_OR_REPLACE当主键冲突时,更新所有列|
244+
| autoFlush | true | 是否自动触发批量提交,若为false,当合并后的插入数量达到batchSize,或合并后的插入数据字节数达到writeBatchByteSize,或距离上次提交超过writeMaxIntervalMs时,不会触发批量提交,此时再次插入会报错 |
227245
| batchSize | 512 | 每个写入线程的最大批次大小,在经过WriteMode合并后的插入数量达到batchSize时进行一次批量提交 |
228246
| threadSize | 1 | 写入并发线程数(每个并发占用1个数据库连接) |
229247
| shardCollectorSize | 2 * threadSize | 每个表的缓冲区个数,建议shardCollectorSize大于threadSize |
230248
| writeBatchByteSize | 2MB | 每个写入线程的最大批次bytes大小,在经过WriteMode合并后的插入数据字节数达到writeBatchByteSize时进行一次批量提交 |
231249
| writeBatchTotalByteSize | writeBatchByteSize * shardCollectorSize | 所有表所有缓冲区所有数据总和最大bytes大小,达到writeBatchTotalByteSize时全部提交 |
232-
| writeMaxIntervalMs | 10000 ms | 距离上次提交超过writeMaxIntervalMs会触发一次批量提交 |
250+
| writeMaxIntervalMs | 10000 ms | 距离上次提交超过writeMaxIntervalMs会触发一次批量提交,若小于等于0表示不检查writeMaxIntervalMs |
233251
| exceptionHandler | handle_exception_by_doing_nothing | 对于写入失败的数据的处理函数 |
234252
| retryCount | 3 | 当连接故障时的重试次数 |
235253
| retrySleepInitMs | 1000 ms | 每次重试的等待时间 = retrySleepInitMs + retry * retrySleepStepMs |
@@ -238,15 +256,12 @@ holo_client_logger_close();
238256
239257
240258
### LOG说明
241-
holo client用的是log库是log4c
242-
243-
在所有跟holo client有关的代码开始前需要调用 holo_client_logger_open();
244-
结束后需要调用 holo_client_logger_close();
259+
holo client默认用的是log库是log4c,用户可以自己实现自己的log函数,并使用holo_client_setup_logger设置log level和自定义log函数(在调用holo_client_new_client之前),参考logger.h。
245260
246261
*注意
247-
248-
holo_client_logger_open()和holo_client_logger_close()在整个代码里分别只能调用一次,建议在所有和holo client有关的代码的开始前和结束后调用
249-
将log4crc文件复制到最终生成的可执行文件的同一文件夹下。如果要修改log的level和打印到的地点,就修改log4crc
262+
默认的log4c需要在所有跟holo client有关的代码开始前调用holo_client_logger_open(),结束后调用holo_client_logger_close();
263+
holo_client_logger_open()和holo_client_logger_close()在整个代码里分别只能调用一次。
264+
log4c库需要配置log4crc文件,并将log4crc文件复制到最终生成的可执行文件的同一文件夹下。如果要修改log的level和打印到的地点,就修改log4crc
250265
251266
log4crc example1(打印到stdout):
252267
```xml
@@ -383,7 +398,6 @@ import "C"
383398
import "unsafe"
384399

385400
func main() {
386-
C.holo_client_logger_open()
387401
connInfo := "host=xxxx port=xx dbname=xxx user=xxx password=xxxxx"
388402
cInfo := C.CString(connInfo)
389403
config := C.holo_client_new_config(cInfo)
@@ -409,7 +423,6 @@ func main() {
409423

410424
C.holo_client_flush_client(client)
411425
C.holo_client_close_client(client)
412-
C.holo_client_logger_close()
413426
C.free(unsafe.Pointer(cInfo))
414427
C.free(unsafe.Pointer(cTableName))
415428
}
@@ -436,7 +449,6 @@ import (
436449
)
437450

438451
func main() {
439-
C.holo_client_logger_open()
440452
connInfo := "host=xxxxx port=xxx dbname=xxxxx user=xxxxx password=xxxxx"
441453
cInfo := C.CString(connInfo)
442454
config := C.holo_client_new_config(cInfo)
@@ -465,7 +477,6 @@ func main() {
465477
}
466478
C.holo_client_flush_client(client)
467479
C.holo_client_close_client(client)
468-
C.holo_client_logger_close()
469480
C.free(unsafe.Pointer(cInfo))
470481
C.free(unsafe.Pointer(cTableName))
471482
C.free(unsafe.Pointer(cSchemaName))

holo-client-c/include/defs.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
# define __HOLO_CLIENT_END_DECLS
1010
#endif
1111

12+
#define HOLO_MAX_LOG_LEN 1024
13+
14+
#define HOLO_CLIENT_MAX_THREAD_SIZE 64
15+
16+
#define HOLO_LOG_LEVEL_DEBUG 200
17+
#define HOLO_LOG_LEVEL_INFO 300
18+
#define HOLO_LOG_LEVEL_WARNING 400
19+
#define HOLO_LOG_LEVEL_ERROR 500
20+
#define HOLO_LOG_LEVEL_FATAL 600
21+
#define HOLO_LOG_LEVEL_NONE 10000
22+
1223
/*
1324
* Oids of holo-client-c support types
1425
* copy from pg_type_d.h
@@ -45,4 +56,34 @@
4556
#define HOLO_TYPE_DATE_ARRAY 1182
4657
#define HOLO_TYPE_TIMESTAMP_ARRAY 1115
4758
#define HOLO_TYPE_TIMESTAMPTZ_ARRAY 1185
59+
60+
/**
61+
* Errcode for holo-client-c
62+
*/
63+
#define HOLO_CLIENT_RET_OK 0
64+
#define HOLO_CLIENT_RET_FAIL -1
65+
#define HOLO_CLIENT_FLUSH_FAIL -100
66+
67+
#define HOLO_CLIENT_INVALID_PARAM -200
68+
#define HOLO_CLIENT_INVALID_COL_IDX -201
69+
#define HOLO_CLIENT_INVALID_COL_NAME -202
70+
#define HOLO_CLIENT_TYPE_NOT_MATCH -203
71+
#define HOLO_CLIENT_COL_ALREADY_SET -204
72+
#define HOLO_CLIENT_NOT_NULL_BUT_SET_NULL -205
73+
#define HOLO_CLIENT_COL_NOT_PK -206
74+
75+
#define HOLO_CLIENT_CHECK_CONSTRAINT_FAIL -300
76+
#define HOLO_CLIENT_PK_IS_NULL -301
77+
#define HOLO_CLIENT_PARTITION_IS_NULL -302
78+
#define HOLO_CLIENT_DELETE_NO_PK_TABLE -303
79+
#define HOLO_CLIENT_PARTITION_NOT_EXIST -304
80+
#define HOLO_CLIENT_PK_NOT_SET_IN_DELETE -305
81+
#define HOLO_CLIENT_NOT_NULL_BUT_NOT_SET -306
82+
#define HOLO_CLIENT_PARTITION_META_CHANGE -307
83+
84+
#define HOLO_CLIENT_EXCEED_MAX_BYTE -400
85+
#define HOLO_CLIENT_EXCEED_MAX_NUM -401
86+
#define HOLO_CLIENT_EXCEED_MAX_INTERVAL -402
87+
#define HOLO_CLIENT_EXCEED_MAX_TOTAL_BYTE -403
88+
4889
#endif

holo-client-c/include/holo_client.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _HOLO_CLIENT_H_
33

44
#include "defs.h"
5+
#include "logger.h"
56
#include "request.h"
67
#include "worker_pool.h"
78
#include "record.h"
@@ -15,18 +16,22 @@ HoloClient* holo_client_new_client(HoloConfig);
1516
HoloClient* holo_client_new_client_with_workerpool(HoloConfig, HoloWorkerPool*);
1617

1718
int holo_client_flush_client(HoloClient*);
19+
int holo_client_flush_client_with_errmsg(HoloClient*, char**);
1820
int holo_client_close_client(HoloClient*);
1921

2022
//Schema name可以为NULL,会被设为"public"
2123
HoloTableSchema* holo_client_get_tableschema(HoloClient*, const char*, const char*, bool);
24+
HoloTableSchema* holo_client_get_tableschema_with_errmsg(HoloClient*, const char*, const char*, bool, char**);
2225

2326
int holo_client_submit(HoloClient*, HoloMutation);
27+
int holo_client_submit_with_errmsg(HoloClient*, HoloMutation, char**);
28+
int holo_client_submit_with_attachments(HoloClient*, HoloMutation, int64_t, int64_t);
2429
int holo_client_get(HoloClient*, HoloGet);
2530
HoloRecord* holo_client_get_record(const HoloGet);
2631
char* holo_client_get_record_val(const HoloRecord* record, int colIndex);
2732

28-
void holo_client_logger_open();
29-
void holo_client_logger_close();
33+
//通过接口返回的error code,可以获取相应错误的error message(字符串形式)
34+
const char* holo_client_get_errmsg_with_errcode(int errCode);
3035

3136
__HOLO_CLIENT_END_DECLS
3237

holo-client-c/include/holo_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ typedef struct _HoloConfig {
3535
bool dynamicPartition; //false
3636
bool useFixedFe; //false
3737
int connectionSizeWhenUseFixedFe; //1
38+
bool autoFlush; //true
39+
bool unnestMode; //false
3840

3941
/*
4042
* HoloExceptionHandler callback, and pointer which will be passed to the actual callback as parameter

holo-client-c/include/logger.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef _LOGGER_H_
2+
#define _LOGGER_H_
3+
4+
#include "defs.h"
5+
6+
__HOLO_CLIENT_BEGIN_DECLS
7+
8+
/**
9+
* Definition of HoloLogger callback, the default logger is log4c
10+
* you can make your own implement of HoloLogger, and use holo_client_setup_logger to setup
11+
* the first arg is log level, the second is message that will be logged
12+
* if you don't want any log, set logger to holo_client_log_do_nothing, which will reduce overhead
13+
*/
14+
typedef void* (*HoloLogger)(const int, const char*);
15+
16+
void* holo_client_log_do_nothing(const int logLevel, const char* msg);
17+
18+
void holo_client_setup_logger(HoloLogger logger, int loglevel);
19+
20+
void holo_client_logger_open();
21+
void holo_client_logger_close();
22+
23+
__HOLO_CLIENT_END_DECLS
24+
25+
#endif

holo-client-c/include/table_schema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ typedef struct _HoloTableSchema {
3434
int partitionColumn;
3535
} HoloTableSchema;
3636

37+
const char* holo_client_get_column_name(HoloTableSchema* schema, int colIndex);
38+
const char* holo_client_get_column_type_name(HoloTableSchema* schema, int colIndex);
39+
3740
//通过HoloColumn的type字段(无符号整型数字),可以获取HoloColumn的类型(字符串)
3841
const char* holo_client_get_type_name_with_type_oid(unsigned int typeOid);
3942

holo-client-c/src/action.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "action.h"
22
#include "utils.h"
3-
#include "logger.h"
3+
#include "logger_private.h"
44

55
ActionItem* create_action_item(Action* action) {
66
ActionItem* item = MALLOC(1, ActionItem);

0 commit comments

Comments
 (0)