From 6042fa1c2b00059ae435b05e8ef266e7200ca888 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Sun, 22 Aug 2021 23:20:39 +0800 Subject: [PATCH 01/39] en --- README.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.en.md b/README.en.md index 60274c5..b3aef80 100644 --- a/README.en.md +++ b/README.en.md @@ -21,7 +21,7 @@ Software architecture description #### Contribution 1. Fork the repository -2. Create Feat_xxx branch +2. Create Feat_xxx branch. 3. Commit your code 4. Create Pull Request -- Gitee From eab3ec64a28c291f3ab1099a3ea140fbbf920fec Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Sun, 22 Aug 2021 23:56:58 +0800 Subject: [PATCH 02/39] readme.en --- README.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.en.md b/README.en.md index b3aef80..3a56339 100644 --- a/README.en.md +++ b/README.en.md @@ -22,7 +22,7 @@ Software architecture description 1. Fork the repository 2. Create Feat_xxx branch. -3. Commit your code +3. Commit your code. 4. Create Pull Request -- Gitee From d886a3bb0f150a25e929026eb0ddc9fd3ff054d3 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Mon, 23 Aug 2021 10:42:40 +0800 Subject: [PATCH 03/39] fix: agent copyright. --- .gitignore | 6 +- src/Makefile | 2 +- src/agent/common/da_array.c | 19 +- src/agent/common/da_array.h | 50 ++- src/agent/common/da_atomic.h | 21 +- src/agent/common/da_atomic_asm.h | 222 +++++----- src/agent/common/da_atomic_asm8.h | 295 ++++++------- src/agent/common/da_atomic_gcc.h | 117 ++--- src/agent/common/da_atomic_gcc8.h | 125 +++--- src/agent/common/da_queue.h | 44 +- src/agent/common/da_rbtree.c | 20 +- src/agent/common/da_rbtree.h | 45 +- src/agent/common/da_string.c | 19 +- src/agent/common/da_string.h | 138 +++--- src/agent/compiler.h | 30 +- src/agent/da.c | 22 +- src/agent/da_buf.c | 25 +- src/agent/da_buf.h | 57 +-- src/agent/da_client.c | 19 +- src/agent/da_client.h | 15 +- src/agent/da_conf.c | 23 +- src/agent/da_conf.h | 185 ++++---- src/agent/da_conn.c | 20 +- src/agent/da_conn.h | 156 +++---- src/agent/da_core.c | 21 +- src/agent/da_core.h | 92 ++-- src/agent/da_errno.h | 129 +++--- src/agent/da_listener.c | 27 +- src/agent/da_listener.h | 19 +- src/agent/da_log.c | 24 +- src/agent/da_log.h | 72 +++- src/agent/da_mem_pool.c | 26 +- src/agent/da_mem_pool.h | 79 ++-- src/agent/da_msg.c | 29 +- src/agent/da_msg.h | 239 ++++++----- src/agent/da_request.c | 21 +- src/agent/da_request.h | 40 +- src/agent/da_response.c | 21 +- src/agent/da_response.h | 19 +- src/agent/da_server.c | 33 +- src/agent/da_server.h | 159 +++---- src/agent/da_signal.c | 19 +- src/agent/da_signal.h | 38 +- src/agent/da_stats.c | 19 +- src/agent/da_stats.h | 413 +++++++++--------- src/agent/da_time.c | 19 +- src/agent/da_time.h | 615 ++++++++++++++------------- src/agent/da_top_percentile.c | 15 + src/agent/da_top_percentile.h | 46 +- src/agent/da_util.c | 19 +- src/agent/da_util.h | 121 +++--- src/agent/event/da_epoll.c | 19 +- src/agent/event/da_event.h | 35 +- src/agent/hashkit/da_chash.c | 19 +- src/agent/hashkit/da_crc16.c | 15 + src/agent/hashkit/da_crc32.c | 19 +- src/agent/hashkit/da_fnv.c | 15 + src/agent/hashkit/da_hsieh.c | 18 +- src/agent/hashkit/da_jenkins.c | 24 +- src/agent/hashkit/da_ketama.c | 29 +- src/agent/hashkit/da_md5.c | 25 +- src/agent/hashkit/da_murmur.c | 29 +- src/agent/hashkit/da_one_at_a_time.c | 27 +- src/agent/proto/da_dtcparse.c | 40 +- src/agent/proto/da_protocal.h | 46 +- src/libs/common/version.h | 2 +- 66 files changed, 2477 insertions(+), 1934 deletions(-) diff --git a/.gitignore b/.gitignore index d81b26c..04b4181 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ # Prerequisites # -.history \ No newline at end of file +.history +.vscode +settings.json +*.o +.dep* diff --git a/src/Makefile b/src/Makefile index 198902f..6b25c6c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ include Make.conf -SUBDIRS := configcenter libs devel daemons core connector +SUBDIRS := agent configcenter libs devel daemons core connector include Make.rules diff --git a/src/agent/common/da_array.c b/src/agent/common/da_array.c index bd52ad9..ca7bbf8 100644 --- a/src/agent/common/da_array.c +++ b/src/agent/common/da_array.c @@ -1,9 +1,18 @@ /* - * da_array.c - * - * Created on: 2014年12月3日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_array.h" #include "../da_log.h" diff --git a/src/agent/common/da_array.h b/src/agent/common/da_array.h index 9f13599..c2089ef 100644 --- a/src/agent/common/da_array.h +++ b/src/agent/common/da_array.h @@ -1,46 +1,54 @@ /* - * da_array.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月3日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_ARRAY_H_ #define DA_ARRAY_H_ -#include "stdlib.h" #include "stdint.h" +#include "stdlib.h" typedef int (*array_compare_t)(const void *, const void *); typedef int (*array_each_t)(void *, void *); struct array { - uint32_t nelem; /* # element */ - void *elem; /* element */ - size_t size; /* element size */ - uint32_t nalloc; /* # allocated element */ + uint32_t nelem; /* # element */ + void *elem; /* element */ + size_t size; /* element size */ + uint32_t nalloc; /* # allocated element */ }; -#define null_array { 0, NULL, 0, 0 } +#define null_array \ + { 0, NULL, 0, 0 } static inline void array_null(struct array *a) { - a->nelem = 0; - a->elem = NULL; - a->size = 0; - a->nalloc = 0; + a->nelem = 0; + a->elem = NULL; + a->size = 0; + a->nalloc = 0; } static inline void array_set(struct array *a, void *elem, size_t size, - uint32_t nalloc) { - a->nelem = 0; - a->elem = elem; - a->size = size; - a->nalloc = nalloc; + uint32_t nalloc) { + a->nelem = 0; + a->elem = elem; + a->size = size; + a->nalloc = nalloc; } -static inline uint32_t array_n(const struct array *a) { - return a->nelem; -} +static inline uint32_t array_n(const struct array *a) { return a->nelem; } struct array *array_create(uint32_t n, size_t size); void array_destroy(struct array *a); diff --git a/src/agent/common/da_atomic.h b/src/agent/common/da_atomic.h index b8ce466..82550c9 100644 --- a/src/agent/common/da_atomic.h +++ b/src/agent/common/da_atomic.h @@ -1,3 +1,18 @@ +/* + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef DA_ATOMIC__T #define DA_ATOMIC__T @@ -9,11 +24,11 @@ #include "da_atomic_gcc.h" #endif -#if __WORDSIZE==64 || __GNUC__ >= 5 || (__GNUC__==4 && __GNUC_MINOR__>=3) -#define HAS_ATOMIC8 1 +#if __WORDSIZE == 64 || __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#define HAS_ATOMIC8 1 #include "da_atomic_gcc8.h" #else -#define HAS_ATOMIC8 1 +#define HAS_ATOMIC8 1 #include "da_atomic_asm8.h" #endif diff --git a/src/agent/common/da_atomic_asm.h b/src/agent/common/da_atomic_asm.h index 1ac5ab0..9b8f692 100644 --- a/src/agent/common/da_atomic_asm.h +++ b/src/agent/common/da_atomic_asm.h @@ -1,3 +1,18 @@ +/* + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __ARCH_I386_ATOMIC__ #define __ARCH_I386_ATOMIC__ @@ -11,171 +26,157 @@ __BEGIN_DECLS * on us. We need to use _exactly_ the address the user gave us, * not some alias that contains the same information. */ -typedef struct { volatile int counter; } atomic_t; +typedef struct { + volatile int counter; +} atomic_t; -#define ATOMIC_INIT(i) { (i) } +#define ATOMIC_INIT(i) \ + { (i) } /** * atomic_read - read atomic variable * @v: pointer of type atomic_t - * + * * Atomically reads the value of @v. - */ -#define atomic_read(v) ((v)->counter) + */ +#define atomic_read(v) ((v)->counter) /** * atomic_set - set atomic variable * @v: pointer of type atomic_t * @i: required value - * + * * Atomically sets the value of @v to @i. - */ -#define atomic_set(v,i) (((v)->counter) = (i)) - -static __inline__ int atomic_clear(atomic_t *v) -{ - int i; - __asm__ __volatile__( - " xorl %0, %0\n" - "lock; xchgl %0, %1;" - :"=r"(i) - :"m"(v->counter)); - return i; + */ +#define atomic_set(v, i) (((v)->counter) = (i)) + +static __inline__ int atomic_clear(atomic_t *v) { + int i; + __asm__ __volatile__(" xorl %0, %0\n" + "lock; xchgl %0, %1;" + : "=r"(i) + : "m"(v->counter)); + return i; } /** * atomic_add - add integer to atomic variable * @i: integer value to add * @v: pointer of type atomic_t - * + * * Atomically adds @i to @v. */ -static __inline__ int atomic_add(int i, atomic_t *v) -{ - int __i = i; - __asm__ __volatile__( - "lock; xaddl %0, %1;" - :"=r"(i) - :"m"(v->counter), "0"(i)); - return __i; +static __inline__ int atomic_add(int i, atomic_t *v) { + int __i = i; + __asm__ __volatile__("lock; xaddl %0, %1;" + : "=r"(i) + : "m"(v->counter), "0"(i)); + return __i; } /** * atomic_sub - subtract the atomic variable * @i: integer value to subtract * @v: pointer of type atomic_t - * + * * Atomically subtracts @i from @v. */ -static __inline__ int atomic_sub(int i, atomic_t *v) -{ - return atomic_add(-i, v); +static __inline__ int atomic_sub(int i, atomic_t *v) { + return atomic_add(-i, v); } /** * atomic_sub_and_test - subtract value from variable and test result * @i: integer value to subtract * @v: pointer of type atomic_t - * + * * Atomically subtracts @i from @v and returns * true if the result is zero, or false for all * other cases. */ -static __inline__ int atomic_sub_and_test(int i, atomic_t *v) -{ - unsigned char c; - - __asm__ __volatile__( - "lock; subl %2,%0; sete %1" - :"=m" (v->counter), "=qm" (c) - :"ir" (i), "m" (v->counter) : "memory"); - return c; +static __inline__ int atomic_sub_and_test(int i, atomic_t *v) { + unsigned char c; + + __asm__ __volatile__("lock; subl %2,%0; sete %1" + : "=m"(v->counter), "=qm"(c) + : "ir"(i), "m"(v->counter) + : "memory"); + return c; } /** * atomic_inc - increment atomic variable * @v: pointer of type atomic_t - * + * * Atomically increments @v by 1. - */ -static __inline__ void atomic_inc(atomic_t *v) -{ - __asm__ __volatile__( - "lock; incl %0" - :"=m" (v->counter) - :"m" (v->counter)); + */ +static __inline__ void atomic_inc(atomic_t *v) { + __asm__ __volatile__("lock; incl %0" : "=m"(v->counter) : "m"(v->counter)); } /** * atomic_dec - decrement atomic variable * @v: pointer of type atomic_t - * + * * Atomically decrements @v by 1. - */ -static __inline__ void atomic_dec(atomic_t *v) -{ - __asm__ __volatile__( - "lock; decl %0" - :"=m" (v->counter) - :"m" (v->counter)); + */ +static __inline__ void atomic_dec(atomic_t *v) { + __asm__ __volatile__("lock; decl %0" : "=m"(v->counter) : "m"(v->counter)); } /** * atomic_dec_and_test - decrement and test * @v: pointer of type atomic_t - * + * * Atomically decrements @v by 1 and * returns true if the result is 0, or false for all other * cases. - */ -static __inline__ int atomic_dec_and_test(atomic_t *v) -{ - unsigned char c; - - __asm__ __volatile__( - "lock; decl %0; sete %1" - :"=m" (v->counter), "=qm" (c) - :"m" (v->counter) : "memory"); - return c != 0; + */ +static __inline__ int atomic_dec_and_test(atomic_t *v) { + unsigned char c; + + __asm__ __volatile__("lock; decl %0; sete %1" + : "=m"(v->counter), "=qm"(c) + : "m"(v->counter) + : "memory"); + return c != 0; } /** - * atomic_inc_and_test - increment and test + * atomic_inc_and_test - increment and test * @v: pointer of type atomic_t - * + * * Atomically increments @v by 1 * and returns true if the result is zero, or false for all * other cases. - */ -static __inline__ int atomic_inc_and_test(atomic_t *v) -{ - unsigned char c; - - __asm__ __volatile__( - "lock; incl %0; sete %1" - :"=m" (v->counter), "=qm" (c) - :"m" (v->counter) : "memory"); - return c != 0; + */ +static __inline__ int atomic_inc_and_test(atomic_t *v) { + unsigned char c; + + __asm__ __volatile__("lock; incl %0; sete %1" + : "=m"(v->counter), "=qm"(c) + : "m"(v->counter) + : "memory"); + return c != 0; } /** * atomic_add_negative - add and test if negative * @v: pointer of type atomic_t * @i: integer value to add - * + * * Atomically adds @i to @v and returns true * if the result is negative, or false when * result is greater than or equal to zero. - */ -static __inline__ int atomic_add_negative(int i, atomic_t *v) -{ - unsigned char c; - - __asm__ __volatile__( - "lock; addl %2,%0; sets %1" - :"=m" (v->counter), "=qm" (c) - :"ir" (i), "m" (v->counter) : "memory"); - return c; + */ +static __inline__ int atomic_add_negative(int i, atomic_t *v) { + unsigned char c; + + __asm__ __volatile__("lock; addl %2,%0; sets %1" + : "=m"(v->counter), "=qm"(c) + : "ir"(i), "m"(v->counter) + : "memory"); + return c; } /** @@ -185,32 +186,31 @@ static __inline__ int atomic_add_negative(int i, atomic_t *v) * * Atomically adds @i to @v and returns @i + @v */ -static __inline__ int atomic_add_return(int i, atomic_t *v) -{ - int __i = i; - __asm__ __volatile__( - "lock; xaddl %0, %1;" - :"=r"(i) - :"m"(v->counter), "0"(i)); - return i + __i; +static __inline__ int atomic_add_return(int i, atomic_t *v) { + int __i = i; + __asm__ __volatile__("lock; xaddl %0, %1;" + : "=r"(i) + : "m"(v->counter), "0"(i)); + return i + __i; } -static __inline__ int atomic_sub_return(int i, atomic_t *v) -{ - return atomic_add_return(-i,v); +static __inline__ int atomic_sub_return(int i, atomic_t *v) { + return atomic_add_return(-i, v); } -#define atomic_inc_return(v) (atomic_add_return(1,v)) -#define atomic_dec_return(v) (atomic_sub_return(1,v)) +#define atomic_inc_return(v) (atomic_add_return(1, v)) +#define atomic_dec_return(v) (atomic_sub_return(1, v)) /* These are x86-specific, used by some header files */ -#define atomic_clear_mask(mask, addr) \ -__asm__ __volatile__("lock; andl %0,%1" \ -: : "r" (~(mask)),"m" (*addr) : "memory") - -#define atomic_set_mask(mask, addr) \ -__asm__ __volatile__("lock; orl %0,%1" \ -: : "r" (mask),"m" (*(addr)) : "memory") +#define atomic_clear_mask(mask, addr) \ + __asm__ __volatile__("lock; andl %0,%1" \ + : \ + : "r"(~(mask)), "m"(*addr) \ + : "memory") + +#define atomic_set_mask(mask, addr) \ + __asm__ __volatile__("lock; orl %0,%1" : : "r"(mask), "m"(*(addr)) : "memor" \ + "y") __END_DECLS #endif diff --git a/src/agent/common/da_atomic_asm8.h b/src/agent/common/da_atomic_asm8.h index e282a5d..2a39af7 100644 --- a/src/agent/common/da_atomic_asm8.h +++ b/src/agent/common/da_atomic_asm8.h @@ -1,3 +1,18 @@ +/* + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __ARCH_I386_ATOMIC8__ #define __ARCH_I386_ATOMIC8__ @@ -16,118 +31,114 @@ __BEGIN_DECLS * on us. We need to use _exactly_ the address the user gave us, * not some alias that contains the same information. */ -typedef struct { volatile long long counter; } atomic8_t; +typedef struct { + volatile long long counter; +} atomic8_t; -#define ATOMIC8_INIT(i) { (i) } +#define ATOMIC8_INIT(i) \ + { (i) } /** * atomic8_read - read atomic variable * @v: pointer of type atomic8_t - * + * * Atomically reads the value of @v. - */ -static __inline__ long long atomic8_read(atomic8_t *v) -{ - register long long r; - __asm__ __volatile__( - /* original value for ebx, ecx doesn't matter */ - " movl %%ecx, %%edx\n" - " movl %%ebx, %%eax\n" - "lock; cmpxchg8b %1\n" - : "=&A" (r), "+o" (v->counter) - : - : "memory", "cc"); - return r; + */ +static __inline__ long long atomic8_read(atomic8_t *v) { + register long long r; + __asm__ __volatile__( + /* original value for ebx, ecx doesn't matter */ + " movl %%ecx, %%edx\n" + " movl %%ebx, %%eax\n" + "lock; cmpxchg8b %1\n" + : "=&A"(r), "+o"(v->counter) + : + : "memory", "cc"); + return r; } /** * atomic8_set - set atomic variable * @v: pointer of type atomic8_t * @i: required value - * + * * Atomically sets the value of @v to @i. - */ -static __inline__ long long atomic8_return_set(atomic8_t *v, long long i) -{ - register long long r = v->counter; + */ +static __inline__ long long atomic8_return_set(atomic8_t *v, long long i) { + register long long r = v->counter; #if __pic__ || __PIC__ - __asm__ __volatile__( - " pushl %%ebx\n" - " movl %2, %%ebx\n" - "1: repz; nop\n" // aka pause - "lock; cmpxchg8b (%1)\n" - " jnz 1b\n" - " popl %%ebx\n" - : "+A"(r) - : "ir"(v), "ir" ((int)i), "c"((int)((unsigned long long)i>>32)) - : "memory", "cc"); + __asm__ __volatile__(" pushl %%ebx\n" + " movl %2, %%ebx\n" + "1: repz; nop\n" // aka pause + "lock; cmpxchg8b (%1)\n" + " jnz 1b\n" + " popl %%ebx\n" + : "+A"(r) + : "ir"(v), "ir"((int)i), + "c"((int)((unsigned long long)i >> 32)) + : "memory", "cc"); #else - __asm__ __volatile__( - "1: repz; nop\n" // aka pause - "lock; cmpxchg8b %1\n" - " jnz 1b\n" - : "+A"(r), "+o" (v->counter) - : "b" ((int)i), "c"((int)((unsigned long long)i>>32)) - : "memory", "cc"); + __asm__ __volatile__("1: repz; nop\n" // aka pause + "lock; cmpxchg8b %1\n" + " jnz 1b\n" + : "+A"(r), "+o"(v->counter) + : "b"((int)i), "c"((int)((unsigned long long)i >> 32)) + : "memory", "cc"); #endif - return r; + return r; } -static __inline__ void atomic8_set(atomic8_t *v, long long i) -{ - atomic8_return_set(v, i); +static __inline__ void atomic8_set(atomic8_t *v, long long i) { + atomic8_return_set(v, i); } /** * atomic8_set - set atomic variable * @v: pointer of type atomic8_t * @i: required value - * + * * Atomically sets the value of @v to @i. - */ -static __inline__ long long atomic8_clear(atomic8_t *v) -{ - return atomic8_return_set(v, 0); + */ +static __inline__ long long atomic8_clear(atomic8_t *v) { + return atomic8_return_set(v, 0); } /** * atomic8_add - add integer to atomic variable * @i: integer value to add * @v: pointer of type atomic8_t - * + * * Atomically adds @i to @v. */ -static __inline__ long long atomic8_add(long long i, atomic8_t *v) -{ - register long long r = v->counter; +static __inline__ long long atomic8_add(long long i, atomic8_t *v) { + register long long r = v->counter; #if __pic__ || __PIC__ - __asm__ __volatile__( - " pushl %%ebx\n" - "1: movl %2, %%ebx\n" - " movl %3, %%ecx\n" - " addl %%eax, %%ebx\n" - " adcl %%edx, %%ecx\n" - "repz; nop\n" - "lock; cmpxchg8b (%1)\n" - " jnz 1b\n" - " popl %%ebx\n" - : "+A" (r) - : "ir"(v), "ir" ((int)i), "ir"((int)((unsigned long long)i>>32)) - : "memory", "ecx", "cc"); + __asm__ __volatile__(" pushl %%ebx\n" + "1: movl %2, %%ebx\n" + " movl %3, %%ecx\n" + " addl %%eax, %%ebx\n" + " adcl %%edx, %%ecx\n" + "repz; nop\n" + "lock; cmpxchg8b (%1)\n" + " jnz 1b\n" + " popl %%ebx\n" + : "+A"(r) + : "ir"(v), "ir"((int)i), + "ir"((int)((unsigned long long)i >> 32)) + : "memory", "ecx", "cc"); #else - __asm__ __volatile__( - "1: movl %2, %%ebx\n" - " movl %3, %%ecx\n" - " addl %%eax, %%ebx\n" - " adcl %%edx, %%ecx\n" - "repz; nop\n" - "lock; cmpxchg8b %1\n" - " jnz 1b\n" - : "+A"(r), "+o" (v->counter) - : "g" ((int)i), "g"((int)((unsigned long long)i>>32)) - : "memory", "ebx", "ecx", "cc"); + __asm__ __volatile__("1: movl %2, %%ebx\n" + " movl %3, %%ecx\n" + " addl %%eax, %%ebx\n" + " adcl %%edx, %%ecx\n" + "repz; nop\n" + "lock; cmpxchg8b %1\n" + " jnz 1b\n" + : "+A"(r), "+o"(v->counter) + : "g"((int)i), "g"((int)((unsigned long long)i >> 32)) + : "memory", "ebx", "ecx", "cc"); #endif - return r; + return r; } /** @@ -137,138 +148,128 @@ static __inline__ long long atomic8_add(long long i, atomic8_t *v) * * Atomically adds @i to @v and returns @i + @v */ -static __inline__ long long atomic8_add_return(long long i, atomic8_t *v) -{ - register long long r = v->counter; +static __inline__ long long atomic8_add_return(long long i, atomic8_t *v) { + register long long r = v->counter; #if __pic__ || __PIC__ - __asm__ __volatile__( - " pushl %%ebx\n" - "1: movl %2, %%ebx\n" - " movl %3, %%ecx\n" - " addl %%eax, %%ebx\n" - " adcl %%edx, %%ecx\n" - "repz; nop\n" - "lock; cmpxchg8b (%1)\n" - " jnz 1b\n" - " movl %%ebx, %%eax\n" - " movl %%ecx, %%edx\n" - " popl %%ebx\n" - : "+A" (r) - : "ir"(v), "ir" ((int)i), "ir"((int)((unsigned long long)i>>32)) - : "memory", "ecx", "cc"); + __asm__ __volatile__(" pushl %%ebx\n" + "1: movl %2, %%ebx\n" + " movl %3, %%ecx\n" + " addl %%eax, %%ebx\n" + " adcl %%edx, %%ecx\n" + "repz; nop\n" + "lock; cmpxchg8b (%1)\n" + " jnz 1b\n" + " movl %%ebx, %%eax\n" + " movl %%ecx, %%edx\n" + " popl %%ebx\n" + : "+A"(r) + : "ir"(v), "ir"((int)i), + "ir"((int)((unsigned long long)i >> 32)) + : "memory", "ecx", "cc"); #else - __asm__ __volatile__( - "1: movl %2, %%ebx\n" - " movl %3, %%ecx\n" - " addl %%eax, %%ebx\n" - " adcl %%edx, %%ecx\n" - "repz; nop\n" - "lock; cmpxchg8b %1\n" - " jnz 1b\n" - " movl %%ebx, %%eax\n" - " movl %%ecx, %%edx\n" - : "+A" (r), "+o" (v->counter) - : "g" ((int)i), "g"((int)((unsigned long long)i>>32)) - : "memory", "ebx", "ecx", "cc"); + __asm__ __volatile__("1: movl %2, %%ebx\n" + " movl %3, %%ecx\n" + " addl %%eax, %%ebx\n" + " adcl %%edx, %%ecx\n" + "repz; nop\n" + "lock; cmpxchg8b %1\n" + " jnz 1b\n" + " movl %%ebx, %%eax\n" + " movl %%ecx, %%edx\n" + : "+A"(r), "+o"(v->counter) + : "g"((int)i), "g"((int)((unsigned long long)i >> 32)) + : "memory", "ebx", "ecx", "cc"); #endif - return r; + return r; } /** * atomic8_sub - subtract the atomic variable * @i: integer value to subtract * @v: pointer of type atomic8_t - * + * * Atomically subtracts @i from @v. */ -static __inline__ long long atomic8_sub(long long i, atomic8_t *v) -{ - return atomic8_add(-i, v); +static __inline__ long long atomic8_sub(long long i, atomic8_t *v) { + return atomic8_add(-i, v); } /** * atomic8_sub_and_test - subtract value from variable and test result * @i: integer value to subtract * @v: pointer of type atomic8_t - * + * * Atomically subtracts @i from @v and returns * true if the result is zero, or false for all * other cases. */ -static __inline__ int atomic8_sub_and_test(long long i, atomic8_t *v) -{ - return atomic8_add_return(-i, v)==0; +static __inline__ int atomic8_sub_and_test(long long i, atomic8_t *v) { + return atomic8_add_return(-i, v) == 0; } /** * atomic8_inc - increment atomic variable * @v: pointer of type atomic8_t - * + * * Atomically increments @v by 1. - */ -static __inline__ long long atomic8_inc(atomic8_t *v) -{ - return atomic8_add(1, v); + */ +static __inline__ long long atomic8_inc(atomic8_t *v) { + return atomic8_add(1, v); } /** * atomic8_dec - decrement atomic variable * @v: pointer of type atomic8_t - * + * * Atomically decrements @v by 1. - */ -static __inline__ long long atomic8_dec(atomic8_t *v) -{ - return atomic8_add(-1, v); + */ +static __inline__ long long atomic8_dec(atomic8_t *v) { + return atomic8_add(-1, v); } /** * atomic8_dec_and_test - decrement and test * @v: pointer of type atomic8_t - * + * * Atomically decrements @v by 1 and * returns true if the result is 0, or false for all other * cases. - */ -static __inline__ int atomic8_dec_and_test(atomic8_t *v) -{ - return atomic8_add_return(-1, v)==0; + */ +static __inline__ int atomic8_dec_and_test(atomic8_t *v) { + return atomic8_add_return(-1, v) == 0; } /** - * atomic8_inc_and_test - increment and test + * atomic8_inc_and_test - increment and test * @v: pointer of type atomic8_t - * + * * Atomically increments @v by 1 * and returns true if the result is zero, or false for all * other cases. - */ -static __inline__ int atomic8_inc_and_test(atomic8_t *v) -{ - return atomic8_add_return(1, v)==0; + */ +static __inline__ int atomic8_inc_and_test(atomic8_t *v) { + return atomic8_add_return(1, v) == 0; } /** * atomic8_add_negative - add and test if negative * @v: pointer of type atomic8_t * @i: integer value to add - * + * * Atomically adds @i to @v and returns true * if the result is negative, or false when * result is greater than or equal to zero. - */ -static __inline__ int atomic8_add_negative(long long i, atomic8_t *v) -{ - return atomic8_add_return(i, v) < 0; + */ +static __inline__ int atomic8_add_negative(long long i, atomic8_t *v) { + return atomic8_add_return(i, v) < 0; } -static __inline__ long long atomic8_sub_return(long long i, atomic8_t *v) -{ - return atomic8_add_return(-i,v); +static __inline__ long long atomic8_sub_return(long long i, atomic8_t *v) { + return atomic8_add_return(-i, v); } -#define atomic8_inc_return(v) (atomic8_add_return(1,v)) -#define atomic8_dec_return(v) (atomic8_sub_return(1,v)) +#define atomic8_inc_return(v) (atomic8_add_return(1, v)) +#define atomic8_dec_return(v) (atomic8_sub_return(1, v)) __END_DECLS #endif diff --git a/src/agent/common/da_atomic_gcc.h b/src/agent/common/da_atomic_gcc.h index 7acb5f9..a6d95bb 100644 --- a/src/agent/common/da_atomic_gcc.h +++ b/src/agent/common/da_atomic_gcc.h @@ -1,3 +1,18 @@ +/* + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __ARCH_I386_ATOMIC__ #define __ARCH_I386_ATOMIC__ @@ -11,128 +26,120 @@ __BEGIN_DECLS */ typedef volatile int atomic_t; -#define ATOMIC_INIT(i) { (i) } +#define ATOMIC_INIT(i) \ + { (i) } /** * atomic_read - read atomic variable * @v: pointer of type atomic_t - * + * * Atomically reads the value of @v. - */ -#define atomic_read(v) (*(v)) + */ +#define atomic_read(v) (*(v)) /** * atomic_set - set atomic variable * @v: pointer of type atomic_t * @i: required value - * + * * Atomically sets the value of @v to @i. - */ -#define atomic_set(v,i) (*(v) = (i)) + */ +#define atomic_set(v, i) (*(v) = (i)) -static __inline__ int atomic_clear(atomic_t *v) -{ - return __sync_fetch_and_and(v, 0); +static __inline__ int atomic_clear(atomic_t *v) { + return __sync_fetch_and_and(v, 0); } /** * atomic_add - add integer to atomic variable * @i: integer value to add * @v: pointer of type atomic_t - * + * * Atomically adds @i to @v. */ -static __inline__ int atomic_add(int i, atomic_t *v) -{ - return __sync_fetch_and_add(v, i); +static __inline__ int atomic_add(int i, atomic_t *v) { + return __sync_fetch_and_add(v, i); } /** * atomic_sub - subtract the atomic variable * @i: integer value to subtract * @v: pointer of type atomic_t - * + * * Atomically subtracts @i from @v. */ -static __inline__ int atomic_sub(int i, atomic_t *v) -{ - return __sync_fetch_and_sub(v, i); +static __inline__ int atomic_sub(int i, atomic_t *v) { + return __sync_fetch_and_sub(v, i); } /** * atomic_sub_and_test - subtract value from variable and test result * @i: integer value to subtract * @v: pointer of type atomic_t - * + * * Atomically subtracts @i from @v and returns * true if the result is zero, or false for all * other cases. */ -static __inline__ int atomic_sub_and_test(int i, atomic_t *v) -{ - return __sync_sub_and_fetch(v, i) == 0; +static __inline__ int atomic_sub_and_test(int i, atomic_t *v) { + return __sync_sub_and_fetch(v, i) == 0; } /** * atomic_inc - increment atomic variable * @v: pointer of type atomic_t - * + * * Atomically increments @v by 1. - */ -static __inline__ int atomic_inc(atomic_t *v) -{ - return __sync_fetch_and_add(v, 1); + */ +static __inline__ int atomic_inc(atomic_t *v) { + return __sync_fetch_and_add(v, 1); } /** * atomic_dec - decrement atomic variable * @v: pointer of type atomic_t - * + * * Atomically decrements @v by 1. - */ -static __inline__ int atomic_dec(atomic_t *v) -{ - return __sync_fetch_and_sub(v, 1); + */ +static __inline__ int atomic_dec(atomic_t *v) { + return __sync_fetch_and_sub(v, 1); } /** * atomic_dec_and_test - decrement and test * @v: pointer of type atomic_t - * + * * Atomically decrements @v by 1 and * returns true if the result is 0, or false for all other * cases. - */ -static __inline__ int atomic_dec_and_test(atomic_t *v) -{ - return __sync_sub_and_fetch(v, 1) == 0; + */ +static __inline__ int atomic_dec_and_test(atomic_t *v) { + return __sync_sub_and_fetch(v, 1) == 0; } /** - * atomic_inc_and_test - increment and test + * atomic_inc_and_test - increment and test * @v: pointer of type atomic_t - * + * * Atomically increments @v by 1 * and returns true if the result is zero, or false for all * other cases. - */ -static __inline__ int atomic_inc_and_test(atomic_t *v) -{ - return __sync_add_and_fetch(v, 1) == 0; + */ +static __inline__ int atomic_inc_and_test(atomic_t *v) { + return __sync_add_and_fetch(v, 1) == 0; } /** * atomic_add_negative - add and test if negative * @v: pointer of type atomic_t * @i: integer value to add - * + * * Atomically adds @i to @v and returns true * if the result is negative, or false when * result is greater than or equal to zero. - */ -static __inline__ int atomic_add_negative(int i, atomic_t *v) -{ - return __sync_add_and_fetch(v, i) < 0; + */ +static __inline__ int atomic_add_negative(int i, atomic_t *v) { + return __sync_add_and_fetch(v, i) < 0; } /** @@ -142,18 +149,16 @@ static __inline__ int atomic_add_negative(int i, atomic_t *v) * * Atomically adds @i to @v and returns @i + @v */ -static __inline__ int atomic_add_return(int i, atomic_t *v) -{ - return __sync_add_and_fetch(v, i); +static __inline__ int atomic_add_return(int i, atomic_t *v) { + return __sync_add_and_fetch(v, i); } -static __inline__ int atomic_sub_return(int i, atomic_t *v) -{ - return __sync_sub_and_fetch(v, i); +static __inline__ int atomic_sub_return(int i, atomic_t *v) { + return __sync_sub_and_fetch(v, i); } -#define atomic_inc_return(v) (atomic_add_return(1,v)) -#define atomic_dec_return(v) (atomic_sub_return(1,v)) +#define atomic_inc_return(v) (atomic_add_return(1, v)) +#define atomic_dec_return(v) (atomic_sub_return(1, v)) __END_DECLS #endif diff --git a/src/agent/common/da_atomic_gcc8.h b/src/agent/common/da_atomic_gcc8.h index 8bce999..50a7a2a 100644 --- a/src/agent/common/da_atomic_gcc8.h +++ b/src/agent/common/da_atomic_gcc8.h @@ -1,3 +1,18 @@ +/* + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __ARCH_I386_ATOMIC8__ #define __ARCH_I386_ATOMIC8__ @@ -11,135 +26,127 @@ __BEGIN_DECLS */ typedef volatile int64_t atomic8_t; -#define ATOMIC_INIT(i) { (i) } +#define ATOMIC_INIT(i) \ + { (i) } /** * atomic8_read - read atomic8 variable * @v: pointer of type atomic8_t - * + * * Atomically reads the value of @v. - */ -#if __WORDSIZE==64 -#define atomic8_read(v) (*(v)) + */ +#if __WORDSIZE == 64 +#define atomic8_read(v) (*(v)) #else -#define atomic8_read(v) atomic8_add_return(0,v) +#define atomic8_read(v) atomic8_add_return(0, v) #endif /** * atomic8_set - set atomic8 variable * @v: pointer of type atomic8_t * @i: required value - * + * * Atomically sets the value of @v to @i. - */ -#if __WORDSIZE==64 -#define atomic8_set(v,i) (*(v) = (i)) + */ +#if __WORDSIZE == 64 +#define atomic8_set(v, i) (*(v) = (i)) #else -#define atomic8_set(v,i) (*(v) = (i)) +#define atomic8_set(v, i) (*(v) = (i)) #endif -static __inline__ int64_t atomic8_clear(atomic8_t *v) -{ - return __sync_fetch_and_and(v, 0); +static __inline__ int64_t atomic8_clear(atomic8_t *v) { + return __sync_fetch_and_and(v, 0); } /** * atomic8_add - add integer to atomic8 variable * @i: integer value to add * @v: pointer of type atomic8_t - * + * * Atomically adds @i to @v. */ -static __inline__ int64_t atomic8_add(int64_t i, atomic8_t *v) -{ - return __sync_fetch_and_add(v, i); +static __inline__ int64_t atomic8_add(int64_t i, atomic8_t *v) { + return __sync_fetch_and_add(v, i); } /** * atomic8_sub - subtract the atomic8 variable * @i: integer value to subtract * @v: pointer of type atomic8_t - * + * * Atomically subtracts @i from @v. */ -static __inline__ int64_t atomic8_sub(int64_t i, atomic8_t *v) -{ - return __sync_fetch_and_sub(v, i); +static __inline__ int64_t atomic8_sub(int64_t i, atomic8_t *v) { + return __sync_fetch_and_sub(v, i); } /** * atomic8_sub_and_test - subtract value from variable and test result * @i: integer value to subtract * @v: pointer of type atomic8_t - * + * * Atomically subtracts @i from @v and returns * true if the result is zero, or false for all * other cases. */ -static __inline__ int atomic8_sub_and_test(int64_t i, atomic8_t *v) -{ - return __sync_sub_and_fetch(v, i) == 0; +static __inline__ int atomic8_sub_and_test(int64_t i, atomic8_t *v) { + return __sync_sub_and_fetch(v, i) == 0; } /** * atomic8_inc - increment atomic8 variable * @v: pointer of type atomic8_t - * + * * Atomically increments @v by 1. - */ -static __inline__ int64_t atomic8_inc(atomic8_t *v) -{ - return __sync_fetch_and_add(v, 1); + */ +static __inline__ int64_t atomic8_inc(atomic8_t *v) { + return __sync_fetch_and_add(v, 1); } /** * atomic8_dec - decrement atomic8 variable * @v: pointer of type atomic8_t - * + * * Atomically decrements @v by 1. - */ -static __inline__ int64_t atomic8_dec(atomic8_t *v) -{ - return __sync_fetch_and_sub(v, 1); + */ +static __inline__ int64_t atomic8_dec(atomic8_t *v) { + return __sync_fetch_and_sub(v, 1); } /** * atomic8_dec_and_test - decrement and test * @v: pointer of type atomic8_t - * + * * Atomically decrements @v by 1 and * returns true if the result is 0, or false for all other * cases. - */ -static __inline__ int atomic8_dec_and_test(atomic8_t *v) -{ - return __sync_sub_and_fetch(v, 1) == 0; + */ +static __inline__ int atomic8_dec_and_test(atomic8_t *v) { + return __sync_sub_and_fetch(v, 1) == 0; } /** - * atomic8_inc_and_test - increment and test + * atomic8_inc_and_test - increment and test * @v: pointer of type atomic8_t - * + * * Atomically increments @v by 1 * and returns true if the result is zero, or false for all * other cases. - */ -static __inline__ int atomic8_inc_and_test(atomic8_t *v) -{ - return __sync_add_and_fetch(v, 1) == 0; + */ +static __inline__ int atomic8_inc_and_test(atomic8_t *v) { + return __sync_add_and_fetch(v, 1) == 0; } /** * atomic8_add_negative - add and test if negative * @v: pointer of type atomic8_t * @i: integer value to add - * + * * Atomically adds @i to @v and returns true * if the result is negative, or false when * result is greater than or equal to zero. - */ -static __inline__ int atomic8_add_negative(int64_t i, atomic8_t *v) -{ - return __sync_add_and_fetch(v, i) < 0; + */ +static __inline__ int atomic8_add_negative(int64_t i, atomic8_t *v) { + return __sync_add_and_fetch(v, i) < 0; } /** @@ -149,18 +156,16 @@ static __inline__ int atomic8_add_negative(int64_t i, atomic8_t *v) * * Atomically adds @i to @v and returns @i + @v */ -static __inline__ int64_t atomic8_add_return(int64_t i, atomic8_t *v) -{ - return __sync_add_and_fetch(v, i); +static __inline__ int64_t atomic8_add_return(int64_t i, atomic8_t *v) { + return __sync_add_and_fetch(v, i); } -static __inline__ int64_t atomic8_sub_return(int64_t i, atomic8_t *v) -{ - return __sync_sub_and_fetch(v, i); +static __inline__ int64_t atomic8_sub_return(int64_t i, atomic8_t *v) { + return __sync_sub_and_fetch(v, i); } -#define atomic8_inc_return(v) (atomic8_add_return(1,v)) -#define atomic8_dec_return(v) (atomic8_sub_return(1,v)) +#define atomic8_inc_return(v) (atomic8_add_return(1, v)) +#define atomic8_dec_return(v) (atomic8_sub_return(1, v)) __END_DECLS #endif diff --git a/src/agent/common/da_queue.h b/src/agent/common/da_queue.h index 569d856..6b8a492 100644 --- a/src/agent/common/da_queue.h +++ b/src/agent/common/da_queue.h @@ -1,34 +1,18 @@ /* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)queue.h 8.5 (Berkeley) 8/20/94 - * $FreeBSD: src/sys/sys/queue.h,v 1.73 2010/02/20 01:05:30 emaste Exp $ - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #ifndef _DA_QUEUE_H_ #define _DA_QUEUE_H_ diff --git a/src/agent/common/da_rbtree.c b/src/agent/common/da_rbtree.c index 2d5c7d8..be3966d 100644 --- a/src/agent/common/da_rbtree.c +++ b/src/agent/common/da_rbtree.c @@ -1,10 +1,18 @@ /* - * da_rbtree.c - * - * Created on: 2014年12月2日 - * Author: Jiansong - */ - +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include"da_rbtree.h" diff --git a/src/agent/common/da_rbtree.h b/src/agent/common/da_rbtree.h index d8ce8da..b5f0e20 100644 --- a/src/agent/common/da_rbtree.h +++ b/src/agent/common/da_rbtree.h @@ -1,40 +1,49 @@ /* - * da_rbtree.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月2日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_RBTREE_H_ #define DA_RBTREE_H_ -#include -#include +#include +#include -#define rbtree_red(_node) ((_node)->color = 1) -#define rbtree_black(_node) ((_node)->color = 0) -#define rbtree_is_red(_node) ((_node)->color) -#define rbtree_is_black(_node) (!rbtree_is_red(_node)) +#define rbtree_red(_node) ((_node)->color = 1) +#define rbtree_black(_node) ((_node)->color = 0) +#define rbtree_is_red(_node) ((_node)->color) +#define rbtree_is_black(_node) (!rbtree_is_red(_node)) #define rbtree_copy_color(_n1, _n2) ((_n1)->color = (_n2)->color) struct rbnode { - struct rbnode *left; /* left link */ - struct rbnode *right; /* right link */ - struct rbnode *parent; /* parent link */ - uint64_t key; /* key for ordering */ - void *data; /* opaque data */ - uint8_t color; /* red | black */ + struct rbnode *left; /* left link */ + struct rbnode *right; /* right link */ + struct rbnode *parent; /* parent link */ + uint64_t key; /* key for ordering */ + void *data; /* opaque data */ + uint8_t color; /* red | black */ }; struct rbtree { - struct rbnode *root; /* root node */ - struct rbnode *sentinel; /* nil node */ + struct rbnode *root; /* root node */ + struct rbnode *sentinel; /* nil node */ }; void rbtree_node_init(struct rbnode *node); void rbtree_init(struct rbtree *tree, struct rbnode *node); struct rbnode *rbtree_min(struct rbtree *tree); -struct rbnode *rbtree_search(struct rbtree *tree,struct rbnode *tnode); +struct rbnode *rbtree_search(struct rbtree *tree, struct rbnode *tnode); void rbtree_insert(struct rbtree *tree, struct rbnode *node); void rbtree_delete(struct rbtree *tree, struct rbnode *node); diff --git a/src/agent/common/da_string.c b/src/agent/common/da_string.c index c851ac0..d2ee610 100644 --- a/src/agent/common/da_string.c +++ b/src/agent/common/da_string.c @@ -1,9 +1,18 @@ /* - * da_string.c - * - * Created on: 2014年12月4日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_string.h" #include diff --git a/src/agent/common/da_string.h b/src/agent/common/da_string.h index 98d51e9..19cccfc 100644 --- a/src/agent/common/da_string.h +++ b/src/agent/common/da_string.h @@ -1,40 +1,53 @@ /* - * da_string.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月4日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_STRING_H_ #define DA_STRING_H_ -#include -#include +#include "../da_util.h" #include #include #include -#include "../da_util.h" +#include +#include /* * warning:you must manage the memory yourself */ struct string { - uint32_t len; /* string length */ - uint8_t *data; /* string data */ + uint32_t len; /* string length */ + uint8_t *data; /* string data */ }; -#define string(_str) { sizeof(_str) - 1, (uint8_t *)(_str) } -#define null_string { 0, NULL } +#define string(_str) \ + { sizeof(_str) - 1, (uint8_t *)(_str) } +#define null_string \ + { 0, NULL } -#define string_set_text(_str, _text) do { \ - (_str)->len = (uint32_t)(sizeof(_text) - 1);\ - (_str)->data = (uint8_t *)(_text); \ -} while (0); +#define string_set_text(_str, _text) \ + do { \ + (_str)->len = (uint32_t)(sizeof(_text) - 1); \ + (_str)->data = (uint8_t *)(_text); \ + } while (0); -#define string_set_raw(_str, _raw) do { \ - (_str)->len = (uint32_t)(da_strlen(_raw)); \ - (_str)->data = (uint8_t *)(_raw); \ -} while (0); +#define string_set_raw(_str, _raw) \ + do { \ + (_str)->len = (uint32_t)(da_strlen(_raw)); \ + (_str)->data = (uint8_t *)(_raw); \ + } while (0); void string_init(struct string *str); void string_deinit(struct string *str); @@ -44,61 +57,52 @@ int string_copy(struct string *dst, const uint8_t *src, uint32_t srclen); int string_compare(const struct string *s1, const struct string *s2); static inline uint8_t *_da_strchr(uint8_t *p, uint8_t *last, uint8_t c) { - while (p < last) { - if (*p == c) { - return p; - } - p++; - } - return NULL; + while (p < last) { + if (*p == c) { + return p; + } + p++; + } + return NULL; } static inline uint8_t *_da_strrchr(uint8_t *p, uint8_t *start, uint8_t c) { - while (p >= start) { - if (*p == c) { - return p; - } - p--; - } + while (p >= start) { + if (*p == c) { + return p; + } + p--; + } - return NULL; + return NULL; } -#define da_strcpy(_d,_s) \ - strcpy((char *)_d,(char *)_s) -#define da_strncpy(_d,_s,_n) \ - strncpy((char *)_d,(char *)_s,(size_t)(_n)) -#define da_strcat(_d,_s) \ - strcat((char *)_d,(char *)_s) -#define da_memcpy(_d, _c, _n) \ - memcpy(_d, _c, (size_t)(_n)) -#define da_memmove(_d, _c, _n) \ - memmove(_d, _c, (size_t)(_n)) -#define da_memchr(_d, _c, _n) \ - memchr(_d, _c, (size_t)(_n)) -#define da_strlen(_s) \ - strlen((char *)(_s)) -#define da_strncmp(_s1, _s2, _n) \ - strncmp((char *)(_s1), (char *)(_s2), (size_t)(_n)) -#define da_strchr(_p, _l, _c) \ - _da_strchr((uint8_t *)(_p), (uint8_t *)(_l), (uint8_t)(_c)) -#define da_strrchr(_p, _s, _c) \ - _da_strrchr((uint8_t *)(_p),(uint8_t *)(_s), (uint8_t)(_c)) -#define da_strndup(_s, _n) \ - (uint8_t *)strndup((char *)(_s), (size_t)(_n)); -#define da_snprintf(_s, _n, ...) \ - snprintf((char *)(_s), (size_t)(_n), __VA_ARGS__) -#define da_scnprintf(_s, _n, ...) \ - _scnprintf((char *)(_s), (size_t)(_n), __VA_ARGS__) -#define da_vscnprintf(_s, _n, _f, _a) \ - _vscnprintf((char *)(_s), (size_t)(_n), _f, _a) -#define da_strftime(_s, _n, fmt, tm) \ - (int)strftime((char *)(_s), (size_t)(_n), fmt, tm) -#define da_safe_snprintf(_s, _n, ...) \ - _safe_snprintf((char *)(_s), (size_t)(_n), __VA_ARGS__) -#define da_safe_vsnprintf(_s, _n, _f, _a) \ - _safe_vsnprintf((char *)(_s), (size_t)(_n), _f, _a) - +#define da_strcpy(_d, _s) strcpy((char *)_d, (char *)_s) +#define da_strncpy(_d, _s, _n) strncpy((char *)_d, (char *)_s, (size_t)(_n)) +#define da_strcat(_d, _s) strcat((char *)_d, (char *)_s) +#define da_memcpy(_d, _c, _n) memcpy(_d, _c, (size_t)(_n)) +#define da_memmove(_d, _c, _n) memmove(_d, _c, (size_t)(_n)) +#define da_memchr(_d, _c, _n) memchr(_d, _c, (size_t)(_n)) +#define da_strlen(_s) strlen((char *)(_s)) +#define da_strncmp(_s1, _s2, _n) \ + strncmp((char *)(_s1), (char *)(_s2), (size_t)(_n)) +#define da_strchr(_p, _l, _c) \ + _da_strchr((uint8_t *)(_p), (uint8_t *)(_l), (uint8_t)(_c)) +#define da_strrchr(_p, _s, _c) \ + _da_strrchr((uint8_t *)(_p), (uint8_t *)(_s), (uint8_t)(_c)) +#define da_strndup(_s, _n) (uint8_t *)strndup((char *)(_s), (size_t)(_n)); +#define da_snprintf(_s, _n, ...) \ + snprintf((char *)(_s), (size_t)(_n), __VA_ARGS__) +#define da_scnprintf(_s, _n, ...) \ + _scnprintf((char *)(_s), (size_t)(_n), __VA_ARGS__) +#define da_vscnprintf(_s, _n, _f, _a) \ + _vscnprintf((char *)(_s), (size_t)(_n), _f, _a) +#define da_strftime(_s, _n, fmt, tm) \ + (int)strftime((char *)(_s), (size_t)(_n), fmt, tm) +#define da_safe_snprintf(_s, _n, ...) \ + _safe_snprintf((char *)(_s), (size_t)(_n), __VA_ARGS__) +#define da_safe_vsnprintf(_s, _n, _f, _a) \ + _safe_vsnprintf((char *)(_s), (size_t)(_n), _f, _a) /* * A (very) limited version of snprintf diff --git a/src/agent/compiler.h b/src/agent/compiler.h index 883fe9f..629811e 100644 --- a/src/agent/compiler.h +++ b/src/agent/compiler.h @@ -1,8 +1,17 @@ /* - * compiler.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月2日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef COMPILER_H_ @@ -12,14 +21,13 @@ * Gcc before 3.0 needs [0] to declare a variable-size array */ #ifndef VAR_ARRAY -#if __GNUC__ < 3 -#define VAR_ARRAY 0 +#if __GNUC__ < 3 +#define VAR_ARRAY 0 #else #define VAR_ARRAY #endif #endif - /* Support passing function parameters in registers. For this, the * CONFIG_REGPARM macro has to be set to the maximal number of registers * allowed. Some functions have intentionally received a regparm lower than @@ -28,7 +36,7 @@ */ #ifndef REGPRM1 #if CONFIG_REGPARM >= 1 && __GNUC__ >= 3 -#define REGPRM1 __attribute__((regparm(1))) +#define REGPRM1 __attribute__((regparm(1))) #else #define REGPRM1 #endif @@ -36,7 +44,7 @@ #ifndef REGPRM2 #if CONFIG_REGPARM >= 2 && __GNUC__ >= 3 -#define REGPRM2 __attribute__((regparm(2))) +#define REGPRM2 __attribute__((regparm(2))) #else #define REGPRM2 REGPRM1 #endif @@ -44,13 +52,12 @@ #ifndef REGPRM3 #if CONFIG_REGPARM >= 3 && __GNUC__ >= 3 -#define REGPRM3 __attribute__((regparm(3))) +#define REGPRM3 __attribute__((regparm(3))) #else #define REGPRM3 REGPRM2 #endif #endif - /* By default, gcc does not inline large chunks of code, but we want it to * respect our choices. */ @@ -62,7 +69,6 @@ #endif #endif - /* * Gcc >= 3 provides the ability for the programme to give hints to the * compiler about what branch of an if is most likely to be taken. This @@ -71,7 +77,7 @@ */ #if !defined(likely) #if __GNUC__ < 3 -#define __builtin_expect(x,y) (x) +#define __builtin_expect(x, y) (x) #define likely(x) (x) #define unlikely(x) (x) #elif __GNUC__ < 4 diff --git a/src/agent/da.c b/src/agent/da.c index 2bf56fa..da4adc0 100644 --- a/src/agent/da.c +++ b/src/agent/da.c @@ -1,12 +1,18 @@ /* - ============================================================================ - Name : da.c - Author : jiansong - Version : - Copyright : Your copyright notice - Description : Hello World in C, Ansi-style - ============================================================================ - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include diff --git a/src/agent/da_buf.c b/src/agent/da_buf.c index 9f73c7f..eb02106 100644 --- a/src/agent/da_buf.c +++ b/src/agent/da_buf.c @@ -1,9 +1,18 @@ /* - * da_buf.c - * - * Created on: 2014年12月3日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_buf.h" #include "stdlib.h" #include "da_mem_pool.h" @@ -78,7 +87,7 @@ struct mbuf *mbuf_get() { } /* - * 将mbuf归还内存池 + * 灏唌buf褰掕繕鍐呭瓨姹 */ void mbuf_put(struct mbuf *mbuf) { uint8_t *buf; @@ -90,7 +99,7 @@ void mbuf_put(struct mbuf *mbuf) { } /* - * 重置mbuf + * 閲嶇疆mbuf */ void mbuf_rewind(struct mbuf *mbuf) { mbuf->pos = mbuf->start; @@ -98,7 +107,7 @@ void mbuf_rewind(struct mbuf *mbuf) { } /* - * 返回mbuf中现有的数据 + * 杩斿洖mbuf涓幇鏈夌殑鏁版嵁 */ uint32_t mbuf_length(struct mbuf *mbuf) { ASSERT(mbuf->last >= mbuf->pos); diff --git a/src/agent/da_buf.h b/src/agent/da_buf.h index 784b99d..8e22f5f 100644 --- a/src/agent/da_buf.h +++ b/src/agent/da_buf.h @@ -1,8 +1,17 @@ /* - * da_buf.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月3日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_BUF_H_ @@ -17,34 +26,30 @@ struct mbuf; typedef void (*mbuf_copy_t)(struct mbuf *, void *); struct mbuf { - uint32_t magic; /* mbuf magic (const) */ - STAILQ_ENTRY(mbuf) next; /* next mbuf */ - uint8_t *pos; /* read marker */ - uint8_t *last; /* write marker */ - uint8_t *start; /* start of buffer (const) */ - uint8_t *end; /* end of buffer (const) */ + uint32_t magic; /* mbuf magic (const) */ + STAILQ_ENTRY(mbuf) next; /* next mbuf */ + uint8_t *pos; /* read marker */ + uint8_t *last; /* write marker */ + uint8_t *start; /* start of buffer (const) */ + uint8_t *end; /* end of buffer (const) */ }; STAILQ_HEAD(buf_stqh, mbuf); -#define MBUF_MAGIC 0xdeadbeef +#define MBUF_MAGIC 0xdeadbeef /* - * 最小的长度应该把msg头接收下来 + * 鏈灏忕殑闀垮害搴旇鎶妋sg澶存帴鏀朵笅鏉 */ -#define MBUF_MIN_SIZE 256 -#define MBUF_MAX_SIZE 16777216 -#define DEF_MBUF_SIZE 16384 - -static inline bool -mbuf_empty(struct mbuf *mbuf) -{ - return mbuf->pos == mbuf->last ? true : false; +#define MBUF_MIN_SIZE 256 +#define MBUF_MAX_SIZE 16777216 +#define DEF_MBUF_SIZE 16384 + +static inline bool mbuf_empty(struct mbuf *mbuf) { + return mbuf->pos == mbuf->last ? true : false; } -static inline bool -mbuf_full(struct mbuf *mbuf) -{ - return mbuf->last == mbuf->end ? true : false; +static inline bool mbuf_full(struct mbuf *mbuf) { + return mbuf->last == mbuf->end ? true : false; } int mbuf_init(struct instance *ins); @@ -58,6 +63,8 @@ size_t mbuf_data_size(void); void mbuf_insert(struct buf_stqh *mhdr, struct mbuf *mbuf); void mbuf_remove(struct buf_stqh *mhdr, struct mbuf *mbuf); void mbuf_copy(struct mbuf *mbuf, uint8_t *pos, size_t n); -struct mbuf* mbuf_split(struct mbuf *mbuf,uint8_t *pos, mbuf_copy_t cb, void *cbarg); -struct mbuf* _mbuf_split(struct mbuf *mbuf, uint8_t *pos, mbuf_copy_t cb,void *cbarg); +struct mbuf *mbuf_split(struct mbuf *mbuf, uint8_t *pos, mbuf_copy_t cb, + void *cbarg); +struct mbuf *_mbuf_split(struct mbuf *mbuf, uint8_t *pos, mbuf_copy_t cb, + void *cbarg); #endif /* DA_BUF_H_ */ diff --git a/src/agent/da_client.c b/src/agent/da_client.c index 371c495..026a19b 100644 --- a/src/agent/da_client.c +++ b/src/agent/da_client.c @@ -1,9 +1,18 @@ /* - * da_client.c - * - * Created on: 2014年12月3日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include "da_client.h" diff --git a/src/agent/da_client.h b/src/agent/da_client.h index b8e6457..7dea6ee 100644 --- a/src/agent/da_client.h +++ b/src/agent/da_client.h @@ -1,8 +1,17 @@ /* - * da_client.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月3日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_CLIENT_H_ diff --git a/src/agent/da_conf.c b/src/agent/da_conf.c index e169de8..1e02c00 100644 --- a/src/agent/da_conf.c +++ b/src/agent/da_conf.c @@ -1,9 +1,18 @@ /* - * da_conf.c - * - * Created on: 2014年12月4日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include @@ -522,7 +531,7 @@ static int conf_parse_core(struct conf *cf) { return -1; } - //转存一下localip到conf_pool中,后续server_pool需要使用 + //杞瓨涓涓媗ocalip鍒癱onf_pool涓紝鍚庣画server_pool闇瑕佷娇鐢 struct conf_pool *tmpCP = (struct conf_pool *)void_cp; strncpy(tmpCP->localip, cf->localip, sizeof(tmpCP->localip)); @@ -1010,7 +1019,7 @@ struct conf *conf_create(char *filename) { return NULL; } - //后续需要用到本地IP,所以放在前面获取 + //鍚庣画闇瑕佺敤鍒版湰鍦癐P锛屾墍浠ユ斁鍦ㄥ墠闈㈣幏鍙 get_local_ip(cf->localip, sizeof(cf->localip)); status = conf_parse(cf); diff --git a/src/agent/da_conf.h b/src/agent/da_conf.h index 0a17dfd..f804e02 100644 --- a/src/agent/da_conf.h +++ b/src/agent/da_conf.h @@ -1,127 +1,134 @@ /* - * da_conf.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月4日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_CONF_H_ #define DA_CONF_H_ -#include "mxml.h" #include "da_hashkit.h" #include "da_string.h" +#include "mxml.h" -#define CONF_ERROR (void *) "has an invalid value" -#define CONF_OK (void *) NULL - -#define CONF_UNSET_HASH (hash_type_t) -1 -#define CONF_UNSET_PTR NULL -#define CONF_UNSET_NUM -1 -#define CONF_DEFAULT_SERVERS 8 - - -#define CONF_DEFAULT_POOL 8 -#define CONF_DEFAULT_INSTANCE 8 -#define CONF_DEFAULT_HASH HASH_CHASH -#define CONF_DEFAULT_TIMEOUT -1 -#define CONF_DEFAULT_LISTEN_BACKLOG 512 -#define CONF_DEFAULT_CLIENT_CONNECTIONS 0 -#define CONF_DEFAULT_REDIS false -#define CONF_DEFAULT_PRECONNECT false -#define CONF_DEFAULT_AUTO_EJECT_HOSTS false -#define CONF_DEFAULT_SERVER_RETRY_TIMEOUT 30 * 1000 /* in msec */ -#define CONF_DEFAULT_SERVER_FAILURE_LIMIT 2 -#define CONF_DEFAULT_SERVER_CONNECTIONS 1 -#define CONF_DEFAULT_TOP_PERCENTILE_ENABLE 1 -#define CONF_DEFAULT_TOP_PERCENTILE_DOMAIN "10.187.152.196" -#define CONF_DEFAULT_TOP_PERCENTILE_PORT 20020 -#define CONF_DEFAULT_LOG_SWITCH 0 /*1:on, 0:off*/ +#define CONF_ERROR (void *)"has an invalid value" +#define CONF_OK (void *)NULL + +#define CONF_UNSET_HASH (hash_type_t) - 1 +#define CONF_UNSET_PTR NULL +#define CONF_UNSET_NUM -1 +#define CONF_DEFAULT_SERVERS 8 + +#define CONF_DEFAULT_POOL 8 +#define CONF_DEFAULT_INSTANCE 8 +#define CONF_DEFAULT_HASH HASH_CHASH +#define CONF_DEFAULT_TIMEOUT -1 +#define CONF_DEFAULT_LISTEN_BACKLOG 512 +#define CONF_DEFAULT_CLIENT_CONNECTIONS 0 +#define CONF_DEFAULT_REDIS false +#define CONF_DEFAULT_PRECONNECT false +#define CONF_DEFAULT_AUTO_EJECT_HOSTS false +#define CONF_DEFAULT_SERVER_RETRY_TIMEOUT 30 * 1000 /* in msec */ +#define CONF_DEFAULT_SERVER_FAILURE_LIMIT 2 +#define CONF_DEFAULT_SERVER_CONNECTIONS 1 +#define CONF_DEFAULT_TOP_PERCENTILE_ENABLE 1 +#define CONF_DEFAULT_TOP_PERCENTILE_DOMAIN "10.187.152.196" +#define CONF_DEFAULT_TOP_PERCENTILE_PORT 20020 +#define CONF_DEFAULT_LOG_SWITCH 0 /*1:on, 0:off*/ #define CONF_DEFAULT_REMOTE_LOG_SWITCH 1 /*1:on, 0:off*/ #define CONF_DEFAULT_REMOTE_LOG_IP "10.187.152.196" #define CONF_DEFAULT_REMOTE_LOG_PORT 9997 - struct conf_listen { - struct string pname; /* listen: as "name:port" */ - struct string name; /* name */ - int port; /* port */ - struct sockinfo info; /* listen socket info */ - unsigned valid :1; /* valid? */ + struct string pname; /* listen: as "name:port" */ + struct string name; /* name */ + int port; /* port */ + struct sockinfo info; /* listen socket info */ + unsigned valid : 1; /* valid? */ }; struct conf_server { - struct string name; /* name */ - struct array instance; /* instance */ - int replica_enable; - struct string idc; - unsigned valid : 1; /* valid? */ + struct string name; /* name */ + struct array instance; /* instance */ + int replica_enable; + struct string idc; + unsigned valid : 1; /* valid? */ }; struct conf_instance { - struct string addr; /* server: as "name:port:weight" */ - int port; /* port */ - int weight; /* weight */ - struct sockinfo info; /* connect socket info */ - struct string idc; /* idc */ - struct string role; /* role */ - unsigned valid : 1; /* valid? */ - int enable; /* Enable */ + struct string addr; /* server: as "name:port:weight" */ + int port; /* port */ + int weight; /* weight */ + struct sockinfo info; /* connect socket info */ + struct string idc; /* idc */ + struct string role; /* role */ + unsigned valid : 1; /* valid? */ + int enable; /* Enable */ }; struct conf_pool { - int mid; - struct string name; /* pool name (root node) */ - struct string accesskey; - struct conf_listen listen; /* listen: */ - hash_type_t hash; /* hash: */ - int timeout; /* timeout: */ - int backlog; /* backlog: */ - int client_connections; /* client_connections: */ - int preconnect; /* preconnect: */ - int server_connections; /* server_connections: */ - struct array server; /* servers: conf_server[] */ - struct string idc; /* idc*/ - int replica_enable; /* ReplicaEnable*/ - int main_report; - int instance_report; - int auto_remove_replica; - - int top_percentile_enable; /*tp99 性能指标开启状态*/ - struct string top_percentile_domain; /*tp99 性能指标上报服务器地址*/ - int top_percentile_port; /*tp99 性能指标上报服务器端口*/ - - char localip[16]; /*本地IP,放在此位置*/ - unsigned valid:1; /* valid? */ - + int mid; + struct string name; /* pool name (root node) */ + struct string accesskey; + struct conf_listen listen; /* listen: */ + hash_type_t hash; /* hash: */ + int timeout; /* timeout: */ + int backlog; /* backlog: */ + int client_connections; /* client_connections: */ + int preconnect; /* preconnect: */ + int server_connections; /* server_connections: */ + struct array server; /* servers: conf_server[] */ + struct string idc; /* idc*/ + int replica_enable; /* ReplicaEnable*/ + int main_report; + int instance_report; + int auto_remove_replica; + + int top_percentile_enable; /*tp99 鎬ц兘鎸囨爣寮鍚姸鎬*/ + struct string top_percentile_domain; /*tp99 鎬ц兘鎸囨爣涓婃姤鏈嶅姟鍣ㄥ湴鍧*/ + int top_percentile_port; /*tp99 鎬ц兘鎸囨爣涓婃姤鏈嶅姟鍣ㄧ鍙*/ + + char localip[16]; /*鏈湴IP锛屾斁鍦ㄦ浣嶇疆*/ + unsigned valid : 1; /* valid? */ }; struct conf_log { - int log_switch; - int remote_log_switch; - struct string remote_log_ip; - int remote_log_port; + int log_switch; + int remote_log_switch; + struct string remote_log_ip; + int remote_log_port; }; struct conf { - char *fname; /* file name (ref in argv[]) */ - FILE *fh; /* file handle */ - struct string arg; /* string[] (parsed {key, value} pairs) */ - struct array pool; /* conf_pool[] (parsed pools) */ - mxml_node_t *tree; - char localip[16]; - struct conf_log stCL; - unsigned parsed:1; /* parsed? */ - unsigned valid:1; /* valid? */ + char *fname; /* file name (ref in argv[]) */ + FILE *fh; /* file handle */ + struct string arg; /* string[] (parsed {key, value} pairs) */ + struct array pool; /* conf_pool[] (parsed pools) */ + mxml_node_t *tree; + char localip[16]; + struct conf_log stCL; + unsigned parsed : 1; /* parsed? */ + unsigned valid : 1; /* valid? */ }; struct command { - struct string name; - char *(*set)(struct conf *cf, struct command *cmd, void *data); - int offset; + struct string name; + char *(*set)(struct conf *cf, struct command *cmd, void *data); + int offset; }; -#define null_command { null_string, NULL, 0 } +#define null_command \ + { null_string, NULL, 0 } int conf_server_each_transform(void *elem, void *data); int conf_pool_each_transform(void *elem, void *data); diff --git a/src/agent/da_conn.c b/src/agent/da_conn.c index f797ba6..bb3d941 100644 --- a/src/agent/da_conn.c +++ b/src/agent/da_conn.c @@ -1,10 +1,18 @@ /* - * da_conn.c - * - * Created on: 2014年11月30日 - * Author: Jiansong - */ - +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include "da_mem_pool.h" #include "da_conn.h" diff --git a/src/agent/da_conn.h b/src/agent/da_conn.h index d73edf9..340ee4a 100644 --- a/src/agent/da_conn.h +++ b/src/agent/da_conn.h @@ -1,45 +1,54 @@ /* - * da_conn.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年11月30日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_CONN_H_ #define DA_CONN_H_ -#include -#include -#include +#include "compiler.h" +#include "da_errno.h" +#include "da_msg.h" #include "da_queue.h" #include "da_rbtree.h" -#include "compiler.h" #include "da_util.h" -#include "da_msg.h" -#include "da_errno.h" - +#include +#include +#include struct conn; struct context; struct msg; -//connection type +// connection type #define FRONTWORK 0x0001 -#define BACKWORK 0x0002 -#define LISTENER 0x0004 +#define BACKWORK 0x0002 +#define LISTENER 0x0004 -//connection epoll flag +// connection epoll flag #define RECV_ACTIVE 0x0001 #define SEND_ACTIVE 0x0002 -#define RECV_READY 0x0004 -#define SEND_READY 0x0008 +#define RECV_READY 0x0004 +#define SEND_READY 0x0008 -typedef int (*conn_recv_t)(struct context *, struct conn*); -typedef struct msg* (*conn_recv_next_t)(struct context *, struct conn *, bool); -typedef void (*conn_recv_done_t)(struct context *, struct conn *, struct msg *,struct msg *); +typedef int (*conn_recv_t)(struct context *, struct conn *); +typedef struct msg *(*conn_recv_next_t)(struct context *, struct conn *, bool); +typedef void (*conn_recv_done_t)(struct context *, struct conn *, struct msg *, + struct msg *); -typedef int (*conn_send_t)(struct context *, struct conn*); -typedef struct msg* (*conn_send_next_t)(struct context *, struct conn *); +typedef int (*conn_send_t)(struct context *, struct conn *); +typedef struct msg *(*conn_send_next_t)(struct context *, struct conn *); typedef void (*conn_send_done_t)(struct context *, struct conn *, struct msg *); typedef void (*conn_close_t)(struct context *, struct conn *); @@ -52,57 +61,56 @@ typedef void (*conn_msgq_t)(struct context *, struct conn *, struct msg *); typedef void (*conn_msgtree_t)(struct context *, struct conn *, struct msg *); struct conn { - TAILQ_ENTRY(conn) conn_tqe; /*list linked in server or server pool*/ - void *owner; /*owner server server_pool*/ - - int fd; /*socket fd*/ - int family; /*socket family*/ - socklen_t addrlen; /*socket addr len*/ - struct sockaddr *addr; /*socket address (ref in server)*/ - - uint32_t type; /*front conn,back conn,or listener*/ - uint32_t events; /*the event need process*/ - uint32_t flag; /*epool flag*/ - - struct rbtree msg_tree; /*tree for message search*/ - struct rbnode msg_rbs; /*sentinel for msg_tree */ - struct msg_tqh imsg_q; /*request msgq */ - struct msg_tqh omsg_q; /*outstanding request Q */ - - - struct msg *rmsg; /* current message being rcvd */ - struct msg *smsg; /* current message being sent */ - - conn_recv_t recv; /* recv (read) handler */ - conn_recv_next_t recv_next; /* recv next message handler */ - conn_recv_done_t recv_done; /* read done handler */ - conn_send_t send; /* send (write) handler */ - conn_send_next_t send_next; /* write next message handler */ - conn_send_done_t send_done; /* write done handler */ - conn_close_t close; /* close handler */ - conn_active_t active; /* active? handler */ - conn_ref_t ref; /* connection reference handler */ - conn_unref_t unref; /* connection unreference handler */ - - conn_msgq_t enqueue_outq; /* connection outq msg enqueue handler */ - conn_msgq_t dequeue_outq; /* connection outq msg dequeue handler */ - conn_msgq_t enqueue_inq; /* connection outq msg enqueue handler */ - conn_msgq_t dequeue_inq; /* connection outq msg dequeue handler */ - - conn_msgtree_t en_msgtree; /* connection msg tree entree handler*/ - conn_msgtree_t de_msgtree; /* connection msg tree detree handler*/ - - size_t recv_bytes; /* received (read) bytes */ - size_t send_bytes; /* sent (written) bytes */ - - int err ; /*connection error no*/ - unsigned error :1; /*connetion err sig*/ - unsigned connecting :1; /*connecting is on*/ - unsigned connected :1; /*connected*/ - unsigned eof:1; /*connection is end,half connection*/ - unsigned done :1; /*connection is done*/ - unsigned writecached:1; - unsigned isvalid:1; + TAILQ_ENTRY(conn) conn_tqe; /*list linked in server or server pool*/ + void *owner; /*owner server server_pool*/ + + int fd; /*socket fd*/ + int family; /*socket family*/ + socklen_t addrlen; /*socket addr len*/ + struct sockaddr *addr; /*socket address (ref in server)*/ + + uint32_t type; /*front conn,back conn,or listener*/ + uint32_t events; /*the event need process*/ + uint32_t flag; /*epool flag*/ + + struct rbtree msg_tree; /*tree for message search*/ + struct rbnode msg_rbs; /*sentinel for msg_tree */ + struct msg_tqh imsg_q; /*request msgq */ + struct msg_tqh omsg_q; /*outstanding request Q */ + + struct msg *rmsg; /* current message being rcvd */ + struct msg *smsg; /* current message being sent */ + + conn_recv_t recv; /* recv (read) handler */ + conn_recv_next_t recv_next; /* recv next message handler */ + conn_recv_done_t recv_done; /* read done handler */ + conn_send_t send; /* send (write) handler */ + conn_send_next_t send_next; /* write next message handler */ + conn_send_done_t send_done; /* write done handler */ + conn_close_t close; /* close handler */ + conn_active_t active; /* active? handler */ + conn_ref_t ref; /* connection reference handler */ + conn_unref_t unref; /* connection unreference handler */ + + conn_msgq_t enqueue_outq; /* connection outq msg enqueue handler */ + conn_msgq_t dequeue_outq; /* connection outq msg dequeue handler */ + conn_msgq_t enqueue_inq; /* connection outq msg enqueue handler */ + conn_msgq_t dequeue_inq; /* connection outq msg dequeue handler */ + + conn_msgtree_t en_msgtree; /* connection msg tree entree handler*/ + conn_msgtree_t de_msgtree; /* connection msg tree detree handler*/ + + size_t recv_bytes; /* received (read) bytes */ + size_t send_bytes; /* sent (written) bytes */ + + int err; /*connection error no*/ + unsigned error : 1; /*connetion err sig*/ + unsigned connecting : 1; /*connecting is on*/ + unsigned connected : 1; /*connected*/ + unsigned eof : 1; /*connection is end,half connection*/ + unsigned done : 1; /*connection is done*/ + unsigned writecached : 1; + unsigned isvalid : 1; }; TAILQ_HEAD(conn_tqh, conn); @@ -138,8 +146,8 @@ struct conn *get_client_conn(void *owner); struct conn *get_server_conn(void *owner); /* -*get instance conn -*/ + *get instance conn + */ struct conn *get_instance_conn(void *owner); /* diff --git a/src/agent/da_core.c b/src/agent/da_core.c index 58deaca..cbb4bad 100644 --- a/src/agent/da_core.c +++ b/src/agent/da_core.c @@ -1,9 +1,18 @@ /* - * da_core.c - * - * Created on: 2014年11月30日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include @@ -35,7 +44,7 @@ void cache_send_event(struct conn *conn) { } /* - * 根据可用连接及后端连接数,计算前端连接可用的连接数 + * 鏍规嵁鍙敤杩炴帴鍙婂悗绔繛鎺ユ暟锛岃绠楀墠绔繛鎺ュ彲鐢ㄧ殑杩炴帴鏁 */ static int core_calc_connections(struct context *ctx) { int status; diff --git a/src/agent/da_core.h b/src/agent/da_core.h index a28a2d1..efbbd07 100644 --- a/src/agent/da_core.h +++ b/src/agent/da_core.h @@ -1,30 +1,39 @@ /* - * da_core.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年11月30日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_CORE_H_ #define DA_CORE_H_ -#include "da_util.h" #include "da_array.h" +#include "da_util.h" #ifdef HAVE_ASSERT_PANIC -# define DA_ASSERT_PANIC 1 +#define DA_ASSERT_PANIC 1 #endif #ifdef HAVE_ASSERT_LOG -# define DA_ASSERT_LOG 1 +#define DA_ASSERT_LOG 1 #endif -# define DA_STATS 1 -# define USE_COMPATIBLE_MODE +#define DA_STATS 1 +#define USE_COMPATIBLE_MODE #ifdef USE_COMPATIBLE_MODE -# define DA_COMPATIBLE_MODE 1 +#define DA_COMPATIBLE_MODE 1 #else -# define DA_COMPATIBLE_MODE 0 +#define DA_COMPATIBLE_MODE 0 #endif #define RESERVED_FDS 32 @@ -38,48 +47,47 @@ struct conn; struct instance; struct context { - uint32_t id; /* unique context id */ - struct conf *cf; /* configuration */ - struct stats *stats; /* stats */ + uint32_t id; /* unique context id */ + struct conf *cf; /* configuration */ + struct stats *stats; /* stats */ - struct array pool; /* server_pool[] */ - struct event_base *evb; /* event base */ - int max_timeout; /* max timeout in msec */ - int timeout; /* timeout in msec */ + struct array pool; /* server_pool[] */ + struct event_base *evb; /* event base */ + int max_timeout; /* max timeout in msec */ + int timeout; /* timeout in msec */ - uint32_t max_nfd; /* max # files */ - uint32_t max_ncconn; /* max # client connections */ - uint32_t max_nsconn; /* max # server connections */ + uint32_t max_nfd; /* max # files */ + uint32_t max_ncconn; /* max # client connections */ + uint32_t max_nsconn; /* max # server connections */ - uint32_t sum_nconn; /* client connections and server connections sum*/ + uint32_t sum_nconn; /* client connections and server connections sum*/ }; struct instance { - struct context *ctx; /* active context */ - int log_level; /* log level */ - char *log_dir; /* log dir*/ - char *conf_filename; /* configuration filename */ - char hostname[DA_MAXHOSTNAMELEN]; /* hostname */ - size_t mbuf_chunk_size; /* mbuf chunk size */ - int event_max_timeout; /* epoll max time out*/ - int stats_interval; /* stats aggregation interval */ - pid_t pid; /* process id */ - char *pid_filename; /* pid filename */ - unsigned pidfile:1; /* pid file created? */ - int cpumask; /*cpu mask for run*/ - char **argv; /* argv of main() */ + struct context *ctx; /* active context */ + int log_level; /* log level */ + char *log_dir; /* log dir*/ + char *conf_filename; /* configuration filename */ + char hostname[DA_MAXHOSTNAMELEN]; /* hostname */ + size_t mbuf_chunk_size; /* mbuf chunk size */ + int event_max_timeout; /* epoll max time out*/ + int stats_interval; /* stats aggregation interval */ + pid_t pid; /* process id */ + char *pid_filename; /* pid filename */ + unsigned pidfile : 1; /* pid file created? */ + int cpumask; /*cpu mask for run*/ + char **argv; /* argv of main() */ }; -//status for server -enum core_status -{ - NORMAL, - RELOADING, - EXITING, - EXITED, +// status for server +enum core_status { + NORMAL, + RELOADING, + EXITING, + EXITED, }; -//extern struct conn *wait_send_queue[]; /*cached conn*/ +// extern struct conn *wait_send_queue[]; /*cached conn*/ void cache_send_event(struct conn *conn); int core_core(void *arg, uint32_t events); diff --git a/src/agent/da_errno.h b/src/agent/da_errno.h index 6575fec..e948511 100644 --- a/src/agent/da_errno.h +++ b/src/agent/da_errno.h @@ -1,72 +1,93 @@ /* - * da_errno.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2015年1月4日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_ERRNO_H_ #define DA_ERRNO_H_ enum conn_errno { - CONN_EPOLLCTL_ERR = 1, - CONN_EPOLLADD_ERR = 2, - CONN_EPOLL_DEL_ERR = 3, - CONN_CONNECT_ERR = 4, - CONN_SETNOBLOCK_ERR = 5, - CONN_CREATSOCK_ERR = 6, - CONN_RECV_ERR = 7, - CONN_SEND_ERR = 8, - CONN_MSG_GET_ERR = 9, - CONN_BUF_GET_ERR = 10, - CONN_MSG_PARSE_ERR = 11, - CONN_NOT_VALID = 12, + CONN_EPOLLCTL_ERR = 1, + CONN_EPOLLADD_ERR = 2, + CONN_EPOLL_DEL_ERR = 3, + CONN_CONNECT_ERR = 4, + CONN_SETNOBLOCK_ERR = 5, + CONN_CREATSOCK_ERR = 6, + CONN_RECV_ERR = 7, + CONN_SEND_ERR = 8, + CONN_MSG_GET_ERR = 9, + CONN_BUF_GET_ERR = 10, + CONN_MSG_PARSE_ERR = 11, + CONN_NOT_VALID = 12, }; enum msg_errno { - MSG_FRAGMENT_ERR=2, - MSG_REQ_FORWARD_ERR=3, - MSG_BACKWORKER_ERR=4, - MSG_COALESCE_ERR =5, - MSG_NOKEY_ERR = 6, + MSG_FRAGMENT_ERR = 2, + MSG_REQ_FORWARD_ERR = 3, + MSG_BACKWORKER_ERR = 4, + MSG_COALESCE_ERR = 5, + MSG_NOKEY_ERR = 6, }; -static inline char* GetMsgErrorCodeStr(int errcode) -{ - enum msg_errno err; - err=(enum msg_errno)errcode; - switch(err) - { - case MSG_FRAGMENT_ERR : return "fragment request error!"; - case MSG_REQ_FORWARD_ERR: return "forward request to server error!"; - case MSG_BACKWORKER_ERR : return "server error!"; - case MSG_COALESCE_ERR : return "coalesce request error!"; - case MSG_NOKEY_ERR : return "request without key!"; - } - return "unknow"; +static inline char *GetMsgErrorCodeStr(int errcode) { + enum msg_errno err; + err = (enum msg_errno)errcode; + switch (err) { + case MSG_FRAGMENT_ERR: + return "fragment request error!"; + case MSG_REQ_FORWARD_ERR: + return "forward request to server error!"; + case MSG_BACKWORKER_ERR: + return "server error!"; + case MSG_COALESCE_ERR: + return "coalesce request error!"; + case MSG_NOKEY_ERR: + return "request without key!"; + } + return "unknow"; } -static inline char * GetConnErrorCodeStr(int errcode) -{ - enum conn_errno err; - err=(enum conn_errno)errcode; - switch(err) - { - case CONN_EPOLLCTL_ERR: return "conn epoll ctl error"; - case CONN_EPOLLADD_ERR: return "conn epoll add error"; - case CONN_EPOLL_DEL_ERR: return "conn epoll del error"; - case CONN_CONNECT_ERR: return "conn server error"; - case CONN_SETNOBLOCK_ERR: return "conn set noblock error"; - case CONN_CREATSOCK_ERR: return "conn create socket error"; - case CONN_RECV_ERR: return "conn recv error"; - case CONN_SEND_ERR: return "conn send error"; - case CONN_MSG_GET_ERR: return "conn get msg error"; - case CONN_BUF_GET_ERR: return "conn get buf error"; - case CONN_MSG_PARSE_ERR: return "conn parse msg error"; - case CONN_NOT_VALID: return "conn accesstoken invalid"; - } - return "unknow"; +static inline char *GetConnErrorCodeStr(int errcode) { + enum conn_errno err; + err = (enum conn_errno)errcode; + switch (err) { + case CONN_EPOLLCTL_ERR: + return "conn epoll ctl error"; + case CONN_EPOLLADD_ERR: + return "conn epoll add error"; + case CONN_EPOLL_DEL_ERR: + return "conn epoll del error"; + case CONN_CONNECT_ERR: + return "conn server error"; + case CONN_SETNOBLOCK_ERR: + return "conn set noblock error"; + case CONN_CREATSOCK_ERR: + return "conn create socket error"; + case CONN_RECV_ERR: + return "conn recv error"; + case CONN_SEND_ERR: + return "conn send error"; + case CONN_MSG_GET_ERR: + return "conn get msg error"; + case CONN_BUF_GET_ERR: + return "conn get buf error"; + case CONN_MSG_PARSE_ERR: + return "conn parse msg error"; + case CONN_NOT_VALID: + return "conn accesstoken invalid"; + } + return "unknow"; } - #endif /* DA_ERRNO_H_ */ diff --git a/src/agent/da_listener.c b/src/agent/da_listener.c index 851b2ab..0dda2f2 100644 --- a/src/agent/da_listener.c +++ b/src/agent/da_listener.c @@ -1,9 +1,18 @@ /* - * da_listener.c - * - * Created on: 2014年12月3日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_listener.h" #include "da_array.h" @@ -243,7 +252,7 @@ static int listener_accept(struct context *ctx, struct conn *l) { continue; } /* - * 多进程情况下,同时accept会出现错误,errno=11,程序吞掉这个错误 + * 澶氳繘绋嬫儏鍐典笅锛屽悓鏃禷ccept浼氬嚭鐜伴敊璇紝errno=11,绋嬪簭鍚炴帀杩欎釜閿欒 */ if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ECONNABORTED) { log_debug("accept on l %d not ready - eagain", l->fd); @@ -265,7 +274,7 @@ static int listener_accept(struct context *ctx, struct conn *l) { } /* - * 对全局的FD资源进行限制,每个进程单独资源 + * 瀵瑰叏灞鐨凢D璧勬簮杩涜闄愬埗,姣忎釜杩涚▼鍗曠嫭璧勬簮 */ if (get_ncurr_cconn() >= ctx->max_ncconn || get_ncurr_cconn() @@ -302,7 +311,7 @@ static int listener_accept(struct context *ctx, struct conn *l) { return status; } - /*所有的客户端连接在exec之后全部关闭*/ + /*鎵鏈夌殑瀹㈡埛绔繛鎺ュ湪exec涔嬪悗鍏ㄩ儴鍏抽棴*/ status = fcntl(c->fd, F_SETFD, FD_CLOEXEC); if (status < 0) { log_error("fcntl FD_CLOEXEC on c %d from p %d failed: %s", @@ -312,7 +321,7 @@ static int listener_accept(struct context *ctx, struct conn *l) { } /* - * 对于ipv4与ipv6协议关闭negale算法 + * 瀵逛簬ipv4涓巌pv6鍗忚鍏抽棴negale绠楁硶 */ if (l->family == AF_INET || l->family == AF_INET6) { status = set_tcpnodelay(c->fd); diff --git a/src/agent/da_listener.h b/src/agent/da_listener.h index 44a672b..287a643 100644 --- a/src/agent/da_listener.h +++ b/src/agent/da_listener.h @@ -1,17 +1,26 @@ /* - * da_listener.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月3日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_LISTENER_H_ #define DA_LISTENER_H_ -#include +#include "da_util.h" #include #include -#include "da_util.h" +#include struct conn; struct context; diff --git a/src/agent/da_log.c b/src/agent/da_log.c index d89c7f9..76936b3 100644 --- a/src/agent/da_log.c +++ b/src/agent/da_log.c @@ -1,9 +1,18 @@ /* - * da_log.c - * - * Created on: 2014年11月29日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include @@ -31,6 +40,7 @@ static int noconsole = 0; //remote log area static struct sockaddr_in remote_log_addr; static int sockaddr_length = 0; +int da_gettid(void); void _set_remote_log_config_(const char *addr, int port, const char *own_addr, int own_port, int businessid, int iSwitch) { @@ -119,7 +129,7 @@ void _set_log_level_(int l) { void _set_log_switch_(int iSwitch) { - //0 不开启本地日志 + //0 涓嶅紑鍚湰鍦版棩蹇 __log_switch__ = iSwitch; } @@ -148,7 +158,7 @@ void _write_log_(int level, char *filename, const char *funcname, filename = basename(filename); off = snprintf(buf, LOGSIZE, "<%d>[%02d:%02d:%02d] pid[%d]: %s(%d)[%s]: ", level, tm.tm_hour, - tm.tm_min, tm.tm_sec, gettid(), filename, lineno, funcname); + tm.tm_min, tm.tm_sec, da_gettid(), filename, lineno, funcname); } if (off >= LOGSIZE) off = LOGSIZE - 1; diff --git a/src/agent/da_log.h b/src/agent/da_log.h index b837c68..69a2fcf 100644 --- a/src/agent/da_log.h +++ b/src/agent/da_log.h @@ -1,51 +1,77 @@ /* - * da_log.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年11月29日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_LOG_H_ #define DA_LOG_H_ -#include -#include -#include #include +#include #include #include -#include +#include #include #include #include #include +#include +#include #include "da_util.h" - extern int __log_level__; extern int __business_id__; -#define log_bare(lvl, fmt, args...) _write_log_(lvl, NULL, NULL, 0 , fmt, ##args) -#define log_generic(lvl, fmt, args...) _write_log_(lvl, __FILE__, __FUNCTION__, __LINE__ , fmt, ##args) -#define log_emerg(fmt, args...) log_generic(0, fmt, ##args) -#define log_alert(fmt, args...) log_generic(1, fmt, ##args) -#define log_crit(fmt, args...) log_generic(2, fmt, ##args) -#define log_error(fmt, args...) log_generic(3, fmt, ##args) -#define log_warning(fmt, args...) do{ if(__log_level__>=4)log_generic(4, fmt, ##args); } while(0) -#define log_notice(fmt, args...) do{ if(__log_level__>=5)log_generic(5, fmt, ##args); } while(0) -#define log_info(fmt, args...) do{ if(__log_level__>=6)log_generic(6, fmt, ##args); } while(0) -#define log_debug(fmt, args...) do{ if(__log_level__>=7)log_generic(7, fmt, ##args); } while(0) - +#define log_bare(lvl, fmt, args...) _write_log_(lvl, NULL, NULL, 0, fmt, ##args) +#define log_generic(lvl, fmt, args...) \ + _write_log_(lvl, __FILE__, __FUNCTION__, __LINE__, fmt, ##args) +#define log_emerg(fmt, args...) log_generic(0, fmt, ##args) +#define log_alert(fmt, args...) log_generic(1, fmt, ##args) +#define log_crit(fmt, args...) log_generic(2, fmt, ##args) +#define log_error(fmt, args...) log_generic(3, fmt, ##args) +#define log_warning(fmt, args...) \ + do { \ + if (__log_level__ >= 4) \ + log_generic(4, fmt, ##args); \ + } while (0) +#define log_notice(fmt, args...) \ + do { \ + if (__log_level__ >= 5) \ + log_generic(5, fmt, ##args); \ + } while (0) +#define log_info(fmt, args...) \ + do { \ + if (__log_level__ >= 6) \ + log_generic(6, fmt, ##args); \ + } while (0) +#define log_debug(fmt, args...) \ + do { \ + if (__log_level__ >= 7) \ + log_generic(7, fmt, ##args); \ + } while (0) void _init_log_(const char *app, const char *dir); void _set_log_level_(int l); void _set_log_switch_(int iSwitch); -void _write_log_ (int, char*, const char *, int, const char *, ...) __attribute__((format(printf,5,6))); +void _write_log_(int, char *, const char *, int, const char *, ...) + __attribute__((format(printf, 5, 6))); int _set_remote_log_fd_(); -void remote_log(int type, const char *key, int op_type, int op_result, char *content, long op_time, int cmd, int magic, int contentlen); +void remote_log(int type, const char *key, int op_type, int op_result, + char *content, long op_time, int cmd, int magic, + int contentlen); void write_stderr(const char *fmt, ...); - -static inline int gettid(void) { return syscall(__NR_gettid); } +static inline int da_gettid(void) { return syscall(__NR_gettid); } #endif /* DA_LOG_H_ */ diff --git a/src/agent/da_mem_pool.c b/src/agent/da_mem_pool.c index cf731a7..1a5c213 100644 --- a/src/agent/da_mem_pool.c +++ b/src/agent/da_mem_pool.c @@ -1,12 +1,18 @@ /* - * da_mem.c - * - * Created on: 2014年11月30日 - * Author: Jiansong - * - * 利用双向尾队列链接内存,经过测试发现为队列的效率略高于双向循环队列 - */ - +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_mem_pool.h" #include "da_log.h" #include "da_util.h" @@ -26,7 +32,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) struct pool_head *start; unsigned int align; - //16字节对齐 + //16瀛楄妭瀵归綈 align = 16; size = (size + align - 1) & -align; @@ -111,7 +117,7 @@ void pool_gc() { static int recurse; struct pool_head *entry; - //预防重复调用 + //棰勯槻閲嶅璋冪敤 if (recurse++) goto out; diff --git a/src/agent/da_mem_pool.h b/src/agent/da_mem_pool.h index 8f645e8..884d0d6 100644 --- a/src/agent/da_mem_pool.h +++ b/src/agent/da_mem_pool.h @@ -1,31 +1,39 @@ /* - * da_mem.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年11月30日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_MEM_POOL_H_ #define DA_MEM_POOL_H_ +#include "da_queue.h" #include #include -#include "da_queue.h" - #define MEM_F_SHARED 0x01 struct pool_head { - void **free_list; - CIRCLEQ_ENTRY(pool_head) pool_circqe; - unsigned int used; - unsigned int allocated; - unsigned int limit; - unsigned int minavail; - unsigned int size; - unsigned int flags; - unsigned int users; - char name[12]; + void **free_list; + CIRCLEQ_ENTRY(pool_head) pool_circqe; + unsigned int used; + unsigned int allocated; + unsigned int limit; + unsigned int minavail; + unsigned int size; + unsigned int flags; + unsigned int users; + char name[12]; }; CIRCLEQ_HEAD(pool_circqh, pool_head); @@ -40,7 +48,8 @@ void init_pools(); * returns it, otherwise creates this one. NULL is returned if no memory * is available for a new creation. */ -struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags); +struct pool_head *create_pool(char *name, unsigned int size, + unsigned int flags); /* Allocate a new entry for pool , and return it for immediate use. * NULL is returned if no memory is available for a new creation. @@ -78,17 +87,17 @@ void dump_pools(void); * first case, is updated to point to the * next element in the list. */ -#define pool_alloc(pool) \ -({ \ - void *__p; \ - if ((__p = (pool)->free_list) == NULL) \ - __p = pool_refill_alloc(pool); \ - else { \ - (pool)->free_list = *(void **)(pool)->free_list;\ - (pool)->used++; \ - } \ - __p; \ -}) +#define pool_alloc(pool) \ + ({ \ + void *__p; \ + if ((__p = (pool)->free_list) == NULL) \ + __p = pool_refill_alloc(pool); \ + else { \ + (pool)->free_list = *(void **)(pool)->free_list; \ + (pool)->used++; \ + } \ + __p; \ + }) /* * Puts a memory area back to the corresponding pool. @@ -99,13 +108,13 @@ void dump_pools(void); * pointer. Just like with the libc's free(), nothing * is done if is NULL. */ -#define pool_free(pool, ptr) \ -({ \ - if (likely((ptr) != NULL)) { \ - *(void **)(ptr) = (void *)(pool)->free_list; \ - (pool)->free_list = (void *)(ptr); \ - (pool)->used--; \ - } \ -}) +#define pool_free(pool, ptr) \ + ({ \ + if (likely((ptr) != NULL)) { \ + *(void **)(ptr) = (void *)(pool)->free_list; \ + (pool)->free_list = (void *)(ptr); \ + (pool)->used--; \ + } \ + }) #endif /* DA_MEM_H_ */ diff --git a/src/agent/da_msg.c b/src/agent/da_msg.c index 21a09a4..c86f789 100644 --- a/src/agent/da_msg.c +++ b/src/agent/da_msg.c @@ -1,9 +1,18 @@ /* - * da_msg.c - * - * Created on: 2014年12月2日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include "da_msg.h" @@ -108,7 +117,7 @@ int msg_init() { } msg_id = 0; frag_id = 0; - //红黑树,超时设置 + //绾㈤粦鏍戯紝瓒呮椂璁剧疆 rbtree_init(&tmo_rbt, &tmo_rbs); return 0; } @@ -226,7 +235,7 @@ struct msg *msg_get(struct conn *conn, bool request) { } /* - *释放msg所对应的资源,回收msg对象 + *閲婃斁msg鎵瀵瑰簲鐨勮祫婧愶紝鍥炴敹msg瀵硅薄 */ void msg_put(struct msg *m) { @@ -428,8 +437,8 @@ int msg_recv(struct context *ctx, struct conn *conn) { do { /* - * 从msg池中获取一个msg,当由于内存原因获取msg失败时置 - * conn->err标志,由于连接客户端关闭原因返回空的不处理 + * 浠巑sg姹犱腑鑾峰彇涓涓猰sg锛屽綋鐢变簬鍐呭瓨鍘熷洜鑾峰彇msg澶辫触鏃剁疆 + * conn->err鏍囧織锛岀敱浜庤繛鎺ュ鎴风鍏抽棴鍘熷洜杩斿洖绌虹殑涓嶅鐞 */ msg = conn->recv_next(ctx, conn, true); @@ -599,7 +608,7 @@ static int msg_send_chain(struct context *ctx, struct conn *conn, msg->sending = 0; conn->send_done(ctx, conn, msg); } - //因为要执行TAILQ_REMOVE(&send_msgq, msg, m_tqe); + //鍥犱负瑕佹墽琛孴AILQ_REMOVE(&send_msgq, msg, m_tqe); continue; } diff --git a/src/agent/da_msg.h b/src/agent/da_msg.h index cf1b941..ff5f8f9 100644 --- a/src/agent/da_msg.h +++ b/src/agent/da_msg.h @@ -1,22 +1,31 @@ /* - * da_msg.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月2日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_MSG_H_ #define DA_MSG_H_ -#include -#include -#include #include "compiler.h" +#include "da_array.h" +#include "da_buf.h" #include "da_queue.h" #include "da_rbtree.h" -#include "da_buf.h" -#include "da_array.h" #include "da_string.h" +#include +#include +#include struct msg; struct conn; @@ -28,130 +37,128 @@ typedef int (*msg_fragment_t)(struct msg *, uint32_t, struct msg_tqh *); typedef int (*msg_coalesce_t)(struct msg *r); typedef enum msg_parse_result { - MSG_PARSE_OK, /* parsing ok */ - MSG_PARSE_ERROR, /* parsing error */ - MSG_PARSE_REPAIR, /* more to parse -> repair parsed & unparsed data */ - MSG_PARSE_AGAIN, /* incomplete -> parse again */ + MSG_PARSE_OK, /* parsing ok */ + MSG_PARSE_ERROR, /* parsing error */ + MSG_PARSE_REPAIR, /* more to parse -> repair parsed & unparsed data */ + MSG_PARSE_AGAIN, /* incomplete -> parse again */ } msg_parse_result_t; -#define MSG_TYPE_CODEC(ACTION) \ - ACTION( NOP ) \ - ACTION( RSP_RESULTCODE ) \ - ACTION( RSP_RESULTSET ) \ - ACTION( REQ_SVRADMIN ) \ - ACTION( REQ_GET ) \ - ACTION( REQ_PURGE ) \ - ACTION( REQ_INSERT ) \ - ACTION( REQ_UPDATE ) \ - ACTION( REQ_DELETE ) \ - ACTION( REQ_REPLACE) \ - ACTION( REQ_FLUSH ) \ - ACTION( REQ_INVALIDATE ) \ - ACTION( REQ_MONITOR ) \ +#define MSG_TYPE_CODEC(ACTION) \ + ACTION(NOP) \ + ACTION(RSP_RESULTCODE) \ + ACTION(RSP_RESULTSET) \ + ACTION(REQ_SVRADMIN) \ + ACTION(REQ_GET) \ + ACTION(REQ_PURGE) \ + ACTION(REQ_INSERT) \ + ACTION(REQ_UPDATE) \ + ACTION(REQ_DELETE) \ + ACTION(REQ_REPLACE) \ + ACTION(REQ_FLUSH) \ + ACTION(REQ_INVALIDATE) \ + ACTION(REQ_MONITOR) #define DEFINE_ACTION(_name) MSG_##_name, -typedef enum msg_type { - MSG_TYPE_CODEC(DEFINE_ACTION) -} msg_type_t; +typedef enum msg_type { MSG_TYPE_CODEC(DEFINE_ACTION) } msg_type_t; #undef DEFINE_ACTION /* * start point and end point must within a mbuf */ struct keypos { - uint8_t *start; /* key start pos */ - uint8_t *end; /* key end pos */ + uint8_t *start; /* key start pos */ + uint8_t *end; /* key end pos */ }; struct msg { - TAILQ_ENTRY(msg) c_i_tqe; /*in client inmsg queue*/ - TAILQ_ENTRY(msg) c_o_tqe; /*in client omsg queue*/ - TAILQ_ENTRY(msg) s_i_tqe; /*in the server inmsg queue*/ - TAILQ_ENTRY(msg) o_tqe; /*in frag_msgq or send q*/ - - - uint64_t id; /* id for svr asyn operation*/ - int idx; /* index of server*/ - uint64_t serialnr; /* client serialnr*/ - msg_type_t cmd; /* msg type */ - struct string accesskey; /* accesskey for the msg*/ - uint64_t keytype; /* keytype of the primary key*/ - uint64_t keyCount; /* number of key count*/ - struct keypos keys[32]; /* array of keys */ - int64_t hitflag; - struct conn *owner; /* message owner - client | server */ - struct conn *peer_conn; /* message peer(client | server) connection*/ - uint64_t peerid; /* id of msg peer*/ - struct msg *peer; /* msg peer*/ - - int64_t affectrows; /* affect rows in result info*/ - uint64_t totalrows; /* total rows in result info*/ - uint64_t numrows; /* result rows*/ - uint32_t fieldnums; /* field nums*/ - int64_t resultcode; /* resultcode in result info*/ - - struct msg *frag_owner; /* owner of fragment message */ - uint32_t nfrag; /* # fragment */ - uint32_t nfrag_done; /* # fragment done */ - uint64_t frag_id; /* id of fragmented message */ - struct msg *frag_seq[32]; /* sequence of fragment message, map from keys to fragments*/ - - struct buf_stqh buf_q; /* buff list in msg*/ - uint32_t mlen; /* message length */ - uint64_t start_ts; /* start timestamp in usec */ - struct rbnode tmo_rbe; /* entry in time rbtree */ - struct rbnode msg_rbe; /* entry in backwork rbtree*/ - - msg_parse_t parser; /* msg parse */ - msg_parse_result_t parse_res; /* msg parse result*/ - - msg_fragment_t fragment; /* message fragment */ - msg_coalesce_t coalesce; /* message post-coalesce */ - - struct mbuf *keyendbuf; /* the buf that end key located*/ - uint8_t *keyendpos; - struct mbuf *keycountendbuf; /* the buf that keycount end*/ - uint8_t *keycountendpos; /* end position in buff*/ - struct mbuf *setsplitbuf; - uint8_t *setsplitpos; - uint64_t keycountstartlen; /* the length until the start of keycount*/ - uint64_t keycountlen; /* keycount len*/ - uint64_t keylen; /* all key len include length and key value*/ - - uint8_t flags; /* header flags*/ - uint32_t *seclen; /* header 8 section len in msg header*/ - uint8_t cur_parse_id; /* current parse id*/ - uint64_t cur_parse_type; /* current parse type*/ - int cur_parse_lenth; /* current parse lenth*/ - int state; /* current parse state*/ - int field; /* current parse field*/ - int sec_parsed_len; - int parsed_len; /* len has been parsed*/ - int subkeylen; /* parsing subkey length*/ - int subkeycount; /* parsing subkey count */ - uint8_t *pos; /* parser position marker */ - uint8_t *token; /* token marker */ - - int err; /* errno on error? */ - unsigned error :1; /* error? */ - unsigned ferror :1; /* error? */ - unsigned request :1; /* request? or response? */ - unsigned done :1; /* done? */ - unsigned fdone :1; /* all fragments are done? */ - unsigned swallow :1; /* swallow response? */ - - unsigned cli_inq:1; /*msg in client in msgq*/ - unsigned cli_outq:1; /*msg in client out msgq*/ - unsigned sev_inq:1; /*msg in server in msgq*/ - unsigned sev_msgtree:1; /*msg in server in msg tree*/ - unsigned sending:1; /*msg is sending*/ + TAILQ_ENTRY(msg) c_i_tqe; /*in client inmsg queue*/ + TAILQ_ENTRY(msg) c_o_tqe; /*in client omsg queue*/ + TAILQ_ENTRY(msg) s_i_tqe; /*in the server inmsg queue*/ + TAILQ_ENTRY(msg) o_tqe; /*in frag_msgq or send q*/ + + uint64_t id; /* id for svr asyn operation*/ + int idx; /* index of server*/ + uint64_t serialnr; /* client serialnr*/ + msg_type_t cmd; /* msg type */ + struct string accesskey; /* accesskey for the msg*/ + uint64_t keytype; /* keytype of the primary key*/ + uint64_t keyCount; /* number of key count*/ + struct keypos keys[32]; /* array of keys */ + int64_t hitflag; + struct conn *owner; /* message owner - client | server */ + struct conn *peer_conn; /* message peer(client | server) connection*/ + uint64_t peerid; /* id of msg peer*/ + struct msg *peer; /* msg peer*/ + + int64_t affectrows; /* affect rows in result info*/ + uint64_t totalrows; /* total rows in result info*/ + uint64_t numrows; /* result rows*/ + uint32_t fieldnums; /* field nums*/ + int64_t resultcode; /* resultcode in result info*/ + + struct msg *frag_owner; /* owner of fragment message */ + uint32_t nfrag; /* # fragment */ + uint32_t nfrag_done; /* # fragment done */ + uint64_t frag_id; /* id of fragmented message */ + struct msg *frag_seq[32]; /* sequence of fragment message, map from keys to + fragments*/ + + struct buf_stqh buf_q; /* buff list in msg*/ + uint32_t mlen; /* message length */ + uint64_t start_ts; /* start timestamp in usec */ + struct rbnode tmo_rbe; /* entry in time rbtree */ + struct rbnode msg_rbe; /* entry in backwork rbtree*/ + + msg_parse_t parser; /* msg parse */ + msg_parse_result_t parse_res; /* msg parse result*/ + + msg_fragment_t fragment; /* message fragment */ + msg_coalesce_t coalesce; /* message post-coalesce */ + + struct mbuf *keyendbuf; /* the buf that end key located*/ + uint8_t *keyendpos; + struct mbuf *keycountendbuf; /* the buf that keycount end*/ + uint8_t *keycountendpos; /* end position in buff*/ + struct mbuf *setsplitbuf; + uint8_t *setsplitpos; + uint64_t keycountstartlen; /* the length until the start of keycount*/ + uint64_t keycountlen; /* keycount len*/ + uint64_t keylen; /* all key len include length and key value*/ + + uint8_t flags; /* header flags*/ + uint32_t *seclen; /* header 8 section len in msg header*/ + uint8_t cur_parse_id; /* current parse id*/ + uint64_t cur_parse_type; /* current parse type*/ + int cur_parse_lenth; /* current parse lenth*/ + int state; /* current parse state*/ + int field; /* current parse field*/ + int sec_parsed_len; + int parsed_len; /* len has been parsed*/ + int subkeylen; /* parsing subkey length*/ + int subkeycount; /* parsing subkey count */ + uint8_t *pos; /* parser position marker */ + uint8_t *token; /* token marker */ + + int err; /* errno on error? */ + unsigned error : 1; /* error? */ + unsigned ferror : 1; /* error? */ + unsigned request : 1; /* request? or response? */ + unsigned done : 1; /* done? */ + unsigned fdone : 1; /* all fragments are done? */ + unsigned swallow : 1; /* swallow response? */ + + unsigned cli_inq : 1; /*msg in client in msgq*/ + unsigned cli_outq : 1; /*msg in client out msgq*/ + unsigned sev_inq : 1; /*msg in server in msgq*/ + unsigned sev_msgtree : 1; /*msg in server in msg tree*/ + unsigned sending : 1; /*msg is sending*/ }; TAILQ_HEAD(msg_tqh, msg); void msg_tmo_delete(struct msg *msg); void msg_tmo_insert(struct msg *msg, struct conn *conn); -struct msg * msg_tmo_min(void); +struct msg *msg_tmo_min(void); int msg_init(); struct msg *msg_get(struct conn *conn, bool request); int msg_deinit(); @@ -163,7 +170,9 @@ bool msg_empty(struct msg *msg); int msg_recv(struct context *ctx, struct conn *conn); int msg_send(struct context *ctx, struct conn *conn); uint64_t msg_gen_frag_id(void); -int msg_append_buf(struct msg *msg, struct mbuf *sbuf, uint8_t *pos, size_t len); -struct mbuf *msg_insert_mem_bulk(struct msg *msg,struct mbuf *mbuf,uint8_t *pos,size_t len); +int msg_append_buf(struct msg *msg, struct mbuf *sbuf, uint8_t *pos, + size_t len); +struct mbuf *msg_insert_mem_bulk(struct msg *msg, struct mbuf *mbuf, + uint8_t *pos, size_t len); uint32_t msg_backend_idx(struct msg *msg, uint8_t *key, uint32_t keylen); #endif /* DA_MSG_H_ */ diff --git a/src/agent/da_request.c b/src/agent/da_request.c index a57f778..a2b0800 100644 --- a/src/agent/da_request.c +++ b/src/agent/da_request.c @@ -1,9 +1,18 @@ /* - * da_request.c - * - * Created on: 2014年12月9日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include "da_request.h" @@ -278,7 +287,7 @@ static void req_forward(struct context *ctx, struct conn *c_conn, struct server_pool *pool; struct cache_instance *ci; - /*insert msg to client imsgq,waiting for + /*insert msg to client imsgq锛寃aiting for *the response,first add to backworker's queue */ c_conn->enqueue_inq(ctx, c_conn, msg); diff --git a/src/agent/da_request.h b/src/agent/da_request.h index f8ad275..29d4d41 100644 --- a/src/agent/da_request.h +++ b/src/agent/da_request.h @@ -1,8 +1,17 @@ /* - * da_request.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月9日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_REQUEST_H_ @@ -15,19 +24,26 @@ struct conn; void req_put(struct msg *msg); struct msg *req_recv_next(struct context *ctx, struct conn *conn, bool alloc); -void req_recv_done(struct context *ctx, struct conn *conn, struct msg *msg,struct msg *nmsg); -void req_client_enqueue_omsgq(struct context *ctx, struct conn *conn,struct msg *msg); -void req_client_dequeue_omsgq(struct context *ctx, struct conn *conn,struct msg *msg); -void req_client_enqueue_imsgq(struct context *ctx, struct conn *conn,struct msg *msg); -void req_client_dequeue_imsgq(struct context *ctx, struct conn *conn,struct msg *msg); +void req_recv_done(struct context *ctx, struct conn *conn, struct msg *msg, + struct msg *nmsg); +void req_client_enqueue_omsgq(struct context *ctx, struct conn *conn, + struct msg *msg); +void req_client_dequeue_omsgq(struct context *ctx, struct conn *conn, + struct msg *msg); +void req_client_enqueue_imsgq(struct context *ctx, struct conn *conn, + struct msg *msg); +void req_client_dequeue_imsgq(struct context *ctx, struct conn *conn, + struct msg *msg); bool req_done(struct conn *c, struct msg *msg); -void req_server_enqueue_imsgq(struct context *ctx, struct conn *conn,struct msg *msg); -void req_server_dequeue_imsgq(struct context *ctx, struct conn *conn,struct msg *msg); +void req_server_enqueue_imsgq(struct context *ctx, struct conn *conn, + struct msg *msg); +void req_server_dequeue_imsgq(struct context *ctx, struct conn *conn, + struct msg *msg); struct msg *req_send_next(struct context *ctx, struct conn *conn); void req_send_done(struct context *ctx, struct conn *conn, struct msg *msg); void req_server_de_msgtree(struct context *ctx, struct conn *conn, - struct msg *msg); + struct msg *msg); void req_server_en_msgtree(struct context *ctx, struct conn *conn, - struct msg *msg); + struct msg *msg); bool req_error(struct conn *conn, struct msg *msg); #endif /* DA_REQUEST_H_ */ diff --git a/src/agent/da_response.c b/src/agent/da_response.c index 013957f..49ee388 100644 --- a/src/agent/da_response.c +++ b/src/agent/da_response.c @@ -1,9 +1,18 @@ /* - * da_response.c - * - * Created on: 2014年12月9日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include @@ -182,7 +191,7 @@ void rsp_recv_done(struct context *ctx, struct conn *conn, struct msg *msg, return; } - //Get请求信息放在此处进行统计 + //Get璇锋眰淇℃伅鏀惧湪姝ゅ杩涜缁熻 if(req->cmd == MSG_REQ_GET) { stats_pool_incr(ctx, c_conn->owner, pool_requests_get); diff --git a/src/agent/da_response.h b/src/agent/da_response.h index 3b23018..e9e7587 100644 --- a/src/agent/da_response.h +++ b/src/agent/da_response.h @@ -1,8 +1,17 @@ /* - * da_response.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月9日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_RESPONSE_H_ @@ -12,11 +21,11 @@ struct conn; struct msg; struct context; - void rsp_put(struct msg *msg); struct msg *rsp_get(struct conn *conn); struct msg *rsp_recv_next(struct context *ctx, struct conn *conn, bool alloc); -void rsp_recv_done(struct context *ctx, struct conn *conn, struct msg *msg,struct msg *nmsg); +void rsp_recv_done(struct context *ctx, struct conn *conn, struct msg *msg, + struct msg *nmsg); void rsp_forward(struct context *ctx, struct conn *s_conn, struct msg *req); struct msg *rsp_send_next(struct context *ctx, struct conn *conn); void rsp_send_done(struct context *ctx, struct conn *conn, struct msg *msg); diff --git a/src/agent/da_server.c b/src/agent/da_server.c index abd54a5..ecbfb6d 100644 --- a/src/agent/da_server.c +++ b/src/agent/da_server.c @@ -1,9 +1,18 @@ /* - * da_server.c - * - * Created on: 2014年12月2日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include "da_server.h" #include "da_hashkit.h" @@ -17,10 +26,10 @@ #include "da_stats.h" #include "da_time.h" -static int keep_alive = 1; // 开启keepalive属性. 缺省值: 0(关闭) -static int keep_idle = 5; // 如果在60秒内没有任何数据交互,则进行探测. 缺省值:7200(s) -static int keep_interval = 5; // 探测时发探测包的时间间隔为5秒. 缺省值:75(s) -static int keep_count = 1; // 探测重试的次数. 全部超时则认定连接失效..缺省值:9(次) +static int keep_alive = 1; // 寮鍚痥eepalive灞炴. 缂虹渷鍊: 0(鍏抽棴) +static int keep_idle = 5; // 濡傛灉鍦60绉掑唴娌℃湁浠讳綍鏁版嵁浜や簰,鍒欒繘琛屾帰娴. 缂虹渷鍊:7200(s) +static int keep_interval = 5; // 鎺㈡祴鏃跺彂鎺㈡祴鍖呯殑鏃堕棿闂撮殧涓5绉. 缂虹渷鍊:75(s) +static int keep_count = 1; // 鎺㈡祴閲嶈瘯鐨勬鏁. 鍏ㄩ儴瓒呮椂鍒欒瀹氳繛鎺ュけ鏁..缂虹渷鍊:9(娆) void instance_ref(struct conn *conn, void *owner) { @@ -876,7 +885,7 @@ int server_pool_run(struct server_pool *pool) { } /* - * 对于每个server pool 构建后台的服务器结构,构建hash环 + * 瀵逛簬姣忎釜server pool 鏋勫缓鍚庡彴鐨勬湇鍔″櫒缁撴瀯锛屾瀯寤篽ash鐜 */ static int server_pool_each_run(void *elem, void *data) { return server_pool_run(elem); @@ -885,7 +894,7 @@ static int server_pool_each_run(void *elem, void *data) { /* - * 初始化server pool + * 鍒濆鍖杝erver pool */ int server_pool_init(struct array *server_pool, struct array *conf_pool, struct context *ctx) { @@ -902,7 +911,7 @@ int server_pool_init(struct array *server_pool, struct array *conf_pool, } /* transform conf pool to server pool */ - // 对于conf_pool中的每个对象调用conf_pool_each_transform函数 + // 瀵逛簬conf_pool涓殑姣忎釜瀵硅薄璋冪敤conf_pool_each_transform鍑芥暟 status = array_each(conf_pool, conf_pool_each_transform, server_pool); if (status != 0) { server_pool_deinit(server_pool); diff --git a/src/agent/da_server.h b/src/agent/da_server.h index 4b167e8..788ce4e 100644 --- a/src/agent/da_server.h +++ b/src/agent/da_server.h @@ -1,111 +1,120 @@ /* - * da_server.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月2日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_SERVER_H_ #define DA_SERVER_H_ +#include "da_array.h" #include "da_conn.h" #include "da_string.h" -#include "da_array.h" -#include #include +#include typedef uint32_t (*hash_t)(const char *, size_t); #define ERROR_UPPER_LIMIT 1 #define FAIL_TIME_LIMIT 6 struct continuum { - uint32_t index; /* server index */ - uint32_t value; /* hash value */ + uint32_t index; /* server index */ + uint32_t value; /* hash value */ }; struct cache_instance { - struct string pname; - void *owner; - int nerr; - int idx; - uint16_t port; /* port */ - uint32_t weight; /* weight */ - int family; /* socket family */ - socklen_t addrlen; /* socket length */ - struct sockaddr *addr; /* socket address (ref in conf_server) */ - uint32_t ns_conn_q; /* # server connection */ - struct conn_tqh s_conn_q; /*server connection*/ - uint64_t last_failure_ms; /*cahche the failure time*/ - uint16_t failure_num;/*cache failure time*/ - int num; + struct string pname; + void *owner; + int nerr; + int idx; + uint16_t port; /* port */ + uint32_t weight; /* weight */ + int family; /* socket family */ + socklen_t addrlen; /* socket length */ + struct sockaddr *addr; /* socket address (ref in conf_server) */ + uint32_t ns_conn_q; /* # server connection */ + struct conn_tqh s_conn_q; /*server connection*/ + uint64_t last_failure_ms; /*cahche the failure time*/ + uint16_t failure_num; /*cache failure time*/ + int num; }; - struct server { - uint32_t idx; /* server index */ - struct server_pool *owner; /* owner pool */ - uint16_t high_prty_idx; - uint16_t high_prty_cnt; - uint16_t low_prty_idx; - uint16_t low_prty_cnt; - struct string name; /* name (ref in conf_server) */ - int weight; - int replica_enable; - struct cache_instance *master; - struct array high_ptry_ins; - struct array low_prty_ins; + uint32_t idx; /* server index */ + struct server_pool *owner; /* owner pool */ + uint16_t high_prty_idx; + uint16_t high_prty_cnt; + uint16_t low_prty_idx; + uint16_t low_prty_cnt; + struct string name; /* name (ref in conf_server) */ + int weight; + int replica_enable; + struct cache_instance *master; + struct array high_ptry_ins; + struct array low_prty_ins; }; struct server_pool { - uint32_t idx; /* pool index */ - uint32_t mid; /* pool manager id*/ - struct context *ctx; /* owner context */ - struct conn *listener; - struct conn_tqh c_conn_q; /*client connection*/ - uint32_t c_conn_count; /* number of client connection */ - struct array server; /* server[] */ - uint32_t ncontinuum; /* # continuum points */ - uint32_t nserver_continuum; /* # servers - live and dead on continuum (const) */ - struct continuum *continuum; /* continuum */ + uint32_t idx; /* pool index */ + uint32_t mid; /* pool manager id*/ + struct context *ctx; /* owner context */ + struct conn *listener; + struct conn_tqh c_conn_q; /*client connection*/ + uint32_t c_conn_count; /* number of client connection */ + struct array server; /* server[] */ + uint32_t ncontinuum; /* # continuum points */ + uint32_t + nserver_continuum; /* # servers - live and dead on continuum (const) */ + struct continuum *continuum; /* continuum */ + + struct string name; /* pool name (ref in conf_pool) */ + struct string addrstr; /* pool address (ref in conf_pool) */ + struct string accesskey; /* access token for this pool */ + uint16_t port; /* port */ + int family; /* socket family */ + socklen_t addrlen; /* socket length */ + struct sockaddr *addr; /* socket address (ref in conf_pool) */ + int key_hash_type; /* key hash type (hash_type_t) */ + hash_t key_hash; /* key hasher */ + int backlog; /* listen backlog */ + int timeout; /* timeout in msec */ + uint32_t client_connections; /* maximum # client connection */ + uint32_t server_connections; /* maximum # server connection */ + int replica_enable; /*Replica enable for whole system*/ + struct string module_idc; /*sp IDC*/ + unsigned preconnect : 1; /* preconnect? */ + int main_report; + int instance_report; + int auto_remove_replica; - struct string name; /* pool name (ref in conf_pool) */ - struct string addrstr; /* pool address (ref in conf_pool) */ - struct string accesskey; /* access token for this pool */ - uint16_t port; /* port */ - int family; /* socket family */ - socklen_t addrlen; /* socket length */ - struct sockaddr *addr; /* socket address (ref in conf_pool) */ - int key_hash_type; /* key hash type (hash_type_t) */ - hash_t key_hash; /* key hasher */ - int backlog; /* listen backlog */ - int timeout; /* timeout in msec */ - uint32_t client_connections;/* maximum # client connection */ - uint32_t server_connections;/* maximum # server connection */ - int replica_enable; /*Replica enable for whole system*/ - struct string module_idc; /*sp IDC*/ - unsigned preconnect :1; /* preconnect? */ - int main_report; - int instance_report; - int auto_remove_replica; - - int top_percentile_enable; - int top_percentile_fd; - struct sockaddr_in top_percentile_addr; - int top_percentile_addr_len; - struct remote_param *top_percentile_param; + int top_percentile_enable; + int top_percentile_fd; + struct sockaddr_in top_percentile_addr; + int top_percentile_addr_len; + struct remote_param *top_percentile_param; }; uint32_t server_pool_idx(struct server_pool *pool, uint8_t *key, - uint32_t keylen); + uint32_t keylen); void server_close(struct context *ctx, struct conn *conn); void instance_ref(struct conn *conn, void *owner); void instance_unref(struct conn *conn); int server_active(struct conn *conn); int server_init(struct array *server, struct array *conf_server, - struct server_pool *sp); + struct server_pool *sp); void server_connected(struct context *ctx, struct conn *conn); int server_init(struct array *server, struct array *conf_server, - struct server_pool *sp); + struct server_pool *sp); void instance_deinit(struct array *server); void server_deinit(struct array *server); int server_pool_preconnect(struct context *ctx); @@ -113,10 +122,10 @@ void server_pool_disconnect(struct context *ctx); int server_pool_run(struct server_pool *pool); void server_pool_deinit(struct array *server_pool); int server_pool_init(struct array *server_pool, struct array *conf_pool, - struct context *ctx); + struct context *ctx); int server_timeout(struct conn *conn); -struct conn * server_pool_conn(struct context *ctx, struct server_pool *pool, - struct msg *msg); +struct conn *server_pool_conn(struct context *ctx, struct server_pool *pool, + struct msg *msg); int incr_instance_failure_time(struct cache_instance *ci); int decr_instance_failure_time(struct msg *msg); #endif /* DA_SERVER_H_ */ diff --git a/src/agent/da_signal.c b/src/agent/da_signal.c index 13bfe0a..3e8840e 100644 --- a/src/agent/da_signal.c +++ b/src/agent/da_signal.c @@ -1,9 +1,18 @@ /* - * da_signal.c - * - * Created on: 2014年12月2日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_signal.h" #include "da_log.h" diff --git a/src/agent/da_signal.h b/src/agent/da_signal.h index a549104..d947121 100644 --- a/src/agent/da_signal.h +++ b/src/agent/da_signal.h @@ -1,33 +1,42 @@ /* - * da_signal.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月2日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_SIGNAL_H_ #define DA_SIGNAL_H_ +#include "compiler.h" +#include "da_queue.h" #include #include -#include "da_queue.h" -#include "compiler.h" #define MAX_SIGNAL 256 /* those are highly dynamic and stored in pools */ struct sig_handler { - TAILQ_ENTRY(sig_handler) sig_tqe; - void *handler; /* function to call or task to wake up */ - int arg; /*arg needed when process function or signals*/ + TAILQ_ENTRY(sig_handler) sig_tqe; + void *handler; /* function to call or task to wake up */ + int arg; /*arg needed when process function or signals*/ }; TAILQ_HEAD(sig_tqh, sig_handler); /* one per signal */ struct signal_descriptor { - int count; /* number of times raised */ - struct sig_tqh sig_tqh; /* sig_handler */ + int count; /* number of times raised */ + struct sig_tqh sig_tqh; /* sig_handler */ }; extern volatile int signal_queue_len; @@ -38,15 +47,14 @@ void signal_handler(int sig); void __signal_process_queue(); int signal_init(); void deinit_signals(); -struct sig_handler *signal_register_fct(int sig,void (*fct)(struct sig_handler *), int arg); +struct sig_handler * +signal_register_fct(int sig, void (*fct)(struct sig_handler *), int arg); void signal_unregister_handler(int sig, struct sig_handler *handler); void signal_unregister_target(int sig, void *target); - - static inline void signal_process_queue() { - if (unlikely(signal_queue_len > 0)) - __signal_process_queue(); + if (unlikely(signal_queue_len > 0)) + __signal_process_queue(); } #endif /* DA_SIGNAL_H_ */ diff --git a/src/agent/da_stats.c b/src/agent/da_stats.c index 553a294..ad90152 100644 --- a/src/agent/da_stats.c +++ b/src/agent/da_stats.c @@ -1,9 +1,18 @@ /* - * da_stats.c - * - * Created on: 2015骞3鏈9鏃 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include diff --git a/src/agent/da_stats.h b/src/agent/da_stats.h index 3a1414a..42f9e70 100644 --- a/src/agent/da_stats.h +++ b/src/agent/da_stats.h @@ -1,15 +1,24 @@ /* - * da_stats.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2015年3月9日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_STATS_H_ #define DA_STATS_H_ -#include "da_string.h" #include "da_array.h" +#include "da_string.h" struct event_base; struct server_pool; @@ -17,236 +26,239 @@ struct context; struct server; struct cache_instance; -typedef void (*event_stats_cb_t)(void *,int); +typedef void (*event_stats_cb_t)(void *, int); #define STATS_FILE "da.stats" #define STATS_DIR "../stats/" -#define STATS_INTERVAL (10 * 1000) /* in msec */ -#define DEFAULT_HTTP_TIMEOUT 5 /*default heep connect and request timeout in second*/ - -#define STATS_POOL_CODEC(ACTION) \ - /* client behavior */ \ - ACTION( client_eof, STATS_COUNTER, "# eof on client connections") \ - ACTION( client_err, STATS_COUNTER, "# errors on client connections") \ - ACTION( client_connections, STATS_GAUGE, "# active client connections") \ - /* forwarder behavior */ \ - ACTION( fragment_error, STATS_COUNTER, "# times we encountered a fragment error") \ - ACTION( forward_error, STATS_COUNTER, "# times we encountered a forwarding error") \ - ACTION( coalesce_error, STATS_COUNTER, "# times we encountered a coalesce error") \ - /* data behavior */ \ - ACTION( pool_requests, STATS_COUNTER, "# pool requests") \ - ACTION( pool_requests_get, STATS_COUNTER, "# pool requests get") \ - ACTION( pool_request_bytes, STATS_COUNTER, " pool total request bytes") \ - ACTION( pool_responses, STATS_COUNTER, "# pool responses") \ - ACTION( pool_response_bytes, STATS_COUNTER, " pool total response bytes") \ - ACTION( pool_withoutkey_req, STATS_COUNTER, "# pool without key requests") \ - ACTION( pool_tech_hit, STATS_COUNTER, "# pool tech hit times") \ - ACTION( pool_logic_hit, STATS_COUNTER, "# pool logic hit times") \ - ACTION( pool_elaspe_time, STATS_COUNTER, "# pool elapse time(us)") \ - ACTION( pool_package_split, STATS_COUNTER, "# pool package split times") \ - ACTION( pool_request_get_keys, STATS_COUNTER, "# pool get request key count") \ - -#define STATS_SERVER_CODEC(ACTION) \ - /* server behavior */ \ - ACTION( server_eof, STATS_COUNTER, "# eof on server connections") \ - ACTION( server_err, STATS_COUNTER, "# errors on server connections") \ - ACTION( server_connections, STATS_GAUGE, "# active server connections") \ - /* data behavior */ \ - ACTION( server_requests, STATS_COUNTER, "# server requests") \ - ACTION( server_request_bytes, STATS_COUNTER, "server total request bytes") \ - ACTION( server_responses, STATS_COUNTER, "# server responses") \ - ACTION( server_response_bytes, STATS_COUNTER, "server total response bytes") \ - ACTION( server_request_error, STATS_COUNTER, "# server requests error") \ - ACTION( server_in_queue, STATS_GAUGE, "# requests in incoming queue") \ - ACTION( server_in_tree, STATS_GAUGE, "# requests in backwork search tree") \ +#define STATS_INTERVAL (10 * 1000) /* in msec */ +#define DEFAULT_HTTP_TIMEOUT \ + 5 /*default heep connect and request timeout in second*/ + +#define STATS_POOL_CODEC(ACTION) \ + /* client behavior */ \ + ACTION(client_eof, STATS_COUNTER, "# eof on client connections") \ + ACTION(client_err, STATS_COUNTER, "# errors on client connections") \ + ACTION(client_connections, STATS_GAUGE, "# active client connections") \ + /* forwarder behavior */ \ + ACTION(fragment_error, STATS_COUNTER, \ + "# times we encountered a fragment error") \ + ACTION(forward_error, STATS_COUNTER, \ + "# times we encountered a forwarding error") \ + ACTION(coalesce_error, STATS_COUNTER, \ + "# times we encountered a coalesce error") \ + /* data behavior */ \ + ACTION(pool_requests, STATS_COUNTER, "# pool requests") \ + ACTION(pool_requests_get, STATS_COUNTER, "# pool requests get") \ + ACTION(pool_request_bytes, STATS_COUNTER, " pool total request bytes") \ + ACTION(pool_responses, STATS_COUNTER, "# pool responses") \ + ACTION(pool_response_bytes, STATS_COUNTER, " pool total response bytes") \ + ACTION(pool_withoutkey_req, STATS_COUNTER, "# pool without key requests") \ + ACTION(pool_tech_hit, STATS_COUNTER, "# pool tech hit times") \ + ACTION(pool_logic_hit, STATS_COUNTER, "# pool logic hit times") \ + ACTION(pool_elaspe_time, STATS_COUNTER, "# pool elapse time(us)") \ + ACTION(pool_package_split, STATS_COUNTER, "# pool package split times") \ + ACTION(pool_request_get_keys, STATS_COUNTER, "# pool get request key count") + +#define STATS_SERVER_CODEC(ACTION) \ + /* server behavior */ \ + ACTION(server_eof, STATS_COUNTER, "# eof on server connections") \ + ACTION(server_err, STATS_COUNTER, "# errors on server connections") \ + ACTION(server_connections, STATS_GAUGE, "# active server connections") \ + /* data behavior */ \ + ACTION(server_requests, STATS_COUNTER, "# server requests") \ + ACTION(server_request_bytes, STATS_COUNTER, "server total request bytes") \ + ACTION(server_responses, STATS_COUNTER, "# server responses") \ + ACTION(server_response_bytes, STATS_COUNTER, "server total response bytes") \ + ACTION(server_request_error, STATS_COUNTER, "# server requests error") \ + ACTION(server_in_queue, STATS_GAUGE, "# requests in incoming queue") \ + ACTION(server_in_tree, STATS_GAUGE, "# requests in backwork search tree") typedef enum stats_type { - STATS_INVALID, - STATS_COUNTER, /* monotonic accumulator */ - STATS_GAUGE, /* non-monotonic accumulator */ - STATS_TIMESTAMP, /* monotonic timestamp (in nsec) */ - STATS_SENTINEL + STATS_INVALID, + STATS_COUNTER, /* monotonic accumulator */ + STATS_GAUGE, /* non-monotonic accumulator */ + STATS_TIMESTAMP, /* monotonic timestamp (in nsec) */ + STATS_SENTINEL } stats_type_t; /* struct for flush data to stats file*/ -struct _map_item -{ - char filename[256]; - void *_map_start; - int _map_size; +struct _map_item { + char filename[256]; + void *_map_start; + int _map_size; }; -struct stats_file_pool_head -{ - char poolname[256]; - uint32_t mid; - uint32_t poolfields; - uint32_t servernum; +struct stats_file_pool_head { + char poolname[256]; + uint32_t mid; + uint32_t poolfields; + uint32_t servernum; }; -struct stats_file_server_head -{ - char servername[256]; - uint32_t sid; - uint32_t serverfields; +struct stats_file_server_head { + char servername[256]; + uint32_t sid; + uint32_t serverfields; }; -struct stats_file_item -{ - stats_type_t type; - int64_t stat_once; - uint64_t stat_all; +struct stats_file_item { + stats_type_t type; + int64_t stat_once; + uint64_t stat_all; }; -struct stats_file_server -{ - struct stats_file_server_head *shead; - struct stats_file_item *server_item_list; +struct stats_file_server { + struct stats_file_server_head *shead; + struct stats_file_item *server_item_list; }; -struct stats_file_pool -{ - struct stats_file_pool_head *phead; - struct stats_file_item *pool_item_list; - struct array stats_file_servers; +struct stats_file_pool { + struct stats_file_pool_head *phead; + struct stats_file_item *pool_item_list; + struct array stats_file_servers; }; struct stats_metric { - stats_type_t type; /* type */ - struct string name; /* name (ref) */ - union { - int64_t counter; /* accumulating counter */ - int64_t timestamp; /* monotonic timestamp */ - } value; + stats_type_t type; /* type */ + struct string name; /* name (ref) */ + union { + int64_t counter; /* accumulating counter */ + int64_t timestamp; /* monotonic timestamp */ + } value; }; struct stats_server { - struct string name; /* server name (ref) */ - struct array metric; /* stats_metric[] for server codec */ + struct string name; /* server name (ref) */ + struct array metric; /* stats_metric[] for server codec */ }; struct stats_pool { - uint32_t mid; - uint16_t port; - struct string name; /* pool name (ref) */ - struct array metric; /* stats_metric[] for pool codec */ - struct array server; /* stats_server[] */ - int main_report; - int instance_report; + uint32_t mid; + uint16_t port; + struct string name; /* pool name (ref) */ + struct array metric; /* stats_metric[] for pool codec */ + struct array server; /* stats_server[] */ + int main_report; + int instance_report; }; struct stats { - int interval; /* stats aggregation interval */ - uint64_t start_ts; /* start timestamp of da */ - struct array _map_items; /* _map_item[] */ - struct array aggregator; /* stats_file_pool[](b,a+b) */ - struct array current; /* stats_pool[] (a)*/ - struct array shadow; /* stats_pool[] (b)*/ - pthread_t tid; /* stats aggregator thread */ - char localip[16]; /* ip address of this machine */ - volatile int aggregate; /* shadow (b) aggregate? */ - volatile int updated; /* current (a) updated? */ + int interval; /* stats aggregation interval */ + uint64_t start_ts; /* start timestamp of da */ + struct array _map_items; /* _map_item[] */ + struct array aggregator; /* stats_file_pool[](b,a+b) */ + struct array current; /* stats_pool[] (a)*/ + struct array shadow; /* stats_pool[] (b)*/ + pthread_t tid; /* stats aggregator thread */ + char localip[16]; /* ip address of this machine */ + volatile int aggregate; /* shadow (b) aggregate? */ + volatile int updated; /* current (a) updated? */ }; #define DEFINE_ACTION(_name, _type, _desc) STATS_POOL_##_name, typedef enum stats_pool_field { - STATS_POOL_CODEC(DEFINE_ACTION) - STATS_POOL_NFIELD + STATS_POOL_CODEC(DEFINE_ACTION) STATS_POOL_NFIELD } stats_pool_field_t; #undef DEFINE_ACTION #define DEFINE_ACTION(_name, _type, _desc) STATS_SERVER_##_name, typedef enum stats_server_field { - STATS_SERVER_CODEC(DEFINE_ACTION) - STATS_SERVER_NFIELD + STATS_SERVER_CODEC(DEFINE_ACTION) STATS_SERVER_NFIELD } stats_server_field_t; #undef DEFINE_ACTION /* struct for report data to monitor centor*/ -struct _ReportParam -{ - uint32_t uCType; - uint32_t uEType; - int64_t iData1; - int64_t iData2; - int64_t iExtra; - int64_t iDateTime; - uint32_t uCmd; +struct _ReportParam { + uint32_t uCType; + uint32_t uEType; + int64_t iData1; + int64_t iData2; + int64_t iExtra; + int64_t iDateTime; + uint32_t uCmd; }; -enum -{ - REQ_ELAPSE = 1, - GET_HIT_RATIO, - REQ_COUNT, - NET_IN_FLOW, - NET_OUT_FLOW = 6, - RESP_COUNT, - GET_TECH_HIT_RATIO = 9, - AGENT_TIMES = 15, //agent count. data1 req, data2 res - AGENT_TIME = 16, //agent time. data1 req count, data2 time - AGENT_ERROR = 17, //agent error count. data1 count, data2 default 0 - AGENT_HIT = 18, //agent logic ratio. data1 get count, data2 hit count - AGENT_TECH_HIT = 19, //agent tech ratio. data1 get count, data2 hit count - AGENT_INOUT_BYTES = 20, //agent request and response bytes. data1 request bytes, data2 response bytes - CONN_COUNT =100 +enum { + REQ_ELAPSE = 1, + GET_HIT_RATIO, + REQ_COUNT, + NET_IN_FLOW, + NET_OUT_FLOW = 6, + RESP_COUNT, + GET_TECH_HIT_RATIO = 9, + AGENT_TIMES = 15, // agent count. data1 req, data2 res + AGENT_TIME = 16, // agent time. data1 req count, data2 time + AGENT_ERROR = 17, // agent error count. data1 count, data2 default 0 + AGENT_HIT = 18, // agent logic ratio. data1 get count, data2 hit count + AGENT_TECH_HIT = 19, // agent tech ratio. data1 get count, data2 hit count + AGENT_INOUT_BYTES = 20, // agent request and response bytes. data1 request + // bytes, data2 response bytes + CONN_COUNT = 100 }; -enum -{ - FIVE_SEC = 1, - TEN_SEC, - THIRTY_SEC, - ONE_MIN, +enum { + FIVE_SEC = 1, + TEN_SEC, + THIRTY_SEC, + ONE_MIN, }; -enum -{ - CMD_INSERT = 0, - CMD_UPDATE, +enum { + CMD_INSERT = 0, + CMD_UPDATE, }; #if defined DA_STATS && DA_STATS == 1 -#define stats_pool_incr(_ctx, _pool, _name) do { \ - _stats_pool_incr(_ctx, _pool, STATS_POOL_##_name); \ -} while (0) - -#define stats_pool_decr(_ctx, _pool, _name) do { \ - _stats_pool_decr(_ctx, _pool, STATS_POOL_##_name); \ -} while (0) - -#define stats_pool_incr_by(_ctx, _pool, _name, _val) do { \ - _stats_pool_incr_by(_ctx, _pool, STATS_POOL_##_name, _val); \ -} while (0) - -#define stats_pool_decr_by(_ctx, _pool, _name, _val) do { \ - _stats_pool_decr_by(_ctx, _pool, STATS_POOL_##_name, _val); \ -} while (0) - -#define stats_pool_set_ts(_ctx, _pool, _name, _val) do { \ - _stats_pool_set_ts(_ctx, _pool, STATS_POOL_##_name, _val); \ -} while (0) - -#define stats_server_incr(_ctx, _server, _name) do { \ - _stats_server_incr(_ctx, _server, STATS_SERVER_##_name); \ -} while (0) - -#define stats_server_decr(_ctx, _server, _name) do { \ - _stats_server_decr(_ctx, _server, STATS_SERVER_##_name); \ -} while (0) - -#define stats_server_incr_by(_ctx, _server, _name, _val) do { \ - _stats_server_incr_by(_ctx, _server, STATS_SERVER_##_name, _val); \ -} while (0) - -#define stats_server_decr_by(_ctx, _server, _name, _val) do { \ - _stats_server_decr_by(_ctx, _server, STATS_SERVER_##_name, _val); \ -} while (0) - -#define stats_server_set_ts(_ctx, _server, _name, _val) do { \ - _stats_server_set_ts(_ctx, _server, STATS_SERVER_##_name, _val); \ -} while (0) +#define stats_pool_incr(_ctx, _pool, _name) \ + do { \ + _stats_pool_incr(_ctx, _pool, STATS_POOL_##_name); \ + } while (0) + +#define stats_pool_decr(_ctx, _pool, _name) \ + do { \ + _stats_pool_decr(_ctx, _pool, STATS_POOL_##_name); \ + } while (0) + +#define stats_pool_incr_by(_ctx, _pool, _name, _val) \ + do { \ + _stats_pool_incr_by(_ctx, _pool, STATS_POOL_##_name, _val); \ + } while (0) + +#define stats_pool_decr_by(_ctx, _pool, _name, _val) \ + do { \ + _stats_pool_decr_by(_ctx, _pool, STATS_POOL_##_name, _val); \ + } while (0) + +#define stats_pool_set_ts(_ctx, _pool, _name, _val) \ + do { \ + _stats_pool_set_ts(_ctx, _pool, STATS_POOL_##_name, _val); \ + } while (0) + +#define stats_server_incr(_ctx, _server, _name) \ + do { \ + _stats_server_incr(_ctx, _server, STATS_SERVER_##_name); \ + } while (0) + +#define stats_server_decr(_ctx, _server, _name) \ + do { \ + _stats_server_decr(_ctx, _server, STATS_SERVER_##_name); \ + } while (0) + +#define stats_server_incr_by(_ctx, _server, _name, _val) \ + do { \ + _stats_server_incr_by(_ctx, _server, STATS_SERVER_##_name, _val); \ + } while (0) + +#define stats_server_decr_by(_ctx, _server, _name, _val) \ + do { \ + _stats_server_decr_by(_ctx, _server, STATS_SERVER_##_name, _val); \ + } while (0) + +#define stats_server_set_ts(_ctx, _server, _name, _val) \ + do { \ + _stats_server_set_ts(_ctx, _server, STATS_SERVER_##_name, _val); \ + } while (0) #else @@ -268,23 +280,34 @@ enum #endif -#define stats_enabled DA_STATS +#define stats_enabled DA_STATS void stats_describe(void); -void _stats_pool_incr(struct context *ctx, struct server_pool *pool, stats_pool_field_t fidx); -void _stats_pool_decr(struct context *ctx, struct server_pool *pool, stats_pool_field_t fidx); -void _stats_pool_incr_by(struct context *ctx, struct server_pool *pool, stats_pool_field_t fidx, int64_t val); -void _stats_pool_decr_by(struct context *ctx, struct server_pool *pool, stats_pool_field_t fidx, int64_t val); -void _stats_pool_set_ts(struct context *ctx, struct server_pool *pool, stats_pool_field_t fidx, int64_t val); - -void _stats_server_incr(struct context *ctx, struct cache_instance *ins, stats_server_field_t fidx); -void _stats_server_decr(struct context *ctx, struct cache_instance *ins, stats_server_field_t fidx); -void _stats_server_incr_by(struct context *ctx, struct cache_instance *ins, stats_server_field_t fidx, int64_t val); -void _stats_server_decr_by(struct context *ctx, struct cache_instance *ins, stats_server_field_t fidx, int64_t val); -void _stats_server_set_ts(struct context *ctx, struct cache_instance *ins, stats_server_field_t fidx, int64_t val); - -struct stats *stats_create(int stats_interval, char *localip, struct array *server_pool); +void _stats_pool_incr(struct context *ctx, struct server_pool *pool, + stats_pool_field_t fidx); +void _stats_pool_decr(struct context *ctx, struct server_pool *pool, + stats_pool_field_t fidx); +void _stats_pool_incr_by(struct context *ctx, struct server_pool *pool, + stats_pool_field_t fidx, int64_t val); +void _stats_pool_decr_by(struct context *ctx, struct server_pool *pool, + stats_pool_field_t fidx, int64_t val); +void _stats_pool_set_ts(struct context *ctx, struct server_pool *pool, + stats_pool_field_t fidx, int64_t val); + +void _stats_server_incr(struct context *ctx, struct cache_instance *ins, + stats_server_field_t fidx); +void _stats_server_decr(struct context *ctx, struct cache_instance *ins, + stats_server_field_t fidx); +void _stats_server_incr_by(struct context *ctx, struct cache_instance *ins, + stats_server_field_t fidx, int64_t val); +void _stats_server_decr_by(struct context *ctx, struct cache_instance *ins, + stats_server_field_t fidx, int64_t val); +void _stats_server_set_ts(struct context *ctx, struct cache_instance *ins, + stats_server_field_t fidx, int64_t val); + +struct stats *stats_create(int stats_interval, char *localip, + struct array *server_pool); void stats_destroy(struct stats *stats); void stats_swap(struct stats *stats); diff --git a/src/agent/da_time.c b/src/agent/da_time.c index de9b327..daa8db3 100644 --- a/src/agent/da_time.c +++ b/src/agent/da_time.c @@ -1,9 +1,18 @@ /* - * da_time.c - * - * Created on: 2014年12月1日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_time.h" diff --git a/src/agent/da_time.h b/src/agent/da_time.h index fc5b671..6d208a5 100644 --- a/src/agent/da_time.h +++ b/src/agent/da_time.h @@ -1,82 +1,93 @@ /* - * da_time.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月1日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_TIME_H_ #define DA_TIME_H_ - -#include +#include "compiler.h" #include +#include #include -#include "compiler.h" /* eternity when exprimed in timeval */ #ifndef TV_ETERNITY -#define TV_ETERNITY (~0UL) +#define TV_ETERNITY (~0UL) #endif /* eternity when exprimed in ms */ #ifndef TV_ETERNITY_MS -#define TV_ETERNITY_MS (-1) +#define TV_ETERNITY_MS (-1) #endif -#define TIME_ETERNITY (TV_ETERNITY_MS) +#define TIME_ETERNITY (TV_ETERNITY_MS) /* we want to be able to detect time jumps. Fix the maximum wait time to a low * value so that we know the time has changed if we wait longer. */ -#define MAX_DELAY_MS 1000 - - -/* returns the lowest delay amongst and , and respects TIME_ETERNITY */ -#define MINTIME(old, new) (((new)<0)?(old):(((old)<0||(new)<(old))?(new):(old))) -#define SETNOW(a) (*a=now) - -extern uint32_t curr_sec_ms; /* millisecond of current second (0..999) */ -extern uint32_t ms_left_scaled; /* milliseconds left for current second (0..2^32-1) */ -extern uint32_t curr_sec_ms_scaled; /* millisecond of current second (0..2^32-1) */ -extern uint64_t now_ms; /* internal date in milliseconds (may wrap) */ -extern uint64_t now_us; /* internal date in us (may wrap) */ -extern uint32_t samp_time; /* total elapsed time over current sample */ -extern uint32_t idle_time; /* total idle time over current sample */ -extern uint32_t idle_pct; /* idle to total ratio over last sample (percent) */ -extern struct timeval now; /* internal date is a monotonic function of real clock */ -extern struct timeval date; /* the real current date */ -extern struct timeval start_date; /* the process's start date */ -extern struct timeval before_poll; /* system date before calling poll() */ -extern struct timeval after_poll; /* system date after leaving poll() */ +#define MAX_DELAY_MS 1000 +/* returns the lowest delay amongst and , and respects TIME_ETERNITY + */ +#define MINTIME(old, new) \ + (((new) < 0) ? (old) : (((old) < 0 || (new) < (old)) ? (new) : (old))) +#define SETNOW(a) (*a = now) + +extern uint32_t curr_sec_ms; /* millisecond of current second (0..999) */ +extern uint32_t + ms_left_scaled; /* milliseconds left for current second (0..2^32-1) */ +extern uint32_t + curr_sec_ms_scaled; /* millisecond of current second (0..2^32-1) */ +extern uint64_t now_ms; /* internal date in milliseconds (may wrap) */ +extern uint64_t now_us; /* internal date in us (may wrap) */ +extern uint32_t samp_time; /* total elapsed time over current sample */ +extern uint32_t idle_time; /* total idle time over current sample */ +extern uint32_t idle_pct; /* idle to total ratio over last sample (percent) */ +extern struct timeval + now; /* internal date is a monotonic function of real clock */ +extern struct timeval date; /* the real current date */ +extern struct timeval start_date; /* the process's start date */ +extern struct timeval before_poll; /* system date before calling poll() */ +extern struct timeval after_poll; /* system date after leaving poll() */ /**** exported functions *************************************************/ /* * adds ms to , set the result to and returns a pointer */ -REGPRM3 struct timeval *tv_ms_add(struct timeval *tv, const struct timeval *from, int ms); +REGPRM3 struct timeval *tv_ms_add(struct timeval *tv, + const struct timeval *from, int ms); /* - * compares and modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2 - * Must not be used when either argument is eternity. Use tv_ms_cmp2() for that. + * compares and modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 + * if tv1 > tv2 Must not be used when either argument is eternity. Use + * tv_ms_cmp2() for that. */ REGPRM2 int tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2); /* - * compares and modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2, - * assuming that TV_ETERNITY is greater than everything. + * compares and modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 + * if tv1 > tv2, assuming that TV_ETERNITY is greater than everything. */ REGPRM2 int tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2); /**** general purpose functions and macros *******************************/ - /* tv_now: sets to the current time */ -REGPRM1 static inline struct timeval *tv_now(struct timeval *tv) -{ - gettimeofday(tv, NULL); - return tv; +REGPRM1 static inline struct timeval *tv_now(struct timeval *tv) { + gettimeofday(tv, NULL); + return tv; } /* tv_udpate_date: sets to system time, and sets to something as @@ -94,11 +105,10 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted); * note that only tv_usec is necessary to detect it since a tv_usec > 999999 * is normally not possible. */ -REGPRM1 static inline struct timeval *tv_eternity(struct timeval *tv) -{ - tv->tv_sec = (typeof(tv->tv_sec))TV_ETERNITY; - tv->tv_usec = (typeof(tv->tv_usec))TV_ETERNITY; - return tv; +REGPRM1 static inline struct timeval *tv_eternity(struct timeval *tv) { + tv->tv_sec = (typeof(tv->tv_sec))TV_ETERNITY; + tv->tv_usec = (typeof(tv->tv_usec))TV_ETERNITY; + return tv; } /* @@ -106,45 +116,44 @@ REGPRM1 static inline struct timeval *tv_eternity(struct timeval *tv) * */ REGPRM1 static inline struct timeval *tv_zero(struct timeval *tv) { - tv->tv_sec = tv->tv_usec = 0; - return tv; + tv->tv_sec = tv->tv_usec = 0; + return tv; } /* * returns non null if tv is [eternity], otherwise 0. */ -#define tv_iseternity(tv) ((tv)->tv_usec == (typeof((tv)->tv_usec))TV_ETERNITY) +#define tv_iseternity(tv) ((tv)->tv_usec == (typeof((tv)->tv_usec))TV_ETERNITY) /* * returns 0 if tv is [eternity], otherwise non-zero. */ -#define tv_isset(tv) ((tv)->tv_usec != (typeof((tv)->tv_usec))TV_ETERNITY) +#define tv_isset(tv) ((tv)->tv_usec != (typeof((tv)->tv_usec))TV_ETERNITY) /* * returns non null if tv is [0], otherwise 0. */ -#define tv_iszero(tv) (((tv)->tv_sec | (tv)->tv_usec) == 0) +#define tv_iszero(tv) (((tv)->tv_sec | (tv)->tv_usec) == 0) /* * Converts a struct timeval to a number of milliseconds. */ -REGPRM1 static inline unsigned long __tv_to_ms(const struct timeval *tv) -{ - unsigned long ret; +REGPRM1 static inline unsigned long __tv_to_ms(const struct timeval *tv) { + unsigned long ret; - ret = tv->tv_sec * 1000; - ret += tv->tv_usec / 1000; - return ret; + ret = tv->tv_sec * 1000; + ret += tv->tv_usec / 1000; + return ret; } /* * Converts a struct timeval to a number of milliseconds. */ -REGPRM2 static inline struct timeval * __tv_from_ms(struct timeval *tv, unsigned long ms) -{ - tv->tv_sec = ms / 1000; - tv->tv_usec = (ms % 1000) * 1000; - return tv; +REGPRM2 static inline struct timeval *__tv_from_ms(struct timeval *tv, + unsigned long ms) { + tv->tv_sec = ms / 1000; + tv->tv_usec = (ms % 1000) * 1000; + return tv; } /* Return a number of 1024Hz ticks between 0 and 1023 for input number of @@ -154,173 +163,169 @@ REGPRM2 static inline struct timeval * __tv_from_ms(struct timeval *tv, unsigned * which is almost twice as low as a direct usec to ms conversion. This version * also has the benefit of returning 1024 for 1000000. */ -REGPRM1 static inline unsigned int __usec_to_1024th(unsigned int usec) -{ - return (usec * 1073 + 742516) >> 20; +REGPRM1 static inline unsigned int __usec_to_1024th(unsigned int usec) { + return (usec * 1073 + 742516) >> 20; } - /**** comparison functions and macros ***********************************/ - -/* tv_cmp: compares and : returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2. */ -REGPRM2 static inline int __tv_cmp(const struct timeval *tv1, const struct timeval *tv2) -{ - if ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec) - return -1; - else if ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec) - return 1; - else if ((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec) - return -1; - else if ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec) - return 1; - else - return 0; +/* tv_cmp: compares and : returns 0 if equal, -1 if tv1 < tv2, 1 if + * tv1 > tv2. */ +REGPRM2 static inline int __tv_cmp(const struct timeval *tv1, + const struct timeval *tv2) { + if ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec) + return -1; + else if ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec) + return 1; + else if ((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec) + return -1; + else if ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec) + return 1; + else + return 0; } /* tv_iseq: compares and : returns 1 if tv1 == tv2, otherwise 0 */ #define tv_iseq __tv_iseq -REGPRM2 static inline int __tv_iseq(const struct timeval *tv1, const struct timeval *tv2) -{ - return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) && - ((unsigned)tv1->tv_usec == (unsigned)tv2->tv_usec); +REGPRM2 static inline int __tv_iseq(const struct timeval *tv1, + const struct timeval *tv2) { + return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) && + ((unsigned)tv1->tv_usec == (unsigned)tv2->tv_usec); } /* tv_isgt: compares and : returns 1 if tv1 > tv2, otherwise 0 */ #define tv_isgt _tv_isgt REGPRM2 int _tv_isgt(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline int __tv_isgt(const struct timeval *tv1, const struct timeval *tv2) -{ - return - ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ? - ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec) : - ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec); +REGPRM2 static inline int __tv_isgt(const struct timeval *tv1, + const struct timeval *tv2) { + return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) + ? ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec) + : ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec); } /* tv_isge: compares and : returns 1 if tv1 >= tv2, otherwise 0 */ #define tv_isge __tv_isge -REGPRM2 static inline int __tv_isge(const struct timeval *tv1, const struct timeval *tv2) -{ - return - ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ? - ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec) : - ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec); +REGPRM2 static inline int __tv_isge(const struct timeval *tv1, + const struct timeval *tv2) { + return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) + ? ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec) + : ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec); } /* tv_islt: compares and : returns 1 if tv1 < tv2, otherwise 0 */ #define tv_islt __tv_islt -REGPRM2 static inline int __tv_islt(const struct timeval *tv1, const struct timeval *tv2) -{ - return - ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ? - ((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec) : - ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec); +REGPRM2 static inline int __tv_islt(const struct timeval *tv1, + const struct timeval *tv2) { + return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) + ? ((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec) + : ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec); } /* tv_isle: compares and : returns 1 if tv1 <= tv2, otherwise 0 */ #define tv_isle _tv_isle REGPRM2 int _tv_isle(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline int __tv_isle(const struct timeval *tv1, const struct timeval *tv2) -{ - return - ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ? - ((unsigned)tv1->tv_usec <= (unsigned)tv2->tv_usec) : - ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec); +REGPRM2 static inline int __tv_isle(const struct timeval *tv1, + const struct timeval *tv2) { + return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) + ? ((unsigned)tv1->tv_usec <= (unsigned)tv2->tv_usec) + : ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec); } /* - * compares and modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2 - * Must not be used when either argument is eternity. Use tv_ms_cmp2() for that. + * compares and modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 + * if tv1 > tv2 Must not be used when either argument is eternity. Use + * tv_ms_cmp2() for that. */ #define tv_ms_cmp _tv_ms_cmp REGPRM2 int _tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline int __tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2) -{ - if ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) { - if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000) - return -1; - else if ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec + 1000) - return 1; - else - return 0; - } - else if (((unsigned)tv2->tv_sec > (unsigned)tv1->tv_sec + 1) || - (((unsigned)tv2->tv_sec == (unsigned)tv1->tv_sec + 1) && - ((unsigned)tv2->tv_usec + 1000000 >= (unsigned)tv1->tv_usec + 1000))) - return -1; - else if (((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1) || - (((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) && - ((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000))) - return 1; - else - return 0; +REGPRM2 static inline int __tv_ms_cmp(const struct timeval *tv1, + const struct timeval *tv2) { + if ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) { + if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000) + return -1; + else if ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec + 1000) + return 1; + else + return 0; + } else if (((unsigned)tv2->tv_sec > (unsigned)tv1->tv_sec + 1) || + (((unsigned)tv2->tv_sec == (unsigned)tv1->tv_sec + 1) && + ((unsigned)tv2->tv_usec + 1000000 >= + (unsigned)tv1->tv_usec + 1000))) + return -1; + else if (((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1) || + (((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) && + ((unsigned)tv1->tv_usec + 1000000 >= + (unsigned)tv2->tv_usec + 1000))) + return 1; + else + return 0; } /* - * compares and modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2, - * assuming that TV_ETERNITY is greater than everything. + * compares and modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 + * if tv1 > tv2, assuming that TV_ETERNITY is greater than everything. */ #define tv_ms_cmp2 _tv_ms_cmp2 REGPRM2 int _tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline int __tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2) -{ - if (tv_iseternity(tv1)) - if (tv_iseternity(tv2)) - return 0; /* same */ - else - return 1; /* tv1 later than tv2 */ - else if (tv_iseternity(tv2)) - return -1; /* tv2 later than tv1 */ - return tv_ms_cmp(tv1, tv2); +REGPRM2 static inline int __tv_ms_cmp2(const struct timeval *tv1, + const struct timeval *tv2) { + if (tv_iseternity(tv1)) + if (tv_iseternity(tv2)) + return 0; /* same */ + else + return 1; /* tv1 later than tv2 */ + else if (tv_iseternity(tv2)) + return -1; /* tv2 later than tv1 */ + return tv_ms_cmp(tv1, tv2); } /* - * compares and modulo 1 ms: returns 1 if tv1 <= tv2, 0 if tv1 > tv2, - * assuming that TV_ETERNITY is greater than everything. Returns 0 if tv1 is - * TV_ETERNITY, and always assumes that tv2 != TV_ETERNITY. Designed to replace - * occurrences of (tv_ms_cmp2(tv,now) <= 0). + * compares and modulo 1 ms: returns 1 if tv1 <= tv2, 0 if tv1 > + * tv2, assuming that TV_ETERNITY is greater than everything. Returns 0 if tv1 + * is TV_ETERNITY, and always assumes that tv2 != TV_ETERNITY. Designed to + * replace occurrences of (tv_ms_cmp2(tv,now) <= 0). */ #define tv_ms_le2 _tv_ms_le2 REGPRM2 int _tv_ms_le2(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline int __tv_ms_le2(const struct timeval *tv1, const struct timeval *tv2) -{ - if (likely((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1)) - return 0; - - if (likely((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec)) - return 1; - - if (likely((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec)) { - if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000) - return 1; - else - return 0; - } - - if (unlikely(((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) && - ((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000))) - return 0; - else - return 1; +REGPRM2 static inline int __tv_ms_le2(const struct timeval *tv1, + const struct timeval *tv2) { + if (likely((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1)) + return 0; + + if (likely((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec)) + return 1; + + if (likely((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec)) { + if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000) + return 1; + else + return 0; + } + + if (unlikely( + ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) && + ((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000))) + return 0; + else + return 1; } - /**** operators **********************************************************/ - /* * Returns the time in ms elapsed between tv1 and tv2, assuming that tv1<=tv2. * Must not be used when either argument is eternity. */ #define tv_ms_elapsed __tv_ms_elapsed -REGPRM2 unsigned long _tv_ms_elapsed(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline unsigned long __tv_ms_elapsed(const struct timeval *tv1, const struct timeval *tv2) -{ - unsigned long ret; - - ret = ((signed long)(tv2->tv_sec - tv1->tv_sec)) * 1000; - ret += ((signed long)(tv2->tv_usec - tv1->tv_usec)) / 1000; - return ret; +REGPRM2 unsigned long _tv_ms_elapsed(const struct timeval *tv1, + const struct timeval *tv2); +REGPRM2 static inline unsigned long __tv_ms_elapsed(const struct timeval *tv1, + const struct timeval *tv2) { + unsigned long ret; + + ret = ((signed long)(tv2->tv_sec - tv1->tv_sec)) * 1000; + ret += ((signed long)(tv2->tv_usec - tv1->tv_usec)) / 1000; + return ret; } /* @@ -330,13 +335,14 @@ REGPRM2 static inline unsigned long __tv_ms_elapsed(const struct timeval *tv1, c */ #define tv_ms_remain __tv_ms_remain -REGPRM2 unsigned long _tv_ms_remain(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline unsigned long __tv_ms_remain(const struct timeval *tv1, const struct timeval *tv2) -{ - if (tv_ms_cmp(tv1, tv2) >= 0) - return 0; /* event elapsed */ - - return __tv_ms_elapsed(tv1, tv2); +REGPRM2 unsigned long _tv_ms_remain(const struct timeval *tv1, + const struct timeval *tv2); +REGPRM2 static inline unsigned long __tv_ms_remain(const struct timeval *tv1, + const struct timeval *tv2) { + if (tv_ms_cmp(tv1, tv2) >= 0) + return 0; /* event elapsed */ + + return __tv_ms_elapsed(tv1, tv2); } /* @@ -345,124 +351,131 @@ REGPRM2 static inline unsigned long __tv_ms_remain(const struct timeval *tv1, co * Returns TIME_ETERNITY if tv2 is eternity. */ #define tv_ms_remain2 _tv_ms_remain2 -REGPRM2 unsigned long _tv_ms_remain2(const struct timeval *tv1, const struct timeval *tv2); -REGPRM2 static inline unsigned long __tv_ms_remain2(const struct timeval *tv1, const struct timeval *tv2) -{ - if (tv_iseternity(tv2)) - return TIME_ETERNITY; - - return tv_ms_remain(tv1, tv2); +REGPRM2 unsigned long _tv_ms_remain2(const struct timeval *tv1, + const struct timeval *tv2); +REGPRM2 static inline unsigned long __tv_ms_remain2(const struct timeval *tv1, + const struct timeval *tv2) { + if (tv_iseternity(tv2)) + return TIME_ETERNITY; + + return tv_ms_remain(tv1, tv2); } /* * adds to , set the result to and returns a pointer */ #define tv_add _tv_add -REGPRM3 struct timeval *_tv_add(struct timeval *tv, const struct timeval *from, const struct timeval *inc); -REGPRM3 static inline struct timeval *__tv_add(struct timeval *tv, const struct timeval *from, const struct timeval *inc) -{ - tv->tv_usec = from->tv_usec + inc->tv_usec; - tv->tv_sec = from->tv_sec + inc->tv_sec; - if (tv->tv_usec >= 1000000) { - tv->tv_usec -= 1000000; - tv->tv_sec++; - } - return tv; +REGPRM3 struct timeval *_tv_add(struct timeval *tv, const struct timeval *from, + const struct timeval *inc); +REGPRM3 static inline struct timeval *__tv_add(struct timeval *tv, + const struct timeval *from, + const struct timeval *inc) { + tv->tv_usec = from->tv_usec + inc->tv_usec; + tv->tv_sec = from->tv_sec + inc->tv_sec; + if (tv->tv_usec >= 1000000) { + tv->tv_usec -= 1000000; + tv->tv_sec++; + } + return tv; } - /* * If is set, then add it to and set the result to , then * return 1, otherwise return 0. It is meant to be used in if conditions. */ #define tv_add_ifset _tv_add_ifset -REGPRM3 int _tv_add_ifset(struct timeval *tv, const struct timeval *from, const struct timeval *inc); -REGPRM3 static inline int __tv_add_ifset(struct timeval *tv, const struct timeval *from, const struct timeval *inc) -{ - if (tv_iseternity(inc)) - return 0; - tv->tv_usec = from->tv_usec + inc->tv_usec; - tv->tv_sec = from->tv_sec + inc->tv_sec; - if (tv->tv_usec >= 1000000) { - tv->tv_usec -= 1000000; - tv->tv_sec++; - } - return 1; +REGPRM3 int _tv_add_ifset(struct timeval *tv, const struct timeval *from, + const struct timeval *inc); +REGPRM3 static inline int __tv_add_ifset(struct timeval *tv, + const struct timeval *from, + const struct timeval *inc) { + if (tv_iseternity(inc)) + return 0; + tv->tv_usec = from->tv_usec + inc->tv_usec; + tv->tv_sec = from->tv_sec + inc->tv_sec; + if (tv->tv_usec >= 1000000) { + tv->tv_usec -= 1000000; + tv->tv_sec++; + } + return 1; } /* * adds to and returns a pointer */ -REGPRM2 static inline struct timeval *__tv_add2(struct timeval *tv, const struct timeval *inc) -{ - tv->tv_usec += inc->tv_usec; - tv->tv_sec += inc->tv_sec; - if (tv->tv_usec >= 1000000) { - tv->tv_usec -= 1000000; - tv->tv_sec++; - } - return tv; +REGPRM2 static inline struct timeval *__tv_add2(struct timeval *tv, + const struct timeval *inc) { + tv->tv_usec += inc->tv_usec; + tv->tv_sec += inc->tv_sec; + if (tv->tv_usec >= 1000000) { + tv->tv_usec -= 1000000; + tv->tv_sec++; + } + return tv; } - /* * Computes the remaining time between tv1=now and event=tv2. if tv2 is passed, * 0 is returned. The result is stored into tv. */ #define tv_remain _tv_remain -REGPRM3 struct timeval *_tv_remain(const struct timeval *tv1, const struct timeval *tv2, struct timeval *tv); -REGPRM3 static inline struct timeval *__tv_remain(const struct timeval *tv1, const struct timeval *tv2, struct timeval *tv) -{ - tv->tv_usec = tv2->tv_usec - tv1->tv_usec; - tv->tv_sec = tv2->tv_sec - tv1->tv_sec; - if ((signed)tv->tv_sec > 0) { - if ((signed)tv->tv_usec < 0) { - tv->tv_usec += 1000000; - tv->tv_sec--; - } - } else if (tv->tv_sec == 0) { - if ((signed)tv->tv_usec < 0) - tv->tv_usec = 0; - } else { - tv->tv_sec = 0; - tv->tv_usec = 0; - } - return tv; +REGPRM3 struct timeval *_tv_remain(const struct timeval *tv1, + const struct timeval *tv2, + struct timeval *tv); +REGPRM3 static inline struct timeval *__tv_remain(const struct timeval *tv1, + const struct timeval *tv2, + struct timeval *tv) { + tv->tv_usec = tv2->tv_usec - tv1->tv_usec; + tv->tv_sec = tv2->tv_sec - tv1->tv_sec; + if ((signed)tv->tv_sec > 0) { + if ((signed)tv->tv_usec < 0) { + tv->tv_usec += 1000000; + tv->tv_sec--; + } + } else if (tv->tv_sec == 0) { + if ((signed)tv->tv_usec < 0) + tv->tv_usec = 0; + } else { + tv->tv_sec = 0; + tv->tv_usec = 0; + } + return tv; } - /* * Computes the remaining time between tv1=now and event=tv2. if tv2 is passed, * 0 is returned. The result is stored into tv. Returns ETERNITY if tv2 is * eternity. */ #define tv_remain2 _tv_remain2 -REGPRM3 struct timeval *_tv_remain2(const struct timeval *tv1, const struct timeval *tv2, struct timeval *tv); -REGPRM3 static inline struct timeval *__tv_remain2(const struct timeval *tv1, const struct timeval *tv2, struct timeval *tv) -{ - if (tv_iseternity(tv2)) - return tv_eternity(tv); - return __tv_remain(tv1, tv2, tv); +REGPRM3 struct timeval *_tv_remain2(const struct timeval *tv1, + const struct timeval *tv2, + struct timeval *tv); +REGPRM3 static inline struct timeval *__tv_remain2(const struct timeval *tv1, + const struct timeval *tv2, + struct timeval *tv) { + if (tv_iseternity(tv2)) + return tv_eternity(tv); + return __tv_remain(tv1, tv2, tv); } - /* * adds ms to , set the result to and returns a pointer */ #define tv_ms_add _tv_ms_add -REGPRM3 struct timeval *_tv_ms_add(struct timeval *tv, const struct timeval *from, int ms); -REGPRM3 static inline struct timeval *__tv_ms_add(struct timeval *tv, const struct timeval *from, int ms) -{ - tv->tv_usec = from->tv_usec + (ms % 1000) * 1000; - tv->tv_sec = from->tv_sec + (ms / 1000); - while (tv->tv_usec >= 1000000) { - tv->tv_usec -= 1000000; - tv->tv_sec++; - } - return tv; +REGPRM3 struct timeval *_tv_ms_add(struct timeval *tv, + const struct timeval *from, int ms); +REGPRM3 static inline struct timeval * +__tv_ms_add(struct timeval *tv, const struct timeval *from, int ms) { + tv->tv_usec = from->tv_usec + (ms % 1000) * 1000; + tv->tv_sec = from->tv_sec + (ms / 1000); + while (tv->tv_usec >= 1000000) { + tv->tv_usec -= 1000000; + tv->tv_sec++; + } + return tv; } - /* * compares and : returns 1 if is before , otherwise 0. * This should be very fast because it's used in schedulers. @@ -470,10 +483,13 @@ REGPRM3 static inline struct timeval *__tv_ms_add(struct timeval *tv, const stru * as long as tv1<=tv2) */ -#define tv_isbefore(tv1, tv2) \ - (unlikely((unsigned)(tv1)->tv_sec < (unsigned)(tv2)->tv_sec) ? 1 : \ - (unlikely((unsigned)(tv1)->tv_sec > (unsigned)(tv2)->tv_sec) ? 0 : \ - unlikely((unsigned)(tv1)->tv_usec < (unsigned)(tv2)->tv_usec))) +#define tv_isbefore(tv1, tv2) \ + (unlikely((unsigned)(tv1)->tv_sec < (unsigned)(tv2)->tv_sec) \ + ? 1 \ + : (unlikely((unsigned)(tv1)->tv_sec > (unsigned)(tv2)->tv_sec) \ + ? 0 \ + : unlikely((unsigned)(tv1)->tv_usec < \ + (unsigned)(tv2)->tv_usec))) /* * returns the first event between and into . @@ -481,54 +497,55 @@ REGPRM3 static inline struct timeval *__tv_ms_add(struct timeval *tv, const stru * to be the same as or , it is recommended to use * tv_bound instead. */ -#define tv_min(tvmin, tv1, tv2) ({ \ - if (tv_isbefore(tv1, tv2)) { \ - *tvmin = *tv1; \ - } \ - else { \ - *tvmin = *tv2; \ - } \ - tvmin; \ -}) +#define tv_min(tvmin, tv1, tv2) \ + ({ \ + if (tv_isbefore(tv1, tv2)) { \ + *tvmin = *tv1; \ + } else { \ + *tvmin = *tv2; \ + } \ + tvmin; \ + }) /* * returns the first event between and into . * a zero tv is ignored. is returned. This function has been * optimized to be called as tv_min(a,a,b) or tv_min(b,a,b). */ -#define tv_bound(tv1, tv2) ({ \ - if (tv_isbefore(tv2, tv1)) \ - *tv1 = *tv2; \ - tv1; \ -}) +#define tv_bound(tv1, tv2) \ + ({ \ + if (tv_isbefore(tv2, tv1)) \ + *tv1 = *tv2; \ + tv1; \ + }) /* Update the idle time value twice a second, to be called after * tv_update_date() when called after poll(). It relies on to be * updated to the system time before calling poll(). */ -static inline void measure_idle() -{ - /* Let's compute the idle to work ratio. We worked between after_poll - * and before_poll, and slept between before_poll and date. The idle_pct - * is updated at most twice every second. Note that the current second - * rarely changes so we avoid a multiply when not needed. - */ - int delta; - - if ((delta = date.tv_sec - before_poll.tv_sec)) - delta *= 1000000; - idle_time += delta + (date.tv_usec - before_poll.tv_usec); - - if ((delta = date.tv_sec - after_poll.tv_sec)) - delta *= 1000000; - samp_time += delta + (date.tv_usec - after_poll.tv_usec); - - after_poll.tv_sec = date.tv_sec; after_poll.tv_usec = date.tv_usec; - if (samp_time < 500000) - return; - - idle_pct = (100 * idle_time + samp_time / 2) / samp_time; - idle_time = samp_time = 0; +static inline void measure_idle() { + /* Let's compute the idle to work ratio. We worked between after_poll + * and before_poll, and slept between before_poll and date. The idle_pct + * is updated at most twice every second. Note that the current second + * rarely changes so we avoid a multiply when not needed. + */ + int delta; + + if ((delta = date.tv_sec - before_poll.tv_sec)) + delta *= 1000000; + idle_time += delta + (date.tv_usec - before_poll.tv_usec); + + if ((delta = date.tv_sec - after_poll.tv_sec)) + delta *= 1000000; + samp_time += delta + (date.tv_usec - after_poll.tv_usec); + + after_poll.tv_sec = date.tv_sec; + after_poll.tv_usec = date.tv_usec; + if (samp_time < 500000) + return; + + idle_pct = (100 * idle_time + samp_time / 2) / samp_time; + idle_time = samp_time = 0; } #endif /* DA_TIME_H_ */ diff --git a/src/agent/da_top_percentile.c b/src/agent/da_top_percentile.c index abb5fd9..cefbd35 100644 --- a/src/agent/da_top_percentile.c +++ b/src/agent/da_top_percentile.c @@ -1,3 +1,18 @@ +/* +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include #include diff --git a/src/agent/da_top_percentile.h b/src/agent/da_top_percentile.h index 0d40dbf..4969a07 100644 --- a/src/agent/da_top_percentile.h +++ b/src/agent/da_top_percentile.h @@ -1,35 +1,41 @@ +/* + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef DA_TOP_PERCENTILE_H_ #define DA_TOP_PERCENTILE_H_ - #include - struct context; struct server_pool; +enum E_REPORT_TYPE { RT_MIN, RT_SHARDING, RT_ALL, RT_MAX }; -enum E_REPORT_TYPE -{ - RT_MIN, - RT_SHARDING, - RT_ALL, - RT_MAX +struct remote_param { + uint64_t app_id; + uint64_t interface_id; }; - -struct remote_param -{ - uint64_t app_id; - uint64_t interface_id; -}; - - int8_t get_host_name_info(const char *addr, char *result); -int8_t set_remote_config(const char *addr, uint16_t port, struct sockaddr_in *remote_addr); -int8_t set_remote_param(uint64_t app_id, uint64_t interface_id, enum E_REPORT_TYPE type, struct remote_param *pParam); +int8_t set_remote_config(const char *addr, uint16_t port, + struct sockaddr_in *remote_addr); +int8_t set_remote_param(uint64_t app_id, uint64_t interface_id, + enum E_REPORT_TYPE type, struct remote_param *pParam); int set_remote_fd(); -void top_percentile_report(struct context* ctx, struct server_pool *pool, int64_t elaspe, int32_t status, enum E_REPORT_TYPE type); - +void top_percentile_report(struct context *ctx, struct server_pool *pool, + int64_t elaspe, int32_t status, + enum E_REPORT_TYPE type); #endif diff --git a/src/agent/da_util.c b/src/agent/da_util.c index 4f8a984..a1f3857 100644 --- a/src/agent/da_util.c +++ b/src/agent/da_util.c @@ -1,9 +1,18 @@ /* - * da_util.c - * - * Created on: 2014年11月29日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_util.h" #include "da_string.h" diff --git a/src/agent/da_util.h b/src/agent/da_util.h index 17d4498..e10359e 100644 --- a/src/agent/da_util.h +++ b/src/agent/da_util.h @@ -1,42 +1,49 @@ /* - * da_util.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年11月29日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_UTIL_H_ #define DA_UTIL_H_ +#include +#include +#include +#include +#include #include #include +#include +#include #include #include -#include -#include -#include -#include -#include -#include #include -#include struct string; -#define LF (uint8_t) 10 -#define CR (uint8_t) 13 -#define CRLF "\x0d\x0a" - -#define NELEMS(a) ((sizeof(a)) / sizeof((a)[0])) +#define LF (uint8_t)10 +#define CR (uint8_t)13 +#define CRLF "\x0d\x0a" -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define NELEMS(a) ((sizeof(a)) / sizeof((a)[0])) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define DA_MAXHOSTNAMELEN 256 -#define DA_UNIX_ADDRSTRLEN \ - (sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path)) - +#define DA_UNIX_ADDRSTRLEN \ + (sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path)) /* * Length of 1 byte, 2 bytes, 4 bytes, 8 bytes and largest integral @@ -48,60 +55,52 @@ struct string; * # define UINT32_MAX (4294967295U) * # define UINT64_MAX (__UINT64_C(18446744073709551615)) */ -#define DA_UINT8_MAXLEN (3 + 1) -#define DA_UINT16_MAXLEN (5 + 1) -#define DA_UINT32_MAXLEN (10 + 1) -#define DA_UINT64_MAXLEN (20 + 1) -#define DA_UINTMAX_MAXLEN DA_UINT64_MAXLEN - - -#define da_sendn(_s, _b, _n) \ - _da_sendn(_s, _b, (size_t)(_n)) -#define da_recvn(_s, _b, _n) \ - _da_recvn(_s, _b, (size_t)(_n)) +#define DA_UINT8_MAXLEN (3 + 1) +#define DA_UINT16_MAXLEN (5 + 1) +#define DA_UINT32_MAXLEN (10 + 1) +#define DA_UINT64_MAXLEN (20 + 1) +#define DA_UINTMAX_MAXLEN DA_UINT64_MAXLEN +#define da_sendn(_s, _b, _n) _da_sendn(_s, _b, (size_t)(_n)) +#define da_recvn(_s, _b, _n) _da_recvn(_s, _b, (size_t)(_n)) -#define da_read(_d, _b, _n) \ - read(_d, _b, (size_t)(_n)) -#define da_readv(_d, _b, _n) \ - readv(_d, _b, (int)(_n)) -#define da_write(_d, _b, _n) \ - write(_d, _b, (size_t)(_n)) -#define da_writev(_d, _b, _n) \ - writev(_d, _b, (int)(_n)) +#define da_read(_d, _b, _n) read(_d, _b, (size_t)(_n)) +#define da_readv(_d, _b, _n) readv(_d, _b, (int)(_n)) +#define da_write(_d, _b, _n) write(_d, _b, (size_t)(_n)) +#define da_writev(_d, _b, _n) writev(_d, _b, (int)(_n)) ssize_t _da_sendn(int sd, const void *vptr, size_t n); ssize_t _da_recvn(int sd, void *vptr, size_t n); -#define da_gethostname(_name, _len) \ - gethostname((char *)_name, (size_t)(_len)) +#define da_gethostname(_name, _len) gethostname((char *)_name, (size_t)(_len)) -#define da_atoi(_line, _n) \ - _da_atoi((uint8_t *)_line, (size_t)(_n)) +#define da_atoi(_line, _n) _da_atoi((uint8_t *)_line, (size_t)(_n)) int _da_atoi(uint8_t *line, size_t n); #ifdef DA_ASSERT_PANIC -#define ASSERT(_x) do { \ - if (!(_x)) { \ - da_assert(#_x, __FILE__, __LINE__,1); \ - } \ -} while (0) +#define ASSERT(_x) \ + do { \ + if (!(_x)) { \ + da_assert(#_x, __FILE__, __LINE__, 1); \ + } \ + } while (0) #elif DA_ASSERT_LOG -#define ASSERT(_x) do { \ - if (!(_x)) { \ - da_assert(#_x, __FILE__, __LINE__,0); \ - } \ -} while (0) +#define ASSERT(_x) \ + do { \ + if (!(_x)) { \ + da_assert(#_x, __FILE__, __LINE__, 0); \ + } \ + } while (0) #else #define ASSERT(_x) #endif -void da_assert(const char * cond, const char *file, int line, int panic); +void da_assert(const char *cond, const char *file, int line, int panic); void da_stacktrace(int skip_count); void da_stacktrace_fd(int fd); @@ -126,13 +125,13 @@ bool da_valid_port(int n); */ struct sockinfo { - int family; /* socket address family */ - socklen_t addrlen; /* socket address length */ - union { - struct sockaddr_in in; /* ipv4 socket address */ - struct sockaddr_in6 in6; /* ipv6 socket address */ - struct sockaddr_un un; /* unix domain address */ - } addr; + int family; /* socket address family */ + socklen_t addrlen; /* socket address length */ + union { + struct sockaddr_in in; /* ipv4 socket address */ + struct sockaddr_in6 in6; /* ipv6 socket address */ + struct sockaddr_un un; /* unix domain address */ + } addr; }; int da_resolve(struct string *name, int port, struct sockinfo *si); diff --git a/src/agent/event/da_epoll.c b/src/agent/event/da_epoll.c index 7b323a3..702b7e0 100644 --- a/src/agent/event/da_epoll.c +++ b/src/agent/event/da_epoll.c @@ -1,9 +1,18 @@ /* - * da_epoll.c - * - * Created on: 2014年11月28日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include diff --git a/src/agent/event/da_event.h b/src/agent/event/da_event.h index 3bda816..0edf27f 100644 --- a/src/agent/event/da_event.h +++ b/src/agent/event/da_event.h @@ -1,35 +1,44 @@ /* - * da_event.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年11月30日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_EVENT_H_ #define DA_EVENT_H_ -#include -#include -#include "errno.h" #include "../da_conn.h" #include "../da_log.h" #include "../da_util.h" +#include "errno.h" +#include +#include -#define EVENT_SIZE 1024 +#define EVENT_SIZE 1024 -#define EVENT_READ 0x0000ff +#define EVENT_READ 0x0000ff #define EVENT_WRITE 0x00ff00 -#define EVENT_ERR 0xff0000 +#define EVENT_ERR 0xff0000 struct conn; typedef int (*event_cb_t)(void *, uint32_t); struct event_base { - int ep; - struct epoll_event *event; - int nevent; - event_cb_t cb; + int ep; + struct epoll_event *event; + int nevent; + event_cb_t cb; }; struct event_base *event_base_create(int nevent, event_cb_t cb); diff --git a/src/agent/hashkit/da_chash.c b/src/agent/hashkit/da_chash.c index a5fb82a..1179c2f 100644 --- a/src/agent/hashkit/da_chash.c +++ b/src/agent/hashkit/da_chash.c @@ -1,9 +1,18 @@ /* - * da_chash.c - * - * Created on: 2015年3月4日 - * Author: Jiansong - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_hashkit.h" diff --git a/src/agent/hashkit/da_crc16.c b/src/agent/hashkit/da_crc16.c index e896df3..3ea12cd 100644 --- a/src/agent/hashkit/da_crc16.c +++ b/src/agent/hashkit/da_crc16.c @@ -1,3 +1,18 @@ +/* +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include static const uint16_t crc16tab[256] = { diff --git a/src/agent/hashkit/da_crc32.c b/src/agent/hashkit/da_crc32.c index 0decc6e..bfe5ca1 100644 --- a/src/agent/hashkit/da_crc32.c +++ b/src/agent/hashkit/da_crc32.c @@ -1,9 +1,18 @@ /* - * The crc32 functions and data was originally written by Spencer - * Garrett and was gleaned from the PostgreSQL source - * tree via the files contrib/ltree/crc32.[ch] and from FreeBSD at - * src/usr.bin/cksum/crc32.c. - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include diff --git a/src/agent/hashkit/da_fnv.c b/src/agent/hashkit/da_fnv.c index 490c1ac..de4bead 100644 --- a/src/agent/hashkit/da_fnv.c +++ b/src/agent/hashkit/da_fnv.c @@ -1,3 +1,18 @@ +/* +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_hashkit.h" diff --git a/src/agent/hashkit/da_hsieh.c b/src/agent/hashkit/da_hsieh.c index a2e3c9d..86968c1 100644 --- a/src/agent/hashkit/da_hsieh.c +++ b/src/agent/hashkit/da_hsieh.c @@ -1,9 +1,17 @@ /* - * By Paul Hsieh (C) 2004, 2005. Covered under the Paul Hsieh - * derivative license. - * See: http://www.azillionmonkeys.com/qed/weblicense.html for license - * details. - * http://www.azillionmonkeys.com/qed/hash.html +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. */ #include"da_hashkit.h" diff --git a/src/agent/hashkit/da_jenkins.c b/src/agent/hashkit/da_jenkins.c index e630663..b9c770e 100644 --- a/src/agent/hashkit/da_jenkins.c +++ b/src/agent/hashkit/da_jenkins.c @@ -1,14 +1,18 @@ /* - * By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this - * code any way you wish, private, educational, or commercial. It's free. - * Use for hash table lookup, or anything where one collision in 2^^32 is - * acceptable. Do NOT use for cryptographic purposes. - * http://burtleburtle.net/bob/hash/index.html - * - * Modified by Brian Pontz for libmemcached - * TODO: - * Add big endian support - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include"da_hashkit.h" diff --git a/src/agent/hashkit/da_ketama.c b/src/agent/hashkit/da_ketama.c index a67968c..55926ad 100644 --- a/src/agent/hashkit/da_ketama.c +++ b/src/agent/hashkit/da_ketama.c @@ -1,3 +1,18 @@ +/* +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include #include @@ -9,7 +24,7 @@ #include "../da_log.h" /* - * 一致性hash节点数 + * 涓鑷存ash鑺傜偣鏁 */ #define KETAMA_CONTINUUM_ADDITION 10 /* # extra slots to build into continuum */ #define KETAMA_POINTS_PER_SERVER 160 /* 40 points per hash */ @@ -68,7 +83,7 @@ int ketama_update(struct server_pool *pool) { if (continuum == NULL) { return -1; } - //设置pool的一致性hash环 + //璁剧疆pool鐨勪竴鑷存ash鐜 pool->continuum = continuum; pool->nserver_continuum = nserver_continuum; /* pool->ncontinuum is initialized later as it could be <= ncontinuum */ @@ -102,7 +117,7 @@ int ketama_update(struct server_pool *pool) { pointer_counter += points_per_server; } pool->ncontinuum = pointer_counter; - //对continum进行排序 + //瀵筩ontinum杩涜鎺掑簭 qsort(pool->continuum, pool->ncontinuum, sizeof(*pool->continuum), ketama_item_cmp); for (pointer_index = 0; @@ -142,7 +157,7 @@ int ketama_update(struct server_pool *pool) { for (server_index = 0; server_index < nserver; server_index++) { struct server *server = array_get(&pool->server, server_index); - //‘host:port:weight’ or ‘host:port:weight name’ + //鈥榟ost:port:weight鈥 or 鈥榟ost:port:weight name鈥 ASSERT(server->weight > 0); total_weight += server->weight; @@ -163,7 +178,7 @@ int ketama_update(struct server_pool *pool) { if (continuum == NULL) { return -1; } - //设置pool的一致性hash环 + //璁剧疆pool鐨勪竴鑷存ash鐜 pool->continuum = continuum; pool->nserver_continuum = nserver_continuum; /* pool->ncontinuum is initialized later as it could be <= ncontinuum */ @@ -181,7 +196,7 @@ int ketama_update(struct server_pool *pool) { server = array_get(&pool->server, server_index); - pct = (float) server->weight / (float) total_weight; //权重计算 + pct = (float) server->weight / (float) total_weight; //鏉冮噸璁$畻 pointer_per_server = (uint32_t) ((floorf( (float) (pct * KETAMA_POINTS_PER_SERVER / 4 * (float) nserver + 0.0000000001))) * 4); @@ -208,7 +223,7 @@ int ketama_update(struct server_pool *pool) { } pool->ncontinuum = pointer_counter; - //对continum进行排序 + //瀵筩ontinum杩涜鎺掑簭 qsort(pool->continuum, pool->ncontinuum, sizeof(*pool->continuum), ketama_item_cmp); diff --git a/src/agent/hashkit/da_md5.c b/src/agent/hashkit/da_md5.c index 0035bcb..d75a372 100644 --- a/src/agent/hashkit/da_md5.c +++ b/src/agent/hashkit/da_md5.c @@ -1,14 +1,19 @@ -#include "da_hashkit.h" - /* - * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. - * MD5 Message-Digest Algorithm (RFC 1321). - * - * Homepage: http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 - * - * Author: Alexander Peslyak, better known as Solar Designer - */ - +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "da_hashkit.h" #include typedef unsigned int MD5_u32plus; diff --git a/src/agent/hashkit/da_murmur.c b/src/agent/hashkit/da_murmur.c index b57d0ce..9c1b241 100644 --- a/src/agent/hashkit/da_murmur.c +++ b/src/agent/hashkit/da_murmur.c @@ -1,19 +1,18 @@ /* - * "Murmur" hash provided by Austin, tanjent@gmail.com - * http://murmurhash.googlepages.com/ - * - * Note - This code makes a few assumptions about how your machine behaves - - * - * 1. We can read a 4-byte value from any address without crashing - * 2. sizeof(int) == 4 - * - * And it has a few limitations - - * 1. It will not work incrementally. - * 2. It will not produce the same results on little-endian and big-endian - * machines. - * - * Updated to murmur2 hash - BP - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_hashkit.h" diff --git a/src/agent/hashkit/da_one_at_a_time.c b/src/agent/hashkit/da_one_at_a_time.c index 46b4d5c..7ff52ea 100644 --- a/src/agent/hashkit/da_one_at_a_time.c +++ b/src/agent/hashkit/da_one_at_a_time.c @@ -1,17 +1,18 @@ /* - * HashKit - * Copyright (C) 2009 Brian Aker - * All rights reserved. - * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. - */ - -/* - * This has is Jenkin's "One at A time Hash". - * http://en.wikipedia.org/wiki/Jenkins_hash_function - */ - +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "da_hashkit.h" uint32_t diff --git a/src/agent/proto/da_dtcparse.c b/src/agent/proto/da_dtcparse.c index 6ef3399..b6da7da 100644 --- a/src/agent/proto/da_dtcparse.c +++ b/src/agent/proto/da_dtcparse.c @@ -1,10 +1,18 @@ /* - * da_dtcparse.c - * - * Created on: 2014年12月24日 - * Author: Jiansong - */ - +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include #include @@ -408,7 +416,7 @@ void dtc_parse_req(struct msg *r) { state = ST_ID; break; } - //级联灰度版本特别的地方 + //绾ц仈鐏板害鐗堟湰鐗瑰埆鐨勫湴鏂 // case 17: { // if (b->last - p < r->cur_parse_lenth) { // log_debug( @@ -563,7 +571,7 @@ void dtc_parse_req(struct msg *r) { r->keys[0].end = p + r->cur_parse_lenth; if (r->keytype == String || r->keytype == Binary) { - r->keys[0].end -= 1; //去除字符串末尾的\0 + r->keys[0].end -= 1; //鍘婚櫎瀛楃涓叉湯灏剧殑\0 } log_debug( @@ -1720,7 +1728,7 @@ static int dtc_encode_agentid(struct msg *r) { } /* - * get分包函数,暂时不考虑联合组件的情况 + * get鍒嗗寘鍑芥暟,鏆傛椂涓嶈冭檻鑱斿悎缁勪欢鐨勬儏鍐 */ static int dtc_fragment_get(struct msg *r, uint32_t ncontinuum, struct msg_tqh *frag_msgq) { @@ -1733,7 +1741,7 @@ static int dtc_fragment_get(struct msg *r, uint32_t ncontinuum, CValue val; uint32_t idx = 0; int version_len = 0, requestinfo_len = 0; - //用于放置分组所有的key + //鐢ㄤ簬鏀剧疆鍒嗙粍鎵鏈夌殑key struct keypos keys[ncontinuum][r->keyCount]; int keynum[ncontinuum]; @@ -1746,7 +1754,7 @@ static int dtc_fragment_get(struct msg *r, uint32_t ncontinuum, struct keypos *kpos = &r->keys[i]; if(r->keytype == Unsigned || r->keytype == Signed) { if(sizeof(uint64_t) == kpos->end - kpos->start) { - //此处没有考虑大端小端问题源于SDK编码 + //姝ゅ娌℃湁鑰冭檻澶х灏忕闂婧愪簬SDK缂栫爜 val.u64 = *(uint64_t*)kpos->start; idx = msg_backend_idx(r, (uint8_t *)&val.u64, sizeof(uint64_t)); log_debug("key is %lu, idx is %u, len is %ld", @@ -1756,7 +1764,7 @@ static int dtc_fragment_get(struct msg *r, uint32_t ncontinuum, return -1; } else { - //多Key时每个key被附加4Byte Key长度 + //澶欿ey鏃舵瘡涓猭ey琚檮鍔4Byte Key闀垮害 int len = kpos->end - kpos->start - sizeof(uint32_t); if(len > 0) { char temp[len + 2]; @@ -1936,7 +1944,7 @@ int dtc_fragment(struct msg *r, uint32_t ncontinuum, struct msg_tqh *frag_msgq) { uint64_t randomkey=randomHashSeed++; r->idx = msg_backend_idx(r, (uint8_t *)&randomkey,sizeof(uint64_t)); - //级联灰度版本特别的地方 + //绾ц仈鐏板害鐗堟湰鐗瑰埆鐨勫湴鏂 status = dtc_encode_agentid(r); return status; } @@ -1989,7 +1997,7 @@ int dtc_fragment(struct msg *r, uint32_t ncontinuum, struct msg_tqh *frag_msgq) break; } } - //级联灰度版本特别的地方 + //绾ц仈鐏板害鐗堟湰鐗瑰埆鐨勫湴鏂 status = dtc_encode_agentid(r); return status; } @@ -2108,7 +2116,7 @@ static int dtc_coalesce_get(struct msg *r) { } } } - if (errortag == 1) { //有分包查找出错,one of the search result is in error + if (errortag == 1) { //鏈夊垎鍖呮煡鎵惧嚭閿,one of the search result is in error cmsg->peer = NULL; cmsg->peerid = 0; peermsg->peer = NULL; @@ -2118,7 +2126,7 @@ static int dtc_coalesce_get(struct msg *r) { peermsg->peer = r; peermsg->id = r->id; goto coalesce_succ_err; - } else if (validmsgcount == 0 || validmsgcount == 1) { //结果集统统处于一个包中,only a package contain search resule + } else if (validmsgcount == 0 || validmsgcount == 1) { //缁撴灉闆嗙粺缁熷浜庝竴涓寘涓紝only a package contain search resule peermsg = singleresmsg->peer; singleresmsg->peer = NULL; singleresmsg->peerid = 0; diff --git a/src/agent/proto/da_protocal.h b/src/agent/proto/da_protocal.h index b993f78..e94d3dd 100644 --- a/src/agent/proto/da_protocal.h +++ b/src/agent/proto/da_protocal.h @@ -1,41 +1,49 @@ /* - * da_protocal.h + * Copyright [2021] JD.com, Inc. * - * Created on: 2014年12月23日 - * Author: Jiansong + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef DA_PROTOCAL_H_ #define DA_PROTOCAL_H_ -#include -#include #include "da_string.h" +#include +#include struct msg; struct msg_tqh; struct CPacketHeader { - uint8_t version; - uint8_t scts; - uint8_t flags; - uint8_t cmd; - uint32_t len[8]; + uint8_t version; + uint8_t scts; + uint8_t flags; + uint8_t cmd; + uint32_t len[8]; }; typedef union CValue { -// member - int64_t s64; - uint64_t u64; - double flt; - struct string str; + // member + int64_t s64; + uint64_t u64; + double flt; + struct string str; -}CValue; +} CValue; void dtc_parse_req(struct msg *r); void dtc_parse_rsp(struct msg *r); int dtc_coalesce(struct msg *r); -int dtc_fragment(struct msg *r,uint32_t ncontinuum,struct msg_tqh *frag_msgq); -int dtc_error_reply(struct msg *smsg,struct msg *dmsg); - +int dtc_fragment(struct msg *r, uint32_t ncontinuum, struct msg_tqh *frag_msgq); +int dtc_error_reply(struct msg *smsg, struct msg *dmsg); #endif /* DA_PROTOCAL_H_ */ diff --git a/src/libs/common/version.h b/src/libs/common/version.h index eb36e5c..c2bb91e 100644 --- a/src/libs/common/version.h +++ b/src/libs/common/version.h @@ -8,7 +8,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "08568c8" BASIS, +* distributed under the License is distributed on an "eab3ec6" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -- Gitee From 6046eeebe365c04418fe8b9e346768389d0a1bc5 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Mon, 23 Aug 2021 15:08:45 +0800 Subject: [PATCH 04/39] travis ci --- .travis.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..65393ce --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +# Build matrix / environment variables are explained on: +# http://about.travis-ci.org/docs/user/build-configuration/ +# This file can be validated on: http://lint.travis-ci.org/ + +language: cpp +sudo: required + +compiler: +- gcc +- g++ +os: +- linux + +install: +- echo ${CC} +- echo ${CXX} +- ${CXX} --version +- cmake --version +- sudo apt-get install snappy libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev + +script: +- cd src/ +- make \ No newline at end of file -- Gitee From 65c0dc86de8c9702aa23c72fef336b7d43b9076f Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Mon, 23 Aug 2021 15:29:55 +0800 Subject: [PATCH 05/39] feat: add travis icon --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 21f9ce8..f8ec102 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ![DTC](http://storage.360buyimg.com/bq-install/release/dtc_logo.png) # DTC - Distributed Table Cache 鍒嗗竷寮忚〃缂撳瓨 +[![Build Status](https://app.travis-ci.com/DTC8/DTC.svg?branch=master)](https://app.travis-ci.com/github/DTC8/DTC) ## 姒傝堪 DTC鏄竴涓垎甯冨紡琛ㄧ骇缂撳瓨绯荤粺銆 -- Gitee From ee41fafcaf610b9be4e77ad45c45308477bd4126 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Mon, 23 Aug 2021 19:49:11 +0800 Subject: [PATCH 06/39] feat: add dockerfile --- dockerfiles/server/dockerfile | 14 ++++++++++++++ dockerfiles/server/start.sh | 17 +++++++++++++++++ script/dtcd.sh | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 dockerfiles/server/dockerfile create mode 100644 dockerfiles/server/start.sh create mode 100644 script/dtcd.sh diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile new file mode 100644 index 0000000..d6cbfc0 --- /dev/null +++ b/dockerfiles/server/dockerfile @@ -0,0 +1,14 @@ +FROM centos:centos7.2.1511 +RUN yum install -y wget + +RUN mkdir -p /usr/local/dtc/bin +RUN mkdir -p /usr/local/dtc/conf +RUN mkdir -p /usr/local/dtc/log + +COPY start.sh /root/start.sh +COPY ../../script/dtcd.sh /usr/local/dtc/bin/dtcd.sh +COPY ../../bin/dtcd /usr/local/dtc/bin/dtcd +COPY ../../conf/table.yaml /usr/local/dtc/conf/table.yaml +COPY ../../conf/cache.yaml /usr/local/dtc/conf/cache.yaml + +CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file diff --git a/dockerfiles/server/start.sh b/dockerfiles/server/start.sh new file mode 100644 index 0000000..2399260 --- /dev/null +++ b/dockerfiles/server/start.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +INIT(){ + cd /usr/local/dtc/bin + chmod +x dtcd + ./dtcd.sh start +} + +PROCESS_DAEMON(){ + while : + do + sleep 60 + done +} + +INIT +PROCESS_DAEMON \ No newline at end of file diff --git a/script/dtcd.sh b/script/dtcd.sh new file mode 100644 index 0000000..e97d4a0 --- /dev/null +++ b/script/dtcd.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +ulimit -c unlimited + +DTC_BIN="dtcd_docker" +rm -f "$DTC_BIN" +ln -s dtcd "$DTC_BIN" + +if [ "$1" = "stop" ] ; then + killall -9 $DTC_BIN +elif [ "$1" = "restart" ]; then + killall -9 $DTC_BIN + sleep 2 + ./$DTC_BIN >> /dev/null 2>&1 +elif [ "$1" = "start" ]; then + ./$DTC_BIN >> /dev/null 2>&1 + sleep 1 +else + echo "usage: $0 stop | start |restart" +fi -- Gitee From 8a45a19ad519c2d019e417a888cad0985cda07f0 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Tue, 24 Aug 2021 09:27:15 +0800 Subject: [PATCH 07/39] feat: dockerfile --- .travis.yml | 12 +++++++++++- dockerfiles/sdk-cpp/dockerfile | 18 ++++++++++++++++++ dockerfiles/sdk-cpp/start.sh | 23 +++++++++++++++++++++++ dockerfiles/server/dockerfile | 16 +++++++++------- 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 dockerfiles/sdk-cpp/dockerfile create mode 100644 dockerfiles/sdk-cpp/start.sh diff --git a/.travis.yml b/.travis.yml index 65393ce..22c9861 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,14 @@ install: script: - cd src/ -- make \ No newline at end of file +- make +- make install + +after_success: +- cd ../dockerfiles/server/ +- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +- docker build -t $DOCKER_USERNAME/server:latest . +- docker push $DOCKER_USERNAME/server:latest +- cd ../sdk-cpp/ +- docker build -t $DOCKER_USERNAME/sdk-cpp:latest . +- docker push $DOCKER_USERNAME/sdk-cpp:latest \ No newline at end of file diff --git a/dockerfiles/sdk-cpp/dockerfile b/dockerfiles/sdk-cpp/dockerfile new file mode 100644 index 0000000..55ae305 --- /dev/null +++ b/dockerfiles/sdk-cpp/dockerfile @@ -0,0 +1,18 @@ +FROM centos:centos7.2.1511 + +COPY start.sh /root/start.sh + +ARG sofile=libdtc.2.so +COPY ../../bin/$sofile /usr/lib/$sofile +RUN ln -sf /usr/lib/$sofile /usr/lib/libdtc.so.1 && \ + ln -sf /usr/lib/libdtc.so.1 /usr/lib/libdtc.so && \ + echo "/usr/lib" >> /etc/ld.so.conf && \ + /sbin/ldconfig -v + +#cpp test +RUN mkdir -p /usr/local/sdk-cpp +COPY ../../tests/get.cc /usr/local/sdk-cpp/get.cc +COPY ../../tests/insert.cc /usr/local/sdk-cpp/insert.cc +COPY ../../tests/build.sh /usr/local/sdk-cpp/build.sh + +CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file diff --git a/dockerfiles/sdk-cpp/start.sh b/dockerfiles/sdk-cpp/start.sh new file mode 100644 index 0000000..cfc4bed --- /dev/null +++ b/dockerfiles/sdk-cpp/start.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +INIT(){ + cd /usr/local/sdk-cpp/ + chmod +x build.sh + echo "=============BUILD===================" + ./build.sh + echo "=============INSERT==================" + ./insert + echo "=============GET=====================" + ./get + echo "=============END=====================" +} + +PROCESS_DAEMON(){ + while : + do + sleep 60 + done +} + +INIT +#PROCESS_DAEMON \ No newline at end of file diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index d6cbfc0..80c7c24 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -1,14 +1,16 @@ FROM centos:centos7.2.1511 RUN yum install -y wget -RUN mkdir -p /usr/local/dtc/bin -RUN mkdir -p /usr/local/dtc/conf -RUN mkdir -p /usr/local/dtc/log +ARG basepath=/usr/local/dtc + +RUN mkdir -p $basepath/bin +RUN mkdir -p $basepath/conf +RUN mkdir -p $basepath/log COPY start.sh /root/start.sh -COPY ../../script/dtcd.sh /usr/local/dtc/bin/dtcd.sh -COPY ../../bin/dtcd /usr/local/dtc/bin/dtcd -COPY ../../conf/table.yaml /usr/local/dtc/conf/table.yaml -COPY ../../conf/cache.yaml /usr/local/dtc/conf/cache.yaml +COPY ../../script/dtcd.sh $basepath/bin/dtcd.sh +COPY ../../bin/dtcd $basepath/bin/dtcd +COPY ../../conf/table.yaml $basepath/conf/table.yaml +COPY ../../conf/cache.yaml $basepath/conf/cache.yaml CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file -- Gitee From b0648ba02ba26ef9df7d4dc99e27006149a098da Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Tue, 24 Aug 2021 17:57:19 +0800 Subject: [PATCH 08/39] feat: alter readme. --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f8ec102..fbe85f1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://app.travis-ci.com/DTC8/DTC.svg?branch=master)](https://app.travis-ci.com/github/DTC8/DTC) ## 姒傝堪 -DTC鏄竴涓垎甯冨紡琛ㄧ骇缂撳瓨绯荤粺銆 +DTC鏄竴涓垎甯冨紡琛ㄧ骇缂撳瓨绯荤粺锛屽彲涓烘暟鎹簱鎻愪緵鐑偣鏁版嵁缂撳瓨鏀寔锛屽噺灏戞暟鎹簱鐨勮闂帇鍔涖 DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: * **Agent** - 鎻愪緵Key璺敱銆佸懡浠よ姹傜殑鏈嶅姟銆 @@ -11,6 +11,19 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: * **Connector** - 姝ょ粍浠朵负缂撳瓨涓庢寔涔呭寲瀛樺偍鏁版嵁搴擄紙渚嬪锛歁ySql锛変箣闂存彁渚涜繛鎺ュ拰鏁版嵁浼犺緭鍔熻兘銆 ## 鐗瑰緛 +* 涓烘暟鎹簱鎻愪緵淇濇姢鏈哄埗锛 + - 淇濇姢绌鸿妭鐐癸紝闃叉缂撳瓨绌块忋 + - 鎻愪緵姘镐笉杩囨湡鐨勭紦瀛樻暟鎹紝闃叉缂撳瓨鍑荤┛銆 + - 鏁版嵁婧愮嚎绋嬫煍鎬у彲鐢紝淇濇姢鏁版嵁搴撴湁闄愮殑杩炴帴鏁般 + - 棰勪及瓒呮椂鏈哄埗锛屽噺灏戞棤鏁堟暟鎹簱璇锋眰銆 +* 淇濋殰缂撳瓨鍜屾暟鎹簱鐨勬暟鎹竴鑷存э細 + - write-through鏈哄埗锛屼繚璇佺紦瀛樺拰鏁版嵁搴撴暟鎹竴鑷淬 + - 鏍呮爮鏈哄埗锛岄槻姝㈤珮骞跺彂鎯呮櫙涓嬫洿鏂拌姹備涪澶便 + - 鏀寔鍒嗗簱鍒嗚〃銆 +* 缂撳瓨楂樻ц兘锛 + - 闆嗘垚鍐呭瓨鍒嗛厤鏈哄埗锛岄伩鍏嶉绻佺郴缁熻皟鐢ㄣ + - I/O澶氳矾澶嶇敤鏈哄埗锛屾壙鎺ュぇ骞跺彂璇锋眰閲忋 + - 澶氱鏁版嵁缁撴瀯妯″瀷锛屾彁楂樺唴瀛樿鍐欓熷害銆 ## 鎬ц兘 鍗曟牳CPU锛屽崟DTC瀹炰緥鎯呭喌涓嬶紝鍙敮鎸60,000 QPS鐨勬煡璇紱 -- Gitee From b9f5bd87fa70ae98e2c364abc079a809b080dbee Mon Sep 17 00:00:00 2001 From: wuxinzhen1 Date: Tue, 24 Aug 2021 18:04:04 +0800 Subject: [PATCH 09/39] fix: cmake --- src/CMakeLists.txt | 6 ++ src/agent/CMakeLists.txt | 25 ++++++++ src/conf/cache.yaml | 27 +++++++++ src/conf/table.yaml | 55 ++++++++++++++++++ src/configcenter/ca_api/CMakeLists.txt | 18 ++++++ src/core/CMakeLists.txt | 58 +++++++++++++++++++ src/daemons/CMakeLists.txt | 40 +++++++++++++ src/libs/CMakeLists.txt | 2 + src/libs/common/CMakeLists.txt | 35 +++++++++++ .../common/config/parse_cluster_config.cc | 13 +++++ src/libs/common/config/parse_cluster_config.h | 4 +- src/libs/common/daemon/daemon.cc | 3 +- src/libs/common/log/log.h | 3 +- src/libs/common/proc_title.c | 1 + src/libs/common/version.h | 2 +- src/libs/stat/CMakeLists.txt | 37 ++++++++++++ src/libs/stat/stat_dtc.h | 4 +- 17 files changed, 326 insertions(+), 7 deletions(-) create mode 100644 src/CMakeLists.txt create mode 100644 src/agent/CMakeLists.txt create mode 100755 src/conf/cache.yaml create mode 100755 src/conf/table.yaml create mode 100644 src/configcenter/ca_api/CMakeLists.txt create mode 100644 src/core/CMakeLists.txt create mode 100644 src/daemons/CMakeLists.txt create mode 100644 src/libs/CMakeLists.txt create mode 100644 src/libs/common/CMakeLists.txt create mode 100644 src/libs/stat/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..a3b4dcd --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required (VERSION 2.8) +project (demo) + +add_subdirectory(./libs) +add_subdirectory(./daemons) +add_subdirectory(./core) diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt new file mode 100644 index 0000000..edbcda2 --- /dev/null +++ b/src/agent/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required (VERSION 3.5) +project (agent) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +include_directories(. ./common ./event + ./hashkit ./proto) + + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 +aux_source_directory(. SRC_LIST1) +aux_source_directory(./common SRC_LIST2) +aux_source_directory(./event SRC_LIST3) +aux_source_directory(./hashkit SRC_LIST4) +aux_source_directory(./proto STRC_LIST5) + +#閾炬帴鐩爣搴 +link_libraries(rt) +link_libraries(mxml) +link_libraries(pthread) +#缂栬瘧鍙傛暟 +add_definitions("-pg -DCONFIG_REGPARM=3 -DHAVE_STATS=1 -DUSE_COMPATIBLE_MODE=1 -DHAVE_ASSERT_LOG=1") + +#缂栬瘧涓.so/.a +add_executable(dtcagent ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3} ${SRC_LIST4} ${SRC_LIST5}) + diff --git a/src/conf/cache.yaml b/src/conf/cache.yaml new file mode 100755 index 0000000..5deaca6 --- /dev/null +++ b/src/conf/cache.yaml @@ -0,0 +1,27 @@ +cache: + LogLevel: debug + BindAddr: '*:20015/tcp' + IdleTimeout: 30 + HelperTimeout: 30 + CacheShmKey: 20015 + CacheMemorySize: 100 + CacheAverageDataSize: 50 + MaxFlushSpeed: 1 + MinDirtyNode: 40 + MaxDirtyNode: 60 + MinDirtyTime: 3600 + MaxDirtyTime: 43200 + DelayUpdate: 0 + DisableDataSource: 1 + OpenningFDAttrID: 41784 + EnableCoreDump: 1 + RemoteLogAddr: 172.28.133.131 + RemoteLogPort: 9876 + UseSingleThread: 1 + DisableLRUUpdate: 2 + MaxIncomingPollers@inc0: 10000 + MaxFdCount: 10240 + MaxBarrierCount: 100000 + # DisableWatchDog: 1 + MaxKeyCount: 10000 + FaultLoggerMode: disable diff --git a/src/conf/table.yaml b/src/conf/table.yaml new file mode 100755 index 0000000..cf4417a --- /dev/null +++ b/src/conf/table.yaml @@ -0,0 +1,55 @@ +DB_DEFINE: + DbName: test + DbNum: (1,1) + dbMax: 1 + MachineNum: 1 + Deploy: 0 + EnableKeyHash: 0 + KeyHashSo: ../lib/key-hash.so + KeyHashFunction: StringHash(1,128) + +MACHINE1: + Procs: 10 + WriteProcs: 10 + CommitProcs: 10 + DbIdx: 0 + DbAddr: 127.0.0.1:3306 + DbUser: root + DbPass: DTC@ecc2014 + +TABLE_DEFINE: + TableName: Table_Test + FieldCount: 5 + eyFieldCount: 1 + TableNum: (1,100) + +# None=0, Signed=1, Unsigned=2, Float=3, String=4, Binary=5 +FIELD1: + FieldName: uid + FieldType: 1 + FieldSize: 4 + UniqField: 0 + +FIELD2: + FieldName: name + FieldType: 4 + FieldSize: 255 + UniqField: 0 + +FIELD3: + FieldName: city + FieldType: 4 + FieldSize: 255 + UniqField: 0 + +FIELD4: + FieldName: sex + FieldType: 1 + FieldSize: 4 + UniqField: 0 + +FIELD5: + FieldName: age + FieldType: 1 + FieldSize: 4 + UniqField: 0 diff --git a/src/configcenter/ca_api/CMakeLists.txt b/src/configcenter/ca_api/CMakeLists.txt new file mode 100644 index 0000000..65416c7 --- /dev/null +++ b/src/configcenter/ca_api/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required (VERSION 3.5) +project (configcenter) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +include_directories (.) + + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 +aux_source_directory (. SRC_LIST1) + +#缂栬瘧鍙傛暟 +add_definitions("-g -Wall -fPIC") + +#缂栬瘧涓.so/.a +add_executable(client-tool ${SRC_LIST1}) +add_library(app-client ${SRC_LIST1}) + + diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 0000000..66003f3 --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,58 @@ +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) +set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 +FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +include_directories ( + . ./algorithm ./chain ./data + ./hotbk ./log ./mem ./misc ./node + ./nodegroup ./raw ./task ./time ./tree ./buffer + ../libs/common + ../devel/cpp + ../daemons + ../libs/stat + ../connector + ../libs/log4cplus/include + ../libs/zlib/include64 + ../libs/yaml-cpp/include) + +#娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L +link_directories ( + ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/libs/zlib/lib/ + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/libs/stat + ${PROJECT_SOURCE_DIR}/daemons) + +#娣诲姞閾炬帴搴擄紝鐩稿綋浜巊cc -l +link_libraries(liblog4cplus.a) +link_libraries(libcommon.a) +link_libraries(libyaml-cpp.a) +linK_libraries(libstat.a) +link_libraries(libdaemons.a) +link_libraries(libz64.a) +link_libraries(pthread) +link_libraries(dl) +#缂栬瘧鍙傛暟 +add_definitions (" -g -rdynamic -fPIC -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -export-dynamic -Wl,--version-script,dtcd.export.lst -std=gnu++11") + +#缂栬瘧涓.so/.a +add_executable (dtcd ${SRC_LIST1} ${SRC_LIST2} ./buffer/buffer_flush ./buffer/buffer_pond ${SRC_LIST4} ${SRC_LIST5} + ${SRC_LIST6} ${SRC_LIST7} ${SRC_LIST8} ${SRC_LIST9} ${SRC_LIST10} + ${SRC_LIST11} ${SRC_LIST12} ${SRC_LIST13} ${SRC_LIST14} ${SRC_LIST15} + ) + + +add_library (dtcdd ${SRC_LIST1} ${SRC_LIST2} ./buffer/buffer_flush ./buffer/buffer_pond ${SRC_LIST4} ${SRC_LIST5} + ${SRC_LIST6} ${SRC_LIST7} ${SRC_LIST8} ${SRC_LIST9} ${SRC_LIST10} + ${SRC_LIST11} ${SRC_LIST12} ${SRC_LIST13} ${SRC_LIST14} ${SRC_LIST15} + ) + +#灏嗙洰鏍囨枃浠朵笌搴撴枃浠堕摼鎺 +target_link_libraries(dtcd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) +target_link_libraries(dtcdd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) + + diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt new file mode 100644 index 0000000..bc29f21 --- /dev/null +++ b/src/daemons/CMakeLists.txt @@ -0,0 +1,40 @@ +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) +set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +include_directories ( + ${PROJECT_SOURCE_DIR}/daemons + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/libs/stat + ${PROJECT_SOURCE_DIR}/libs/log4cplus/include + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) + +#娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L +link_directories ( + ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/libs/stat) + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 +aux_source_directory (${PROJECT_SOURCE_DIR}/daemons SRC_LIST1) +aux_source_directory (${PROJECT_SOURCE_DIR}/libs/stat/stat_alarm_reporter SRC_LIST2) + +#閾炬帴鐩爣搴 +link_libraries(liblog4cplus.a) +link_libraries(libcommon.a) +link_libraries(libyaml-cpp.a) +linK_libraries(libstat.a) +link_libraries(pthread) +link_libraries(dl) + +#缂栬瘧鍙傛暟 +add_definitions("-g -fPIC -fpermissive -std=gnu++11") + +#缂栬瘧涓.so/.a +add_executable(faultlogger ${SRC_LIST1} ${SRC_LIST2}) +add_library(daemons ${SRC_LIST1} ${SRC_LIST2}) + +#鎶婄洰鏍囨枃浠朵笌搴撴枃浠惰繘琛岄摼鎺 +target_link_libraries(faultlogger libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a) +target_link_libraries(daemons libstat.a liblog4cplus.a libyaml-cpp.a libcommon.a) diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt new file mode 100644 index 0000000..5d7bf52 --- /dev/null +++ b/src/libs/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory (./common) +add_subdirectory (./stat) \ No newline at end of file diff --git a/src/libs/common/CMakeLists.txt b/src/libs/common/CMakeLists.txt new file mode 100644 index 0000000..d7e7e27 --- /dev/null +++ b/src/libs/common/CMakeLists.txt @@ -0,0 +1,35 @@ +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/common) + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 +FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +INCLUDE_DIRECTORIES ( + . + ../../devel/cpp + ../../daemons + ../stat + ../log4cplus/include/ + ../zlib/include64 + ../yaml-cpp/include/) + +#娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L +LINK_DIRECTORIES ( + ${PROJECT_SOURCE_DIR}/libs/zlib/lib/libz64.a + ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs +) + +#娣诲姞閾炬帴搴擄紝鐩稿綋浜巊cc -l +LINK_LIBRARIES(liblog4cplus.a) +LINK_LIBRARIES(libyaml-cpp.a) +LINK_LIBRARIES(libz64.a) +LINK_LIBRARIES(pthread) + +#缂栬瘧鍙傛暟 +ADD_DEFINITIONS ("-g -fPIC -fpermissive -std=gnu++11") +#缂栬瘧涓.so/.a +ADD_LIBRARY (common ${SRC_LIST}) + +#灏嗙洰鏍囨枃浠朵笌搴撴枃浠堕摼鎺 +TARGET_LINK_LIBRARIES(common liblog4cplus.a libyaml-cpp.a libz64.a) \ No newline at end of file diff --git a/src/libs/common/config/parse_cluster_config.cc b/src/libs/common/config/parse_cluster_config.cc index 5943e27..845385d 100644 --- a/src/libs/common/config/parse_cluster_config.cc +++ b/src/libs/common/config/parse_cluster_config.cc @@ -35,27 +35,38 @@ bool parse_cluster_config(std::string &strSelfName, std::vector *result, const char *buf, int len) { + log4cplus_debug("%.*s", len, buf); //閰嶇疆涓笉鍏佽鏈夌浉鍚宻ervername鐨勮妭鐐瑰嚭鐜帮紝鏈瑂et鐢ㄤ簬妫鏌ラ噸澶峴ervername + std::set filter; + pair::iterator, bool> ret; string xmldoc(buf, len); + MarkupSTL xml; + if (!xml.set_doc(xmldoc.c_str())) { + log4cplus_error("parse config file error"); + return false; } + xml.reset_main_pos(); if (!xml.find_elem("serverlist")) { log4cplus_error("no serverlist info"); return -1; } + strSelfName = xml.get_attrib("selfname"); + log4cplus_debug("strSelfName is %s", strSelfName.c_str()); while (xml.find_child_elem("server")) { + if (xml.into_elem()) { struct ClusterNode node; node.name = xml.get_attrib("name"); @@ -83,7 +94,9 @@ bool parse_cluster_config(std::string &strSelfName, result->push_back(node); xml.out_of_elem(); } + log4cplus_debug("*********No.11************"); } + log4cplus_debug("*********No.12************"); if (result->empty()) log4cplus_info( "ClusterConfig is empty,dtc runing in normal mode"); diff --git a/src/libs/common/config/parse_cluster_config.h b/src/libs/common/config/parse_cluster_config.h index e7306d8..fe1cf99 100644 --- a/src/libs/common/config/parse_cluster_config.h +++ b/src/libs/common/config/parse_cluster_config.h @@ -21,8 +21,8 @@ #include namespace ClusterConfig { -#define CLUSTER_CONFIG_FILE "../conf/ClusterConfig.xml" - +//#define CLUSTER_CONFIG_FILE "../conf/ClusterConfig.xml" +#define CLUSTER_CONFIG_FILE "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/ClusterConfig.xml" struct ClusterNode { std::string name; std::string addr; diff --git a/src/libs/common/daemon/daemon.cc b/src/libs/common/daemon/daemon.cc index e7d529b..35e5f33 100644 --- a/src/libs/common/daemon/daemon.cc +++ b/src/libs/common/daemon/daemon.cc @@ -99,7 +99,8 @@ int load_entry_parameter(int argc, char **argv) //init_log("dtcd"); log4cplus_info("%s v%s: starting....", project_name, version); - + strcpy(table_file, "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/table.yaml"); + strcpy(cache_file, "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/cache.yaml"); g_dtc_config = new DTCConfig; //load config file and copy it to ../stat if (g_dtc_config->parse_config(table_file, "DB_DEFINE", true) == -1) diff --git a/src/libs/common/log/log.h b/src/libs/common/log/log.h index 20adefc..7d70217 100644 --- a/src/libs/common/log/log.h +++ b/src/libs/common/log/log.h @@ -66,7 +66,8 @@ using namespace log4cplus::helpers; static Logger logger = Logger::getRoot(); -#define LOG4CPLUS_CONF_FILE "../conf/log4cplus.conf" +#define LOG4CPLUS_CONF_FILE "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/log4cplus.conf" + /********************************************* **TRACE锛氳皟璇曞簲鐢ㄧ殑璇︾粏姝ラ **DEBUG锛氱畻娉曞叧閿儴鍒嗙殑鐩稿叧淇℃伅 diff --git a/src/libs/common/proc_title.c b/src/libs/common/proc_title.c index a5e29fa..ebc33a6 100644 --- a/src/libs/common/proc_title.c +++ b/src/libs/common/proc_title.c @@ -30,6 +30,7 @@ static char *arg_start; static char *arg_end; static char *env_start; +extern char **environ; //鍒濆鍖栬繘绋嬪悕 void init_proc_title(int argc, char **argv) diff --git a/src/libs/common/version.h b/src/libs/common/version.h index c2bb91e..059b364 100644 --- a/src/libs/common/version.h +++ b/src/libs/common/version.h @@ -8,7 +8,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "eab3ec6" BASIS, +* distributed under the License is distributed on an "3bbc168" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/src/libs/stat/CMakeLists.txt b/src/libs/stat/CMakeLists.txt new file mode 100644 index 0000000..9cca9f1 --- /dev/null +++ b/src/libs/stat/CMakeLists.txt @@ -0,0 +1,37 @@ +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/stat) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +include_directories ( +${PROJECT_SOURCE_DIR}/libs/stat +${PROJECT_SOURCE_DIR}/libs/common +${PROJECT_SOURCE_DIR}/libs/log4cplus/include +${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) + +#娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L +link_directories ( +${PROJECT_SOURCE_DIR}/libs/log4cplus/libs +${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs +${PROJECT_SOURCE_DIR}/libs/common) + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 +aux_source_directory (. SRC_LIST1) + +#閾炬帴鐩爣搴 +link_libraries(liblog4cplus.a) +link_libraries(libcommon.a) +link_libraries(libyaml-cpp.a) +link_libraries(pthread) +link_libraries(dl) + +#缂栬瘧鍙傛暟 +add_definitions("-g -fPIC -fpermissive -std=gnu++11") + +#缂栬瘧涓.so/.a +add_executable(stattool ${SRC_LIST1}) +add_library(stat ${SRC_LIST1}) + +#鎶婄洰鏍囨枃浠朵笌搴撴枃浠惰繘琛岄摼鎺 +target_link_libraries(stattool libcommon.a libyaml-cpp.a liblog4cplus.a) +target_link_libraries(stat liblog4cplus.a libyaml-cpp.a libcommon.a) + + diff --git a/src/libs/stat/stat_dtc.h b/src/libs/stat/stat_dtc.h index 827c541..d4450fb 100644 --- a/src/libs/stat/stat_dtc.h +++ b/src/libs/stat/stat_dtc.h @@ -20,8 +20,8 @@ #include "stat_thread.h" #include "stat_dtc_def.h" -#define STATIDX "../stat/dtc.stat.idx" - +//#define STATIDX "../stat/dtc.stat.idx" +#define STATIDX "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/stat/dtc.stat.idx" extern StatThread g_stat_mgr; extern int init_statistics(void); -- Gitee From 9aa435fe7d09294481b9712627e48257d9eacabe Mon Sep 17 00:00:00 2001 From: wuxinzhen1 Date: Wed, 25 Aug 2021 10:11:48 +0800 Subject: [PATCH 10/39] fix: core/CMakeLists.exe --- src/core/CMakeLists.txt | 29 +++-- src/core/buffer/buffer_reader.cc | 182 ----------------------------- src/core/buffer/buffer_reader.h | 78 ------------- src/core/buffer/buffer_writer.cc | 195 ------------------------------- src/core/buffer/buffer_writer.h | 56 --------- 5 files changed, 18 insertions(+), 522 deletions(-) delete mode 100644 src/core/buffer/buffer_reader.cc delete mode 100644 src/core/buffer/buffer_reader.h delete mode 100644 src/core/buffer/buffer_writer.cc delete mode 100644 src/core/buffer/buffer_writer.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 66003f3..84c2dd4 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -3,12 +3,11 @@ set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c) +FILE(GLOB_RECURSE SRC_LIST_INC ./*.h) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I include_directories ( - . ./algorithm ./chain ./data - ./hotbk ./log ./mem ./misc ./node - ./nodegroup ./raw ./task ./time ./tree ./buffer + . ../libs/common ../devel/cpp ../daemons @@ -18,6 +17,20 @@ include_directories ( ../libs/zlib/include64 ../libs/yaml-cpp/include) + # ./algorithm + # ./buffer + # ./chain + # ./data + # ./hotbk + # ./log + # ./mem + # ./misc + # ./node + # ./nodegroup + # ./raw + # ./task + # ./time + # ./tree #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L link_directories ( ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs @@ -40,16 +53,10 @@ link_libraries(dl) add_definitions (" -g -rdynamic -fPIC -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -export-dynamic -Wl,--version-script,dtcd.export.lst -std=gnu++11") #缂栬瘧涓.so/.a -add_executable (dtcd ${SRC_LIST1} ${SRC_LIST2} ./buffer/buffer_flush ./buffer/buffer_pond ${SRC_LIST4} ${SRC_LIST5} - ${SRC_LIST6} ${SRC_LIST7} ${SRC_LIST8} ${SRC_LIST9} ${SRC_LIST10} - ${SRC_LIST11} ${SRC_LIST12} ${SRC_LIST13} ${SRC_LIST14} ${SRC_LIST15} - ) +add_executable (dtcd ${SRC_LIST}) -add_library (dtcdd ${SRC_LIST1} ${SRC_LIST2} ./buffer/buffer_flush ./buffer/buffer_pond ${SRC_LIST4} ${SRC_LIST5} - ${SRC_LIST6} ${SRC_LIST7} ${SRC_LIST8} ${SRC_LIST9} ${SRC_LIST10} - ${SRC_LIST11} ${SRC_LIST12} ${SRC_LIST13} ${SRC_LIST14} ${SRC_LIST15} - ) +add_library (dtcdd ${SRC_LIST}) #灏嗙洰鏍囨枃浠朵笌搴撴枃浠堕摼鎺 target_link_libraries(dtcd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) diff --git a/src/core/buffer/buffer_reader.cc b/src/core/buffer/buffer_reader.cc deleted file mode 100644 index d262432..0000000 --- a/src/core/buffer/buffer_reader.cc +++ /dev/null @@ -1,182 +0,0 @@ -/* -* Copyright [2021] JD.com, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include -#include - -#include "task/task_pkey.h" -#include "buffer_reader.h" -#include "log/log.h" -#include "sys_malloc.h" - -BufferReader::BufferReader(void) : BufferPond(NULL) -{ - pstItem = NULL; - pstDataProcess = NULL; - iInDirtyLRU = 1; - notFetch = 1; -} - -BufferReader::~BufferReader(void) -{ - if (pstItem != NULL) - delete pstItem; - pstItem = NULL; -} - -int BufferReader::cache_open(int shmKey, int keySize, - DTCTableDefinition *p_table_definition_) -{ - int iRet; - - BlockProperties stInfo; - memset(&stInfo, 0, sizeof(stInfo)); - stInfo.ipcMemKey = shmKey; - stInfo.keySize = keySize; - stInfo.readOnly = 1; - - iRet = BufferPond::cache_open(&stInfo); - if (iRet != E_OK) - return -1; - - pstItem = new RawData(&g_stSysMalloc, 1); - if (pstItem == NULL) { - snprintf(error_message, sizeof(error_message), - "new RawData error: %m"); - return -1; - } - - UpdateMode stUpdateMod; - stUpdateMod.m_iAsyncServer = MODE_SYNC; - stUpdateMod.m_iUpdateMode = MODE_SYNC; - stUpdateMod.m_iInsertMode = MODE_SYNC; - stUpdateMod.m_uchInsertOrder = 0; - - if (p_table_definition_->index_fields() > 0) { -#if HAS_TREE_DATA - pstDataProcess = new TreeDataProcess(PtMalloc::instance(), - p_table_definition_, this, - &stUpdateMod); -#else - log4cplus_error("tree index not supported, index field num[%d]", - p_table_definition_->index_fields()); - return -1; -#endif - } else - pstDataProcess = new RawDataProcess(PtMalloc::instance(), - p_table_definition_, this, - &stUpdateMod); - if (pstDataProcess == NULL) { - log4cplus_error("create %s error: %m", - p_table_definition_->index_fields() > 0 ? - "TreeDataProcess" : - "RawDataProcess"); - return -1; - } - - return 0; -} - -int BufferReader::begin_read() -{ - stDirtyHead = dirty_lru_head(); - stClrHead = clean_lru_head(); - if (!dirty_lru_empty()) { - iInDirtyLRU = 1; - stCurNode = stDirtyHead; - } else { - iInDirtyLRU = 0; - stCurNode = stClrHead; - } - return 0; -} - -int BufferReader::fetch_node() -{ - pstItem->destory(); - if (!stCurNode) { - snprintf(error_message, sizeof(error_message), - "begin read first!"); - return -1; - } - if (end()) { - snprintf(error_message, sizeof(error_message), - "reach end of cache"); - return -2; - } - notFetch = 0; - - curRowIdx = 0; - if (iInDirtyLRU) { - while (stCurNode != stDirtyHead && is_time_marker(stCurNode)) - stCurNode = stCurNode.Next(); - if (stCurNode != stDirtyHead && !is_time_marker(stCurNode)) { - if (pstDataProcess->get_node_all_rows_count( - &stCurNode, pstItem) != 0) { - snprintf(error_message, sizeof(error_message), - "get node's data error"); - return -3; - } - return (0); - } - - iInDirtyLRU = 0; - stCurNode = stClrHead.Next(); - } - - stCurNode = stCurNode.Next(); - if (stCurNode != stClrHead) { - if (pstDataProcess->get_node_all_rows_count(&stCurNode, - pstItem) != 0) { - snprintf(error_message, sizeof(error_message), - "get node's data error"); - return -3; - } - } else { - snprintf(error_message, sizeof(error_message), - "reach end of cache"); - return -2; - } - - return (0); -} - -int BufferReader::num_rows() -{ - if (pstItem == NULL) - return (-1); - - return pstItem->total_rows(); -} - -int BufferReader::read_row(RowValue &row) -{ - while (notFetch || curRowIdx >= (int)pstItem->total_rows()) { - if (fetch_node() != 0) - return -1; - } - - TaskPackedKey::unpack_key(row.table_definition(), pstItem->key(), - row.field_value(0)); - - if (pstItem->decode_row(row, uchRowFlags, 0) != 0) - return -2; - - curRowIdx++; - - return 0; -} diff --git a/src/core/buffer/buffer_reader.h b/src/core/buffer/buffer_reader.h deleted file mode 100644 index 9097983..0000000 --- a/src/core/buffer/buffer_reader.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright [2021] JD.com, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef __CACHE_READER_H -#define __CACHE_READER_H - -#include "reader_interface.h" -#include "buffer_pond.h" -#include "table/table_def.h" -#include "raw_data_process.h" - -class BufferReader : public ReaderInterface, public BufferPond { - private: - Node stClrHead; - Node stDirtyHead; - int iInDirtyLRU; - Node stCurNode; - unsigned char uchRowFlags; - RawData *pstItem; - DataProcess *pstDataProcess; - int notFetch; - int curRowIdx; - char error_message[200]; - - public: - BufferReader(void); - ~BufferReader(void); - - int cache_open(int shmKey, int keySize, - DTCTableDefinition *p_table_definition_); - - const char *err_msg() - { - return error_message; - } - int begin_read(); - int read_row(RowValue &row); - int end(); - int key_flags(void) const - { - return stCurNode.is_dirty(); - } - int key_flag_dirty(void) const - { - return stCurNode.is_dirty(); - } - int row_flags(void) const - { - return uchRowFlags; - } - int row_flag_dirty(void) const - { - return uchRowFlags & OPER_DIRTY; - } - int fetch_node(); - int num_rows(); -}; - -inline int BufferReader::end() -{ - return (iInDirtyLRU == 0) && (notFetch == 0) && - (stCurNode == stClrHead); -} - -#endif diff --git a/src/core/buffer/buffer_writer.cc b/src/core/buffer/buffer_writer.cc deleted file mode 100644 index ec7dc85..0000000 --- a/src/core/buffer/buffer_writer.cc +++ /dev/null @@ -1,195 +0,0 @@ -/* -* Copyright [2021] JD.com, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include -#include - -#include "task/task_pkey.h" -#include "buffer_writer.h" -#include "pt_malloc.h" -#include "sys_malloc.h" -#include "log/log.h" - -BufferWriter::BufferWriter(void) : BufferPond(NULL) -{ - pstItem = NULL; - iRowIdx = 0; - iIsFull = 0; - memset(achPackKey, 0, sizeof(achPackKey)); -} - -BufferWriter::~BufferWriter(void) -{ - if (pstItem != NULL) - delete pstItem; - pstItem = NULL; -} - -int BufferWriter::cache_open(BlockProperties *pstInfo, - DTCTableDefinition *p_table_definition_) -{ - int iRet; - - iRet = BufferPond::cache_open(pstInfo); - if (iRet != E_OK) { - log4cplus_error("cache open error: %d, %s", iRet, Error()); - return -1; - } - - pstItem = new RawData(&g_stSysMalloc, 1); - if (pstItem == NULL) { - snprintf(szErrMsg, sizeof(szErrMsg), "new RawData error: %m"); - return -2; - } - - UpdateMode stUpdateMod; - stUpdateMod.m_iAsyncServer = - pstInfo->syncUpdate ? MODE_SYNC : MODE_ASYNC; - stUpdateMod.m_iUpdateMode = - pstInfo->syncUpdate ? MODE_SYNC : MODE_ASYNC; - stUpdateMod.m_iInsertMode = - pstInfo->syncUpdate ? MODE_SYNC : MODE_ASYNC; - stUpdateMod.m_uchInsertOrder = 0; - - if (p_table_definition_->index_fields() > 0) { -#if HAS_TREE_DATA - pstDataProcess = new TreeDataProcess(PtMalloc::instance(), - p_table_definition_, this, - &stUpdateMod); -#else - log4cplus_error("tree index not supported, index field num[%d]", - p_table_definition_->index_fields()); - return -1; -#endif - } else - pstDataProcess = new RawDataProcess(PtMalloc::instance(), - p_table_definition_, this, - &stUpdateMod); - if (pstDataProcess == NULL) { - log4cplus_error("create %s error: %m", - p_table_definition_->index_fields() > 0 ? - "TreeDataProcess" : - "RawDataProcess"); - return -3; - } - - return 0; -} - -int BufferWriter::begin_write() -{ - iRowIdx = 0; - - return 0; -} - -int BufferWriter::full() -{ - return (iIsFull); -} - -int BufferWriter::AllocNode(const RowValue &row) -{ - int iRet; - - iRet = TaskPackedKey::build_packed_key(row.table_definition(), - row.field_value(0), - sizeof(achPackKey), achPackKey); - if (iRet != 0) { - snprintf(szErrMsg, sizeof(szErrMsg), - "build packed key error: %d", iRet); - return -1; - } - - stCurNode = cache_allocation(achPackKey); - if (!stCurNode) { - snprintf(szErrMsg, sizeof(szErrMsg), "cache alloc node error"); - iIsFull = 1; - return -2; - } - - iRet = pstItem->init(row.table_definition()->key_fields() - 1, - row.table_definition()->key_format(), achPackKey, - 0); - if (iRet != 0) { - snprintf(szErrMsg, sizeof(szErrMsg), "raw data init error: %s", - pstItem->get_err_msg()); - cache_purge(achPackKey); - return -3; - } - - return 0; -} - -int BufferWriter::write_row(const RowValue &row) -{ - int iRet; - - if (iRowIdx == 0) { - if (AllocNode(row) != 0) - return -1; - } - - iRet = pstItem->insert_row(row, false, false); - if (iRet != 0) { - snprintf(szErrMsg, sizeof(szErrMsg), "insert row error: %s", - pstItem->get_err_msg()); - cache_purge(achPackKey); - return -2; - } - - iRowIdx++; - return 0; -} - -int BufferWriter::commit_node() -{ - int iRet; - - if (iRowIdx < 1) - return 0; - - const MemHead *pstHead = PtMalloc::instance()->get_head_info(); - if (pstHead->m_hTop + pstItem->data_size() + MINSIZE >= - pstHead->m_tSize) { - iIsFull = 1; - cache_purge(achPackKey); - return -1; - } - - iRet = pstDataProcess->do_replace_all(&stCurNode, pstItem); - if (iRet != 0) { - snprintf(szErrMsg, sizeof(szErrMsg), - "write data into cache error"); - cache_purge(achPackKey); - return -2; - } - - iRowIdx = 0; - memset(achPackKey, 0, sizeof(achPackKey)); - pstItem->destory(); - return 0; -} - -int BufferWriter::rollback_node() -{ - pstItem->destory(); - cache_purge(achPackKey); - memset(achPackKey, 0, sizeof(achPackKey)); - - return 0; -} diff --git a/src/core/buffer/buffer_writer.h b/src/core/buffer/buffer_writer.h deleted file mode 100644 index 09a9d98..0000000 --- a/src/core/buffer/buffer_writer.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Copyright [2021] JD.com, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef __CACHE_WRITER_H -#define __CACHE_WRITER_H - -#include "buffer_pond.h" -#include "table/table_def.h" -#include "writer_interface.h" -#include "raw_data_process.h" - -class BufferWriter : public WriterInterface, public BufferPond { - private: - RawData *pstItem; - DataProcess *pstDataProcess; - int iIsFull; - int iRowIdx; - Node stCurNode; - char achPackKey[MAX_KEY_LEN + 1]; - char szErrMsg[200]; - - protected: - int AllocNode(const RowValue &row); - - public: - BufferWriter(void); - ~BufferWriter(void); - - int cache_open(BlockProperties *pstInfo, - DTCTableDefinition *p_table_definition_); - - const char *err_msg() - { - return szErrMsg; - } - int begin_write(); - int full(); - int write_row(const RowValue &row); - int commit_node(); - int rollback_node(); -}; - -#endif -- Gitee From 37cb4f758ede3fa5c41cd5c624bd40e09a60099f Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Wed, 25 Aug 2021 11:30:34 +0800 Subject: [PATCH 11/39] fix: readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fbe85f1..d190b22 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: `git clone https://github.com/gflags/gflags.git`
`cd gflags`
`git checkout -b 2.2 v2.2.2`
- `cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
+ `cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
`make && sudo make install`
`sudo ldconfig `
`sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
-- Gitee From 8c154f3dfe99a4975aeefe2358f0daceea3e9352 Mon Sep 17 00:00:00 2001 From: wuxinzhen1 Date: Wed, 25 Aug 2021 15:25:30 +0800 Subject: [PATCH 12/39] fix: cmakelists --- README.md | 2 +- src/core/CMakeLists.txt | 82 ++++++++++++++++------------------ src/daemons/CMakeLists.txt | 48 +++++++++++--------- src/libs/common/CMakeLists.txt | 6 ++- src/libs/stat/CMakeLists.txt | 46 ++++++++++--------- 5 files changed, 94 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 21f9ce8..99eaa4d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: `git clone https://github.com/gflags/gflags.git`
`cd gflags`
`git checkout -b 2.2 v2.2.2`
- `cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
+ `cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
`make && sudo make install`
`sudo ldconfig `
`sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 84c2dd4..e300f34 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,38 +1,33 @@ -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) -set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) +#璁剧疆搴撴枃浠惰緭鍑鸿矾寰 +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) +#璁剧疆鍙墽琛屾枃浠惰緭鍑鸿矾寰 +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) + +if(CMAKE_COMPILER_IS_GNUCXX) + add_compile_options(-std=gnu++11) +endif(CMAKE_COMPILER_IS_GNUCXX) + #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c) -FILE(GLOB_RECURSE SRC_LIST_INC ./*.h) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I -include_directories ( - . - ../libs/common - ../devel/cpp - ../daemons - ../libs/stat - ../connector - ../libs/log4cplus/include - ../libs/zlib/include64 - ../libs/yaml-cpp/include) - - # ./algorithm - # ./buffer - # ./chain - # ./data - # ./hotbk - # ./log - # ./mem - # ./misc - # ./node - # ./nodegroup - # ./raw - # ./task - # ./time - # ./tree +INCLUDE_DIRECTORIES( + . ./algorithm ./buffer ./chain + ./data ./hotbk ./log ./mem + ./misc ./node ./nodegroup ./raw + ./task ./time ./tree + ../libs/common + ../devel/cpp + ../daemons + ../libs/stat + ../connector + ../libs/log4cplus/include + ../libs/zlib/include64 + ../libs/yaml-cpp/include) + #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L -link_directories ( +LINK_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs ${PROJECT_SOURCE_DIR}/libs/zlib/lib/ @@ -41,25 +36,24 @@ link_directories ( ${PROJECT_SOURCE_DIR}/daemons) #娣诲姞閾炬帴搴擄紝鐩稿綋浜巊cc -l -link_libraries(liblog4cplus.a) -link_libraries(libcommon.a) -link_libraries(libyaml-cpp.a) -linK_libraries(libstat.a) -link_libraries(libdaemons.a) -link_libraries(libz64.a) -link_libraries(pthread) -link_libraries(dl) +LINK_LIBRARIES(liblog4cplus.a) +LINK_LIBRARIES(libcommon.a) +LINK_LIBRARIES(libyaml-cpp.a) +LINK_LIBRARIES(libstat.a) +LINK_LIBRARIES(libdaemons.a) +LINK_LIBRARIES(libz64.a) +LINK_LIBRARIES(pthread) +LINK_LIBRARIES(dl) + #缂栬瘧鍙傛暟 -add_definitions (" -g -rdynamic -fPIC -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -export-dynamic -Wl,--version-script,dtcd.export.lst -std=gnu++11") +ADD_DEFINITIONS(" -g -rdynamic -fPIC -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -export-dynamic -Wl,--version-script,dtcd.export.lst") #缂栬瘧涓.so/.a -add_executable (dtcd ${SRC_LIST}) - - -add_library (dtcdd ${SRC_LIST}) +ADD_EXECUTABLE(dtcd ${SRC_LIST}) +ADD_LIBRARY(dtcdd ${SRC_LIST}) #灏嗙洰鏍囨枃浠朵笌搴撴枃浠堕摼鎺 -target_link_libraries(dtcd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) -target_link_libraries(dtcdd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) +TARGET_LINK_LIBRARIES(dtcd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) +TARGET_LINK_LIBRARIES(dtcdd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index bc29f21..f729c53 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -1,40 +1,44 @@ -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) -set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) + +if(CMAKE_COMPILER_IS_GNUCXX) + add_compile_options(-std=gnu++11) +endif(CMAKE_COMPILER_IS_GNUCXX) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I -include_directories ( - ${PROJECT_SOURCE_DIR}/daemons - ${PROJECT_SOURCE_DIR}/libs/common - ${PROJECT_SOURCE_DIR}/libs/stat - ${PROJECT_SOURCE_DIR}/libs/log4cplus/include - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/daemons + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/libs/stat + ${PROJECT_SOURCE_DIR}/libs/log4cplus/include + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L -link_directories ( +LINK_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs ${PROJECT_SOURCE_DIR}/libs/common ${PROJECT_SOURCE_DIR}/libs/stat) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 -aux_source_directory (${PROJECT_SOURCE_DIR}/daemons SRC_LIST1) -aux_source_directory (${PROJECT_SOURCE_DIR}/libs/stat/stat_alarm_reporter SRC_LIST2) +FILE(GLOB_RECURSE SRC_LIST1 ./*.cc ./*.c) +#aux_source_directory(${PROJECT_SOURCE_DIR}/libs/stat/stat_alarm_reporter SRC_LIST2) #閾炬帴鐩爣搴 -link_libraries(liblog4cplus.a) -link_libraries(libcommon.a) -link_libraries(libyaml-cpp.a) -linK_libraries(libstat.a) -link_libraries(pthread) -link_libraries(dl) +LINK_LIBRARIES(liblog4cplus.a) +LINK_LIBRARIES(libcommon.a) +LINK_LIBRARIES(libyaml-cpp.a) +LINK_LIBRARIES(libstat.a) +LINK_LIBRARIES(pthread) +LINK_LIBRARIES(dl) #缂栬瘧鍙傛暟 -add_definitions("-g -fPIC -fpermissive -std=gnu++11") +ADD_DEFINITIONS("-g -fPIC -fpermissive") #缂栬瘧涓.so/.a -add_executable(faultlogger ${SRC_LIST1} ${SRC_LIST2}) -add_library(daemons ${SRC_LIST1} ${SRC_LIST2}) +ADD_EXECUTABLE(faultlogger ${SRC_LIST1}) +ADD_LIBRARY(daemons ${SRC_LIST1}) #鎶婄洰鏍囨枃浠朵笌搴撴枃浠惰繘琛岄摼鎺 -target_link_libraries(faultlogger libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a) -target_link_libraries(daemons libstat.a liblog4cplus.a libyaml-cpp.a libcommon.a) +TARGET_LINK_LIBRARIES(faultlogger libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a) +TARGET_LINK_LIBRARIES(daemons libstat.a liblog4cplus.a libyaml-cpp.a libcommon.a) diff --git a/src/libs/common/CMakeLists.txt b/src/libs/common/CMakeLists.txt index d7e7e27..60c024c 100644 --- a/src/libs/common/CMakeLists.txt +++ b/src/libs/common/CMakeLists.txt @@ -1,5 +1,9 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/common) +if(CMAKE_COMPILER_IS_GNUCXX) + add_compile_options(-std=gnu++11) +endif(CMAKE_COMPILER_IS_GNUCXX) + #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c) @@ -27,7 +31,7 @@ LINK_LIBRARIES(libz64.a) LINK_LIBRARIES(pthread) #缂栬瘧鍙傛暟 -ADD_DEFINITIONS ("-g -fPIC -fpermissive -std=gnu++11") +ADD_DEFINITIONS ("-g -fPIC -fpermissive") #缂栬瘧涓.so/.a ADD_LIBRARY (common ${SRC_LIST}) diff --git a/src/libs/stat/CMakeLists.txt b/src/libs/stat/CMakeLists.txt index 9cca9f1..66f3ff5 100644 --- a/src/libs/stat/CMakeLists.txt +++ b/src/libs/stat/CMakeLists.txt @@ -1,37 +1,39 @@ -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/stat) - +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/stat) +if(CMAKE_COMPILER_IS_GNUCXX) + add_compile_options(-std=gnu++11) +endif(CMAKE_COMPILER_IS_GNUCXX) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I -include_directories ( -${PROJECT_SOURCE_DIR}/libs/stat -${PROJECT_SOURCE_DIR}/libs/common -${PROJECT_SOURCE_DIR}/libs/log4cplus/include -${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/libs/stat + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/libs/log4cplus/include + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L -link_directories ( -${PROJECT_SOURCE_DIR}/libs/log4cplus/libs -${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs -${PROJECT_SOURCE_DIR}/libs/common) +LINK_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/libs/common) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 -aux_source_directory (. SRC_LIST1) +FILE(GLOB_RECURSE SRC_LIST1 ./*.cc ./*.c) #閾炬帴鐩爣搴 -link_libraries(liblog4cplus.a) -link_libraries(libcommon.a) -link_libraries(libyaml-cpp.a) -link_libraries(pthread) -link_libraries(dl) +LINK_LIBRARIES(liblog4cplus.a) +LINK_LIBRARIES(libcommon.a) +LINK_LIBRARIES(libyaml-cpp.a) +LINK_LIBRARIES(pthread) +LINK_LIBRARIES(dl) #缂栬瘧鍙傛暟 -add_definitions("-g -fPIC -fpermissive -std=gnu++11") +ADD_DEFINITIONS("-g -fPIC -fpermissive") #缂栬瘧涓.so/.a -add_executable(stattool ${SRC_LIST1}) -add_library(stat ${SRC_LIST1}) +ADD_EXECUTABLE(stattool ${SRC_LIST1}) +ADD_LIBRARY(stat ${SRC_LIST1}) #鎶婄洰鏍囨枃浠朵笌搴撴枃浠惰繘琛岄摼鎺 -target_link_libraries(stattool libcommon.a libyaml-cpp.a liblog4cplus.a) -target_link_libraries(stat liblog4cplus.a libyaml-cpp.a libcommon.a) +TARGET_LINK_LIBRARIES(stattool libcommon.a libyaml-cpp.a liblog4cplus.a) +TARGET_LINK_LIBRARIES(stat liblog4cplus.a libyaml-cpp.a libcommon.a) -- Gitee From 1633a7a1c1e71f972adcdfb7c98c6b7fc58f179a Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Wed, 25 Aug 2021 17:04:38 +0800 Subject: [PATCH 13/39] fix: Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d190b22..a413efa 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,10 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: `sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
### CentOS - 鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆锛
- `sudo yum install -y snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan openssl-devel cmake3 mysql-devel mxml-devel`
+ `sudo yum install -y make snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan openssl-devel cmake3 mysql-devel mxml-devel`
### Ubuntu - 鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆锛
- `sudo apt-get install snappy聽libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev`
+ `sudo apt-get install make snappy聽libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev`
* src鐩綍涓嬶紝鎵цmake鍗冲彲缂栬瘧銆 ## 绗笁鏂逛緷璧 -- Gitee From 7f12b126904c899697bfcb2546b9aebbe9929246 Mon Sep 17 00:00:00 2001 From: wuxinzhen1 Date: Thu, 26 Aug 2021 14:14:38 +0800 Subject: [PATCH 14/39] fix: fix CMakeLIsts.txt --- src/CMakeLists.txt | 10 +++- src/agent/CMakeLists.txt | 53 +++++++++++++++------- src/agent/da_log.c | 2 +- src/agent/da_msg.c | 4 ++ src/conf/log4cplus.conf | 17 +++++++ src/configcenter/CMakeLists.txt | 1 + src/configcenter/ca_api/CMakeLists.txt | 5 +- src/connector/CMakeLists.txt | 63 ++++++++++++++++++++++++++ src/connector/comm_main.cc | 1 + src/core/CMakeLists.txt | 10 +++- src/core/misc/main_supply.cc | 4 +- src/devel/CMakeLists.txt | 1 + src/devel/cpp/CMakeLists.txt | 63 ++++++++++++++++++++++++++ src/libs/common/CMakeLists.txt | 7 +-- src/libs/common/config/config.cc | 2 +- src/libs/common/daemon/daemon.cc | 4 +- src/libs/common/log/log.cc | 5 -- src/libs/common/log/log.h | 2 +- src/libs/stat/stat_dtc.h | 3 +- 19 files changed, 216 insertions(+), 41 deletions(-) create mode 100644 src/conf/log4cplus.conf create mode 100644 src/configcenter/CMakeLists.txt create mode 100644 src/connector/CMakeLists.txt create mode 100644 src/devel/CMakeLists.txt create mode 100644 src/devel/cpp/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3b4dcd..8d5914b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,14 @@ cmake_minimum_required (VERSION 2.8) -project (demo) +project (dtc) +add_subdirectory(./agent) +add_subdirectory(./configcenter) add_subdirectory(./libs) +add_subdirectory(./devel) add_subdirectory(./daemons) add_subdirectory(./core) +#add_subdirectory(./connector) + + +#鎯冲嵏杞絤ake install瀹夎鐨勫簱锛岃繘鍏ュ埌build鏂囦欢澶癸紝鎵ц +# cat install_manifest.txt | sudo xargs rm \ No newline at end of file diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt index edbcda2..3d9b467 100644 --- a/src/agent/CMakeLists.txt +++ b/src/agent/CMakeLists.txt @@ -1,25 +1,44 @@ -cmake_minimum_required (VERSION 3.5) -project (agent) - -#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I -include_directories(. ./common ./event - ./hashkit ./proto) +#璁剧疆搴撴枃浠惰緭鍑鸿矾寰 +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/agent) +IF("${GPROF}" EQUAL 1) + ADD_COMPILE_OPTIONS(-pg) +ENDIF() +IF("${USE_REGPARM}" EQUAL 1) + ADD_COMPILE_OPTIONS(-DCONFIG_REGPARM=3) +ENDIF() +IF("${HAVE_STATS}" EQUAL 1) + ADD_COMPILE_OPTIONS(-DHAVE_STATS=1) +ENDIF() +IF("${USE_COMPATIBLE_MODE}" EQUAL 1) + ADD_COMPILE_OPTIONS(-DUSE_COMPATIBLE_MODE=1) +ENDIF() +IF("${HAVE_ASSERT_LOG}" EQUAL 1) + ADD_COMPILE_OPTIONS(-DHAVE_ASSERT_LOG=1) +ENDIF() #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 -aux_source_directory(. SRC_LIST1) -aux_source_directory(./common SRC_LIST2) -aux_source_directory(./event SRC_LIST3) -aux_source_directory(./hashkit SRC_LIST4) -aux_source_directory(./proto STRC_LIST5) +#FILE(GLOB_RECURSE SRC_LIST ${PROJECT_SOURCE_DIR}/*.c) +FILE(GLOB SRC_LIST1 ./*.c) +FILE(GLOB SRC_LIST2 ./common/*.c) +FILE(GLOB SRC_LIST3 ./event/*.c) +FILE(GLOB SRC_LIST4 ./hashkit/*.c) +FILE(GLOB SRC_LIST5 ./proto/*.c) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +INCLUDE_DIRECTORIES( + . + ./common + ./event + ./hashkit + ./proto) #閾炬帴鐩爣搴 -link_libraries(rt) -link_libraries(mxml) -link_libraries(pthread) +LINK_LIBRARIES(rt) +LINK_LIBRARIES(mxml) +LINK_LIBRARIES(pthread) #缂栬瘧鍙傛暟 -add_definitions("-pg -DCONFIG_REGPARM=3 -DHAVE_STATS=1 -DUSE_COMPATIBLE_MODE=1 -DHAVE_ASSERT_LOG=1") - +ADD_DEFINITIONS ("-D_GNU_SOURCE") #缂栬瘧涓.so/.a -add_executable(dtcagent ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3} ${SRC_LIST4} ${SRC_LIST5}) +ADD_EXECUTABLE(dtcagent ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3} ${SRC_LIST4} ${SRC_LIST5}) diff --git a/src/agent/da_log.c b/src/agent/da_log.c index 76936b3..ed70a50 100644 --- a/src/agent/da_log.c +++ b/src/agent/da_log.c @@ -24,7 +24,7 @@ #define MSGSIZE 4096 #define REMOTELOG_ERR_TYPE 14 #define AGENT_CLIENT_TYPE 1 - +#define O_LARGEFILE __O_LARGEFILE int __log_level__ = 6; int __log_switch__ = 1; int __business_id__ = 0; diff --git a/src/agent/da_msg.c b/src/agent/da_msg.c index c86f789..2d1256a 100644 --- a/src/agent/da_msg.c +++ b/src/agent/da_msg.c @@ -27,6 +27,10 @@ #include "da_conn.h" #include "da_stats.h" + +#define __IOV_MAX 1024 +# define IOV_MAX __IOV_MAX + #if (IOV_MAX > 128) #define NC_IOV_MAX 128 #else diff --git a/src/conf/log4cplus.conf b/src/conf/log4cplus.conf new file mode 100644 index 0000000..3fbeca2 --- /dev/null +++ b/src/conf/log4cplus.conf @@ -0,0 +1,17 @@ +log4cplus.rootLogger=TRACE, STDOUT, apdPlatform + +log4cplus.appender.STDOUT=log4cplus::ConsoleAppender +log4cplus.appender.STDOUT.Encoding=utf-8 +log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout +log4cplus.appender.STDOUT.layout.ConversionPattern=[%T] %D{%Y-%m-%d %H:%M:%S} %-5p - %m %n + +## synchronous log properties. +log4cplus.appender.apdPlatform=log4cplus::TimeBasedRollingFileAppender +log4cplus.appender.apdPlatform.FilenamePattern=../log/%d{yyyy-MM-dd}_SQFront.log +log4cplus.appender.apdPlatform.Append=true +log4cplus.appender.apdPlatform.MaxHistory=999 +log4cplus.appender.apdPlatform.ImmediateFlush=false +log4cplus.appender.apdPlatform.RollOnClose=false +log4cplus.appender.apdPlatform.CreateDirs=true +log4cplus.appender.apdPlatform.layout=log4cplus::PatternLayout +log4cplus.appender.apdPlatform.layout.ConversionPattern=[%T] %D{%Y-%m-%d %H:%M:%S} %-5p - -%m %n \ No newline at end of file diff --git a/src/configcenter/CMakeLists.txt b/src/configcenter/CMakeLists.txt new file mode 100644 index 0000000..11a3336 --- /dev/null +++ b/src/configcenter/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(./ca_api) \ No newline at end of file diff --git a/src/configcenter/ca_api/CMakeLists.txt b/src/configcenter/ca_api/CMakeLists.txt index 65416c7..19820ff 100644 --- a/src/configcenter/ca_api/CMakeLists.txt +++ b/src/configcenter/ca_api/CMakeLists.txt @@ -1,10 +1,7 @@ -cmake_minimum_required (VERSION 3.5) -project (configcenter) - +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/configcenter/ca_api) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I include_directories (.) - #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 aux_source_directory (. SRC_LIST1) diff --git a/src/connector/CMakeLists.txt b/src/connector/CMakeLists.txt new file mode 100644 index 0000000..b0a72fd --- /dev/null +++ b/src/connector/CMakeLists.txt @@ -0,0 +1,63 @@ +#璁剧疆搴撴枃浠惰緭鍑鸿矾寰 +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/connector) + +IF(CMAKE_COMPILER_IS_GNUCXX) + ADD_COMPILE_OPTIONS(-std=gnu++11) +ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 +FILE(GLOB_RECURSE SRC_LIST ./*.cc) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +INCLUDE_DIRECTORIES ( + . + ../daemons + ../libs/stat + ../libs/common + ../libs/common/log + ../libs/common/config + ../libs/common/daemon + ../libs/common/socket + ../libs/common/listener + ../libs/common/task + ../core + ../libs/rocksdb/include + ../libs/rocksdb/logging + ../libs/log4cplus/include/ + ../libs/zlib/include64 + ../libs/yaml-cpp/include/) + +#娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L +LINK_DIRECTORIES ( + ${PROJECT_SOURCE_DIR}/libs/rocksdb/lib + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/core + ${PROJECT_SOURCE_DIR}/libs/zlib/lib/libz64.a + ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/daemons + ${PROJECT_SOURCE_DIR}/libs/stat +) + +#娣诲姞閾炬帴搴擄紝鐩稿綋浜巊cc -l +LINK_LIBRARIES(liblog4cplus.a) +LINK_LIBRARIES(libyaml-cpp.a) +LINK_LIBRARIES(libz64.a) +LINK_LIBRARIES(pthread) +LINK_LIBRARIES(nsl) +LINK_LIBRARIES(stdc++) +LINK_LIBRARIES(dl) +LINK_LIBRARIES(z) +LINK_LIBRARIES(rocksdb) +LINK_LIBRARIES(libdtcd.a) +LINK_LIBRARIES(libcommon.a) +LINK_LIBRARIES(libdaemons.a) +LINK_LIBRARIES(libstat.a) + +#缂栬瘧鍙傛暟 +ADD_DEFINITIONS ("-g -fPIC -fpermissive -DROCKSDB_COMPILER=1 -DOMN_PLATFORM_UNIX -Wl,--no-undefined -Xlinker -zmuldefs") +#缂栬瘧涓.so/.a +ADD_LIBRARY (rocksdb_connector ${SRC_LIST}) + +#灏嗙洰鏍囨枃浠朵笌搴撴枃浠堕摼鎺 +TARGET_LINK_LIBRARIES(rocksdb_connector liblog4cplus.a libyaml-cpp.a libz64.a lbdtcd.a libcommon.a libdaemons.a libstat.a) \ No newline at end of file diff --git a/src/connector/comm_main.cc b/src/connector/comm_main.cc index a3b3c10..d754d65 100644 --- a/src/connector/comm_main.cc +++ b/src/connector/comm_main.cc @@ -38,6 +38,7 @@ #include #include #include +#include const char service_file[] = "./helper-service.so"; const char create_handle_name[] = "create_process"; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e300f34..02db421 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -50,10 +50,16 @@ ADD_DEFINITIONS(" -g -rdynamic -fPIC -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -ex #缂栬瘧涓.so/.a ADD_EXECUTABLE(dtcd ${SRC_LIST}) -ADD_LIBRARY(dtcdd ${SRC_LIST}) +ADD_LIBRARY(dtcd_static ${SRC_LIST}) #灏嗙洰鏍囨枃浠朵笌搴撴枃浠堕摼鎺 TARGET_LINK_LIBRARIES(dtcd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) -TARGET_LINK_LIBRARIES(dtcdd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) +TARGET_LINK_LIBRARIES(dtcd_static libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a) +SET_TARGET_PROPERTIES (dtcd_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) +SET_TARGET_PROPERTIES (dtcd PROPERTIES CLEAN_DIRECT_OUTPUT 1) +SET_TARGET_PROPERTIES(dtcd_static PROPERTIES OUTPUT_NAME "dtcd") + +#璁剧疆make install 瀹夎璺緞 +INSTALL(TARGETS dtcd RUNTIME DESTINATION /usr/local/dtc/bin) diff --git a/src/core/misc/main_supply.cc b/src/core/misc/main_supply.cc index c212711..0016173 100644 --- a/src/core/misc/main_supply.cc +++ b/src/core/misc/main_supply.cc @@ -593,8 +593,8 @@ int init_data_connector_ask_chain(PollerBase *thread) //鑾峰彇銆侀厤缃熀纭淇℃伅 int init_config_info() { - mkdir("../stat", 0777); - mkdir("../data", 0777); + mkdir("/usr/local/dtc/stat", 0777); + mkdir("/usr/local/dtc/data", 0777); g_hash_changing = g_dtc_config->get_int_val("cache", "HashChanging", 0); g_target_new_hash = diff --git a/src/devel/CMakeLists.txt b/src/devel/CMakeLists.txt new file mode 100644 index 0000000..61126a2 --- /dev/null +++ b/src/devel/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(./cpp) \ No newline at end of file diff --git a/src/devel/cpp/CMakeLists.txt b/src/devel/cpp/CMakeLists.txt new file mode 100644 index 0000000..f739dba --- /dev/null +++ b/src/devel/cpp/CMakeLists.txt @@ -0,0 +1,63 @@ + +#璁剧疆搴撴枃浠惰緭鍑鸿矾寰 +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/devel/cpp) + +#鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 +FILE(GLOB SRC_LIST1 ./*.c) +SET(${SRC_LIST2} ../../libs/common/value.c + ../../libs/common/poll/poller.cc + ../../libs/common/timer/timer_lsit.cc + ../../libs/common/table/table_def.cc + ../../libs/common/mem_check.cc + ../../libs/common/algorithm/md5.cc + ../../libs/common/section.cc + ../../libs/common/decode/decode.cc + ../../libs/common/encode.cc + ../../libs/common/field/field_api.cc + ../../libs/common/packet/packet_base.cc + ../../libs/common/packet/packet_client.cc + ../../libs/common/task/task_base.cc + ../../libs/common/task/task_const.cc + ../../libs/common/algorithm/compress.cc + ../../libs/common/buffer.cc + ../../libs/common/thread/thread.cc) + +#娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I +INCLUDE_DIRECTORIES( + . + ../../libs/common + ../../configcenter/ca_api + ../../libs/log4cplus/include/ + ../../libs/zlib/include64 + ../../libs/yaml-cpp/include/) + +#娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L +LINK_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/libs/zlib/lib/ + ${PROJECT_SOURCE_DIR}/libs/common + ${PROJECT_SOURCE_DIR}/configcenter/ca_api/) + +#閾炬帴鐩爣搴 +LINK_LIBRARIES(dl) +LINK_LIBRARIES(pthread) +LINK_LIBRARIES(liblog4cplus.a) +LINK_LIBRARIES(libyaml-cpp.a) +LINK_LIBRARIES(libz64.a) +LINK_LIBRARIES(libapp-client.a) +LINK_LIBRARIES(libcommon.a) + +#缂栬瘧鍙傛暟 +ADD_DEFINITIONS ("-g -rdynamic -fPIC -fpermissive -DCLIENTAPI -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++11 ") + +#缂栬瘧涓.so/.a +ADD_LIBRARY(dtc.2 SHARED ${SRC_LIST1} ${SRC_LIST2}) +ADD_LIBRARY(dtc STATIC ${SRC_LIST1} ${SRC_LIST2}) +ADD_LIBRARY(dtc.pic SHARED ${SRC_LIST1} ${SRC_LIST2}) + +#璁剧疆make install 瀹夎璺緞 +INSTALL(TARGETS dtc.2 LIBRARY DESTINATION /usr/lib/) +# SET_TARGET_PROPERTIES(dtc_static PROPERTIES OUTPUT_NAME "dtc") +# SET_TARGET_PROPERTIES (dtc_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) +# SET_TARGET_PROPERTIES (dtc PROPERTIES CLEAN_DIRECT_OUTPUT 1) \ No newline at end of file diff --git a/src/libs/common/CMakeLists.txt b/src/libs/common/CMakeLists.txt index 60c024c..26bdc9a 100644 --- a/src/libs/common/CMakeLists.txt +++ b/src/libs/common/CMakeLists.txt @@ -1,8 +1,9 @@ +#璁剧疆搴撴枃浠惰緭鍑鸿矾寰 SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/common) -if(CMAKE_COMPILER_IS_GNUCXX) - add_compile_options(-std=gnu++11) -endif(CMAKE_COMPILER_IS_GNUCXX) +IF(CMAKE_COMPILER_IS_GNUCXX) + ADD_COMPILE_OPTIONS(-std=gnu++11) +ENDIF(CMAKE_COMPILER_IS_GNUCXX) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST閲 FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c) diff --git a/src/libs/common/config/config.cc b/src/libs/common/config/config.cc index d26aefe..3cbe253 100644 --- a/src/libs/common/config/config.cc +++ b/src/libs/common/config/config.cc @@ -125,7 +125,7 @@ int DTCConfig::parse_config(const char *fn, const char *defsec, bool bakconfig) if (bakconfig) { char bak_config[1024]; int err = 0; - snprintf(bak_config, sizeof(bak_config), "cp %s ../stat/", fn); + snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn); if (err == 0) err = system(bak_config); } diff --git a/src/libs/common/daemon/daemon.cc b/src/libs/common/daemon/daemon.cc index 35e5f33..72da1af 100644 --- a/src/libs/common/daemon/daemon.cc +++ b/src/libs/common/daemon/daemon.cc @@ -99,8 +99,8 @@ int load_entry_parameter(int argc, char **argv) //init_log("dtcd"); log4cplus_info("%s v%s: starting....", project_name, version); - strcpy(table_file, "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/table.yaml"); - strcpy(cache_file, "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/cache.yaml"); + strcpy(table_file, "/etc/dtc/table.yaml"); + strcpy(cache_file, "/etc/dtc/cache.yaml"); g_dtc_config = new DTCConfig; //load config file and copy it to ../stat if (g_dtc_config->parse_config(table_file, "DB_DEFINE", true) == -1) diff --git a/src/libs/common/log/log.cc b/src/libs/common/log/log.cc index 6e52620..3c584b0 100644 --- a/src/libs/common/log/log.cc +++ b/src/libs/common/log/log.cc @@ -31,11 +31,6 @@ #include "config/config.h" #include "../../stat/stat_dtc.h" -static char log_dir[128] = "../log"; -static char appname[32] = ""; -static int (*alert_hook)(const char *, int); - - void init_log4cplus() { PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT(LOG4CPLUS_CONF_FILE)); diff --git a/src/libs/common/log/log.h b/src/libs/common/log/log.h index 7d70217..e9dea44 100644 --- a/src/libs/common/log/log.h +++ b/src/libs/common/log/log.h @@ -66,7 +66,7 @@ using namespace log4cplus::helpers; static Logger logger = Logger::getRoot(); -#define LOG4CPLUS_CONF_FILE "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/log4cplus.conf" +#define LOG4CPLUS_CONF_FILE "/etc/dtc/log4cplus.conf" /********************************************* **TRACE锛氳皟璇曞簲鐢ㄧ殑璇︾粏姝ラ diff --git a/src/libs/stat/stat_dtc.h b/src/libs/stat/stat_dtc.h index d4450fb..bf4b69f 100644 --- a/src/libs/stat/stat_dtc.h +++ b/src/libs/stat/stat_dtc.h @@ -20,8 +20,7 @@ #include "stat_thread.h" #include "stat_dtc_def.h" -//#define STATIDX "../stat/dtc.stat.idx" -#define STATIDX "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/stat/dtc.stat.idx" +#define STATIDX "/usr/local/dtc/stat/dtc.stat.idx" extern StatThread g_stat_mgr; extern int init_statistics(void); -- Gitee From 690c0b5e62bf57b6a5948fd293bf5c39c9eefcd1 Mon Sep 17 00:00:00 2001 From: wuxz <1067764612@qq.com> Date: Thu, 26 Aug 2021 15:11:23 +0800 Subject: [PATCH 15/39] fix: clusterconfig.xml path --- src/libs/common/config/parse_cluster_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/common/config/parse_cluster_config.h b/src/libs/common/config/parse_cluster_config.h index fe1cf99..d233294 100644 --- a/src/libs/common/config/parse_cluster_config.h +++ b/src/libs/common/config/parse_cluster_config.h @@ -22,7 +22,7 @@ namespace ClusterConfig { //#define CLUSTER_CONFIG_FILE "../conf/ClusterConfig.xml" -#define CLUSTER_CONFIG_FILE "/export/servers/dtc_instance/000022859249515bcccac13ebaee2c399c67471e/20015/conf/ClusterConfig.xml" +#define CLUSTER_CONFIG_FILE "/etc/dtc/clusterconfig.xml" struct ClusterNode { std::string name; std::string addr; -- Gitee From 156625b08985b0939105b4ce708f3689782daf11 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 16:54:26 +0800 Subject: [PATCH 16/39] feat: dockerfile. --- .travis.yml | 3 ++- {src/conf => conf}/cache.yaml | 0 {src/conf => conf}/log4cplus.conf | 2 +- {src/conf => conf}/table.yaml | 0 dockerfiles/sdk-cpp/dockerfile | 2 +- dockerfiles/server/dockerfile | 13 ++++++++----- 6 files changed, 12 insertions(+), 8 deletions(-) rename {src/conf => conf}/cache.yaml (100%) rename {src/conf => conf}/log4cplus.conf (90%) rename {src/conf => conf}/table.yaml (100%) diff --git a/.travis.yml b/.travis.yml index 22c9861..f4bf8c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,9 @@ install: script: - cd src/ +- mkdir build/ +- cmake ../ - make -- make install after_success: - cd ../dockerfiles/server/ diff --git a/src/conf/cache.yaml b/conf/cache.yaml similarity index 100% rename from src/conf/cache.yaml rename to conf/cache.yaml diff --git a/src/conf/log4cplus.conf b/conf/log4cplus.conf similarity index 90% rename from src/conf/log4cplus.conf rename to conf/log4cplus.conf index 3fbeca2..0350a56 100644 --- a/src/conf/log4cplus.conf +++ b/conf/log4cplus.conf @@ -7,7 +7,7 @@ log4cplus.appender.STDOUT.layout.ConversionPattern=[%T] %D{%Y-%m-%d %H:%M:%S} %- ## synchronous log properties. log4cplus.appender.apdPlatform=log4cplus::TimeBasedRollingFileAppender -log4cplus.appender.apdPlatform.FilenamePattern=../log/%d{yyyy-MM-dd}_SQFront.log +log4cplus.appender.apdPlatform.FilenamePattern=/var/log/dtc/%d{yyyy-MM-dd}.log log4cplus.appender.apdPlatform.Append=true log4cplus.appender.apdPlatform.MaxHistory=999 log4cplus.appender.apdPlatform.ImmediateFlush=false diff --git a/src/conf/table.yaml b/conf/table.yaml similarity index 100% rename from src/conf/table.yaml rename to conf/table.yaml diff --git a/dockerfiles/sdk-cpp/dockerfile b/dockerfiles/sdk-cpp/dockerfile index 55ae305..bd1aa57 100644 --- a/dockerfiles/sdk-cpp/dockerfile +++ b/dockerfiles/sdk-cpp/dockerfile @@ -3,7 +3,7 @@ FROM centos:centos7.2.1511 COPY start.sh /root/start.sh ARG sofile=libdtc.2.so -COPY ../../bin/$sofile /usr/lib/$sofile +COPY ../../src/devel/cpp/$sofile /usr/lib/$sofile RUN ln -sf /usr/lib/$sofile /usr/lib/libdtc.so.1 && \ ln -sf /usr/lib/libdtc.so.1 /usr/lib/libdtc.so && \ echo "/usr/lib" >> /etc/ld.so.conf && \ diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 80c7c24..70ad760 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -2,15 +2,18 @@ FROM centos:centos7.2.1511 RUN yum install -y wget ARG basepath=/usr/local/dtc +ARG confpath=/etc/dtc +ARG logpath=/var/log/dtc RUN mkdir -p $basepath/bin -RUN mkdir -p $basepath/conf -RUN mkdir -p $basepath/log +RUN mkdir -p $confpath +RUN mkdir -p $logpath COPY start.sh /root/start.sh COPY ../../script/dtcd.sh $basepath/bin/dtcd.sh -COPY ../../bin/dtcd $basepath/bin/dtcd -COPY ../../conf/table.yaml $basepath/conf/table.yaml -COPY ../../conf/cache.yaml $basepath/conf/cache.yaml +COPY ../../src/core/dtcd $basepath/bin/dtcd +COPY ../../conf/table.yaml $confpath/table.yaml +COPY ../../conf/cache.yaml $confpath/cache.yaml +COPY ../../conf/log4cplus.conf $logpath/log4cplus.conf CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file -- Gitee From eb3dc61fda7ba304bdb09f5afbd171e8cb7b4ed1 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:01:10 +0800 Subject: [PATCH 17/39] 1 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f4bf8c0..a7bcc77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ os: install: - echo ${CC} +- ${CC} --version - echo ${CXX} - ${CXX} --version - cmake --version -- Gitee From 4cc854a8dffdf8bc15073cb7b64e012d6ebf7bfa Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:11:53 +0800 Subject: [PATCH 18/39] 1 --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index a7bcc77..562ae44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,15 @@ compiler: - g++ os: - linux +addons: + apt: + packages: + - g++-4.9 +env: +- DTC_EVAL="CC=gcc-4.9 && CXX=g++-4.9" + +befor_install: +- eval "${DTC_EVAL}" install: - echo ${CC} -- Gitee From 6d9370970ab28de8d096f8fdc3b73a96ddc6cb67 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:14:22 +0800 Subject: [PATCH 19/39] 1 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 562ae44..c74065a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ install: script: - cd src/ - mkdir build/ +- cd build/ - cmake ../ - make -- Gitee From 5c81114ab2e5b21a17f6efc4ea026394a9cf6fb9 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:22:03 +0800 Subject: [PATCH 20/39] 2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c74065a..395cb06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ script: - make after_success: -- cd ../dockerfiles/server/ +- cd ../../dockerfiles/server/ - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker build -t $DOCKER_USERNAME/server:latest . - docker push $DOCKER_USERNAME/server:latest -- Gitee From fd3d6fc13ff24b09a85547f2c287d5d6c414ddbc Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:40:57 +0800 Subject: [PATCH 21/39] 2 --- .travis.yml | 6 +++++- README.md | 10 ++++++++++ dockerfiles/sdk-cpp/dockerfile | 8 ++++---- dockerfiles/server/dockerfile | 1 - 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 395cb06..7e3fc03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,11 @@ script: - make after_success: -- cd ../../dockerfiles/server/ +- cd ../../ +- cp conf/* dockerfiles/server/ +- cp src/core/dtcd dockerfiles/server/ +- cp src/devel/cpp/libdtc.2.so dockerfiles/sdk-cpp/ +- cd dockerfiles/server/ - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker build -t $DOCKER_USERNAME/server:latest . - docker push $DOCKER_USERNAME/server:latest diff --git a/README.md b/README.md index a413efa..5b0b931 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,16 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: * [mxml](https://www.msweet.org/mxml/) * [twemproxy](https://github.com/twitter/twemproxy) +## 椤圭洰鎴愬憳 +浠樺瀹--椤圭洰鍙戣捣鑰呫佸甯堛佹昏璁″笀 +鏋楅噾鏄--椤圭洰寮鍙 +鏉ㄧ埥--椤圭洰寮鍙 +浠囪矾--椤圭洰寮鍙 +鍚存槙鑷--椤圭洰寮鍙 +鏇规矝--椤圭洰寮鍙 +闄堥洦鏉--椤圭洰寮鍙 +鏈辨灄--椤圭洰寮鍙 + ## 璁稿彲璇 浜笢闆嗗洟 鐗堟潈鎵鏈 漏 Copyright 2021 [JD.com](https://www.jd.com), Inc. diff --git a/dockerfiles/sdk-cpp/dockerfile b/dockerfiles/sdk-cpp/dockerfile index bd1aa57..89f9a05 100644 --- a/dockerfiles/sdk-cpp/dockerfile +++ b/dockerfiles/sdk-cpp/dockerfile @@ -10,9 +10,9 @@ RUN ln -sf /usr/lib/$sofile /usr/lib/libdtc.so.1 && \ /sbin/ldconfig -v #cpp test -RUN mkdir -p /usr/local/sdk-cpp -COPY ../../tests/get.cc /usr/local/sdk-cpp/get.cc -COPY ../../tests/insert.cc /usr/local/sdk-cpp/insert.cc -COPY ../../tests/build.sh /usr/local/sdk-cpp/build.sh +#RUN mkdir -p /usr/local/sdk-cpp +#COPY ../../tests/get.cc /usr/local/sdk-cpp/get.cc +#COPY ../../tests/insert.cc /usr/local/sdk-cpp/insert.cc +#COPY ../../tests/build.sh /usr/local/sdk-cpp/build.sh CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 70ad760..97e2b22 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -1,5 +1,4 @@ FROM centos:centos7.2.1511 -RUN yum install -y wget ARG basepath=/usr/local/dtc ARG confpath=/etc/dtc -- Gitee From b807c18da81224fce8b367a7a6bf52566e33bee5 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:46:53 +0800 Subject: [PATCH 22/39] 1 --- README.md | 16 ++++++++-------- dockerfiles/sdk-cpp/dockerfile | 2 +- dockerfiles/server/dockerfile | 9 ++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5b0b931..866acf2 100644 --- a/README.md +++ b/README.md @@ -60,14 +60,14 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: * [twemproxy](https://github.com/twitter/twemproxy) ## 椤圭洰鎴愬憳 -浠樺瀹--椤圭洰鍙戣捣鑰呫佸甯堛佹昏璁″笀 -鏋楅噾鏄--椤圭洰寮鍙 -鏉ㄧ埥--椤圭洰寮鍙 -浠囪矾--椤圭洰寮鍙 -鍚存槙鑷--椤圭洰寮鍙 -鏇规矝--椤圭洰寮鍙 -闄堥洦鏉--椤圭洰寮鍙 -鏈辨灄--椤圭洰寮鍙 +- 浠樺瀹--椤圭洰鍙戣捣鑰呫佸甯堛佹昏璁″笀 +- 鏋楅噾鏄--椤圭洰寮鍙 +- 鏉ㄧ埥--椤圭洰寮鍙 +- 浠囪矾--椤圭洰寮鍙 +- 鍚存槙鑷--椤圭洰寮鍙 +- 鏇规矝--椤圭洰寮鍙 +- 闄堥洦鏉--椤圭洰寮鍙 +- 鏈辨灄--椤圭洰寮鍙 ## 璁稿彲璇 diff --git a/dockerfiles/sdk-cpp/dockerfile b/dockerfiles/sdk-cpp/dockerfile index 89f9a05..3955d8c 100644 --- a/dockerfiles/sdk-cpp/dockerfile +++ b/dockerfiles/sdk-cpp/dockerfile @@ -3,7 +3,7 @@ FROM centos:centos7.2.1511 COPY start.sh /root/start.sh ARG sofile=libdtc.2.so -COPY ../../src/devel/cpp/$sofile /usr/lib/$sofile +COPY $sofile /usr/lib/$sofile RUN ln -sf /usr/lib/$sofile /usr/lib/libdtc.so.1 && \ ln -sf /usr/lib/libdtc.so.1 /usr/lib/libdtc.so && \ echo "/usr/lib" >> /etc/ld.so.conf && \ diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 97e2b22..f2a516d 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -9,10 +9,9 @@ RUN mkdir -p $confpath RUN mkdir -p $logpath COPY start.sh /root/start.sh -COPY ../../script/dtcd.sh $basepath/bin/dtcd.sh -COPY ../../src/core/dtcd $basepath/bin/dtcd -COPY ../../conf/table.yaml $confpath/table.yaml -COPY ../../conf/cache.yaml $confpath/cache.yaml -COPY ../../conf/log4cplus.conf $logpath/log4cplus.conf +COPY dtcd $basepath/bin/dtcd +COPY table.yaml $confpath/table.yaml +COPY cache.yaml $confpath/cache.yaml +COPY log4cplus.conf $logpath/log4cplus.conf CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file -- Gitee From ad9241b2fe91486c2af769f0454bd8b3d99919c4 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 17:52:14 +0800 Subject: [PATCH 23/39] 1 --- dockerfiles/server/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/server/start.sh b/dockerfiles/server/start.sh index 2399260..8d490ad 100644 --- a/dockerfiles/server/start.sh +++ b/dockerfiles/server/start.sh @@ -3,7 +3,7 @@ INIT(){ cd /usr/local/dtc/bin chmod +x dtcd - ./dtcd.sh start + ./dtcd } PROCESS_DAEMON(){ -- Gitee From 2a93d389f3dc15a06b95aec70ae6496c50a306c4 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 18:10:05 +0800 Subject: [PATCH 24/39] 1 --- README.md | 12 ++++++------ dockerfiles/server/dockerfile | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 866acf2..dfdf57e 100644 --- a/README.md +++ b/README.md @@ -61,13 +61,13 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: ## 椤圭洰鎴愬憳 - 浠樺瀹--椤圭洰鍙戣捣鑰呫佸甯堛佹昏璁″笀 -- 鏋楅噾鏄--椤圭洰寮鍙 -- 鏉ㄧ埥--椤圭洰寮鍙 -- 浠囪矾--椤圭洰寮鍙 -- 鍚存槙鑷--椤圭洰寮鍙 +- [鏋楅噾鏄嶿(https://gitee.com/shrewdlin)--椤圭洰寮鍙 +- [鏉ㄧ埥](https://gitee.com/kfysck)--椤圭洰寮鍙 +- [浠囪矾](https://gitee.com/qiuluAbel)--椤圭洰寮鍙 +- [鍚存槙鑷籡(https://gitee.com/wuxinzhen_1997)--椤圭洰寮鍙 - 鏇规矝--椤圭洰寮鍙 -- 闄堥洦鏉--椤圭洰寮鍙 -- 鏈辨灄--椤圭洰寮鍙 +- [闄堥洦鏉癩(https://gitee.com/chenyujie28)--椤圭洰寮鍙 +- [鏈辨灄](https://gitee.com/leol3)--椤圭洰寮鍙 ## 璁稿彲璇 diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index f2a516d..9b53732 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -1,4 +1,4 @@ -FROM centos:centos7.2.1511 +FROM centos:centos8 ARG basepath=/usr/local/dtc ARG confpath=/etc/dtc -- Gitee From 77c6e62d1d9b9f8dcfae4db87fe5b3ffb0774fa8 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 18:37:11 +0800 Subject: [PATCH 25/39] 1 --- src/libs/common/config/config.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/common/config/config.cc b/src/libs/common/config/config.cc index 3cbe253..7d25f17 100644 --- a/src/libs/common/config/config.cc +++ b/src/libs/common/config/config.cc @@ -126,6 +126,7 @@ int DTCConfig::parse_config(const char *fn, const char *defsec, bool bakconfig) char bak_config[1024]; int err = 0; snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn); + printf("bakconfig:%s\n", bak_config); if (err == 0) err = system(bak_config); } -- Gitee From 5229fb1ad07c0146d310968283eddd82413d4812 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 18:37:15 +0800 Subject: [PATCH 26/39] 1 --- dockerfiles/server/dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 9b53732..9ad2674 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -12,6 +12,6 @@ COPY start.sh /root/start.sh COPY dtcd $basepath/bin/dtcd COPY table.yaml $confpath/table.yaml COPY cache.yaml $confpath/cache.yaml -COPY log4cplus.conf $logpath/log4cplus.conf +COPY log4cplus.conf $confpath/log4cplus.conf CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file -- Gitee From 0c15f326767138c5dc8cb1523ef0b6036147fdf6 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Thu, 26 Aug 2021 19:29:46 +0800 Subject: [PATCH 27/39] 1 --- dockerfiles/server/dockerfile | 2 + src/core/misc/main_supply.cc | 1190 ++++++++++++++---------------- src/libs/common/config/config.cc | 805 ++++++++++---------- 3 files changed, 950 insertions(+), 1047 deletions(-) diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 9ad2674..9ba471e 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -5,6 +5,8 @@ ARG confpath=/etc/dtc ARG logpath=/var/log/dtc RUN mkdir -p $basepath/bin +RUN mkdir -p $basepath/data +RUN mkdir -p $basepath/stat RUN mkdir -p $confpath RUN mkdir -p $logpath diff --git a/src/core/misc/main_supply.cc b/src/core/misc/main_supply.cc index 0016173..da52a7d 100644 --- a/src/core/misc/main_supply.cc +++ b/src/core/misc/main_supply.cc @@ -1,18 +1,18 @@ /* -* Copyright [2021] JD.com, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "main_supply.h" @@ -48,652 +48,594 @@ extern BlackHoleAskChain *g_black_hole_ask_instance; extern void StopTaskExecutor(void); -int plugin_start(void) -{ - init_plugin = 0; - main_plugin_mgr = PluginManager::instance(); - if (NULL == main_plugin_mgr) { - log4cplus_error("create PluginManager instance failed."); - return DTC_CODE_FAILED; - } - - if (main_plugin_mgr->open(g_dtc_config->get_int_val( - "cache", "PluginNetworkMode", 0)) != 0) { - log4cplus_error("init plugin manager failed."); - return DTC_CODE_FAILED; - } - - init_plugin = 1; - return DTC_CODE_SUCCESS; +int plugin_start(void) { + init_plugin = 0; + main_plugin_mgr = PluginManager::instance(); + if (NULL == main_plugin_mgr) { + log4cplus_error("create PluginManager instance failed."); + return DTC_CODE_FAILED; + } + + if (main_plugin_mgr->open( + g_dtc_config->get_int_val("cache", "PluginNetworkMode", 0)) != 0) { + log4cplus_error("init plugin manager failed."); + return DTC_CODE_FAILED; + } + + init_plugin = 1; + return DTC_CODE_SUCCESS; } -int plugin_stop(void) -{ - main_plugin_mgr->close(); - PluginManager::destory(); - main_plugin_mgr = NULL; - return DTC_CODE_SUCCESS; +int plugin_stop(void) { + main_plugin_mgr->close(); + PluginManager::destory(); + main_plugin_mgr = NULL; + return DTC_CODE_SUCCESS; } -int stat_open_fd() -{ - int count = 0; - for (int i = 0; i < 1000; i++) { - if (fcntl(i, F_GETFL, 0) != -1) - count++; - } - return count; +int stat_open_fd() { + int count = 0; + for (int i = 0; i < 1000; i++) { + if (fcntl(i, F_GETFL, 0) != -1) + count++; + } + return count; } -int init_cache_mode() -{ - g_datasource_mode = g_dtc_config->get_int_val( - "cache", "DisableDataSource", DTC_MODE_CACHE_ONLY); - switch (g_datasource_mode) { - case DTC_MODE_DATABASE_ADDITION: - log4cplus_info("dtc datasource mode: %s(%d)", - "DTC_MODE_DATABASE_ADDITION", g_datasource_mode); - break; - case DTC_MODE_CACHE_ONLY: - log4cplus_info("dtc datasource mode: %s(%d)", - "DTC_MODE_CACHE_ONLY", g_datasource_mode); - break; - case DTC_MODE_DATABASE_ONLY: - log4cplus_info("dtc datasource mode: %s(%d)", - "DTC_MODE_DATABASE_ONLY", g_datasource_mode); - break; - default: - log4cplus_error("datasource config error: %d", - g_datasource_mode); - return DTC_CODE_FAILED; - } - - async_update = g_dtc_config->get_int_val("cache", "DelayUpdate", 0); - if (async_update < 0 || async_update > 1) { - log4cplus_error("Invalid DelayUpdate value"); - return DTC_CODE_FAILED; - } - - const char *keyStr = g_dtc_config->get_str_val("cache", "CacheShmKey"); - if (keyStr == NULL) { - cache_key = 0; - } else if (!strcasecmp(keyStr, "none") && - g_datasource_mode != DTC_MODE_DATABASE_ONLY) { - log4cplus_error( - "Can not set DisableDataSource=(DTC_MODE_CACHE_ONLY|DTC_MODE_DATABASE_ADDITION) and CacheShmKey=NONE together."); - return DTC_CODE_FAILED; - } else if (isdigit(keyStr[0])) { - cache_key = strtol(keyStr, NULL, 0); - } else { - log4cplus_error("Invalid CacheShmKey value \"%s\"", keyStr); - return DTC_CODE_FAILED; - } - - if (g_datasource_mode == DTC_MODE_DATABASE_ONLY && async_update) { - log4cplus_error( - "can't DelayUpdate when CacheShmKey set to NONE"); - return DTC_CODE_FAILED; - } - - if (g_datasource_mode != DTC_MODE_DATABASE_ONLY && cache_key == 0) - log4cplus_info("CacheShmKey not set, cache data is volatile"); - - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) - log4cplus_info("disable data source, cache data is volatile"); - - return DTC_CODE_SUCCESS; +int init_cache_mode() { + g_datasource_mode = g_dtc_config->get_int_val("cache", "DisableDataSource", + DTC_MODE_CACHE_ONLY); + switch (g_datasource_mode) { + case DTC_MODE_DATABASE_ADDITION: + log4cplus_info("dtc datasource mode: %s(%d)", "DTC_MODE_DATABASE_ADDITION", + g_datasource_mode); + break; + case DTC_MODE_CACHE_ONLY: + log4cplus_info("dtc datasource mode: %s(%d)", "DTC_MODE_CACHE_ONLY", + g_datasource_mode); + break; + case DTC_MODE_DATABASE_ONLY: + log4cplus_info("dtc datasource mode: %s(%d)", "DTC_MODE_DATABASE_ONLY", + g_datasource_mode); + break; + default: + log4cplus_error("datasource config error: %d", g_datasource_mode); + return DTC_CODE_FAILED; + } + + async_update = g_dtc_config->get_int_val("cache", "DelayUpdate", 0); + if (async_update < 0 || async_update > 1) { + log4cplus_error("Invalid DelayUpdate value"); + return DTC_CODE_FAILED; + } + + const char *keyStr = g_dtc_config->get_str_val("cache", "CacheShmKey"); + if (keyStr == NULL) { + cache_key = 0; + } else if (!strcasecmp(keyStr, "none") && + g_datasource_mode != DTC_MODE_DATABASE_ONLY) { + log4cplus_error("Can not set " + "DisableDataSource=(DTC_MODE_CACHE_ONLY|DTC_MODE_DATABASE_" + "ADDITION) and CacheShmKey=NONE together."); + return DTC_CODE_FAILED; + } else if (isdigit(keyStr[0])) { + cache_key = strtol(keyStr, NULL, 0); + } else { + log4cplus_error("Invalid CacheShmKey value \"%s\"", keyStr); + return DTC_CODE_FAILED; + } + + if (g_datasource_mode == DTC_MODE_DATABASE_ONLY && async_update) { + log4cplus_error("can't DelayUpdate when CacheShmKey set to NONE"); + return DTC_CODE_FAILED; + } + + if (g_datasource_mode != DTC_MODE_DATABASE_ONLY && cache_key == 0) + log4cplus_info("CacheShmKey not set, cache data is volatile"); + + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) + log4cplus_info("disable data source, cache data is volatile"); + + return DTC_CODE_SUCCESS; } -int init_main_chain_thread() -{ - g_main_thread = new PollerBase("dtc-thread-main"); - if (g_main_thread == NULL) - return DTC_CODE_FAILED; - if (g_main_thread->initialize_thread() == DTC_CODE_FAILED) - return DTC_CODE_FAILED; +int init_main_chain_thread() { + g_main_thread = new PollerBase("dtc-thread-main"); + if (g_main_thread == NULL) + return DTC_CODE_FAILED; + if (g_main_thread->initialize_thread() == DTC_CODE_FAILED) + return DTC_CODE_FAILED; - return DTC_CODE_SUCCESS; + return DTC_CODE_SUCCESS; } -int init_hotbackup_chain_thread() -{ - log4cplus_debug("StartHotbackThread begin"); - g_hot_backup_thread = new PollerBase("dtc-thread-hotbackup"); - g_hot_backup_ask_instance = new HotBackupAskChain(g_hot_backup_thread); - - if (g_hot_backup_thread == NULL || g_hot_backup_ask_instance == NULL) { - log4cplus_error( - "hot backup thread or instance created failed."); - return DTC_CODE_FAILED; - } - - if (g_hot_backup_thread->initialize_thread() == DTC_CODE_FAILED) { - log4cplus_error("init hotback thread fail"); - return DTC_CODE_FAILED; - } - if (g_hot_backup_ask_instance->do_init( - g_dtc_config->get_size_val("cache", "BinlogTotalSize", - BINLOG_MAX_TOTAL_SIZE, 'M'), - g_dtc_config->get_size_val("cache", "BinlogOneSize", - BINLOG_MAX_SIZE, 'M')) == -1) { - log4cplus_error("hotbackProcess init fail"); - return DTC_CODE_FAILED; - } - - log4cplus_debug("StartHotbackThread end"); - return DTC_CODE_SUCCESS; +int init_hotbackup_chain_thread() { + log4cplus_debug("StartHotbackThread begin"); + g_hot_backup_thread = new PollerBase("dtc-thread-hotbackup"); + g_hot_backup_ask_instance = new HotBackupAskChain(g_hot_backup_thread); + + if (g_hot_backup_thread == NULL || g_hot_backup_ask_instance == NULL) { + log4cplus_error("hot backup thread or instance created failed."); + return DTC_CODE_FAILED; + } + + if (g_hot_backup_thread->initialize_thread() == DTC_CODE_FAILED) { + log4cplus_error("init hotback thread fail"); + return DTC_CODE_FAILED; + } + if (g_hot_backup_ask_instance->do_init( + g_dtc_config->get_size_val("cache", "BinlogTotalSize", + BINLOG_MAX_TOTAL_SIZE, 'M'), + g_dtc_config->get_size_val("cache", "BinlogOneSize", BINLOG_MAX_SIZE, + 'M')) == -1) { + log4cplus_error("hotbackProcess init fail"); + return DTC_CODE_FAILED; + } + + log4cplus_debug("StartHotbackThread end"); + return DTC_CODE_SUCCESS; } -int init_buffer_process_ask_chain_thread() -{ - log4cplus_error("init_buffer_process_ask_chain_thread start"); - g_buffer_multi_thread = new PollerBase("dtc-multi-thread-cache"); - g_buffer_process_ask_instance = new BufferProcessAskChain( - g_buffer_multi_thread, - TableDefinitionManager::instance()->get_cur_table_def(), - async_update ? MODE_ASYNC : MODE_SYNC); - g_buffer_process_ask_instance->set_limit_node_size( - g_dtc_config->get_int_val("cache", "LimitNodeSize", - 100 * 1024 * 1024)); - g_buffer_process_ask_instance->set_limit_node_rows( - g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); - g_buffer_process_ask_instance->set_limit_empty_nodes( - g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); - - if (g_buffer_multi_thread->initialize_thread() == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - unsigned long long cache_size = - g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); - if (cache_size <= (50ULL << 20)) // 50M - { - log4cplus_error("CacheMemorySize too small"); - return DTC_CODE_FAILED; - } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { - log4cplus_error("CacheMemorySize %lld too large", cache_size); - } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( - cache_size, - g_dtc_config->get_int_val("cache", "CacheShmVersion", - 4)) == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - /* disable async transaction log */ - g_buffer_process_ask_instance->disable_async_log(1); - - int lruLevel = - g_dtc_config->get_int_val("cache", "disable_lru_update", 0); - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { - if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { - return DTC_CODE_FAILED; - } - if (g_dtc_config->get_int_val("cache", "disable_auto_purge", - 0) > 0) { - g_buffer_process_ask_instance->disable_auto_purge(); - // lruLevel = 3; /* LRU_WRITE */ - } - int autoPurgeAlertTime = g_dtc_config->get_int_val( - "cache", "AutoPurgeAlertTime", 0); - g_buffer_process_ask_instance->set_date_expire_alert_time( - autoPurgeAlertTime); - if (autoPurgeAlertTime > 0 && - TableDefinitionManager::instance() - ->get_cur_table_def() - ->lastcmod_field_id() <= 0) { - log4cplus_error( - "Can't start AutoPurgeAlert without lastcmod field"); - return DTC_CODE_FAILED; - } - } - g_buffer_process_ask_instance->disable_lru_update(lruLevel); - g_buffer_process_ask_instance->enable_lossy_data_source( - g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); - - if (async_update != MODE_SYNC && cache_key == 0) { - log4cplus_error( - "Anonymous shared memory don't support DelayUpdate"); - return DTC_CODE_FAILED; - } - - int iAutoDeleteDirtyShm = g_dtc_config->get_int_val( - "cache", "AutoDeleteDirtyShareMemory", 0); - /*disable empty node filter*/ - if (g_buffer_process_ask_instance->open_init_buffer( - cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - if (g_buffer_process_ask_instance->update_mode() || - g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active - { - if (TableDefinitionManager::instance() - ->get_cur_table_def() - ->uniq_fields() < 1) { - log4cplus_error("DelayUpdate needs uniq-field(s)"); - return DTC_CODE_FAILED; - } - - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { - if (g_buffer_process_ask_instance->update_mode()) { - log4cplus_error( - "Can't start async mode when disableDataSource."); - return DTC_CODE_FAILED; - } else { - log4cplus_error( - "Can't start disableDataSource with shm dirty,please flush async shm to db first or delete shm"); - return DTC_CODE_FAILED; - } - } else { - if ((TableDefinitionManager::instance() - ->get_cur_table_def() - ->compress_field_id() >= 0)) { - log4cplus_error( - "sorry,DTC just support compress in disableDataSource mode now."); - return DTC_CODE_FAILED; - } - } - - /*marker is the only source of flush speed calculattion, inc precision to 10*/ - g_buffer_process_ask_instance->set_flush_parameter( - g_dtc_config->get_int_val("cache", "MarkerPrecision", - 10), - g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), - g_dtc_config->get_int_val("cache", "MinDirtyTime", - 3600), - g_dtc_config->get_int_val("cache", "MaxDirtyTime", - 43200)); - - g_buffer_process_ask_instance->set_drop_count( - g_dtc_config->get_int_val("cache", "MaxDropCount", - 1000)); - } else { - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) - g_data_connector_ask_instance->disable_commit_group(); - } - - if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < - 0) - return DTC_CODE_FAILED; - - log4cplus_error("init_buffer_process_ask_chain_thread end"); - - return DTC_CODE_SUCCESS; +int init_buffer_process_ask_chain_thread() { + log4cplus_error("init_buffer_process_ask_chain_thread start"); + g_buffer_multi_thread = new PollerBase("dtc-multi-thread-cache"); + g_buffer_process_ask_instance = new BufferProcessAskChain( + g_buffer_multi_thread, + TableDefinitionManager::instance()->get_cur_table_def(), + async_update ? MODE_ASYNC : MODE_SYNC); + g_buffer_process_ask_instance->set_limit_node_size( + g_dtc_config->get_int_val("cache", "LimitNodeSize", 100 * 1024 * 1024)); + g_buffer_process_ask_instance->set_limit_node_rows( + g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); + g_buffer_process_ask_instance->set_limit_empty_nodes( + g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); + + if (g_buffer_multi_thread->initialize_thread() == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + unsigned long long cache_size = + g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); + if (cache_size <= (50ULL << 20)) // 50M + { + log4cplus_error("CacheMemorySize too small"); + return DTC_CODE_FAILED; + } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { + log4cplus_error("CacheMemorySize %lld too large", cache_size); + } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( + cache_size, + g_dtc_config->get_int_val("cache", "CacheShmVersion", 4)) == + DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + /* disable async transaction log */ + g_buffer_process_ask_instance->disable_async_log(1); + + int lruLevel = g_dtc_config->get_int_val("cache", "disable_lru_update", 0); + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { + if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { + return DTC_CODE_FAILED; + } + if (g_dtc_config->get_int_val("cache", "disable_auto_purge", 0) > 0) { + g_buffer_process_ask_instance->disable_auto_purge(); + // lruLevel = 3; /* LRU_WRITE */ + } + int autoPurgeAlertTime = + g_dtc_config->get_int_val("cache", "AutoPurgeAlertTime", 0); + g_buffer_process_ask_instance->set_date_expire_alert_time( + autoPurgeAlertTime); + if (autoPurgeAlertTime > 0 && TableDefinitionManager::instance() + ->get_cur_table_def() + ->lastcmod_field_id() <= 0) { + log4cplus_error("Can't start AutoPurgeAlert without lastcmod field"); + return DTC_CODE_FAILED; + } + } + g_buffer_process_ask_instance->disable_lru_update(lruLevel); + g_buffer_process_ask_instance->enable_lossy_data_source( + g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); + + if (async_update != MODE_SYNC && cache_key == 0) { + log4cplus_error("Anonymous shared memory don't support DelayUpdate"); + return DTC_CODE_FAILED; + } + + int iAutoDeleteDirtyShm = + g_dtc_config->get_int_val("cache", "AutoDeleteDirtyShareMemory", 0); + /*disable empty node filter*/ + if (g_buffer_process_ask_instance->open_init_buffer( + cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + if (g_buffer_process_ask_instance->update_mode() || + g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active + { + if (TableDefinitionManager::instance()->get_cur_table_def()->uniq_fields() < + 1) { + log4cplus_error("DelayUpdate needs uniq-field(s)"); + return DTC_CODE_FAILED; + } + + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { + if (g_buffer_process_ask_instance->update_mode()) { + log4cplus_error("Can't start async mode when disableDataSource."); + return DTC_CODE_FAILED; + } else { + log4cplus_error("Can't start disableDataSource with shm dirty,please " + "flush async shm to db first or delete shm"); + return DTC_CODE_FAILED; + } + } else { + if ((TableDefinitionManager::instance() + ->get_cur_table_def() + ->compress_field_id() >= 0)) { + log4cplus_error( + "sorry,DTC just support compress in disableDataSource mode now."); + return DTC_CODE_FAILED; + } + } + + /*marker is the only source of flush speed calculattion, inc precision to + * 10*/ + g_buffer_process_ask_instance->set_flush_parameter( + g_dtc_config->get_int_val("cache", "MarkerPrecision", 10), + g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), + g_dtc_config->get_int_val("cache", "MinDirtyTime", 3600), + g_dtc_config->get_int_val("cache", "MaxDirtyTime", 43200)); + + g_buffer_process_ask_instance->set_drop_count( + g_dtc_config->get_int_val("cache", "MaxDropCount", 1000)); + } else { + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) + g_data_connector_ask_instance->disable_commit_group(); + } + + if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < 0) + return DTC_CODE_FAILED; + + log4cplus_error("init_buffer_process_ask_chain_thread end"); + + return DTC_CODE_SUCCESS; } -int collect_load_config(DbConfig *dbconfig) -{ - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) - return DTC_CODE_SUCCESS; +int collect_load_config(DbConfig *dbconfig) { + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) + return DTC_CODE_SUCCESS; - if (!g_data_connector_ask_instance) - return DTC_CODE_FAILED; + if (!g_data_connector_ask_instance) + return DTC_CODE_FAILED; - if (dbconfig == NULL) { - log4cplus_error("dbconfig == NULL"); - return DTC_CODE_FAILED; - } + if (dbconfig == NULL) { + log4cplus_error("dbconfig == NULL"); + return DTC_CODE_FAILED; + } - if (g_data_connector_ask_instance->renew_config(dbconfig)) { - log4cplus_error("helperunit renew config error!"); - return DTC_CODE_FAILED; - } + if (g_data_connector_ask_instance->renew_config(dbconfig)) { + log4cplus_error("helperunit renew config error!"); + return DTC_CODE_FAILED; + } - return DTC_CODE_SUCCESS; + return DTC_CODE_SUCCESS; } -int init_remote_dtc_chain_thread() -{ - log4cplus_debug("init_remote_dtc_chain_thread begin"); - g_remote_thread = new PollerBase("dtc-thread-remote"); - g_remote_dtc_instance = new RemoteDtcAskAnswerChain( - g_remote_thread, - g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); - if (g_remote_thread->initialize_thread() == DTC_CODE_FAILED) { - log4cplus_error("init remote thread error"); - return DTC_CODE_FAILED; - } - - //get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = - g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - - g_remote_dtc_instance->set_timer_handler( - g_remote_thread->get_timer_list(timeout), - g_remote_thread->get_timer_list(connect), - g_remote_thread->get_timer_list(retry)); - log4cplus_debug("init_remote_dtc_chain_thread end"); - - return DTC_CODE_SUCCESS; +int init_remote_dtc_chain_thread() { + log4cplus_debug("init_remote_dtc_chain_thread begin"); + g_remote_thread = new PollerBase("dtc-thread-remote"); + g_remote_dtc_instance = new RemoteDtcAskAnswerChain( + g_remote_thread, + g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); + if (g_remote_thread->initialize_thread() == DTC_CODE_FAILED) { + log4cplus_error("init remote thread error"); + return DTC_CODE_FAILED; + } + + // get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + + g_remote_dtc_instance->set_timer_handler( + g_remote_thread->get_timer_list(timeout), + g_remote_thread->get_timer_list(connect), + g_remote_thread->get_timer_list(retry)); + log4cplus_debug("init_remote_dtc_chain_thread end"); + + return DTC_CODE_SUCCESS; } -int init_remote_dtc_chain(PollerBase *thread) -{ - log4cplus_debug("init_remote_dtc_chain begin"); +int init_remote_dtc_chain(PollerBase *thread) { + log4cplus_debug("init_remote_dtc_chain begin"); - g_remote_dtc_instance = new RemoteDtcAskAnswerChain( - thread, - g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); + g_remote_dtc_instance = new RemoteDtcAskAnswerChain( + thread, g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); - //get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = - g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + // get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - g_remote_dtc_instance->set_timer_handler( - thread->get_timer_list(timeout), - thread->get_timer_list(connect), thread->get_timer_list(retry)); - log4cplus_debug("init_remote_dtc_chain end"); + g_remote_dtc_instance->set_timer_handler(thread->get_timer_list(timeout), + thread->get_timer_list(connect), + thread->get_timer_list(retry)); + log4cplus_debug("init_remote_dtc_chain end"); - return DTC_CODE_SUCCESS; + return DTC_CODE_SUCCESS; } -int init_data_connector_chain_thread() -{ - log4cplus_debug("init_data_connector_chain_thread begin"); - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) { - g_data_connector_ask_instance = new DataConnectorAskChain(); - if (g_data_connector_ask_instance->load_config( - dbConfig, TableDefinitionManager::instance() - ->get_cur_table_def() - ->key_format()) == -1) { - return DTC_CODE_FAILED; - } - } - - //get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = - g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - - g_datasource_thread = new PollerBase("dtc-thread-datasource"); - if (g_datasource_thread->initialize_thread() == DTC_CODE_FAILED) - return DTC_CODE_FAILED; - - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) - g_data_connector_ask_instance->set_timer_handler( - g_datasource_thread->get_timer_list(timeout), - g_datasource_thread->get_timer_list(connect), - g_datasource_thread->get_timer_list(retry)); - log4cplus_debug("init_data_connector_chain_thread end"); - - return DTC_CODE_SUCCESS; +int init_data_connector_chain_thread() { + log4cplus_debug("init_data_connector_chain_thread begin"); + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) { + g_data_connector_ask_instance = new DataConnectorAskChain(); + if (g_data_connector_ask_instance->load_config( + dbConfig, TableDefinitionManager::instance() + ->get_cur_table_def() + ->key_format()) == -1) { + return DTC_CODE_FAILED; + } + } + + // get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + + g_datasource_thread = new PollerBase("dtc-thread-datasource"); + if (g_datasource_thread->initialize_thread() == DTC_CODE_FAILED) + return DTC_CODE_FAILED; + + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) + g_data_connector_ask_instance->set_timer_handler( + g_datasource_thread->get_timer_list(timeout), + g_datasource_thread->get_timer_list(connect), + g_datasource_thread->get_timer_list(retry)); + log4cplus_debug("init_data_connector_chain_thread end"); + + return DTC_CODE_SUCCESS; } -int init_buffer_process_ask_chain(PollerBase *thread) -{ - log4cplus_error("init_buffer_process_ask_chain start"); - g_buffer_process_ask_instance = new BufferProcessAskChain( - thread, TableDefinitionManager::instance()->get_cur_table_def(), - async_update ? MODE_ASYNC : MODE_SYNC); - g_buffer_process_ask_instance->set_limit_node_size( - g_dtc_config->get_int_val("cache", "LimitNodeSize", - 100 * 1024 * 1024)); - g_buffer_process_ask_instance->set_limit_node_rows( - g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); - g_buffer_process_ask_instance->set_limit_empty_nodes( - g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); - - unsigned long long cache_size = - g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); - if (cache_size <= (50ULL << 20)) // 50M - { - log4cplus_error("CacheMemorySize too small"); - return DTC_CODE_FAILED; - } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { - log4cplus_error("CacheMemorySize %lld too large", cache_size); - } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( - cache_size, - g_dtc_config->get_int_val("cache", "CacheShmVersion", - 4)) == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - /* disable async transaction log */ - g_buffer_process_ask_instance->disable_async_log(1); - - int lruLevel = - g_dtc_config->get_int_val("cache", "disable_lru_update", 0); - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { - if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { - return DTC_CODE_FAILED; - } - if (g_dtc_config->get_int_val("cache", "disable_auto_purge", - 0) > 0) { - g_buffer_process_ask_instance->disable_auto_purge(); - // lruLevel = 3; /* LRU_WRITE */ - } - int autoPurgeAlertTime = g_dtc_config->get_int_val( - "cache", "AutoPurgeAlertTime", 0); - g_buffer_process_ask_instance->set_date_expire_alert_time( - autoPurgeAlertTime); - if (autoPurgeAlertTime > 0 && - TableDefinitionManager::instance() - ->get_cur_table_def() - ->lastcmod_field_id() <= 0) { - log4cplus_error( - "Can't start AutoPurgeAlert without lastcmod field"); - return DTC_CODE_FAILED; - } - } - g_buffer_process_ask_instance->disable_lru_update(lruLevel); - g_buffer_process_ask_instance->enable_lossy_data_source( - g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); - - if (async_update != MODE_SYNC && cache_key == 0) { - log4cplus_error( - "Anonymous shared memory don't support DelayUpdate"); - return DTC_CODE_FAILED; - } - - int iAutoDeleteDirtyShm = g_dtc_config->get_int_val( - "cache", "AutoDeleteDirtyShareMemory", 0); - /*disable empty node filter*/ - if (g_buffer_process_ask_instance->open_init_buffer( - cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - if (g_buffer_process_ask_instance->update_mode() || - g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active - { - if (TableDefinitionManager::instance() - ->get_cur_table_def() - ->uniq_fields() < 1) { - log4cplus_error("DelayUpdate needs uniq-field(s)"); - return DTC_CODE_FAILED; - } - - switch (g_datasource_mode) { - case DTC_MODE_CACHE_ONLY: - if (g_buffer_process_ask_instance->update_mode()) { - log4cplus_error( - "Can't start async mode when disableDataSource."); - return DTC_CODE_FAILED; - } else { - log4cplus_error( - "Can't start disableDataSource with shm dirty,please flush async shm to db first or delete shm"); - return DTC_CODE_FAILED; - } - break; - case DTC_MODE_DATABASE_ADDITION: - if ((TableDefinitionManager::instance() - ->get_cur_table_def() - ->compress_field_id() >= 0)) { - log4cplus_error( - "sorry,DTC just support compress in disableDataSource mode now."); - return DTC_CODE_FAILED; - } - break; - default: - log4cplus_error("datasource mode error:%d", - g_datasource_mode); - return DTC_CODE_FAILED; - } - - /*marker is the only source of flush speed calculattion, inc precision to 10*/ - g_buffer_process_ask_instance->set_flush_parameter( - g_dtc_config->get_int_val("cache", "MarkerPrecision", - 10), - g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), - g_dtc_config->get_int_val("cache", "MinDirtyTime", - 3600), - g_dtc_config->get_int_val("cache", "MaxDirtyTime", - 43200)); - - g_buffer_process_ask_instance->set_drop_count( - g_dtc_config->get_int_val("cache", "MaxDropCount", - 1000)); - } else { - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) - g_data_connector_ask_instance->disable_commit_group(); - } - - if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < - 0) - return DTC_CODE_FAILED; - - log4cplus_error("init_buffer_process_ask_chain end"); - - return DTC_CODE_SUCCESS; +int init_buffer_process_ask_chain(PollerBase *thread) { + log4cplus_error("init_buffer_process_ask_chain start"); + g_buffer_process_ask_instance = new BufferProcessAskChain( + thread, TableDefinitionManager::instance()->get_cur_table_def(), + async_update ? MODE_ASYNC : MODE_SYNC); + g_buffer_process_ask_instance->set_limit_node_size( + g_dtc_config->get_int_val("cache", "LimitNodeSize", 100 * 1024 * 1024)); + g_buffer_process_ask_instance->set_limit_node_rows( + g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); + g_buffer_process_ask_instance->set_limit_empty_nodes( + g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); + + unsigned long long cache_size = + g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); + if (cache_size <= (50ULL << 20)) // 50M + { + log4cplus_error("CacheMemorySize too small"); + return DTC_CODE_FAILED; + } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { + log4cplus_error("CacheMemorySize %lld too large", cache_size); + } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( + cache_size, + g_dtc_config->get_int_val("cache", "CacheShmVersion", 4)) == + DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + /* disable async transaction log */ + g_buffer_process_ask_instance->disable_async_log(1); + + int lruLevel = g_dtc_config->get_int_val("cache", "disable_lru_update", 0); + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { + if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { + return DTC_CODE_FAILED; + } + if (g_dtc_config->get_int_val("cache", "disable_auto_purge", 0) > 0) { + g_buffer_process_ask_instance->disable_auto_purge(); + // lruLevel = 3; /* LRU_WRITE */ + } + int autoPurgeAlertTime = + g_dtc_config->get_int_val("cache", "AutoPurgeAlertTime", 0); + g_buffer_process_ask_instance->set_date_expire_alert_time( + autoPurgeAlertTime); + if (autoPurgeAlertTime > 0 && TableDefinitionManager::instance() + ->get_cur_table_def() + ->lastcmod_field_id() <= 0) { + log4cplus_error("Can't start AutoPurgeAlert without lastcmod field"); + return DTC_CODE_FAILED; + } + } + g_buffer_process_ask_instance->disable_lru_update(lruLevel); + g_buffer_process_ask_instance->enable_lossy_data_source( + g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); + + if (async_update != MODE_SYNC && cache_key == 0) { + log4cplus_error("Anonymous shared memory don't support DelayUpdate"); + return DTC_CODE_FAILED; + } + + int iAutoDeleteDirtyShm = + g_dtc_config->get_int_val("cache", "AutoDeleteDirtyShareMemory", 0); + /*disable empty node filter*/ + if (g_buffer_process_ask_instance->open_init_buffer( + cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + if (g_buffer_process_ask_instance->update_mode() || + g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active + { + if (TableDefinitionManager::instance()->get_cur_table_def()->uniq_fields() < + 1) { + log4cplus_error("DelayUpdate needs uniq-field(s)"); + return DTC_CODE_FAILED; + } + + switch (g_datasource_mode) { + case DTC_MODE_CACHE_ONLY: + if (g_buffer_process_ask_instance->update_mode()) { + log4cplus_error("Can't start async mode when disableDataSource."); + return DTC_CODE_FAILED; + } else { + log4cplus_error("Can't start disableDataSource with shm dirty,please " + "flush async shm to db first or delete shm"); + return DTC_CODE_FAILED; + } + break; + case DTC_MODE_DATABASE_ADDITION: + if ((TableDefinitionManager::instance() + ->get_cur_table_def() + ->compress_field_id() >= 0)) { + log4cplus_error( + "sorry,DTC just support compress in disableDataSource mode now."); + return DTC_CODE_FAILED; + } + break; + default: + log4cplus_error("datasource mode error:%d", g_datasource_mode); + return DTC_CODE_FAILED; + } + + /*marker is the only source of flush speed calculattion, inc precision to + * 10*/ + g_buffer_process_ask_instance->set_flush_parameter( + g_dtc_config->get_int_val("cache", "MarkerPrecision", 10), + g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), + g_dtc_config->get_int_val("cache", "MinDirtyTime", 3600), + g_dtc_config->get_int_val("cache", "MaxDirtyTime", 43200)); + + g_buffer_process_ask_instance->set_drop_count( + g_dtc_config->get_int_val("cache", "MaxDropCount", 1000)); + } else { + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) + g_data_connector_ask_instance->disable_commit_group(); + } + + if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < 0) + return DTC_CODE_FAILED; + + log4cplus_error("init_buffer_process_ask_chain end"); + + return DTC_CODE_SUCCESS; } -int init_data_connector_ask_chain(PollerBase *thread) -{ - log4cplus_debug("init_data_connector_ask_chain begin"); - - g_data_connector_ask_instance = new DataConnectorAskChain(); - if (g_data_connector_ask_instance->load_config( - dbConfig, TableDefinitionManager::instance() - ->get_cur_table_def() - ->key_format()) == -1) { - return DTC_CODE_FAILED; - } - //get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = - g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - - g_data_connector_ask_instance->set_timer_handler( - thread->get_timer_list(timeout), - thread->get_timer_list(connect), thread->get_timer_list(retry)); - - g_data_connector_ask_instance->do_attach(thread); - if (g_datasource_mode == DTC_MODE_DATABASE_ONLY) { - g_data_connector_ask_instance->disable_commit_group(); - } - log4cplus_debug("init_data_connector_ask_chain end"); - - return DTC_CODE_SUCCESS; +int init_data_connector_ask_chain(PollerBase *thread) { + log4cplus_debug("init_data_connector_ask_chain begin"); + + g_data_connector_ask_instance = new DataConnectorAskChain(); + if (g_data_connector_ask_instance->load_config( + dbConfig, TableDefinitionManager::instance() + ->get_cur_table_def() + ->key_format()) == -1) { + return DTC_CODE_FAILED; + } + // get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + + g_data_connector_ask_instance->set_timer_handler( + thread->get_timer_list(timeout), thread->get_timer_list(connect), + thread->get_timer_list(retry)); + + g_data_connector_ask_instance->do_attach(thread); + if (g_datasource_mode == DTC_MODE_DATABASE_ONLY) { + g_data_connector_ask_instance->disable_commit_group(); + } + log4cplus_debug("init_data_connector_ask_chain end"); + + return DTC_CODE_SUCCESS; } //鑾峰彇銆侀厤缃熀纭淇℃伅 -int init_config_info() -{ - mkdir("/usr/local/dtc/stat", 0777); - mkdir("/usr/local/dtc/data", 0777); - - g_hash_changing = g_dtc_config->get_int_val("cache", "HashChanging", 0); - g_target_new_hash = - g_dtc_config->get_int_val("cache", "TargetNewHash", 0); - - DTCGlobal::pre_alloc_nodegroup_count = - g_dtc_config->get_int_val("cache", "PreAllocNGNum", 1024); - DTCGlobal::pre_alloc_nodegroup_count = - DTCGlobal::pre_alloc_nodegroup_count <= 1 ? - 1 : - DTCGlobal::pre_alloc_nodegroup_count >= (1 << 12) ? - 1 : - DTCGlobal::pre_alloc_nodegroup_count; - - DTCGlobal::min_chunk_size_ = - g_dtc_config->get_int_val("cache", "MinChunkSize", 0); - if (DTCGlobal::min_chunk_size_ < 0) { - DTCGlobal::min_chunk_size_ = 0; - } - - DTCGlobal::pre_purge_nodes_ = - g_dtc_config->get_int_val("cache", "pre_purge_nodes", 0); - if (DTCGlobal::pre_purge_nodes_ < 0) { - DTCGlobal::pre_purge_nodes_ = 0; - } else if (DTCGlobal::pre_purge_nodes_ > 10000) { - DTCGlobal::pre_purge_nodes_ = 10000; - } - - RELATIVE_HOUR_CALCULATOR->set_base_hour( - g_dtc_config->get_int_val("cache", "RelativeYear", 2014)); - - log4cplus_info("Table %s: key/field# %d/%d, keysize %d", - dbConfig->tblName, - TableDefinitionManager::instance() - ->get_cur_table_def() - ->key_fields(), - TableDefinitionManager::instance() - ->get_cur_table_def() - ->num_fields() + - 1, - TableDefinitionManager::instance() - ->get_cur_table_def() - ->max_key_size()); - - return DTC_CODE_SUCCESS; +int init_config_info() { + g_hash_changing = g_dtc_config->get_int_val("cache", "HashChanging", 0); + g_target_new_hash = g_dtc_config->get_int_val("cache", "TargetNewHash", 0); + + DTCGlobal::pre_alloc_nodegroup_count = + g_dtc_config->get_int_val("cache", "PreAllocNGNum", 1024); + DTCGlobal::pre_alloc_nodegroup_count = + DTCGlobal::pre_alloc_nodegroup_count <= 1 + ? 1 + : DTCGlobal::pre_alloc_nodegroup_count >= (1 << 12) + ? 1 + : DTCGlobal::pre_alloc_nodegroup_count; + + DTCGlobal::min_chunk_size_ = + g_dtc_config->get_int_val("cache", "MinChunkSize", 0); + if (DTCGlobal::min_chunk_size_ < 0) { + DTCGlobal::min_chunk_size_ = 0; + } + + DTCGlobal::pre_purge_nodes_ = + g_dtc_config->get_int_val("cache", "pre_purge_nodes", 0); + if (DTCGlobal::pre_purge_nodes_ < 0) { + DTCGlobal::pre_purge_nodes_ = 0; + } else if (DTCGlobal::pre_purge_nodes_ > 10000) { + DTCGlobal::pre_purge_nodes_ = 10000; + } + + RELATIVE_HOUR_CALCULATOR->set_base_hour( + g_dtc_config->get_int_val("cache", "RelativeYear", 2014)); + + log4cplus_info( + "Table %s: key/field# %d/%d, keysize %d", dbConfig->tblName, + TableDefinitionManager::instance()->get_cur_table_def()->key_fields(), + TableDefinitionManager::instance()->get_cur_table_def()->num_fields() + 1, + TableDefinitionManager::instance()->get_cur_table_def()->max_key_size()); + + return DTC_CODE_SUCCESS; } -void free_all_resource() -{ - //stop plugin - if (enable_plugin && init_plugin) { - plugin_stop(); - } - - DELETE(main_listener); - - if (g_buffer_multi_thread) { - g_buffer_multi_thread->interrupt(); - } - if (g_hot_backup_thread) { - g_hot_backup_thread->interrupt(); - } - if (g_datasource_thread) { - g_datasource_thread->interrupt(); - } - - if (g_remote_thread) { - g_remote_thread->interrupt(); - } - - if (g_main_thread) { - g_main_thread->interrupt(); - } - - StopTaskExecutor(); - - DELETE(g_buffer_process_ask_instance); - DELETE(g_data_connector_ask_instance); - DELETE(g_buffer_barrier_instance); - DELETE(g_key_route_ask_instance); - DELETE(g_connector_barrier_instance); - DELETE(g_buffer_bypass_ask_instance); - DELETE(g_hot_backup_ask_instance); - DELETE(g_remote_dtc_instance); - DELETE(g_black_hole_ask_instance); - DELETE(g_agent_hub_ask_instance); - DELETE(g_job_hub_ask_instance); - - DELETE(g_buffer_multi_thread); - DELETE(g_datasource_thread); - DELETE(g_remote_thread); - DELETE(g_main_thread); - DELETE(g_hot_backup_thread); - g_stat_mgr.stop_background_thread(); - log4cplus_info("--------%s-v%s END!--------", project_name, version); - daemon_cleanup(); +void free_all_resource() { + // stop plugin + if (enable_plugin && init_plugin) { + plugin_stop(); + } + + DELETE(main_listener); + + if (g_buffer_multi_thread) { + g_buffer_multi_thread->interrupt(); + } + if (g_hot_backup_thread) { + g_hot_backup_thread->interrupt(); + } + if (g_datasource_thread) { + g_datasource_thread->interrupt(); + } + + if (g_remote_thread) { + g_remote_thread->interrupt(); + } + + if (g_main_thread) { + g_main_thread->interrupt(); + } + + StopTaskExecutor(); + + DELETE(g_buffer_process_ask_instance); + DELETE(g_data_connector_ask_instance); + DELETE(g_buffer_barrier_instance); + DELETE(g_key_route_ask_instance); + DELETE(g_connector_barrier_instance); + DELETE(g_buffer_bypass_ask_instance); + DELETE(g_hot_backup_ask_instance); + DELETE(g_remote_dtc_instance); + DELETE(g_black_hole_ask_instance); + DELETE(g_agent_hub_ask_instance); + DELETE(g_job_hub_ask_instance); + + DELETE(g_buffer_multi_thread); + DELETE(g_datasource_thread); + DELETE(g_remote_thread); + DELETE(g_main_thread); + DELETE(g_hot_backup_thread); + g_stat_mgr.stop_background_thread(); + log4cplus_info("--------%s-v%s END!--------", project_name, version); + daemon_cleanup(); #if MEMCHECK - dump_non_delete(); - log4cplus_debug("memory allocated %lu virtual %lu", count_alloc_size(), - count_virtual_size()); + dump_non_delete(); + log4cplus_debug("memory allocated %lu virtual %lu", count_alloc_size(), + count_virtual_size()); #endif } \ No newline at end of file diff --git a/src/libs/common/config/config.cc b/src/libs/common/config/config.cc index 7d25f17..edaa963 100644 --- a/src/libs/common/config/config.cc +++ b/src/libs/common/config/config.cc @@ -1,485 +1,444 @@ /* -* Copyright [2021] JD.com, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright [2021] JD.com, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include -#include -#include -#include #include -#include -#include #include +#include +#include +#include #include +#include -#include "mem_check.h" #include "config.h" #include "log/log.h" +#include "mem_check.h" -int str2int(const char *strval, int def) -{ - int ret_code = def; - if (isdigit(strval[0]) || (strval[0] == '-' && isdigit(strval[1]))) - return atoi(strval); - - if (!strcasecmp(strval, "On")) - ret_code = 1; - else if (!strcasecmp(strval, "Off")) - ret_code = 0; - else if (!strcasecmp(strval, "Yes")) - ret_code = 1; - else if (!strcasecmp(strval, "No")) - ret_code = 0; - else if (!strcasecmp(strval, "True")) - ret_code = 1; - else if (!strcasecmp(strval, "False")) - ret_code = 0; - else if (!strcasecmp(strval, "Enable")) - ret_code = 1; - else if (!strcasecmp(strval, "Disable")) - ret_code = 0; - else if (!strcasecmp(strval, "Enabled")) - ret_code = 1; - else if (!strcasecmp(strval, "Disabled")) - ret_code = 0; - - return ret_code; +int str2int(const char *strval, int def) { + int ret_code = def; + if (isdigit(strval[0]) || (strval[0] == '-' && isdigit(strval[1]))) + return atoi(strval); + + if (!strcasecmp(strval, "On")) + ret_code = 1; + else if (!strcasecmp(strval, "Off")) + ret_code = 0; + else if (!strcasecmp(strval, "Yes")) + ret_code = 1; + else if (!strcasecmp(strval, "No")) + ret_code = 0; + else if (!strcasecmp(strval, "True")) + ret_code = 1; + else if (!strcasecmp(strval, "False")) + ret_code = 0; + else if (!strcasecmp(strval, "Enable")) + ret_code = 1; + else if (!strcasecmp(strval, "Disable")) + ret_code = 0; + else if (!strcasecmp(strval, "Enabled")) + ret_code = 1; + else if (!strcasecmp(strval, "Disabled")) + ret_code = 0; + + return ret_code; } -int DTCConfig::Dump(const char *fn, bool dec) -{ - FILE *fp = fopen(fn, "w"); - if (fp == NULL) - return -1; - //fprintf(fp, "##### ORIGINAL FILE %s #####\n", filename_.c_str()); - for (YAML::const_iterator ite = table_config_.begin(); - ite != table_config_.end(); ++ite) { - YAML::Node inception_sec = ite->first; - std::string sec = inception_sec.as(); - fprintf(fp, "%s:\n", sec.c_str()); - YAML::Node key_map = ite->second; - for (YAML::const_iterator ite_map = key_map.begin(); - ite_map != key_map.end(); ++ite_map) { - YAML::Node key = ite_map->first; - YAML::Node value = ite_map->second; - std::string now_key = key.as(); - std::string now_value = value.as(); - if (dec == true) - fprintf(fp, "# %s NOT SET\n", now_key.c_str()); - if (dec == false) - fprintf(fp, " %s: %s\n", now_key.c_str(), - now_value.c_str()); - } - } - fclose(fp); - return 0; +int DTCConfig::Dump(const char *fn, bool dec) { + FILE *fp = fopen(fn, "w"); + if (fp == NULL) + return -1; + // fprintf(fp, "##### ORIGINAL FILE %s #####\n", filename_.c_str()); + for (YAML::const_iterator ite = table_config_.begin(); + ite != table_config_.end(); ++ite) { + YAML::Node inception_sec = ite->first; + std::string sec = inception_sec.as(); + fprintf(fp, "%s:\n", sec.c_str()); + YAML::Node key_map = ite->second; + for (YAML::const_iterator ite_map = key_map.begin(); + ite_map != key_map.end(); ++ite_map) { + YAML::Node key = ite_map->first; + YAML::Node value = ite_map->second; + std::string now_key = key.as(); + std::string now_value = value.as(); + if (dec == true) + fprintf(fp, "# %s NOT SET\n", now_key.c_str()); + if (dec == false) + fprintf(fp, " %s: %s\n", now_key.c_str(), now_value.c_str()); + } + } + fclose(fp); + return 0; } int DTCConfig::parse_buffered_config(char *buf, const char *fn, - const char *defsec, bool bakconfig) -{ - int ret_code = -1; - try { - printf("open config file:%s\n", fn); - if (defsec && strcmp(defsec, "cache") == 0) { - cache_config_ = YAML::Load(buf); - } else { - table_config_ = YAML::Load(buf); - } - ret_code = 0; - } catch (const YAML::Exception &e) { - printf("config file error:%s\n", e.what()); - return ret_code; - } - return; + const char *defsec, bool bakconfig) { + int ret_code = -1; + try { + if (defsec && strcmp(defsec, "cache") == 0) { + cache_config_ = YAML::Load(buf); + } else { + table_config_ = YAML::Load(buf); + } + ret_code = 0; + } catch (const YAML::Exception &e) { + printf("config file error:%s\n", e.what()); + return ret_code; + } + return; } -int DTCConfig::parse_config(const char *fn, const char *defsec, bool bakconfig) -{ - int ret_code = -1; - - try { - printf("open config file:%s\n", fn); - if (strcmp(defsec, "cache") == 0) { - cache_config_ = YAML::LoadFile(fn); - } else { - table_config_ = YAML::LoadFile(fn); - } - ret_code = 0; - } catch (const YAML::Exception &e) { - printf("config file error:%s\n", e.what()); - return ret_code; - } - - if (bakconfig) { - char bak_config[1024]; - int err = 0; - snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn); - printf("bakconfig:%s\n", bak_config); - if (err == 0) - err = system(bak_config); - } - return ret_code; +int DTCConfig::parse_config(const char *fn, const char *defsec, + bool bakconfig) { + int ret_code = -1; + + try { + printf("open config file:%s\n", fn); + if (strcmp(defsec, "cache") == 0) { + cache_config_ = YAML::LoadFile(fn); + } else { + table_config_ = YAML::LoadFile(fn); + } + ret_code = 0; + } catch (const YAML::Exception &e) { + printf("config file error:%s\n", e.what()); + return ret_code; + } + + if (bakconfig) { + char bak_config[1024]; + int err = 0; + snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn); + if (err == 0) + err = system(bak_config); + } + return ret_code; } -bool DTCConfig::has_section(const char *sec) -{ - YAML::Node inception = table_config_[sec]; - if (inception && inception.IsMap()) - return true; - else - return false; +bool DTCConfig::has_section(const char *sec) { + YAML::Node inception = table_config_[sec]; + if (inception && inception.IsMap()) + return true; + else + return false; } -bool DTCConfig::has_key(const char *sec, const char *key) -{ - if (!table_config_[sec]) - return false; +bool DTCConfig::has_key(const char *sec, const char *key) { + if (!table_config_[sec]) + return false; - YAML::Node inception = table_config_[sec][key]; - if (inception && inception.IsScalar()) - return true; - else - return false; + YAML::Node inception = table_config_[sec][key]; + if (inception && inception.IsScalar()) + return true; + else + return false; } /******************************************** * eg锛歡et_str_val("cache", "RemoteLogAddr") * 璇诲彇 conf/cache.conf涓璕emoteLogAdd鐨勫弬鏁 * ******************************************/ -const char *DTCConfig::get_str_val(const char *sec, const char *key) -{ - const char *val = NULL; - - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - - if (val == NULL) - return NULL; - - return val; +const char *DTCConfig::get_str_val(const char *sec, const char *key) { + const char *val = NULL; + + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + + if (val == NULL) + return NULL; + + return val; } -int DTCConfig::get_int_val(const char *sec, const char *key, int def) -{ - const char *val = NULL; - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - - if (val == NULL) - return def; - - return str2int(val, def); +int DTCConfig::get_int_val(const char *sec, const char *key, int def) { + const char *val = NULL; + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + + if (val == NULL) + return def; + + return str2int(val, def); } unsigned long long DTCConfig::get_size_val(const char *sec, const char *key, - unsigned long long def, char unit) -{ - const char *val = NULL; - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - - if (val == NULL || !isdigit(val[0])) - return def; - - const char *p; - double a = strtod(val, (char **)&p); - if (*p) - unit = *p; - switch (unit) { - case 'b': - break; - case 'B': - break; - case 'k': - a *= 1000; - break; - case 'K': - a *= 1 << 10; - break; - case 'm': - a *= 1000000; - break; - case 'M': - a *= 1 << 20; - break; - case 'g': - a *= 1000000000; - break; - case 'G': - a *= 1 << 30; - break; - case 't': - a *= 1000000000000LL; - break; - case 'T': - a *= 1ULL << 40; - break; - } - - return (unsigned long long)a; + unsigned long long def, char unit) { + const char *val = NULL; + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + + if (val == NULL || !isdigit(val[0])) + return def; + + const char *p; + double a = strtod(val, (char **)&p); + if (*p) + unit = *p; + switch (unit) { + case 'b': + break; + case 'B': + break; + case 'k': + a *= 1000; + break; + case 'K': + a *= 1 << 10; + break; + case 'm': + a *= 1000000; + break; + case 'M': + a *= 1 << 20; + break; + case 'g': + a *= 1000000000; + break; + case 'G': + a *= 1 << 30; + break; + case 't': + a *= 1000000000000LL; + break; + case 'T': + a *= 1ULL << 40; + break; + } + + return (unsigned long long)a; } int DTCConfig::get_idx_val(const char *sec, const char *key, - const char *const *array, int nDefault) -{ - const char *val = NULL; - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key] - .as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - if (val == NULL) - return nDefault; - - if (isdigit(val[0])) { - char *p; - int n = strtol(val, &p, 0); - if (*p == '\0') { - for (int i = 0; array[i]; ++i) { - if (n == i) - return i; - } - } - } - - for (int i = 0; array[i]; ++i) { - if (!strcasecmp(val, array[i])) - return i; - } - return -1; + const char *const *array, int nDefault) { + const char *val = NULL; + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key].as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + if (val == NULL) + return nDefault; + + if (isdigit(val[0])) { + char *p; + int n = strtol(val, &p, 0); + if (*p == '\0') { + for (int i = 0; array[i]; ++i) { + if (n == i) + return i; + } + } + } + + for (int i = 0; array[i]; ++i) { + if (!strcasecmp(val, array[i])) + return i; + } + return -1; } class AutoConfigSection : public AutoConfig { - private: - static pthread_mutex_t glock; - void GlobalLock(void) - { - pthread_mutex_lock(&glock); - } - void GlobalUnlock(void) - { - pthread_mutex_unlock(&glock); - } - - private: - DTCConfig *parent; - char *section; - // buf must have enough room place composed key name - char buf[256]; - char *last; - - public: - AutoConfigSection(DTCConfig *p, const char *sec); - ~AutoConfigSection(); - - virtual int get_int_val(const char *key, const char *inst, int def = 0); - virtual unsigned long long get_size_val(const char *key, - const char *inst, - unsigned long long def = 0, - char unit = 0); - virtual int get_idx_val(const char *, const char *, const char *const *, - int = 0); - virtual const char *get_str_val(const char *key, const char *inst); - - private: - // return composed key, or vanilla key, always non-null - const char *findkey(const char *key, const char *inst); - // strip suffix digits - int stripnumber(void); - // strip suffix alphaphetic - int stripalpha(void); - // strip suffix punct - int strippunct(void); +private: + static pthread_mutex_t glock; + void GlobalLock(void) { pthread_mutex_lock(&glock); } + void GlobalUnlock(void) { pthread_mutex_unlock(&glock); } + +private: + DTCConfig *parent; + char *section; + // buf must have enough room place composed key name + char buf[256]; + char *last; + +public: + AutoConfigSection(DTCConfig *p, const char *sec); + ~AutoConfigSection(); + + virtual int get_int_val(const char *key, const char *inst, int def = 0); + virtual unsigned long long get_size_val(const char *key, const char *inst, + unsigned long long def = 0, + char unit = 0); + virtual int get_idx_val(const char *, const char *, const char *const *, + int = 0); + virtual const char *get_str_val(const char *key, const char *inst); + +private: + // return composed key, or vanilla key, always non-null + const char *findkey(const char *key, const char *inst); + // strip suffix digits + int stripnumber(void); + // strip suffix alphaphetic + int stripalpha(void); + // strip suffix punct + int strippunct(void); }; pthread_mutex_t AutoConfigSection::glock = PTHREAD_MUTEX_INITIALIZER; -AutoConfigSection::AutoConfigSection(DTCConfig *p, const char *sec) -{ - this->parent = p; - this->section = STRDUP(sec); -} - -AutoConfigSection::~AutoConfigSection() -{ - FREE_CLEAR(section); +AutoConfigSection::AutoConfigSection(DTCConfig *p, const char *sec) { + this->parent = p; + this->section = STRDUP(sec); } -int AutoConfigSection::stripnumber(void) -{ - int n = 0; - while (last >= buf && isdigit(*last)) { - last--; - n++; - } - last[1] = 0; - strippunct(); - return n; +AutoConfigSection::~AutoConfigSection() { FREE_CLEAR(section); } + +int AutoConfigSection::stripnumber(void) { + int n = 0; + while (last >= buf && isdigit(*last)) { + last--; + n++; + } + last[1] = 0; + strippunct(); + return n; } -int AutoConfigSection::stripalpha(void) -{ - int n = 0; - while (last >= buf && isalpha(*last)) { - last--; - n++; - } - last[1] = 0; - strippunct(); - return n; +int AutoConfigSection::stripalpha(void) { + int n = 0; + while (last >= buf && isalpha(*last)) { + last--; + n++; + } + last[1] = 0; + strippunct(); + return n; } -int AutoConfigSection::strippunct(void) -{ - int n = 0; - while (last >= buf && *last != '@' && !isalnum(*last)) { - last--; - n++; - } - last[1] = 0; - return n; +int AutoConfigSection::strippunct(void) { + int n = 0; + while (last >= buf && *last != '@' && !isalnum(*last)) { + last--; + n++; + } + last[1] = 0; + return n; } -const char *AutoConfigSection::findkey(const char *key, const char *inst) -{ - snprintf(buf, sizeof(buf), "%s@%s", key, inst); - last = buf + strlen(buf) - 1; - strippunct(); +const char *AutoConfigSection::findkey(const char *key, const char *inst) { + snprintf(buf, sizeof(buf), "%s@%s", key, inst); + last = buf + strlen(buf) - 1; + strippunct(); - do { - if (parent->get_str_val(section, buf) != NULL) { - return buf; - } - } while (isdigit(*last) ? stripnumber() : stripalpha()); + do { + if (parent->get_str_val(section, buf) != NULL) { + return buf; + } + } while (isdigit(*last) ? stripnumber() : stripalpha()); - return key; + return key; } -int AutoConfigSection::get_int_val(const char *key, const char *inst, int def) -{ - int ret; - GlobalLock(); - ret = parent->get_int_val(section, findkey(key, inst), def); - GlobalUnlock(); - return ret; +int AutoConfigSection::get_int_val(const char *key, const char *inst, int def) { + int ret; + GlobalLock(); + ret = parent->get_int_val(section, findkey(key, inst), def); + GlobalUnlock(); + return ret; } unsigned long long AutoConfigSection::get_size_val(const char *key, - const char *inst, - unsigned long long def, - char unit) -{ - unsigned long long ret; - GlobalLock(); - ret = parent->get_size_val(section, findkey(key, inst), def, unit); - GlobalUnlock(); - return ret; + const char *inst, + unsigned long long def, + char unit) { + unsigned long long ret; + GlobalLock(); + ret = parent->get_size_val(section, findkey(key, inst), def, unit); + GlobalUnlock(); + return ret; } int AutoConfigSection::get_idx_val(const char *key, const char *inst, - const char *const *idxval, int def) -{ - int ret; - GlobalLock(); - ret = parent->get_idx_val(section, findkey(key, inst), idxval, def); - GlobalUnlock(); - return ret; + const char *const *idxval, int def) { + int ret; + GlobalLock(); + ret = parent->get_idx_val(section, findkey(key, inst), idxval, def); + GlobalUnlock(); + return ret; } -const char *AutoConfigSection::get_str_val(const char *key, const char *inst) -{ - const char *ret; - GlobalLock(); - ret = parent->get_str_val(section, findkey(key, inst)); - GlobalUnlock(); - return ret; +const char *AutoConfigSection::get_str_val(const char *key, const char *inst) { + const char *ret; + GlobalLock(); + ret = parent->get_str_val(section, findkey(key, inst)); + GlobalUnlock(); + return ret; } -AutoConfig *DTCConfig::get_auto_config_instance(const char *section) -{ - AutoConfigSection *inst; - NEW(AutoConfigSection(this, section), inst); - return inst; +AutoConfig *DTCConfig::get_auto_config_instance(const char *section) { + AutoConfigSection *inst; + NEW(AutoConfigSection(this, section), inst); + return inst; } -- Gitee From d9860eb9a1319b25878e7fb9d7e185cc7bff61dc Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 08:45:12 +0800 Subject: [PATCH 28/39] 1 --- README.md | 47 ++++++++++++++++++++--------------------------- docs/buiding.md | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 docs/buiding.md diff --git a/README.md b/README.md index dfdf57e..8b8d55d 100644 --- a/README.md +++ b/README.md @@ -26,28 +26,21 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: - 澶氱鏁版嵁缁撴瀯妯″瀷锛屾彁楂樺唴瀛樿鍐欓熷害銆 ## 鎬ц兘 - 鍗曟牳CPU锛屽崟DTC瀹炰緥鎯呭喌涓嬶紝鍙敮鎸60,000 QPS鐨勬煡璇紱 + 鍗曟牳CPU锛屽崟DTC瀹炰緥鎯呭喌涓嬶紝鍙敮鎸90,000 QPS鐨勬煡璇紱 鍦ㄧ湡瀹炵殑鍒嗗竷寮忓満鏅腑锛孌TC鍙敮鎸佽秴杩3,000,000 QPS鐨勬煡璇㈡湇鍔★紝涓斿懡涓巼鍦99.9%浠ヤ笂銆 ## 鏋勫缓 -* gcc/g++ 4.8 -* cmake >= 3.6.2 -* 瀹夎gflags:
- gflags鏄痝oogle寮婧愮殑涓濂楀懡浠よ鍙傛暟瑙f瀽宸ュ叿锛屾敮鎸佷粠鐜鍙橀噺鍜岄厤缃枃浠惰鍙栧弬鏁
- `git clone https://github.com/gflags/gflags.git`
- `cd gflags`
- `git checkout -b 2.2 v2.2.2`
- `cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
- `make && sudo make install`
- `sudo ldconfig `
- `sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
- ### CentOS - - 鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆锛
- `sudo yum install -y make snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan openssl-devel cmake3 mysql-devel mxml-devel`
- ### Ubuntu - - 鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆锛
- `sudo apt-get install make snappy聽libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev`
-* src鐩綍涓嬶紝鎵цmake鍗冲彲缂栬瘧銆 + 椤圭洰鎻愪緵docker闀滃儚锛屽彲蹇熷惎鍔ㄥ拰杩愯绀轰緥锛 + - 鍚姩server闀滃儚锛
+ `docker pull dtc/server:latest`
+ `docker run -i -t -p localhost:20015:20015 dtc/server:latest /bin/bash` + - 鍚姩SDK闀滃儚锛 + - C++:
+ `docker pull dtc/sdk-cpp:latest`
+ `docker run -i -t dtc/sdk-cpp:latest /bin/bash` + - 鍚庣画璁″垝SDK鏀寔鏇村璇█鐗堟湰銆 + + 鏇村缂栬瘧璇︽儏锛岃绉绘[buiding](docs/buiding.md). ## 绗笁鏂逛緷璧 * [cJson](https://github.com/DaveGamble/cJSON) @@ -60,14 +53,14 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: * [twemproxy](https://github.com/twitter/twemproxy) ## 椤圭洰鎴愬憳 -- 浠樺瀹--椤圭洰鍙戣捣鑰呫佸甯堛佹昏璁″笀 -- [鏋楅噾鏄嶿(https://gitee.com/shrewdlin)--椤圭洰寮鍙 -- [鏉ㄧ埥](https://gitee.com/kfysck)--椤圭洰寮鍙 -- [浠囪矾](https://gitee.com/qiuluAbel)--椤圭洰寮鍙 -- [鍚存槙鑷籡(https://gitee.com/wuxinzhen_1997)--椤圭洰寮鍙 -- 鏇规矝--椤圭洰寮鍙 -- [闄堥洦鏉癩(https://gitee.com/chenyujie28)--椤圭洰寮鍙 -- [鏈辨灄](https://gitee.com/leol3)--椤圭洰寮鍙 +- 浠樺瀹濓紙椤圭洰鍙戣捣鑰呫佸甯堛佹昏璁″笀锛 +- [鏋楅噾鏄嶿(https://gitee.com/shrewdlin)锛堥」鐩紑鍙戯級 +- [鏉ㄧ埥](https://gitee.com/kfysck)锛堥」鐩紑鍙戯級 +- [浠囪矾](https://gitee.com/qiuluAbel)锛堥」鐩紑鍙戯級 +- [鍚存槙鑷籡(https://gitee.com/wuxinzhen_1997)锛堥」鐩紑鍙戯級 +- 鏇规矝锛堥」鐩紑鍙戯級 +- [闄堥洦鏉癩(https://gitee.com/chenyujie28)锛堥」鐩紑鍙戯級 +- [鏈辨灄](https://gitee.com/leol3)锛堥」鐩紑鍙戯級 ## 璁稿彲璇 diff --git a/docs/buiding.md b/docs/buiding.md new file mode 100644 index 0000000..f4ba6e7 --- /dev/null +++ b/docs/buiding.md @@ -0,0 +1,18 @@ +* gcc/g++ 4.8 +* cmake >= 3.6.2 +* 瀹夎gflags:
+ gflags鏄痝oogle寮婧愮殑涓濂楀懡浠よ鍙傛暟瑙f瀽宸ュ叿锛屾敮鎸佷粠鐜鍙橀噺鍜岄厤缃枃浠惰鍙栧弬鏁
+ `git clone https://github.com/gflags/gflags.git`
+ `cd gflags`
+ `git checkout -b 2.2 v2.2.2`
+ `cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
+ `make && sudo make install`
+ `sudo ldconfig `
+ `sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
+ ### CentOS + - 鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆锛
+ `sudo yum install -y make snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan openssl-devel cmake3 mysql-devel mxml-devel`
+ ### Ubuntu + - 鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆锛
+ `sudo apt-get install make snappy聽libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev`
+* src鐩綍涓嬶紝鎵цmake鍗冲彲缂栬瘧銆 \ No newline at end of file -- Gitee From 4bba46d010619aa296ef0b596b0a8955609f794a Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 09:09:31 +0800 Subject: [PATCH 29/39] 1 --- README.md | 2 +- dockerfiles/server/dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b8d55d..dc9ca2b 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: 椤圭洰鎻愪緵docker闀滃儚锛屽彲蹇熷惎鍔ㄥ拰杩愯绀轰緥锛 - 鍚姩server闀滃儚锛
`docker pull dtc/server:latest`
- `docker run -i -t -p localhost:20015:20015 dtc/server:latest /bin/bash` + `docker run -i -t -p 127.0.0.1:20015:20015 dtc/server:latest /bin/bash` - 鍚姩SDK闀滃儚锛 - C++:
`docker pull dtc/sdk-cpp:latest`
diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 9ba471e..dea62dc 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -16,4 +16,4 @@ COPY table.yaml $confpath/table.yaml COPY cache.yaml $confpath/cache.yaml COPY log4cplus.conf $confpath/log4cplus.conf -CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file +#CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file -- Gitee From 690b272826f55ea7a176f0643504690151011869 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 09:25:23 +0800 Subject: [PATCH 30/39] 1 --- dockerfiles/server/dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index dea62dc..087ebc7 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -16,4 +16,6 @@ COPY table.yaml $confpath/table.yaml COPY cache.yaml $confpath/cache.yaml COPY log4cplus.conf $confpath/log4cplus.conf -#CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file +#CMD ["/bin/bash", "/root/start.sh"] +CMD ["/bin/echo", "DTC SERVER..."] +CMD ["/usr/local/dtc/bin/dtcd"] \ No newline at end of file -- Gitee From 6fa99d77e44bb145e220e71ee9a17b723feec4b5 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 10:00:13 +0800 Subject: [PATCH 31/39] 1 --- dockerfiles/server/dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 087ebc7..01adc3a 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -17,5 +17,4 @@ COPY cache.yaml $confpath/cache.yaml COPY log4cplus.conf $confpath/log4cplus.conf #CMD ["/bin/bash", "/root/start.sh"] -CMD ["/bin/echo", "DTC SERVER..."] -CMD ["/usr/local/dtc/bin/dtcd"] \ No newline at end of file +CMD ["/usr/local/dtc/bin/dtcd", "-d"] \ No newline at end of file -- Gitee From a11b561678d05f59036bf46406d5f0f4af511f37 Mon Sep 17 00:00:00 2001 From: wuxz <1067764612@qq.com> Date: Fri, 27 Aug 2021 11:08:21 +0800 Subject: [PATCH 32/39] fix: CMakeLists --- CMakeLists.txt | 9 +++++++++ src/CMakeLists.txt | 15 ++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4334079 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required (VERSION 2.8) +project (dtc) + +add_subdirectory(./src) + + + +#鎯冲嵏杞絤ake install瀹夎鐨勫簱锛岃繘鍏ュ埌build鏂囦欢澶癸紝鎵ц +# cat install_manifest.txt | sudo xargs rm \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d5914b..20e8ba6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,9 @@ -cmake_minimum_required (VERSION 2.8) -project (dtc) - -add_subdirectory(./agent) -add_subdirectory(./configcenter) -add_subdirectory(./libs) -add_subdirectory(./devel) -add_subdirectory(./daemons) -add_subdirectory(./core) +ADD_SUBDIRECTORY(./agent) +ADD_SUBDIRECTORY(./configcenter) +ADD_SUBDIRECTORY(./libs) +ADD_SUBDIRECTORY(./devel) +ADD_SUBDIRECTORY(./daemons) +ADD_SUBDIRECTORY(./core) #add_subdirectory(./connector) -- Gitee From e557603a81ba2d55e1a1404cb45cf7541c35b91c Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 11:11:36 +0800 Subject: [PATCH 33/39] 1 --- README.md | 2 +- dockerfiles/server/dockerfile | 1 - dockerfiles/server/start.sh | 17 ----------------- 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 dockerfiles/server/start.sh diff --git a/README.md b/README.md index dc9ca2b..e947356 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ DTC绯荤粺鐢变互涓嬬粍浠剁粍鎴: - [鏉ㄧ埥](https://gitee.com/kfysck)锛堥」鐩紑鍙戯級 - [浠囪矾](https://gitee.com/qiuluAbel)锛堥」鐩紑鍙戯級 - [鍚存槙鑷籡(https://gitee.com/wuxinzhen_1997)锛堥」鐩紑鍙戯級 -- 鏇规矝锛堥」鐩紑鍙戯級 +- [鏇规矝](https://gitee.com/warm-byte)锛堥」鐩紑鍙戯級 - [闄堥洦鏉癩(https://gitee.com/chenyujie28)锛堥」鐩紑鍙戯級 - [鏈辨灄](https://gitee.com/leol3)锛堥」鐩紑鍙戯級 diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile index 01adc3a..317d177 100644 --- a/dockerfiles/server/dockerfile +++ b/dockerfiles/server/dockerfile @@ -16,5 +16,4 @@ COPY table.yaml $confpath/table.yaml COPY cache.yaml $confpath/cache.yaml COPY log4cplus.conf $confpath/log4cplus.conf -#CMD ["/bin/bash", "/root/start.sh"] CMD ["/usr/local/dtc/bin/dtcd", "-d"] \ No newline at end of file diff --git a/dockerfiles/server/start.sh b/dockerfiles/server/start.sh deleted file mode 100644 index 8d490ad..0000000 --- a/dockerfiles/server/start.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -INIT(){ - cd /usr/local/dtc/bin - chmod +x dtcd - ./dtcd -} - -PROCESS_DAEMON(){ - while : - do - sleep 60 - done -} - -INIT -PROCESS_DAEMON \ No newline at end of file -- Gitee From 55a535938ce76f1dd66e59e9f8cf12a9e517f900 Mon Sep 17 00:00:00 2001 From: caopei11 Date: Fri, 27 Aug 2021 11:24:41 +0800 Subject: [PATCH 34/39] dtc: test --- test/allcase/Makefile | 38 ++ test/allcase/dtcapi.h | 1019 +++++++++++++++++++++++++++++++++++++++++ test/allcase/test.cpp | 410 +++++++++++++++++ 3 files changed, 1467 insertions(+) create mode 100755 test/allcase/Makefile create mode 100755 test/allcase/dtcapi.h create mode 100755 test/allcase/test.cpp diff --git a/test/allcase/Makefile b/test/allcase/Makefile new file mode 100755 index 0000000..09a703d --- /dev/null +++ b/test/allcase/Makefile @@ -0,0 +1,38 @@ +LIB = ../../libdtc.so + +OUTPUT = test + +SOURCES = test.cpp + + +OBJECTS= test.o + CPPFLAGS = -g -O -Wall -fPIC -DMACROFOR64BIT -Wl,--no-undefined -Xlinker -zmuldefs + CFLAGS = $(CPPFLAGS) + +all:$(OUTPUT) + +.SUFFIXES: .o .cpp + .cpp.o: + $(CXX) $(CPPFLAGS) $(INCLUDE) -c $(filter %.cpp, $^) + +.o: + $(CXX) $(CPPFLAGS) $(INCLUDE) -o $@ $^ + +$(OUTPUT): $(OBJECTS) + $(CXX) $(CFLAGS) -fPIC -o $@ $^ $(LIB) + + +clean: + rm -f *.o *.so *.~ *.bak + rm -f $(OUTPUT) + +install: + cp -f $(OUTPUT) $(INSTALL_PATH) + +dep: + mkdep -p$(VPATH) $(INCLUDE) $(SOURCES) > .depend + +ifneq ($(wildcard .depend),) + include .depend +endif + diff --git a/test/allcase/dtcapi.h b/test/allcase/dtcapi.h new file mode 100755 index 0000000..93ea247 --- /dev/null +++ b/test/allcase/dtcapi.h @@ -0,0 +1,1019 @@ +#ifndef __DTC_API_H__ +#define __DTC_API_H__ + +#include +#include +#include +#include + +#define IP_LENGHT 16 + +namespace DTC { + + typedef struct route_node + { + int bid; + int port; + int status; + int weight; + char ip[IP_LENGHT]; + }ROUTE_NODE; + + class Server; + class ServerPool; + class Request; + class Result; + + const int kRequestSvrAdmin = 3; + const int kRequestGet = 4; + const int kRequestPurge = 5; + const int kRequestInsert = 6; + const int kRequestUpdate = 7; + const int kRequestDelete = 8; + const int kRequestReplace = 12; + const int kRequestFlush = 13; + const int kRequestInvalidate = 14; + + //mem monior Request;2014/06/6;by seanzheng + const int kRequestMonitor = 15; + + // sub-code of admin cmd + const int RegisterHB = 1; + const int LogoutHB = 2; + const int GetKeyList = 3; + const int GetUpdateKey = 4; + const int GetRawData = 5; + const int ReplaceRawData = 6; + const int AdjustLRU = 7; + const int VerifyHBT = 8; + const int GetHBTime = 9; + const int kSetReadOnly = 10; + const int kSetReadWrite = 11; + const int kQueryBinlogID = 12; + const int kNodeHandleChange = 13; + const int Migrate = 14; + const int kReloadClusterNodeList = 15; + const int kSetClusterNodeState = 16; + const int kChangeNodeAddress = 17; + const int kGetClusterState = 18; + const int kPurgeForHit = 19; + const int ClearCache = 21; + const int ColExpandStatus = 24; + const int kColExpand = 25; + const int ColExpandDone = 26; + const int ColExpandKey = 27; + + const int kKeyTypeNone = 0; // undefined + const int kKeyTypeInt = 1; // Signed Integer + const int kKeyTypeString = 4; // String, case insensitive, null ended + + const int kFieldTypeNone = 0; // undefined + const int kFieldTypeSigned = 1; // Signed Integer + const int kFieldTypeUnsigned = 2; // Unsigned Integer + const int kFieldTypeFloat = 3; // float + const int kFieldTypeString = 4; // String, case insensitive, null ended + const int kFieldTypeBinary = 5; // binary + + int set_key_value_max(unsigned int count); // 璁剧疆鎵归噺鎿嶄綔涓娆℃渶澶氬灏戜釜key(榛樿鏈澶32涓) +#ifndef WIN32 + void write_log (int level, + const char*file, const char *func, int lineno, + const char *fmt, ...) + __attribute__((format(printf,5,6))); +#endif + + class Result; + class Server { + private: + void *addr_; + long check; + public: + friend class Request; + friend class Result; + friend class ServerPool; + friend class QOSServerPool; + + Server(void); + ~Server(void); + Server(const Server &); + void clone_table_define(const Server& source); + int set_address(const char *host, const char *port=0); + int set_table_name(const char *); + //for compress + void set_compress_level(int); + //get address and tablename set by user + const char * get_address(void) const; + const char * get_table_name(void) const; + //get address and tablename set by dtc frame,for plugin only; + const char * get_server_address(void) const; + const char * get_server_table_name(void) const; + int int_key(void); + int binary_key(void); + int string_key(void); + int add_key(const char* name, int type); + int get_field_type(const char* name); + const char *get_error_message(void) const; + void SetTimeout(int); + void set_timeout(int); + int connect(void); + void close(void); + int ping(void); + void auto_ping(void); + void set_fd(int); // UNSUPPORTED API + void set_auto_Update_table(bool autoUpdate); + void set_auto_reconnect(int auto_reconnect); + int decode_packet(Result &, const char *, int); + int check_packet_size(const char *, int); + + void set_accesskey(const char *token); + + public: + void increase_error_count_(); + uint64_t get_error_count(); + void clear_error_count(); + + void increase_remove_count(); + int get_remove_count(); + void clear_remove_count(); + + void increase_total_request(); + uint64_t get_total_request(); + void clear_total_request(); + + void add_total_elaps(uint64_t iElaps); + uint64_t get_total_elaps(); + void clear_total_elaps(); + }; + + class DTCQosServer; + + class DTCServers + { + public: + DTCServers(); + ~DTCServers(); + + private: + DTCServers(const DTCServers&); + DTCServers& operator=(const DTCServers&); + + public: + int set_route_list(std::vector& ip_list); + void set_idc_no(int IDCNo); + Server* get_server(); + + int set_accesskey(const char *token); + int set_table_name(const char *tableName); + /* + Signed=1, // Signed Integer + String=4, // String, case insensitive, null ended + Binary=5, // opaque binary data + */ + int set_key_type(int type); + void set_agenttime(int t); + void set_timeout(int n); + std::string get_error_msg(); + + private: + int is_server_has_existed(ROUTE_NODE& ip); + int construct_servers(); + int construct_servers2(std::vector& IPList); + void disorder_list(int *tmpBuckets, int size); + int construct_balance_buckets(); + int refresh_balance_buckets(uint64_t ); + void remove_server_from_buckets(uint64_t ); + Server* get_one_server_from_buckets(); + void set_error_msg(int err, std::string from, std::string msg); + + private: + int m_time_out; + int m_agent_time; + int m_key_type; + char* m_table_name; + std::string m_access_token; + std::string m_err_msg; + + private: + bool m_set_route; + bool m_constructed_by_set_i_ps; + int m_bid; + int m_idc_no; + int m_buckets_pos; + int m_balance_bucket_size; + uint64_t m_bid_version; + uint64_t m_last_get_ca_time; + uint64_t m_refresh_buckets_time; + uint64_t m_remove_buckets_time; + int* m_load_balance_buckets; + DTCQosServer* m_qos_severs; + std::vector m_ip_list; + }; + + class Request { + private: + void *addr_; + long check; + Request(const Request &); + public: + friend class Server; + friend class Result; + friend class ServerPool; + + Request(Server *srv, int op); + Request(void); + ~Request(void); + void Reset(void); + void Reset(int); + int attach_server(Server *srv); + + void set_admin_code(int code); + void set_hotbackup_id(long long); + void set_master_hotbackup_timestamp(long long); + void set_slave_hotbackup_timestamp(long long); + +#define _API_DEFINE_LONG_(op, t) int op(const char *n, t a) { return op(n, (long long)a); } +#define _API_DEFINE_FLOAT_(op, t) int op(const char *n, t a) { return op(n, (double)a); } + int need(const char *); + int need(const char *, int); + int get_field_type(const char*); + void no_cache(void); + void no_next_server(void); + void limit(unsigned int, unsigned int); + int EQ(const char *, long long); + int NE(const char *, long long); + int LT(const char *, long long); + int LE(const char *, long long); + int GT(const char *, long long); + int GE(const char *, long long); + int EQ(const char *, const char *); + int NE(const char *, const char *); + int EQ(const char *, const char *, int); + int NE(const char *, const char *, int); + + _API_DEFINE_LONG_(EQ, unsigned long long); + _API_DEFINE_LONG_(EQ, long); + _API_DEFINE_LONG_(EQ, unsigned long); + _API_DEFINE_LONG_(EQ, int); + _API_DEFINE_LONG_(EQ, unsigned int); + _API_DEFINE_LONG_(EQ, short); + _API_DEFINE_LONG_(EQ, unsigned short); + _API_DEFINE_LONG_(EQ, char); + _API_DEFINE_LONG_(EQ, unsigned char); + + _API_DEFINE_LONG_(NE, unsigned long long); + _API_DEFINE_LONG_(NE, long); + _API_DEFINE_LONG_(NE, unsigned long); + _API_DEFINE_LONG_(NE, int); + _API_DEFINE_LONG_(NE, unsigned int); + _API_DEFINE_LONG_(NE, short); + _API_DEFINE_LONG_(NE, unsigned short); + _API_DEFINE_LONG_(NE, char); + _API_DEFINE_LONG_(NE, unsigned char); + + _API_DEFINE_LONG_(GT, unsigned long long); + _API_DEFINE_LONG_(GT, long); + _API_DEFINE_LONG_(GT, unsigned long); + _API_DEFINE_LONG_(GT, int); + _API_DEFINE_LONG_(GT, unsigned int); + _API_DEFINE_LONG_(GT, short); + _API_DEFINE_LONG_(GT, unsigned short); + _API_DEFINE_LONG_(GT, char); + _API_DEFINE_LONG_(GT, unsigned char); + + _API_DEFINE_LONG_(GE, unsigned long long); + _API_DEFINE_LONG_(GE, long); + _API_DEFINE_LONG_(GE, unsigned long); + _API_DEFINE_LONG_(GE, int); + _API_DEFINE_LONG_(GE, unsigned int); + _API_DEFINE_LONG_(GE, short); + _API_DEFINE_LONG_(GE, unsigned short); + _API_DEFINE_LONG_(GE, char); + _API_DEFINE_LONG_(GE, unsigned char); + + _API_DEFINE_LONG_(LT, unsigned long long); + _API_DEFINE_LONG_(LT, long); + _API_DEFINE_LONG_(LT, unsigned long); + _API_DEFINE_LONG_(LT, int); + _API_DEFINE_LONG_(LT, unsigned int); + _API_DEFINE_LONG_(LT, short); + _API_DEFINE_LONG_(LT, unsigned short); + _API_DEFINE_LONG_(LT, char); + _API_DEFINE_LONG_(LT, unsigned char); + + _API_DEFINE_LONG_(LE, unsigned long long); + _API_DEFINE_LONG_(LE, long); + _API_DEFINE_LONG_(LE, unsigned long); + _API_DEFINE_LONG_(LE, int); + _API_DEFINE_LONG_(LE, unsigned int); + _API_DEFINE_LONG_(LE, short); + _API_DEFINE_LONG_(LE, unsigned short); + _API_DEFINE_LONG_(LE, char); + _API_DEFINE_LONG_(LE, unsigned char); + + int Set(const char *, long long); + int OR(const char *, long long); + int Add(const char *, long long); + int Sub(const char *, long long); + int Set(const char *, double); + int Add(const char *, double); + int Sub(const char *, double); + int Set(const char *, const char *); + int Set(const char *, const char *, int); + + //just for compress,only support binary field + int compress_set(const char *, const char *, int); + //just compress and set. Don't need compressflag + int compress_set_force(const char *, const char *, int); + + //bits op + int set_multi_bits(const char *, int, int, unsigned int); + int set_bit (const char *f, int o) { return set_multi_bits(f, o, 1, 1);} + int clear_bit(const char *f, int o) { return set_multi_bits(f, o, 1, 0);} + + _API_DEFINE_LONG_(Set, unsigned long long); + _API_DEFINE_LONG_(Set, long); + _API_DEFINE_LONG_(Set, unsigned long); + _API_DEFINE_LONG_(Set, int); + _API_DEFINE_LONG_(Set, unsigned int); + _API_DEFINE_LONG_(Set, short); + _API_DEFINE_LONG_(Set, unsigned short); + _API_DEFINE_LONG_(Set, char); + _API_DEFINE_LONG_(Set, unsigned char); + _API_DEFINE_FLOAT_(Set, float); + _API_DEFINE_FLOAT_(Set, long double); + + _API_DEFINE_LONG_(OR, unsigned long long); + _API_DEFINE_LONG_(OR, long); + _API_DEFINE_LONG_(OR, unsigned long); + _API_DEFINE_LONG_(OR, int); + _API_DEFINE_LONG_(OR, unsigned int); + _API_DEFINE_LONG_(OR, short); + _API_DEFINE_LONG_(OR, unsigned short); + + _API_DEFINE_LONG_(Add, unsigned long long); + _API_DEFINE_LONG_(Add, long); + _API_DEFINE_LONG_(Add, unsigned long); + _API_DEFINE_LONG_(Add, int); + _API_DEFINE_LONG_(Add, unsigned int); + _API_DEFINE_LONG_(Add, short); + _API_DEFINE_LONG_(Add, unsigned short); + _API_DEFINE_LONG_(Add, char); + _API_DEFINE_LONG_(Add, unsigned char); + _API_DEFINE_FLOAT_(Add, float); + _API_DEFINE_FLOAT_(Add, long double); + + _API_DEFINE_LONG_(Sub, unsigned long long); + _API_DEFINE_LONG_(Sub, long); + _API_DEFINE_LONG_(Sub, unsigned long); + _API_DEFINE_LONG_(Sub, int); + _API_DEFINE_LONG_(Sub, unsigned int); + _API_DEFINE_LONG_(Sub, short); + _API_DEFINE_LONG_(Sub, unsigned short); + _API_DEFINE_LONG_(Sub, char); + _API_DEFINE_LONG_(Sub, unsigned char); + _API_DEFINE_FLOAT_(Sub, float); + _API_DEFINE_FLOAT_(Sub, long double); +#undef _API_DEFINE_LONG_ + + void unset_key(void); + int set_key(long long); + int set_key(const char *); + int set_key(const char *, int); +#define _API_DEFINE_LONG_(t) int set_key(t a) { return set_key((long long)a); } + _API_DEFINE_LONG_(unsigned long long); + _API_DEFINE_LONG_(long); + _API_DEFINE_LONG_(unsigned long); + _API_DEFINE_LONG_(int); + _API_DEFINE_LONG_(unsigned int); + _API_DEFINE_LONG_(short); + _API_DEFINE_LONG_(unsigned short); + _API_DEFINE_LONG_(char); + _API_DEFINE_LONG_(unsigned char); +#undef _API_DEFINE_LONG_ + + int add_key_value(const char* name, long long v); + int add_key_value(const char* name, const char *str); + int add_key_value(const char* name, const char *ptr, int len); +#define _API_DEFINE_LONG_(t) int add_key_value(const char* name, t a) { return add_key_value(name, (long long)a); } + _API_DEFINE_LONG_(unsigned long long); + _API_DEFINE_LONG_(long); + _API_DEFINE_LONG_(unsigned long); + _API_DEFINE_LONG_(int); + _API_DEFINE_LONG_(unsigned int); + _API_DEFINE_LONG_(short); + _API_DEFINE_LONG_(unsigned short); + _API_DEFINE_LONG_(char); + _API_DEFINE_LONG_(unsigned char); +#undef _API_DEFINE_LONG_ + + Result *do_execute(void); + Result *do_execute(long long); + Result *do_execute(const char *); + Result *do_execute(const char *, int); + +#define _API_DEFINE_LONG_(t) Result *do_execute(t a) { return do_execute((long long)a); } + _API_DEFINE_LONG_(unsigned long long); + _API_DEFINE_LONG_(long); + _API_DEFINE_LONG_(unsigned long); + _API_DEFINE_LONG_(int); + _API_DEFINE_LONG_(unsigned int); + _API_DEFINE_LONG_(short); + _API_DEFINE_LONG_(unsigned short); + _API_DEFINE_LONG_(char); + _API_DEFINE_LONG_(unsigned char); +#undef _API_DEFINE_LONG_ + + int do_execute(Result&); + int do_execute(Result&, long long); + int do_execute(Result&, const char *); + int do_execute(Result&, const char *, int); + +#define _API_DEFINE_LONG_(t) int do_execute(Result &r, t a) { return do_execute(r, (long long)a); } + _API_DEFINE_LONG_(unsigned long long); + _API_DEFINE_LONG_(long); + _API_DEFINE_LONG_(unsigned long); + _API_DEFINE_LONG_(int); + _API_DEFINE_LONG_(unsigned int); + _API_DEFINE_LONG_(short); + _API_DEFINE_LONG_(unsigned short); + _API_DEFINE_LONG_(char); + _API_DEFINE_LONG_(unsigned char); +#undef _API_DEFINE_LONG_ + + int encode_packet(char *&, int&, long long&); + int encode_packet(char *&, int&, long long&, long long); + int encode_packet(char *&, int&, long long&, const char *); + int encode_packet(char *&, int&, long long&, const char *, int); + +#define _API_DEFINE_LONG_(t) int encode_packet(char *&p, int &l, long long &m, t a) { return encode_packet(p,l,m,(long long)a); } + _API_DEFINE_LONG_(unsigned long long); + _API_DEFINE_LONG_(long); + _API_DEFINE_LONG_(unsigned long); + _API_DEFINE_LONG_(int); + _API_DEFINE_LONG_(unsigned int); + _API_DEFINE_LONG_(short); + _API_DEFINE_LONG_(unsigned short); + _API_DEFINE_LONG_(char); + _API_DEFINE_LONG_(unsigned char); +#undef _API_DEFINE_LONG_ + + int set_cache_id(long long); +#define _API_DEFINE_LONG_(t) int set_cache_id(t a) {return set_cache_id((long long)a);} + _API_DEFINE_LONG_(unsigned long long); + _API_DEFINE_LONG_(long); + _API_DEFINE_LONG_(unsigned long); + _API_DEFINE_LONG_(int); + _API_DEFINE_LONG_(unsigned int); + _API_DEFINE_LONG_(short); + _API_DEFINE_LONG_(unsigned short); + _API_DEFINE_LONG_(char); + _API_DEFINE_LONG_(unsigned char); +#undef _API_DEFINE_LONG_ + const char *get_error_message(void) const; + + //鏃犳簮妯″紡瓒呮椂鏃堕棿 add by xuxinxin, 2014/12/09 + int set_expire_time(const char* key, int time); + int get_expire_time(const char* key); + }; + + class GetRequest : public Request { + public: + GetRequest(Server *srv): Request(srv, kRequestGet) {} + GetRequest(): Request((Server *)0, kRequestGet) {} + }; + + class InsertRequest : public Request { + public: + InsertRequest(Server *srv) : Request(srv, kRequestInsert) {} + InsertRequest() : Request((Server *)0, kRequestInsert) {} + }; + + class DeleteRequest : public Request { + public: + DeleteRequest(Server *srv) : Request(srv, kRequestDelete) {} + DeleteRequest() : Request((Server *)0, kRequestDelete) {} + }; + + class UpdateRequest : public Request { + public: + UpdateRequest(Server *srv) : Request(srv, kRequestUpdate) {} + UpdateRequest() : Request((Server *)0, kRequestUpdate) {} + }; + + class PurgeRequest : public Request { + public: + PurgeRequest(Server *srv) : Request(srv, kRequestPurge) {} + PurgeRequest() : Request((Server *)0, kRequestPurge) {} + }; + + class ReplaceRequest:public Request { + public: + ReplaceRequest(Server *srv) : Request(srv, kRequestReplace) {} + ReplaceRequest() : Request((Server *)0, kRequestReplace) {} + }; + + class FlushRequest : public Request { + public: + FlushRequest(Server *srv) : Request(srv, kRequestFlush) {} + FlushRequest(void) : Request((Server *)0, kRequestFlush) {} + }; + + class InvalidateRequest: public Request { + public: + InvalidateRequest(Server *srv) : Request(srv, kRequestInvalidate) {} + }; + + class SvrAdminRequest: public Request { + public: + SvrAdminRequest(Server *srv) : Request(srv, kRequestSvrAdmin) {} + }; + + class MonitorRequest: public Request { + public: + MonitorRequest(Server *srv) : Request(srv, kRequestMonitor){} + }; + + class Result { + private: + void *addr_; + long check; + Result(const Result &); + char *ServerInfo() const; + public: + friend class Server; + friend class Request; + friend class ServerPool; + + Result(void); + ~Result(void); + void Reset(void); + + void set_error(int errcode, const char *from, const char *detail); // from will not dupped + int get_result_code(void) const; + const char *get_error_message(void) const; + const char *get_error_from(void) const; + long long get_hotbackup_id() const; + long long get_master_hotbackup_timestamp() const; + long long slave_hotbackup_timestamp() const; + long long get_binlog_id() const; + long long get_binlog_offset() const; + long long get_mem_size() const; + long long get_datd_size() const; + int get_num_row_size(void) const; + int get_total_rows_size(void) const; + int get_affected_rows_size(void) const; + int get_num_fields_size(void) const; + const char* get_field_name(int n) const; + int get_field_present(const char* name) const; + int get_field_type(int n) const; + long long get_tag(void) const; + void *get_tag_ptr(void) const; + long long magic(void) const; + long long get_server_timestamp(void) const; + long long get_insert_id(void) const; + long long int_key(void) const; + const char *binary_key(void) const; + const char *binary_key(int *) const; + const char *binary_key(int &) const; + const char *string_key(void) const; + const char *string_key(int *) const; + const char *string_key(int &) const; + long long int_value(const char *) const; + double float_value(const char *) const; + const char *string_value(const char *) const; + const char *string_value(const char *, int*) const; + const char *string_value(const char *, int&) const; + const char *binary_value(const char *) const; + const char *binary_value(const char *, int*) const; + const char *binary_value(const char *, int&) const; + int uncompress_binary_value(const char *name,char **buf,int *lenp); + //Uncompress Binary Value without check compressflag + int uncompress_binary_value_force(const char *name,char **buf,int *lenp); + const char * uncompress_error_message() const; + long long int_value(int) const; + double float_value(int) const; + const char *string_value(int) const; + const char *string_value(int, int*) const; + const char *string_value(int, int&) const; + const char *binary_value(int) const; + const char *binary_value(int, int*) const; + const char *binary_value(int, int&) const; + int fetch_row(void); + int rewind(void); + }; + + class ServerPool { + private: + void *addr_; + long check; + ServerPool(ServerPool &); + public: + friend class Server; + friend class Request; + friend class Result; + + ServerPool(int max_servers, int max_requests); + ~ServerPool(void); + + int get_epoll_fd(int size); + int add_server(Server *srv, int mReq=1, int mConn=0); + int add_request(Request *, long long); + int add_request(Request *, long long, long long); + int add_request(Request *, long long, const char *); + int add_request(Request *, long long, const char *, int); + int add_request(Request *, void *); + int add_request(Request *, void *, long long); + int add_request(Request *, void *, const char *); + int add_request(Request *, void *, const char *, int); + int do_execute(int msec); + int execute_all(int msec); + int cancel_request(int); + int cancel_all_request(int type); + int abort_request(int); + int abort_all_request(int type); + Result *get_result(void); + Result *get_result(int); + int get_result(Result&); + int get_result(Result&, int); + + int server_count(void) const; + int request_count(int type) const; + int request_state(int reqId) const; + }; + + const int WAIT = 1; + const int SEND = 2; + const int RECV = 4; + const int DONE = 8; + const int ALL_STATE = WAIT|SEND|RECV|DONE; + + enum { + EC_ERROR_BASE = 2000, + EC_BAD_COMMAND, // unsupported command + EC_MISSING_SECTION, // missing mandatory section + EC_EXTRA_SECTION, // incompatible section present + EC_DUPLICATE_TAG, // same tag appear twice + + EC_DUPLICATE_FIELD, //5: same field appear twice in .need() + EC_BAD_SECTION_LENGTH, // section length too short + EC_BAD_VALUE_LENGTH, // value length not allow + EC_BAD_STRING_VALUE, // string value w/o NULL + EC_BAD_FLOAT_VALUE, // invalid float format + + EC_BAD_FIELD_NUM, //10: invalid total field# + EC_EXTRA_SECTION_DATA, // section length too large + EC_BAD_VALUE_TYPE, // incompatible value type + EC_BAD_OPERATOR, // incompatible operator/comparison + EC_BAD_FIELD_ID, // invalid field ID + + EC_BAD_FIELD_NAME, //15: invalud field name + EC_BAD_FIELD_TYPE, // invalid field type + EC_BAD_FIELD_SIZE, // invalid field size + EC_TABLE_REDEFINED, // table defined twice + EC_TABLE_MISMATCH, // request table != server table + + EC_VERSION_MISMATCH, //20: unsupported protocol version + EC_CHECKSUM_MISMATCH, // table hash not equal + EC_NO_MORE_DATA, // End of Result + EC_NEED_FULL_FIELDSET, // only full field set accepted by helper + EC_BAD_KEY_TYPE, // key type incompatible + + EC_BAD_KEY_SIZE, // 25: key size incompatible + EC_SERVER_BUSY, //server error + EC_BAD_SOCKET, // network failed + EC_NOT_INITIALIZED, // object didn't initialized + EC_BAD_HOST_STRING, + + EC_BAD_TABLE_NAME, // 30 + EC_TASK_NEED_DELETE, + EC_KEY_NEEDED, + EC_SERVER_ERROR, + EC_UPSTREAM_ERROR, + + EC_KEY_OVERFLOW, // 35 + EC_BAD_MULTIKEY, + EC_READONLY_FIELD, + EC_BAD_ASYNC_CMD, + EC_OUT_OF_KEY_RANGE, + + EC_REQUEST_ABORTED, // 40 + EC_PARALLEL_MODE, + EC_KEY_NOTEXIST, + EC_SERVER_READONLY, + EC_BAD_INVALID_FIELD, + + EC_DUPLICATE_KEY, // 45 + EC_TOO_MANY_KEY_VALUE, + EC_BAD_KEY_NAME, + EC_BAD_RAW_DATA, + EC_BAD_HOTBACKUP_JID, + + EC_FULL_SYNC_COMPLETE, //50 + EC_FULL_SYNC_STAGE, + EC_INC_SYNC_STAGE, + EC_ERR_SYNC_STAGE, + EC_NOT_ALLOWED_INSERT, + + EC_COMPRESS_ERROR, //55 + EC_UNCOMPRESS_ERROR, + EC_TASKPOOL, + EC_STATE_ERROR, + EC_DATA_NEEDED, + + EC_TASK_TIMEOUT, + + EC_BUSINESS_WITHOUT_EXPIRETIME, //62 + EC_EMPTY_TBDEF, //63 + EC_INVALID_KEY_VALUE, //64 + EC_INVALID_EXPIRETIME, //65 + + EC_GET_EXPIRETIME_END_OF_RESULT, //66 + }; + + enum { + ER_HASHCHK=1000, + ER_NISAMCHK=1001, + ER_NO=1002, + ER_YES=1003, + ER_CANT_CREATE_FILE=1004, + ER_CANT_CREATE_TABLE=1005, + ER_CANT_CREATE_DB=1006, + ER_DB_CREATE_EXISTS=1007, + ER_DB_DROP_EXISTS=1008, + ER_DB_DROP_DELETE=1009, + ER_DB_DROP_RMDIR=1010, + ER_CANT_DELETE_FILE=1011, + ER_CANT_FIND_SYSTEM_REC=1012, + ER_CANT_GET_STAT=1013, + ER_CANT_GET_WD=1014, + ER_CANT_LOCK=1015, + ER_CANT_OPEN_FILE=1016, + ER_FILE_NOT_FOUND=1017, + ER_CANT_READ_DIR=1018, + ER_CANT_SET_WD=1019, + ER_CHECKREAD=1020, + ER_DISK_FULL=1021, + ER_DUP_KEY=1022, + ER_ERROR_ON_CLOSE=1023, + ER_ERROR_ON_READ=1024, + ER_ERROR_ON_RENAME=1025, + ER_ERROR_ON_WRITE=1026, + ER_FILE_USED=1027, + ER_FILSORT_ABORT=1028, + ER_FORM_NOT_FOUND=1029, + ER_GET_ERRNO=1030, + ER_ILLEGAL_HA=1031, + ER_KEY_NOT_FOUND=1032, + ER_NOT_FORM_FILE=1033, + ER_NOT_KEYFILE=1034, + ER_OLD_KEYFILE=1035, + ER_OPEN_AS_READONLY=1036, + ER_OUTOFMEMORY=1037, + ER_OUT_OF_SORTMEMORY=1038, + ER_UNEXPECTED_EOF=1039, + ER_CON_COUNT_ERROR=1040, + ER_OUT_OF_RESOURCES=1041, + ER_BAD_HOST_ERROR=1042, + ER_HANDSHAKE_ERROR=1043, + ER_DBACCESS_DENIED_ERROR=1044, + ER_ACCESS_DENIED_ERROR=1045, + ER_NO_DB_ERROR=1046, + ER_UNKNOWN_COM_ERROR=1047, + ER_BAD_NULL_ERROR=1048, + ER_BAD_DB_ERROR=1049, + ER_TABLE_EXISTS_ERROR=1050, + ER_BAD_TABLE_ERROR=1051, + ER_NON_UNIQ_ERROR=1052, + ER_SERVER_SHUTDOWN=1053, + ER_BAD_FIELD_ERROR=1054, + ER_WRONG_FIELD_WITH_GROUP=1055, + ER_WRONG_GROUP_FIELD=1056, + ER_WRONG_SUM_SELECT=1057, + ER_WRONG_VALUE_COUNT=1058, + ER_TOO_LONG_IDENT=1059, + ER_DUP_FIELDNAME=1060, + ER_DUP_KEYNAME=1061, + ER_DUP_ENTRY=1062, + ER_WRONG_FIELD_SPEC=1063, + ER_PARSE_ERROR=1064, + ER_EMPTY_QUERY=1065, + ER_NONUNIQ_TABLE=1066, + ER_INVALID_DEFAULT=1067, + ER_MULTIPLE_PRI_KEY=1068, + ER_TOO_MANY_KEYS=1069, + ER_TOO_MANY_KEY_PARTS=1070, + ER_TOO_LONG_KEY=1071, + ER_KEY_COLUMN_DOES_NOT_EXITS=1072, + ER_BLOB_USED_AS_KEY=1073, + ER_TOO_BIG_FIELDLENGTH=1074, + ER_WRONG_AUTO_KEY=1075, + ER_READY=1076, + ER_NORMAL_SHUTDOWN=1077, + ER_GOT_SIGNAL=1078, + ER_SHUTDOWN_COMPLETE=1079, + ER_FORCING_CLOSE=1080, + ER_IPSOCK_ERROR=1081, + ER_NO_SUCH_INDEX=1082, + ER_WRONG_FIELD_TERMINATORS=1083, + ER_BLOBS_AND_NO_TERMINATED=1084, + ER_TEXTFILE_NOT_READABLE=1085, + ER_FILE_EXISTS_ERROR=1086, + ER_LOAD_INFO=1087, + ER_ALTER_INFO=1088, + ER_WRONG_SUB_KEY=1089, + ER_CANT_REMOVE_ALL_FIELDS=1090, + ER_CANT_DROP_FIELD_OR_KEY=1091, + ER_INSERT_INFO=1092, + ER_INSERT_TABLE_USED=1093, + ER_NO_SUCH_THREAD=1094, + ER_KILL_DENIED_ERROR=1095, + ER_NO_TABLES_USED=1096, + ER_TOO_BIG_SET=1097, + ER_NO_UNIQUE_LOGFILE=1098, + ER_TABLE_NOT_LOCKED_FOR_WRITE=1099, + ER_TABLE_NOT_LOCKED=1100, + ER_BLOB_CANT_HAVE_DEFAULT=1101, + ER_WRONG_DB_NAME=1102, + ER_WRONG_TABLE_NAME=1103, + ER_TOO_BIG_SELECT=1104, + ER_UNKNOWN_ERROR=1105, + ER_UNKNOWN_PROCEDURE=1106, + ER_WRONG_PARAMCOUNT_TO_PROCEDURE=1107, + ER_WRONG_PARAMETERS_TO_PROCEDURE=1108, + ER_UNKNOWN_TABLE=1109, + ER_FIELD_SPECIFIED_TWICE=1110, + ER_INVALID_GROUP_FUNC_USE=1111, + ER_UNSUPPORTED_EXTENSION=1112, + ER_TABLE_MUST_HAVE_COLUMNS=1113, + ER_RECORD_FILE_FULL=1114, + ER_UNKNOWN_CHARACTER_SET=1115, + ER_TOO_MANY_TABLES=1116, + ER_TOO_MANY_FIELDS=1117, + ER_TOO_BIG_ROWSIZE=1118, + ER_STACK_OVERRUN=1119, + ER_WRONG_OUTER_JOIN=1120, + ER_NULL_COLUMN_IN_INDEX=1121, + ER_CANT_FIND_UDF=1122, + ER_CANT_INITIALIZE_UDF=1123, + ER_UDF_NO_PATHS=1124, + ER_UDF_EXISTS=1125, + ER_CANT_OPEN_LIBRARY=1126, + ER_CANT_FIND_DL_ENTRY=1127, + ER_FUNCTION_NOT_DEFINED=1128, + ER_HOST_IS_BLOCKED=1129, + ER_HOST_NOT_PRIVILEGED=1130, + ER_PASSWORD_ANONYMOUS_USER=1131, + ER_PASSWORD_NOT_ALLOWED=1132, + ER_PASSWORD_NO_MATCH=1133, + ER_UPDATE_INFO=1134, + ER_CANT_CREATE_THREAD=1135, + ER_WRONG_VALUE_COUNT_ON_ROW=1136, + ER_CANT_REOPEN_TABLE=1137, + ER_INVALID_USE_OF_NULL=1138, + ER_REGEXP_ERROR=1139, + ER_MIX_OF_GROUP_FUNC_AND_FIELDS=1140, + ER_NONEXISTING_GRANT=1141, + ER_TABLEACCESS_DENIED_ERROR=1142, + ER_COLUMNACCESS_DENIED_ERROR=1143, + ER_ILLEGAL_GRANT_FOR_TABLE=1144, + ER_GRANT_WRONG_HOST_OR_USER=1145, + ER_NO_SUCH_TABLE=1146, + ER_NONEXISTING_TABLE_GRANT=1147, + ER_NOT_ALLOWED_COMMAND=1148, + ER_SYNTAX_ERROR=1149, + ER_DELAYED_CANT_CHANGE_LOCK=1150, + ER_TOO_MANY_DELAYED_THREADS=1151, + ER_ABORTING_CONNECTION=1152, + ER_NET_PACKET_TOO_LARGE=1153, + ER_NET_READ_ERROR_FROM_PIPE=1154, + ER_NET_FCNTL_ERROR=1155, + ER_NET_PACKETS_OUT_OF_ORDER=1156, + ER_NET_UNCOMPRESS_ERROR=1157, + ER_NET_READ_ERROR=1158, + ER_NET_READ_INTERRUPTED=1159, + ER_NET_ERROR_ON_WRITE=1160, + ER_NET_WRITE_INTERRUPTED=1161, + ER_TOO_LONG_STRING=1162, + ER_TABLE_CANT_HANDLE_BLOB=1163, + ER_TABLE_CANT_HANDLE_AUTO_INCREMENT=1164, + ER_DELAYED_INSERT_TABLE_LOCKED=1165, + ER_WRONG_COLUMN_NAME=1166, + ER_WRONG_KEY_COLUMN=1167, + ER_WRONG_MRG_TABLE=1168, + ER_DUP_UNIQUE=1169, + ER_BLOB_KEY_WITHOUT_LENGTH=1170, + ER_PRIMARY_CANT_HAVE_NULL=1171, + ER_TOO_MANY_ROWS=1172, + ER_REQUIRES_PRIMARY_KEY=1173, + ER_NO_RAID_COMPILED=1174, + ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE=1175, + ER_KEY_DOES_NOT_EXITS=1176, + ER_CHECK_NO_SUCH_TABLE=1177, + ER_CHECK_NOT_IMPLEMENTED=1178, + ER_CANT_DO_THIS_DURING_AN_TRANSACTION=1179, + ER_ERROR_DURING_COMMIT=1180, + ER_ERROR_DURING_ROLLBACK=1181, + ER_ERROR_DURING_FLUSH_LOGS=1182, + ER_ERROR_DURING_CHECKPOINT=1183, + ER_NEW_ABORTING_CONNECTION=1184, + ER_DUMP_NOT_IMPLEMENTED= 1185, + ER_FLUSH_MASTER_BINLOG_CLOSED=1186, + ER_INDEX_REBUILD= 1187, + ER_MASTER=1188, + ER_MASTER_NET_READ=1189, + ER_MASTER_NET_WRITE=1190, + ER_FT_MATCHING_KEY_NOT_FOUND=1191, + ER_LOCK_OR_ACTIVE_TRANSACTION=1192, + ER_UNKNOWN_SYSTEM_VARIABLE=1193, + ER_CRASHED_ON_USAGE=1194, + ER_CRASHED_ON_REPAIR=1195, + ER_WARNING_NOT_COMPLETE_ROLLBACK=1196, + ER_TRANS_CACHE_FULL=1197, + ER_SLAVE_MUST_STOP=1198, + ER_SLAVE_NOT_RUNNING=1199, + ER_BAD_SLAVE=1200, + ER_MASTER_INFO=1201, + ER_SLAVE_THREAD=1202, + ER_TOO_MANY_USER_CONNECTIONS=1203, + ER_SET_CONSTANTS_ONLY=1204, + ER_LOCK_WAIT_TIMEOUT=1205, + ER_LOCK_TABLE_FULL=1206, + ER_READ_ONLY_TRANSACTION=1207, + ER_DROP_DB_WITH_READ_LOCK=1208, + ER_CREATE_DB_WITH_READ_LOCK=1209, + ER_WRONG_ARGUMENTS=1210, + ER_NO_PERMISSION_TO_CREATE_USER=1211, + ER_UNION_TABLES_IN_DIFFERENT_DIR=1212, + ER_LOCK_DEADLOCK=1213, + ER_TABLE_CANT_HANDLE_FULLTEXT=1214, + ER_CANNOT_ADD_FOREIGN=1215, + ER_NO_REFERENCED_ROW=1216, + ER_ROW_IS_REFERENCED=1217, + ER_CONNECT_TO_MASTER=1218, + ER_QUERY_ON_MASTER=1219, + ER_ERROR_WHEN_EXECUTING_COMMAND=1220, + ER_WRONG_USAGE=1221, + ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT=1222, + ER_CANT_UPDATE_WITH_READLOCK=1223, + ER_MIXING_NOT_ALLOWED=1224, + ER_DUP_ARGUMENT=1225, + ER_USER_LIMIT_REACHED=1226, + ER_SPECIFIC_ACCESS_DENIED_ERROR=1227, + ER_LOCAL_VARIABLE=1228, + ER_GLOBAL_VARIABLE=1229, + ER_NO_DEFAULT=1230, + ER_WRONG_VALUE_FOR_VAR=1231, + ER_WRONG_TYPE_FOR_VAR=1232, + ER_VAR_CANT_BE_READ=1233, + ER_CANT_USE_OPTION_HERE=1234, + ER_NOT_SUPPORTED_YET=1235, + ER_MASTER_FATAL_ERROR_READING_BINLOG=1236, + ER_SLAVE_IGNORED_TABLE=1237, + ER_INCORRECT_GLOBAL_LOCAL_VAR=1238, + CR_UNKNOWN_ERROR=1900, + CR_SOCKET_CREATE_ERROR=1901, + CR_CONNECTION_ERROR=1902, + CR_CONN_HOST_ERROR=1903, + CR_IPSOCK_ERROR =1904, + CR_UNKNOWN_HOST =1905, + CR_SERVER_GONE_ERROR=1906, + CR_VERSION_ERROR=1907, + CR_OUT_OF_MEMORY=1908, + CR_WRONG_HOST_INFO=1909, + CR_LOCALHOST_CONNECTION=1910, + CR_TCP_CONNECTION=1911, + CR_SERVER_HANDSHAKE_ERR=1912, + CR_SERVER_LOST=1913, + CR_COMMANDS_OUT_OF_SYNC=1914, + CR_NAMEDPIPE_CONNECTION=1915, + CR_NAMEDPIPEWAIT_ERROR=1916, + CR_NAMEDPIPEOPEN_ERROR=1917, + CR_NAMEDPIPESETSTATE_ERROR=1918, + CR_CANT_READ_CHARSET=1919, + CR_NET_PACKET_TOO_LARGE=1920, + CR_EMBEDDED_CONNECTION=1921, + CR_PROBE_SLAVE_STATUS=1922, + CR_PROBE_SLAVE_HOSTS=1923, + CR_PROBE_SLAVE_CONNECT=1924, + CR_PROBE_MASTER_CONNECT=1925, + CR_SSL_CONNECTION_ERROR=1926, + CR_MALFORMED_PACKET=1927, + CR_WRONG_LICENSE=1928, + }; + + enum{ + ER_SET_IPLIST_NULL = 20001, + ER_SET_INSTANCE_PROPERTIES_ERR, + ER_KEY_TYPE, + ER_CC_VERSION_ERR, + ER_ROUTE_INFO_NULL, + ER_BID_VERSION_ERR, + ER_PORT_OUT_RANGE, + ER_STATUS_ERROR_VALUE, + ER_WEIGHT_ERROR_VALUE, + ER_IP_ERROR_VALUE, + }; + +}; + +#endif diff --git a/test/allcase/test.cpp b/test/allcase/test.cpp new file mode 100755 index 0000000..fed0698 --- /dev/null +++ b/test/allcase/test.cpp @@ -0,0 +1,410 @@ +#include +#include +#include +#include +#include + +#include "dtcapi.h" + +enum TypeIns{ + E_INSERT_CORRENT_DATA = 1, + E_INSERT_DELETION_FIELD, + E_INSERT_DELETION_KEY, + E_INSERT_BAD_TYPE, + E_INSERT_BAD_ORDER, + E_INSERT_SAME, + E_INSERT_ONCE_MULTIPLE, + + E_TOTAL_NUM_INS +}; + +enum TypeDel{ + E_DELETE_EXISTENCE =10, + E_DELETE_NO_EXISTENCE, + E_DELETE_BAD_TYPE_KEY, + E_DELETE_NO_KEY_FIELD, + E_DELETE_EMPTY_TABLE, + E_DELETE_ONCE_MULTIPLE, + + E_TOTAL_NUM_DEL +}; + +enum TypeUpd{ + E_UPDATE_CORRENT_DATA = 20, + E_UPDATE_KEY, + E_UPDATE_DELETION_FIELD, + E_UPDATE_DELETION_KEY, + E_UPDATE_ONCE_MULTIPLE, + E_UPDATE_EMPTY_TABLE, + E_SELECT_ADD_SUB, + E_TOTAL_NUM_UPD +}; + +enum TypeSel{ + E_SELECT_CORRENT_KEY = 30, + E_SELECT_BAD_KEY, + E_SELECT_BAD_TYPE_KEY, + E_SELECT_NO_KEY_FIELD, + E_SELECT_ONCE_MULTIPLE, + E_SELECT_EMPTY_TABLE, + E_SELECT_FIELD_TYPE, + E_SELECT_ADDRESS, + E_SELECT_TABLENAAE, + + E_SELECT_LIMIT, + E_SELECT_LIMIT_RESULT_NUM, + E_SELECT_NO_LIMIT_RESULT_NUM, + + E_TOTAL_NUM_SEL +}; + + +void insert(DTC::Server server,TypeIns type) +{ + int retCode = 0; + + DTC::InsertRequest insertReq(&server); + DTC::Result stResult; + switch (type) + { + case E_INSERT_CORRENT_DATA: + case E_INSERT_SAME: + /* 缁戝畾鎻掑叆鐨勫瓧娈靛拰鏁版嵁 */ + insertReq.set_key(1); + insertReq.Set("uid", 1); + insertReq.Set("name", "姹豹"); + insertReq.Set("city", "涓婃捣"); + insertReq.Set("age", 3); + insertReq.Set("sex", 1); + break; + case E_INSERT_DELETION_FIELD: + insertReq.set_key(1); + insertReq.Set("uid", 1); + insertReq.Set("name", "鍠靛柕"); + break; + case E_INSERT_DELETION_KEY: + insertReq.Set("city", "鏉窞"); + insertReq.Set("age", 9); + break; + case E_INSERT_BAD_TYPE: + insertReq.set_key("jd"); + break; + case E_INSERT_BAD_ORDER: + insertReq.set_key(1); + insertReq.Set("age", 2); + insertReq.Set("name", "鍛卞懕"); + insertReq.Set("uid", 1); + insertReq.Set("city", "涓婃捣"); + insertReq.Set("sex", 0); + break; + case E_INSERT_ONCE_MULTIPLE: + insertReq.set_key(1); + insertReq.Set("uid", 1); + insertReq.Set("name", "鍜╁挬"); + insertReq.Set("city", "瑗垮畨"); + insertReq.Set("age", 7); + insertReq.Set("sex", 1); + insertReq.do_execute(stResult); + insertReq.Reset(); + insertReq.set_key(2); + insertReq.Set("uid", 2); + insertReq.Set("name", "甯冭胺"); + insertReq.Set("city", "绂忓缓"); + insertReq.Set("age", 11); + insertReq.Set("sex", 0); + break; + default: + break; + } + retCode = insertReq.do_execute(stResult); + if(retCode != 0) + printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.get_error_message(), stResult.get_error_from()); + else + printf("insert success!\n"); + printf("==========================================================\n"); +} + +void delet(DTC::Server server,TypeDel type) +{ + + int retCode = 0; + + DTC::DeleteRequest deleteReq(&server); + DTC::Result stResult; + switch (type) + { + case E_DELETE_EXISTENCE: + deleteReq.set_key(1); + break; + case E_DELETE_NO_EXISTENCE: + deleteReq.set_key(-1); + break; + case E_DELETE_BAD_TYPE_KEY: + deleteReq.set_key("jd"); + break; + case E_DELETE_NO_KEY_FIELD: + deleteReq.Set("age", 12); + break; + case E_DELETE_EMPTY_TABLE: + deleteReq.set_key(10000); + break; + case E_DELETE_ONCE_MULTIPLE: + deleteReq.set_key(2); + deleteReq.do_execute(stResult); + deleteReq.Reset(); + deleteReq.set_key(3); + break; + default: + break; + } + retCode = deleteReq.do_execute(stResult); + if(retCode == 0) + printf("delete success!\n"); + if(retCode != 0) + printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.get_error_message(), stResult.get_error_from()); + printf("==========================================================\n"); +} +void updata(DTC::Server server,TypeUpd type) +{ + int retCode = 0; + + DTC::UpdateRequest UpdateReq(&server); + DTC::Result stResult; + UpdateReq.set_key(1); + + switch (type) + { + case E_UPDATE_CORRENT_DATA: + UpdateReq.Set("name", "娴风坏瀹濆疂"); + UpdateReq.Set("city", "澶ф捣"); + UpdateReq.Set("age", 5); + UpdateReq.Set("sex", 1); + break; + case E_UPDATE_KEY: + UpdateReq.Set("uid", 2); + break; + case E_UPDATE_DELETION_FIELD: + UpdateReq.Set("uid", 3); + UpdateReq.Set("age", 11); + break; + case E_UPDATE_EMPTY_TABLE: + UpdateReq.set_key(-2); + break; + case E_UPDATE_DELETION_KEY: + UpdateReq.set_key(10000); + break; + case E_UPDATE_ONCE_MULTIPLE: + UpdateReq.set_key(1); + UpdateReq.Set("name", "娲惧ぇ鏄"); + UpdateReq.Set("city", "娣辨捣"); + UpdateReq.Set("age", 8); + UpdateReq.Set("sex", 0); + UpdateReq.do_execute(stResult); + UpdateReq.Reset(); + UpdateReq.set_key(2); + UpdateReq.Set("name", "锜硅佹澘"); + UpdateReq.Set("city", "澶ф捣"); + UpdateReq.Set("age", 12); + UpdateReq.Set("sex", 1); + break; + case E_SELECT_ADD_SUB: + UpdateReq.set_key(1); + UpdateReq.Add("age", 8); + UpdateReq.Sub("sex", 1); + default: + break; + } + retCode = UpdateReq.do_execute(stResult); + if(retCode != 0) + printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.get_error_message(), stResult.get_error_from()); + else + printf("update success!\n"); + /* 鏌ヨ淇敼褰卞搷鐨勮鏁 */ + printf("affected rows size %d\n",stResult.get_affected_rows_size()); + printf("==========================================================\n"); +} + +void select(DTC::Server server,TypeSel type) +{ + /* 鐩存帴鏋勯犳寚瀹氭搷浣滅殑瀵硅薄锛氭煡璇㈡搷浣 */ + DTC::GetRequest get_request(&server); + int uid; + /* 鎵ц鐨勭粨鏋:鍖呭惈閿欒淇℃伅浠ュ強杩斿洖鐨剅ow鏁版嵁 */ + DTC::Result result; + int iRet; + switch (type) + { + case E_SELECT_CORRENT_KEY: + get_request.set_key(1); + uid = 1; + break; + case E_SELECT_BAD_KEY: + get_request.set_key(-1); + uid = -1; + break; + case E_SELECT_BAD_TYPE_KEY: + get_request.set_key("jd"); + break; + case E_SELECT_NO_KEY_FIELD: + get_request.need("age", 7); + break; + case E_SELECT_ONCE_MULTIPLE: + get_request.set_key(2); + uid = 2; + break; + case E_SELECT_EMPTY_TABLE: + get_request.set_key(10000); + uid = 10000; + break; + case E_SELECT_FIELD_TYPE: + /** + * Signed = 1, Signed Integer + * Unsigned = 2, Unsigned Integer + * FloatPoint = 3 FloatPoint + * String = 4, String, case insensitive, null ended + * Binary = 5, opaque binary data + */ + printf("FieldType uid: %d\n",server.get_field_type("uid")); + printf("FieldType name: %d\n",server.get_field_type("name")); + printf("FieldType city: %d\n",server.get_field_type("city")); + printf("FieldType age: %d\n",server.get_field_type("age")); + printf("FieldType sex: %d\n",server.get_field_type("sex")); + printf("==========================================================\n"); + return; + break; + case E_SELECT_ADDRESS: + /* 杩斿洖鏈嶅姟鍣ㄧip鍦板潃 */ + printf("ip_address: %s\n",server.get_address()); + printf("==========================================================\n"); + return; + break; + case E_SELECT_TABLENAAE: + /* 杩斿洖琛ㄥ悕 */ + printf("tablename: %s\n",server.get_table_name()); + printf("==========================================================\n"); + return; + break; + case E_SELECT_LIMIT: + case E_SELECT_LIMIT_RESULT_NUM: + get_request.set_key(1); + /* 杩斿洖缁撴瀯闆嗗紑濮嬩綅缃 浠ュ強缁撴灉琛屾暟 */ + get_request.limit(2, 2); + uid = 1; + break; + case E_SELECT_NO_LIMIT_RESULT_NUM: + get_request.set_key(1); + get_request.do_execute(result); + printf("total nubrow:%d\n", result.get_total_rows_size()); + uid = 1; + printf("==========================================================\n"); + return; + break; + default: + break; + } + + /* 璁剧疆闇瑕乻elect鐨勫瓧娈 */ + if(iRet == 0) + iRet = get_request.need("uid"); + if(iRet == 0) + iRet = get_request.need("name"); + if(iRet == 0) + iRet = get_request.need("city"); + if(iRet == 0) + iRet = get_request.need("age"); + if(iRet == 0) + iRet = get_request.need("sex"); + if(iRet != 0) + { + printf("get-req need error: %d", iRet); + fflush(stdout); + } + + /* 鎻愪氦璇锋眰锛屾墽琛岀粨鏋滃瓨鍦≧esult瀵硅薄閲 */ + iRet = get_request.do_execute(result); + /* 濡傛灉鍑洪敊,鍒欒緭鍑洪敊璇爜銆侀敊璇樁娈碉紝閿欒淇℃伅锛宻tResult.get_error_from(), result.get_error_message() 杩欎袱涓敊璇俊鎭緢閲嶈锛屼竴瀹氳鎵撳嵃鍑烘潵锛屾柟渚垮畾浣嶉棶棰 */ + if(iRet != 0) + { + printf ("uin[%u] dtc execute get error: %d, error_from:%s, msg:%s\n", + uid, // 鍑洪敊鐨刱ey鏄灏 + iRet, // 閿欒鐮佷负澶氬皯 + result.get_error_from(), // 杩斿洖閿欒闃舵 + result.get_error_message() // 杩斿洖閿欒淇℃伅 + ); + fflush(stdout); + } + /* 鏁版嵁涓嶅瓨鍦 */ + if(result.get_num_row_size() <= 0) + printf("uin[%u] data not exist.\n", uid); + + /* 璇诲彇缁撴灉鐨凨ey鍊 */ + printf("result key: %d\n", result.int_key()); + + /* 杈撳嚭缁撴灉鐨勮鏁 */ + printf("NumRows:%d\n", result.get_num_row_size()); + + /* 杈撳嚭缁撴灉 */ + for(int i=0;i<=result.get_num_row_size();++i) + { + /* 璇诲彇涓琛屾暟鎹 */ + iRet = result.fetch_row(); + if(iRet < 0) + { + printf ("uid[%lu] dtc fetch row error: %d\n", uid, iRet); + fflush(stdout); + } + /* 濡傛灉涓鍒囨纭紝鍒欏彲浠ヨ緭鍑烘暟鎹簡 */ + /* 杈撳嚭int绫诲瀷鐨勬暟鎹 */ + printf("uid: %d\n", result.int_value("uid")); + /* 杈撳嚭binary绫诲瀷鐨勬暟鎹 */ + printf("name: %s\n", result.binary_value("name")); + /* 杈撳嚭string绫诲瀷鐨勬暟鎹 */ + printf("city: %s\n", result.string_value("city")); + printf("age:%d\n", result.int_value("age")); + printf("sex:%d\n",result.int_value("sex")); + } + printf("==========================================================\n"); +} + +int main(int argc,char* argv[]) +{ + std::string ip; + ip = std::string(argv[1]); + + /* 鍙server涓嶆瀽鏋勶紝鍚庡彴浼氫繚鎸侀暱杩炴帴 */ + DTC::Server server; + + /* 璁剧疆鐨刣tc鐨刬p鍜岀鍙 */ + server.set_address(ip.c_str(), "20015"); + /* 璁剧疆缃戠粶瓒呮椂鏃堕棿,鍗曟缃戠粶IO鐨勮秴鏃,鍗曚綅绉 */ + server.SetTimeout(5); + /* 璁剧疆璁块棶鐮 AccessToken锛屽湪鐢宠dtc瀹炰緥鐨勬椂鍊欑綉绔欑浼氱敓鎴 */ + server.set_accesskey("000022907e64e117fa92f892a85307782a68afc6"); + /* 璁剧疆dtc鐨勮〃鍚 */ + server.set_table_name("dtc_opensource"); + /* 澹版槑key绫诲瀷 */ + server.int_key(); + + int i; + for(i = E_INSERT_CORRENT_DATA;i < E_TOTAL_NUM_INS;i++) + { + insert(server,(TypeIns)i); + } + select(server,E_SELECT_CORRENT_KEY); + for(i = E_UPDATE_CORRENT_DATA;i < E_TOTAL_NUM_UPD;i++) + { + updata(server,(TypeUpd)i); + } + for(i = E_SELECT_CORRENT_KEY;i < E_TOTAL_NUM_SEL;i++) + { + select(server,(TypeSel)i); + } + for(int i = E_DELETE_EXISTENCE;i < E_TOTAL_NUM_DEL;i++) + { + delet(server,(TypeDel)i); + } + return 0; +} + + + -- Gitee From 4221c4ea224a77995b3a937dea289f1ffe4641c4 Mon Sep 17 00:00:00 2001 From: wuxz <1067764612@qq.com> Date: Fri, 27 Aug 2021 11:35:58 +0800 Subject: [PATCH 35/39] 4 --- CMakeLists.txt | 10 +- src/CMakeLists.txt | 6 +- src/agent/CMakeLists.txt | 3 +- {conf => src/conf}/cache.yaml | 0 {conf => src/conf}/log4cplus.conf | 2 +- {conf => src/conf}/table.yaml | 0 src/configcenter/ca_api/CMakeLists.txt | 10 +- src/core/misc/main_supply.cc | 1190 +++++++++++++----------- src/libs/common/config/config.cc | 804 ++++++++-------- 9 files changed, 1061 insertions(+), 964 deletions(-) rename {conf => src/conf}/cache.yaml (100%) rename {conf => src/conf}/log4cplus.conf (90%) rename {conf => src/conf}/table.yaml (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4334079..4bf6e18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,7 @@ -cmake_minimum_required (VERSION 2.8) -project (dtc) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(dtc) -add_subdirectory(./src) +ADD_SUBDIRECTORY(./src) - - -#鎯冲嵏杞絤ake install瀹夎鐨勫簱锛岃繘鍏ュ埌build鏂囦欢澶癸紝鎵ц +#if you want to uninstall the library ,you should enter the build folder, and use this command. # cat install_manifest.txt | sudo xargs rm \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20e8ba6..135766e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,11 @@ + ADD_SUBDIRECTORY(./agent) ADD_SUBDIRECTORY(./configcenter) ADD_SUBDIRECTORY(./libs) ADD_SUBDIRECTORY(./devel) ADD_SUBDIRECTORY(./daemons) ADD_SUBDIRECTORY(./core) -#add_subdirectory(./connector) - +#ADD_SUBDIRECTORY(./connector) -#鎯冲嵏杞絤ake install瀹夎鐨勫簱锛岃繘鍏ュ埌build鏂囦欢澶癸紝鎵ц +#if you want to uninstall the library ,you should enter the build folder, and use this command. # cat install_manifest.txt | sudo xargs rm \ No newline at end of file diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt index 3d9b467..7cd2c4a 100644 --- a/src/agent/CMakeLists.txt +++ b/src/agent/CMakeLists.txt @@ -18,7 +18,6 @@ IF("${HAVE_ASSERT_LOG}" EQUAL 1) ENDIF() #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 -#FILE(GLOB_RECURSE SRC_LIST ${PROJECT_SOURCE_DIR}/*.c) FILE(GLOB SRC_LIST1 ./*.c) FILE(GLOB SRC_LIST2 ./common/*.c) FILE(GLOB SRC_LIST3 ./event/*.c) @@ -37,8 +36,10 @@ INCLUDE_DIRECTORIES( LINK_LIBRARIES(rt) LINK_LIBRARIES(mxml) LINK_LIBRARIES(pthread) + #缂栬瘧鍙傛暟 ADD_DEFINITIONS ("-D_GNU_SOURCE") + #缂栬瘧涓.so/.a ADD_EXECUTABLE(dtcagent ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3} ${SRC_LIST4} ${SRC_LIST5}) diff --git a/conf/cache.yaml b/src/conf/cache.yaml similarity index 100% rename from conf/cache.yaml rename to src/conf/cache.yaml diff --git a/conf/log4cplus.conf b/src/conf/log4cplus.conf similarity index 90% rename from conf/log4cplus.conf rename to src/conf/log4cplus.conf index 0350a56..ad10cd1 100644 --- a/conf/log4cplus.conf +++ b/src/conf/log4cplus.conf @@ -7,7 +7,7 @@ log4cplus.appender.STDOUT.layout.ConversionPattern=[%T] %D{%Y-%m-%d %H:%M:%S} %- ## synchronous log properties. log4cplus.appender.apdPlatform=log4cplus::TimeBasedRollingFileAppender -log4cplus.appender.apdPlatform.FilenamePattern=/var/log/dtc/%d{yyyy-MM-dd}.log +log4cplus.appender.apdPlatform.FilenamePattern==/var/log/dtc/%d{yyyy-MM-dd}.log log4cplus.appender.apdPlatform.Append=true log4cplus.appender.apdPlatform.MaxHistory=999 log4cplus.appender.apdPlatform.ImmediateFlush=false diff --git a/conf/table.yaml b/src/conf/table.yaml similarity index 100% rename from conf/table.yaml rename to src/conf/table.yaml diff --git a/src/configcenter/ca_api/CMakeLists.txt b/src/configcenter/ca_api/CMakeLists.txt index 19820ff..e9b84f8 100644 --- a/src/configcenter/ca_api/CMakeLists.txt +++ b/src/configcenter/ca_api/CMakeLists.txt @@ -1,15 +1,15 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/configcenter/ca_api) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I -include_directories (.) +INCLUDE_DIRECTORIES(.) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 -aux_source_directory (. SRC_LIST1) +AUX_SOURCE_DIRECTORY(. SRC_LIST1) #缂栬瘧鍙傛暟 -add_definitions("-g -Wall -fPIC") +ADD_DEFINITIONS("-g -Wall -fPIC") #缂栬瘧涓.so/.a -add_executable(client-tool ${SRC_LIST1}) -add_library(app-client ${SRC_LIST1}) +ADD_EXECUTABLE(client-tool ${SRC_LIST1}) +ADD_LIBRARY(app-client ${SRC_LIST1}) diff --git a/src/core/misc/main_supply.cc b/src/core/misc/main_supply.cc index da52a7d..32d5a01 100644 --- a/src/core/misc/main_supply.cc +++ b/src/core/misc/main_supply.cc @@ -1,18 +1,18 @@ /* - * Copyright [2021] JD.com, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include "main_supply.h" @@ -48,594 +48,652 @@ extern BlackHoleAskChain *g_black_hole_ask_instance; extern void StopTaskExecutor(void); -int plugin_start(void) { - init_plugin = 0; - main_plugin_mgr = PluginManager::instance(); - if (NULL == main_plugin_mgr) { - log4cplus_error("create PluginManager instance failed."); - return DTC_CODE_FAILED; - } - - if (main_plugin_mgr->open( - g_dtc_config->get_int_val("cache", "PluginNetworkMode", 0)) != 0) { - log4cplus_error("init plugin manager failed."); - return DTC_CODE_FAILED; - } - - init_plugin = 1; - return DTC_CODE_SUCCESS; +int plugin_start(void) +{ + init_plugin = 0; + main_plugin_mgr = PluginManager::instance(); + if (NULL == main_plugin_mgr) { + log4cplus_error("create PluginManager instance failed."); + return DTC_CODE_FAILED; + } + + if (main_plugin_mgr->open(g_dtc_config->get_int_val( + "cache", "PluginNetworkMode", 0)) != 0) { + log4cplus_error("init plugin manager failed."); + return DTC_CODE_FAILED; + } + + init_plugin = 1; + return DTC_CODE_SUCCESS; } -int plugin_stop(void) { - main_plugin_mgr->close(); - PluginManager::destory(); - main_plugin_mgr = NULL; - return DTC_CODE_SUCCESS; +int plugin_stop(void) +{ + main_plugin_mgr->close(); + PluginManager::destory(); + main_plugin_mgr = NULL; + return DTC_CODE_SUCCESS; } -int stat_open_fd() { - int count = 0; - for (int i = 0; i < 1000; i++) { - if (fcntl(i, F_GETFL, 0) != -1) - count++; - } - return count; +int stat_open_fd() +{ + int count = 0; + for (int i = 0; i < 1000; i++) { + if (fcntl(i, F_GETFL, 0) != -1) + count++; + } + return count; } -int init_cache_mode() { - g_datasource_mode = g_dtc_config->get_int_val("cache", "DisableDataSource", - DTC_MODE_CACHE_ONLY); - switch (g_datasource_mode) { - case DTC_MODE_DATABASE_ADDITION: - log4cplus_info("dtc datasource mode: %s(%d)", "DTC_MODE_DATABASE_ADDITION", - g_datasource_mode); - break; - case DTC_MODE_CACHE_ONLY: - log4cplus_info("dtc datasource mode: %s(%d)", "DTC_MODE_CACHE_ONLY", - g_datasource_mode); - break; - case DTC_MODE_DATABASE_ONLY: - log4cplus_info("dtc datasource mode: %s(%d)", "DTC_MODE_DATABASE_ONLY", - g_datasource_mode); - break; - default: - log4cplus_error("datasource config error: %d", g_datasource_mode); - return DTC_CODE_FAILED; - } - - async_update = g_dtc_config->get_int_val("cache", "DelayUpdate", 0); - if (async_update < 0 || async_update > 1) { - log4cplus_error("Invalid DelayUpdate value"); - return DTC_CODE_FAILED; - } - - const char *keyStr = g_dtc_config->get_str_val("cache", "CacheShmKey"); - if (keyStr == NULL) { - cache_key = 0; - } else if (!strcasecmp(keyStr, "none") && - g_datasource_mode != DTC_MODE_DATABASE_ONLY) { - log4cplus_error("Can not set " - "DisableDataSource=(DTC_MODE_CACHE_ONLY|DTC_MODE_DATABASE_" - "ADDITION) and CacheShmKey=NONE together."); - return DTC_CODE_FAILED; - } else if (isdigit(keyStr[0])) { - cache_key = strtol(keyStr, NULL, 0); - } else { - log4cplus_error("Invalid CacheShmKey value \"%s\"", keyStr); - return DTC_CODE_FAILED; - } - - if (g_datasource_mode == DTC_MODE_DATABASE_ONLY && async_update) { - log4cplus_error("can't DelayUpdate when CacheShmKey set to NONE"); - return DTC_CODE_FAILED; - } - - if (g_datasource_mode != DTC_MODE_DATABASE_ONLY && cache_key == 0) - log4cplus_info("CacheShmKey not set, cache data is volatile"); - - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) - log4cplus_info("disable data source, cache data is volatile"); - - return DTC_CODE_SUCCESS; +int init_cache_mode() +{ + g_datasource_mode = g_dtc_config->get_int_val( + "cache", "DisableDataSource", DTC_MODE_CACHE_ONLY); + switch (g_datasource_mode) { + case DTC_MODE_DATABASE_ADDITION: + log4cplus_info("dtc datasource mode: %s(%d)", + "DTC_MODE_DATABASE_ADDITION", g_datasource_mode); + break; + case DTC_MODE_CACHE_ONLY: + log4cplus_info("dtc datasource mode: %s(%d)", + "DTC_MODE_CACHE_ONLY", g_datasource_mode); + break; + case DTC_MODE_DATABASE_ONLY: + log4cplus_info("dtc datasource mode: %s(%d)", + "DTC_MODE_DATABASE_ONLY", g_datasource_mode); + break; + default: + log4cplus_error("datasource config error: %d", + g_datasource_mode); + return DTC_CODE_FAILED; + } + + async_update = g_dtc_config->get_int_val("cache", "DelayUpdate", 0); + if (async_update < 0 || async_update > 1) { + log4cplus_error("Invalid DelayUpdate value"); + return DTC_CODE_FAILED; + } + + const char *keyStr = g_dtc_config->get_str_val("cache", "CacheShmKey"); + if (keyStr == NULL) { + cache_key = 0; + } else if (!strcasecmp(keyStr, "none") && + g_datasource_mode != DTC_MODE_DATABASE_ONLY) { + log4cplus_error( + "Can not set DisableDataSource=(DTC_MODE_CACHE_ONLY|DTC_MODE_DATABASE_ADDITION) and CacheShmKey=NONE together."); + return DTC_CODE_FAILED; + } else if (isdigit(keyStr[0])) { + cache_key = strtol(keyStr, NULL, 0); + } else { + log4cplus_error("Invalid CacheShmKey value \"%s\"", keyStr); + return DTC_CODE_FAILED; + } + + if (g_datasource_mode == DTC_MODE_DATABASE_ONLY && async_update) { + log4cplus_error( + "can't DelayUpdate when CacheShmKey set to NONE"); + return DTC_CODE_FAILED; + } + + if (g_datasource_mode != DTC_MODE_DATABASE_ONLY && cache_key == 0) + log4cplus_info("CacheShmKey not set, cache data is volatile"); + + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) + log4cplus_info("disable data source, cache data is volatile"); + + return DTC_CODE_SUCCESS; } -int init_main_chain_thread() { - g_main_thread = new PollerBase("dtc-thread-main"); - if (g_main_thread == NULL) - return DTC_CODE_FAILED; - if (g_main_thread->initialize_thread() == DTC_CODE_FAILED) - return DTC_CODE_FAILED; +int init_main_chain_thread() +{ + g_main_thread = new PollerBase("dtc-thread-main"); + if (g_main_thread == NULL) + return DTC_CODE_FAILED; + if (g_main_thread->initialize_thread() == DTC_CODE_FAILED) + return DTC_CODE_FAILED; - return DTC_CODE_SUCCESS; + return DTC_CODE_SUCCESS; } -int init_hotbackup_chain_thread() { - log4cplus_debug("StartHotbackThread begin"); - g_hot_backup_thread = new PollerBase("dtc-thread-hotbackup"); - g_hot_backup_ask_instance = new HotBackupAskChain(g_hot_backup_thread); - - if (g_hot_backup_thread == NULL || g_hot_backup_ask_instance == NULL) { - log4cplus_error("hot backup thread or instance created failed."); - return DTC_CODE_FAILED; - } - - if (g_hot_backup_thread->initialize_thread() == DTC_CODE_FAILED) { - log4cplus_error("init hotback thread fail"); - return DTC_CODE_FAILED; - } - if (g_hot_backup_ask_instance->do_init( - g_dtc_config->get_size_val("cache", "BinlogTotalSize", - BINLOG_MAX_TOTAL_SIZE, 'M'), - g_dtc_config->get_size_val("cache", "BinlogOneSize", BINLOG_MAX_SIZE, - 'M')) == -1) { - log4cplus_error("hotbackProcess init fail"); - return DTC_CODE_FAILED; - } - - log4cplus_debug("StartHotbackThread end"); - return DTC_CODE_SUCCESS; +int init_hotbackup_chain_thread() +{ + log4cplus_debug("StartHotbackThread begin"); + g_hot_backup_thread = new PollerBase("dtc-thread-hotbackup"); + g_hot_backup_ask_instance = new HotBackupAskChain(g_hot_backup_thread); + + if (g_hot_backup_thread == NULL || g_hot_backup_ask_instance == NULL) { + log4cplus_error( + "hot backup thread or instance created failed."); + return DTC_CODE_FAILED; + } + + if (g_hot_backup_thread->initialize_thread() == DTC_CODE_FAILED) { + log4cplus_error("init hotback thread fail"); + return DTC_CODE_FAILED; + } + if (g_hot_backup_ask_instance->do_init( + g_dtc_config->get_size_val("cache", "BinlogTotalSize", + BINLOG_MAX_TOTAL_SIZE, 'M'), + g_dtc_config->get_size_val("cache", "BinlogOneSize", + BINLOG_MAX_SIZE, 'M')) == -1) { + log4cplus_error("hotbackProcess init fail"); + return DTC_CODE_FAILED; + } + + log4cplus_debug("StartHotbackThread end"); + return DTC_CODE_SUCCESS; } -int init_buffer_process_ask_chain_thread() { - log4cplus_error("init_buffer_process_ask_chain_thread start"); - g_buffer_multi_thread = new PollerBase("dtc-multi-thread-cache"); - g_buffer_process_ask_instance = new BufferProcessAskChain( - g_buffer_multi_thread, - TableDefinitionManager::instance()->get_cur_table_def(), - async_update ? MODE_ASYNC : MODE_SYNC); - g_buffer_process_ask_instance->set_limit_node_size( - g_dtc_config->get_int_val("cache", "LimitNodeSize", 100 * 1024 * 1024)); - g_buffer_process_ask_instance->set_limit_node_rows( - g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); - g_buffer_process_ask_instance->set_limit_empty_nodes( - g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); - - if (g_buffer_multi_thread->initialize_thread() == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - unsigned long long cache_size = - g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); - if (cache_size <= (50ULL << 20)) // 50M - { - log4cplus_error("CacheMemorySize too small"); - return DTC_CODE_FAILED; - } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { - log4cplus_error("CacheMemorySize %lld too large", cache_size); - } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( - cache_size, - g_dtc_config->get_int_val("cache", "CacheShmVersion", 4)) == - DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - /* disable async transaction log */ - g_buffer_process_ask_instance->disable_async_log(1); - - int lruLevel = g_dtc_config->get_int_val("cache", "disable_lru_update", 0); - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { - if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { - return DTC_CODE_FAILED; - } - if (g_dtc_config->get_int_val("cache", "disable_auto_purge", 0) > 0) { - g_buffer_process_ask_instance->disable_auto_purge(); - // lruLevel = 3; /* LRU_WRITE */ - } - int autoPurgeAlertTime = - g_dtc_config->get_int_val("cache", "AutoPurgeAlertTime", 0); - g_buffer_process_ask_instance->set_date_expire_alert_time( - autoPurgeAlertTime); - if (autoPurgeAlertTime > 0 && TableDefinitionManager::instance() - ->get_cur_table_def() - ->lastcmod_field_id() <= 0) { - log4cplus_error("Can't start AutoPurgeAlert without lastcmod field"); - return DTC_CODE_FAILED; - } - } - g_buffer_process_ask_instance->disable_lru_update(lruLevel); - g_buffer_process_ask_instance->enable_lossy_data_source( - g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); - - if (async_update != MODE_SYNC && cache_key == 0) { - log4cplus_error("Anonymous shared memory don't support DelayUpdate"); - return DTC_CODE_FAILED; - } - - int iAutoDeleteDirtyShm = - g_dtc_config->get_int_val("cache", "AutoDeleteDirtyShareMemory", 0); - /*disable empty node filter*/ - if (g_buffer_process_ask_instance->open_init_buffer( - cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - if (g_buffer_process_ask_instance->update_mode() || - g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active - { - if (TableDefinitionManager::instance()->get_cur_table_def()->uniq_fields() < - 1) { - log4cplus_error("DelayUpdate needs uniq-field(s)"); - return DTC_CODE_FAILED; - } - - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { - if (g_buffer_process_ask_instance->update_mode()) { - log4cplus_error("Can't start async mode when disableDataSource."); - return DTC_CODE_FAILED; - } else { - log4cplus_error("Can't start disableDataSource with shm dirty,please " - "flush async shm to db first or delete shm"); - return DTC_CODE_FAILED; - } - } else { - if ((TableDefinitionManager::instance() - ->get_cur_table_def() - ->compress_field_id() >= 0)) { - log4cplus_error( - "sorry,DTC just support compress in disableDataSource mode now."); - return DTC_CODE_FAILED; - } - } - - /*marker is the only source of flush speed calculattion, inc precision to - * 10*/ - g_buffer_process_ask_instance->set_flush_parameter( - g_dtc_config->get_int_val("cache", "MarkerPrecision", 10), - g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), - g_dtc_config->get_int_val("cache", "MinDirtyTime", 3600), - g_dtc_config->get_int_val("cache", "MaxDirtyTime", 43200)); - - g_buffer_process_ask_instance->set_drop_count( - g_dtc_config->get_int_val("cache", "MaxDropCount", 1000)); - } else { - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) - g_data_connector_ask_instance->disable_commit_group(); - } - - if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < 0) - return DTC_CODE_FAILED; - - log4cplus_error("init_buffer_process_ask_chain_thread end"); - - return DTC_CODE_SUCCESS; +int init_buffer_process_ask_chain_thread() +{ + log4cplus_error("init_buffer_process_ask_chain_thread start"); + g_buffer_multi_thread = new PollerBase("dtc-multi-thread-cache"); + g_buffer_process_ask_instance = new BufferProcessAskChain( + g_buffer_multi_thread, + TableDefinitionManager::instance()->get_cur_table_def(), + async_update ? MODE_ASYNC : MODE_SYNC); + g_buffer_process_ask_instance->set_limit_node_size( + g_dtc_config->get_int_val("cache", "LimitNodeSize", + 100 * 1024 * 1024)); + g_buffer_process_ask_instance->set_limit_node_rows( + g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); + g_buffer_process_ask_instance->set_limit_empty_nodes( + g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); + + if (g_buffer_multi_thread->initialize_thread() == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + unsigned long long cache_size = + g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); + if (cache_size <= (50ULL << 20)) // 50M + { + log4cplus_error("CacheMemorySize too small"); + return DTC_CODE_FAILED; + } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { + log4cplus_error("CacheMemorySize %lld too large", cache_size); + } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( + cache_size, + g_dtc_config->get_int_val("cache", "CacheShmVersion", + 4)) == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + /* disable async transaction log */ + g_buffer_process_ask_instance->disable_async_log(1); + + int lruLevel = + g_dtc_config->get_int_val("cache", "disable_lru_update", 0); + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { + if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { + return DTC_CODE_FAILED; + } + if (g_dtc_config->get_int_val("cache", "disable_auto_purge", + 0) > 0) { + g_buffer_process_ask_instance->disable_auto_purge(); + // lruLevel = 3; /* LRU_WRITE */ + } + int autoPurgeAlertTime = g_dtc_config->get_int_val( + "cache", "AutoPurgeAlertTime", 0); + g_buffer_process_ask_instance->set_date_expire_alert_time( + autoPurgeAlertTime); + if (autoPurgeAlertTime > 0 && + TableDefinitionManager::instance() + ->get_cur_table_def() + ->lastcmod_field_id() <= 0) { + log4cplus_error( + "Can't start AutoPurgeAlert without lastcmod field"); + return DTC_CODE_FAILED; + } + } + g_buffer_process_ask_instance->disable_lru_update(lruLevel); + g_buffer_process_ask_instance->enable_lossy_data_source( + g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); + + if (async_update != MODE_SYNC && cache_key == 0) { + log4cplus_error( + "Anonymous shared memory don't support DelayUpdate"); + return DTC_CODE_FAILED; + } + + int iAutoDeleteDirtyShm = g_dtc_config->get_int_val( + "cache", "AutoDeleteDirtyShareMemory", 0); + /*disable empty node filter*/ + if (g_buffer_process_ask_instance->open_init_buffer( + cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + if (g_buffer_process_ask_instance->update_mode() || + g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active + { + if (TableDefinitionManager::instance() + ->get_cur_table_def() + ->uniq_fields() < 1) { + log4cplus_error("DelayUpdate needs uniq-field(s)"); + return DTC_CODE_FAILED; + } + + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { + if (g_buffer_process_ask_instance->update_mode()) { + log4cplus_error( + "Can't start async mode when disableDataSource."); + return DTC_CODE_FAILED; + } else { + log4cplus_error( + "Can't start disableDataSource with shm dirty,please flush async shm to db first or delete shm"); + return DTC_CODE_FAILED; + } + } else { + if ((TableDefinitionManager::instance() + ->get_cur_table_def() + ->compress_field_id() >= 0)) { + log4cplus_error( + "sorry,DTC just support compress in disableDataSource mode now."); + return DTC_CODE_FAILED; + } + } + + /*marker is the only source of flush speed calculattion, inc precision to 10*/ + g_buffer_process_ask_instance->set_flush_parameter( + g_dtc_config->get_int_val("cache", "MarkerPrecision", + 10), + g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), + g_dtc_config->get_int_val("cache", "MinDirtyTime", + 3600), + g_dtc_config->get_int_val("cache", "MaxDirtyTime", + 43200)); + + g_buffer_process_ask_instance->set_drop_count( + g_dtc_config->get_int_val("cache", "MaxDropCount", + 1000)); + } else { + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) + g_data_connector_ask_instance->disable_commit_group(); + } + + if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < + 0) + return DTC_CODE_FAILED; + + log4cplus_error("init_buffer_process_ask_chain_thread end"); + + return DTC_CODE_SUCCESS; } -int collect_load_config(DbConfig *dbconfig) { - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) - return DTC_CODE_SUCCESS; +int collect_load_config(DbConfig *dbconfig) +{ + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) + return DTC_CODE_SUCCESS; - if (!g_data_connector_ask_instance) - return DTC_CODE_FAILED; + if (!g_data_connector_ask_instance) + return DTC_CODE_FAILED; - if (dbconfig == NULL) { - log4cplus_error("dbconfig == NULL"); - return DTC_CODE_FAILED; - } + if (dbconfig == NULL) { + log4cplus_error("dbconfig == NULL"); + return DTC_CODE_FAILED; + } - if (g_data_connector_ask_instance->renew_config(dbconfig)) { - log4cplus_error("helperunit renew config error!"); - return DTC_CODE_FAILED; - } + if (g_data_connector_ask_instance->renew_config(dbconfig)) { + log4cplus_error("helperunit renew config error!"); + return DTC_CODE_FAILED; + } - return DTC_CODE_SUCCESS; + return DTC_CODE_SUCCESS; } -int init_remote_dtc_chain_thread() { - log4cplus_debug("init_remote_dtc_chain_thread begin"); - g_remote_thread = new PollerBase("dtc-thread-remote"); - g_remote_dtc_instance = new RemoteDtcAskAnswerChain( - g_remote_thread, - g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); - if (g_remote_thread->initialize_thread() == DTC_CODE_FAILED) { - log4cplus_error("init remote thread error"); - return DTC_CODE_FAILED; - } - - // get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - - g_remote_dtc_instance->set_timer_handler( - g_remote_thread->get_timer_list(timeout), - g_remote_thread->get_timer_list(connect), - g_remote_thread->get_timer_list(retry)); - log4cplus_debug("init_remote_dtc_chain_thread end"); - - return DTC_CODE_SUCCESS; +int init_remote_dtc_chain_thread() +{ + log4cplus_debug("init_remote_dtc_chain_thread begin"); + g_remote_thread = new PollerBase("dtc-thread-remote"); + g_remote_dtc_instance = new RemoteDtcAskAnswerChain( + g_remote_thread, + g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); + if (g_remote_thread->initialize_thread() == DTC_CODE_FAILED) { + log4cplus_error("init remote thread error"); + return DTC_CODE_FAILED; + } + + //get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = + g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + + g_remote_dtc_instance->set_timer_handler( + g_remote_thread->get_timer_list(timeout), + g_remote_thread->get_timer_list(connect), + g_remote_thread->get_timer_list(retry)); + log4cplus_debug("init_remote_dtc_chain_thread end"); + + return DTC_CODE_SUCCESS; } -int init_remote_dtc_chain(PollerBase *thread) { - log4cplus_debug("init_remote_dtc_chain begin"); +int init_remote_dtc_chain(PollerBase *thread) +{ + log4cplus_debug("init_remote_dtc_chain begin"); - g_remote_dtc_instance = new RemoteDtcAskAnswerChain( - thread, g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); + g_remote_dtc_instance = new RemoteDtcAskAnswerChain( + thread, + g_dtc_config->get_int_val("cache", "HelperCountPerGroup", 16)); - // get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + //get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = + g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - g_remote_dtc_instance->set_timer_handler(thread->get_timer_list(timeout), - thread->get_timer_list(connect), - thread->get_timer_list(retry)); - log4cplus_debug("init_remote_dtc_chain end"); + g_remote_dtc_instance->set_timer_handler( + thread->get_timer_list(timeout), + thread->get_timer_list(connect), thread->get_timer_list(retry)); + log4cplus_debug("init_remote_dtc_chain end"); - return DTC_CODE_SUCCESS; + return DTC_CODE_SUCCESS; } -int init_data_connector_chain_thread() { - log4cplus_debug("init_data_connector_chain_thread begin"); - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) { - g_data_connector_ask_instance = new DataConnectorAskChain(); - if (g_data_connector_ask_instance->load_config( - dbConfig, TableDefinitionManager::instance() - ->get_cur_table_def() - ->key_format()) == -1) { - return DTC_CODE_FAILED; - } - } - - // get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - - g_datasource_thread = new PollerBase("dtc-thread-datasource"); - if (g_datasource_thread->initialize_thread() == DTC_CODE_FAILED) - return DTC_CODE_FAILED; - - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) - g_data_connector_ask_instance->set_timer_handler( - g_datasource_thread->get_timer_list(timeout), - g_datasource_thread->get_timer_list(connect), - g_datasource_thread->get_timer_list(retry)); - log4cplus_debug("init_data_connector_chain_thread end"); - - return DTC_CODE_SUCCESS; +int init_data_connector_chain_thread() +{ + log4cplus_debug("init_data_connector_chain_thread begin"); + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) { + g_data_connector_ask_instance = new DataConnectorAskChain(); + if (g_data_connector_ask_instance->load_config( + dbConfig, TableDefinitionManager::instance() + ->get_cur_table_def() + ->key_format()) == -1) { + return DTC_CODE_FAILED; + } + } + + //get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = + g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + + g_datasource_thread = new PollerBase("dtc-thread-datasource"); + if (g_datasource_thread->initialize_thread() == DTC_CODE_FAILED) + return DTC_CODE_FAILED; + + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) + g_data_connector_ask_instance->set_timer_handler( + g_datasource_thread->get_timer_list(timeout), + g_datasource_thread->get_timer_list(connect), + g_datasource_thread->get_timer_list(retry)); + log4cplus_debug("init_data_connector_chain_thread end"); + + return DTC_CODE_SUCCESS; } -int init_buffer_process_ask_chain(PollerBase *thread) { - log4cplus_error("init_buffer_process_ask_chain start"); - g_buffer_process_ask_instance = new BufferProcessAskChain( - thread, TableDefinitionManager::instance()->get_cur_table_def(), - async_update ? MODE_ASYNC : MODE_SYNC); - g_buffer_process_ask_instance->set_limit_node_size( - g_dtc_config->get_int_val("cache", "LimitNodeSize", 100 * 1024 * 1024)); - g_buffer_process_ask_instance->set_limit_node_rows( - g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); - g_buffer_process_ask_instance->set_limit_empty_nodes( - g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); - - unsigned long long cache_size = - g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); - if (cache_size <= (50ULL << 20)) // 50M - { - log4cplus_error("CacheMemorySize too small"); - return DTC_CODE_FAILED; - } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { - log4cplus_error("CacheMemorySize %lld too large", cache_size); - } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( - cache_size, - g_dtc_config->get_int_val("cache", "CacheShmVersion", 4)) == - DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - /* disable async transaction log */ - g_buffer_process_ask_instance->disable_async_log(1); - - int lruLevel = g_dtc_config->get_int_val("cache", "disable_lru_update", 0); - if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { - if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { - return DTC_CODE_FAILED; - } - if (g_dtc_config->get_int_val("cache", "disable_auto_purge", 0) > 0) { - g_buffer_process_ask_instance->disable_auto_purge(); - // lruLevel = 3; /* LRU_WRITE */ - } - int autoPurgeAlertTime = - g_dtc_config->get_int_val("cache", "AutoPurgeAlertTime", 0); - g_buffer_process_ask_instance->set_date_expire_alert_time( - autoPurgeAlertTime); - if (autoPurgeAlertTime > 0 && TableDefinitionManager::instance() - ->get_cur_table_def() - ->lastcmod_field_id() <= 0) { - log4cplus_error("Can't start AutoPurgeAlert without lastcmod field"); - return DTC_CODE_FAILED; - } - } - g_buffer_process_ask_instance->disable_lru_update(lruLevel); - g_buffer_process_ask_instance->enable_lossy_data_source( - g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); - - if (async_update != MODE_SYNC && cache_key == 0) { - log4cplus_error("Anonymous shared memory don't support DelayUpdate"); - return DTC_CODE_FAILED; - } - - int iAutoDeleteDirtyShm = - g_dtc_config->get_int_val("cache", "AutoDeleteDirtyShareMemory", 0); - /*disable empty node filter*/ - if (g_buffer_process_ask_instance->open_init_buffer( - cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { - return DTC_CODE_FAILED; - } - - if (g_buffer_process_ask_instance->update_mode() || - g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active - { - if (TableDefinitionManager::instance()->get_cur_table_def()->uniq_fields() < - 1) { - log4cplus_error("DelayUpdate needs uniq-field(s)"); - return DTC_CODE_FAILED; - } - - switch (g_datasource_mode) { - case DTC_MODE_CACHE_ONLY: - if (g_buffer_process_ask_instance->update_mode()) { - log4cplus_error("Can't start async mode when disableDataSource."); - return DTC_CODE_FAILED; - } else { - log4cplus_error("Can't start disableDataSource with shm dirty,please " - "flush async shm to db first or delete shm"); - return DTC_CODE_FAILED; - } - break; - case DTC_MODE_DATABASE_ADDITION: - if ((TableDefinitionManager::instance() - ->get_cur_table_def() - ->compress_field_id() >= 0)) { - log4cplus_error( - "sorry,DTC just support compress in disableDataSource mode now."); - return DTC_CODE_FAILED; - } - break; - default: - log4cplus_error("datasource mode error:%d", g_datasource_mode); - return DTC_CODE_FAILED; - } - - /*marker is the only source of flush speed calculattion, inc precision to - * 10*/ - g_buffer_process_ask_instance->set_flush_parameter( - g_dtc_config->get_int_val("cache", "MarkerPrecision", 10), - g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), - g_dtc_config->get_int_val("cache", "MinDirtyTime", 3600), - g_dtc_config->get_int_val("cache", "MaxDirtyTime", 43200)); - - g_buffer_process_ask_instance->set_drop_count( - g_dtc_config->get_int_val("cache", "MaxDropCount", 1000)); - } else { - if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) - g_data_connector_ask_instance->disable_commit_group(); - } - - if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < 0) - return DTC_CODE_FAILED; - - log4cplus_error("init_buffer_process_ask_chain end"); - - return DTC_CODE_SUCCESS; +int init_buffer_process_ask_chain(PollerBase *thread) +{ + log4cplus_error("init_buffer_process_ask_chain start"); + g_buffer_process_ask_instance = new BufferProcessAskChain( + thread, TableDefinitionManager::instance()->get_cur_table_def(), + async_update ? MODE_ASYNC : MODE_SYNC); + g_buffer_process_ask_instance->set_limit_node_size( + g_dtc_config->get_int_val("cache", "LimitNodeSize", + 100 * 1024 * 1024)); + g_buffer_process_ask_instance->set_limit_node_rows( + g_dtc_config->get_int_val("cache", "LimitNodeRows", 0)); + g_buffer_process_ask_instance->set_limit_empty_nodes( + g_dtc_config->get_int_val("cache", "LimitEmptyNodes", 0)); + + unsigned long long cache_size = + g_dtc_config->get_size_val("cache", "CacheMemorySize", 0, 'M'); + if (cache_size <= (50ULL << 20)) // 50M + { + log4cplus_error("CacheMemorySize too small"); + return DTC_CODE_FAILED; + } else if (sizeof(long) == 4 && cache_size >= 4000000000ULL) { + log4cplus_error("CacheMemorySize %lld too large", cache_size); + } else if (g_buffer_process_ask_instance->set_buffer_size_and_version( + cache_size, + g_dtc_config->get_int_val("cache", "CacheShmVersion", + 4)) == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + /* disable async transaction log */ + g_buffer_process_ask_instance->disable_async_log(1); + + int lruLevel = + g_dtc_config->get_int_val("cache", "disable_lru_update", 0); + if (g_datasource_mode == DTC_MODE_CACHE_ONLY) { + if (g_buffer_process_ask_instance->enable_no_db_mode() < 0) { + return DTC_CODE_FAILED; + } + if (g_dtc_config->get_int_val("cache", "disable_auto_purge", + 0) > 0) { + g_buffer_process_ask_instance->disable_auto_purge(); + // lruLevel = 3; /* LRU_WRITE */ + } + int autoPurgeAlertTime = g_dtc_config->get_int_val( + "cache", "AutoPurgeAlertTime", 0); + g_buffer_process_ask_instance->set_date_expire_alert_time( + autoPurgeAlertTime); + if (autoPurgeAlertTime > 0 && + TableDefinitionManager::instance() + ->get_cur_table_def() + ->lastcmod_field_id() <= 0) { + log4cplus_error( + "Can't start AutoPurgeAlert without lastcmod field"); + return DTC_CODE_FAILED; + } + } + g_buffer_process_ask_instance->disable_lru_update(lruLevel); + g_buffer_process_ask_instance->enable_lossy_data_source( + g_dtc_config->get_int_val("cache", "LossyDataSource", 0)); + + if (async_update != MODE_SYNC && cache_key == 0) { + log4cplus_error( + "Anonymous shared memory don't support DelayUpdate"); + return DTC_CODE_FAILED; + } + + int iAutoDeleteDirtyShm = g_dtc_config->get_int_val( + "cache", "AutoDeleteDirtyShareMemory", 0); + /*disable empty node filter*/ + if (g_buffer_process_ask_instance->open_init_buffer( + cache_key, 0, iAutoDeleteDirtyShm) == DTC_CODE_FAILED) { + return DTC_CODE_FAILED; + } + + if (g_buffer_process_ask_instance->update_mode() || + g_buffer_process_ask_instance->is_mem_dirty()) // asyncUpdate active + { + if (TableDefinitionManager::instance() + ->get_cur_table_def() + ->uniq_fields() < 1) { + log4cplus_error("DelayUpdate needs uniq-field(s)"); + return DTC_CODE_FAILED; + } + + switch (g_datasource_mode) { + case DTC_MODE_CACHE_ONLY: + if (g_buffer_process_ask_instance->update_mode()) { + log4cplus_error( + "Can't start async mode when disableDataSource."); + return DTC_CODE_FAILED; + } else { + log4cplus_error( + "Can't start disableDataSource with shm dirty,please flush async shm to db first or delete shm"); + return DTC_CODE_FAILED; + } + break; + case DTC_MODE_DATABASE_ADDITION: + if ((TableDefinitionManager::instance() + ->get_cur_table_def() + ->compress_field_id() >= 0)) { + log4cplus_error( + "sorry,DTC just support compress in disableDataSource mode now."); + return DTC_CODE_FAILED; + } + break; + default: + log4cplus_error("datasource mode error:%d", + g_datasource_mode); + return DTC_CODE_FAILED; + } + + /*marker is the only source of flush speed calculattion, inc precision to 10*/ + g_buffer_process_ask_instance->set_flush_parameter( + g_dtc_config->get_int_val("cache", "MarkerPrecision", + 10), + g_dtc_config->get_int_val("cache", "MaxFlushSpeed", 1), + g_dtc_config->get_int_val("cache", "MinDirtyTime", + 3600), + g_dtc_config->get_int_val("cache", "MaxDirtyTime", + 43200)); + + g_buffer_process_ask_instance->set_drop_count( + g_dtc_config->get_int_val("cache", "MaxDropCount", + 1000)); + } else { + if (g_datasource_mode == DTC_MODE_DATABASE_ADDITION) + g_data_connector_ask_instance->disable_commit_group(); + } + + if (g_buffer_process_ask_instance->set_insert_order(dbConfig->ordIns) < + 0) + return DTC_CODE_FAILED; + + log4cplus_error("init_buffer_process_ask_chain end"); + + return DTC_CODE_SUCCESS; } -int init_data_connector_ask_chain(PollerBase *thread) { - log4cplus_debug("init_data_connector_ask_chain begin"); - - g_data_connector_ask_instance = new DataConnectorAskChain(); - if (g_data_connector_ask_instance->load_config( - dbConfig, TableDefinitionManager::instance() - ->get_cur_table_def() - ->key_format()) == -1) { - return DTC_CODE_FAILED; - } - // get helper timeout - int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); - int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); - int connect = g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); - - g_data_connector_ask_instance->set_timer_handler( - thread->get_timer_list(timeout), thread->get_timer_list(connect), - thread->get_timer_list(retry)); - - g_data_connector_ask_instance->do_attach(thread); - if (g_datasource_mode == DTC_MODE_DATABASE_ONLY) { - g_data_connector_ask_instance->disable_commit_group(); - } - log4cplus_debug("init_data_connector_ask_chain end"); - - return DTC_CODE_SUCCESS; +int init_data_connector_ask_chain(PollerBase *thread) +{ + log4cplus_debug("init_data_connector_ask_chain begin"); + + g_data_connector_ask_instance = new DataConnectorAskChain(); + if (g_data_connector_ask_instance->load_config( + dbConfig, TableDefinitionManager::instance() + ->get_cur_table_def() + ->key_format()) == -1) { + return DTC_CODE_FAILED; + } + //get helper timeout + int timeout = g_dtc_config->get_int_val("cache", "HelperTimeout", 30); + int retry = g_dtc_config->get_int_val("cache", "HelperRetryTimeout", 1); + int connect = + g_dtc_config->get_int_val("cache", "HelperConnectTimeout", 10); + + g_data_connector_ask_instance->set_timer_handler( + thread->get_timer_list(timeout), + thread->get_timer_list(connect), thread->get_timer_list(retry)); + + g_data_connector_ask_instance->do_attach(thread); + if (g_datasource_mode == DTC_MODE_DATABASE_ONLY) { + g_data_connector_ask_instance->disable_commit_group(); + } + log4cplus_debug("init_data_connector_ask_chain end"); + + return DTC_CODE_SUCCESS; } //鑾峰彇銆侀厤缃熀纭淇℃伅 -int init_config_info() { - g_hash_changing = g_dtc_config->get_int_val("cache", "HashChanging", 0); - g_target_new_hash = g_dtc_config->get_int_val("cache", "TargetNewHash", 0); - - DTCGlobal::pre_alloc_nodegroup_count = - g_dtc_config->get_int_val("cache", "PreAllocNGNum", 1024); - DTCGlobal::pre_alloc_nodegroup_count = - DTCGlobal::pre_alloc_nodegroup_count <= 1 - ? 1 - : DTCGlobal::pre_alloc_nodegroup_count >= (1 << 12) - ? 1 - : DTCGlobal::pre_alloc_nodegroup_count; - - DTCGlobal::min_chunk_size_ = - g_dtc_config->get_int_val("cache", "MinChunkSize", 0); - if (DTCGlobal::min_chunk_size_ < 0) { - DTCGlobal::min_chunk_size_ = 0; - } - - DTCGlobal::pre_purge_nodes_ = - g_dtc_config->get_int_val("cache", "pre_purge_nodes", 0); - if (DTCGlobal::pre_purge_nodes_ < 0) { - DTCGlobal::pre_purge_nodes_ = 0; - } else if (DTCGlobal::pre_purge_nodes_ > 10000) { - DTCGlobal::pre_purge_nodes_ = 10000; - } - - RELATIVE_HOUR_CALCULATOR->set_base_hour( - g_dtc_config->get_int_val("cache", "RelativeYear", 2014)); - - log4cplus_info( - "Table %s: key/field# %d/%d, keysize %d", dbConfig->tblName, - TableDefinitionManager::instance()->get_cur_table_def()->key_fields(), - TableDefinitionManager::instance()->get_cur_table_def()->num_fields() + 1, - TableDefinitionManager::instance()->get_cur_table_def()->max_key_size()); - - return DTC_CODE_SUCCESS; +int init_config_info() +{ + // mkdir("/usr/local/dtc/stat", 0777); + // mkdir("/usr/local/dtc/data", 0777); + + g_hash_changing = g_dtc_config->get_int_val("cache", "HashChanging", 0); + g_target_new_hash = + g_dtc_config->get_int_val("cache", "TargetNewHash", 0); + + DTCGlobal::pre_alloc_nodegroup_count = + g_dtc_config->get_int_val("cache", "PreAllocNGNum", 1024); + DTCGlobal::pre_alloc_nodegroup_count = + DTCGlobal::pre_alloc_nodegroup_count <= 1 ? + 1 : + DTCGlobal::pre_alloc_nodegroup_count >= (1 << 12) ? + 1 : + DTCGlobal::pre_alloc_nodegroup_count; + + DTCGlobal::min_chunk_size_ = + g_dtc_config->get_int_val("cache", "MinChunkSize", 0); + if (DTCGlobal::min_chunk_size_ < 0) { + DTCGlobal::min_chunk_size_ = 0; + } + + DTCGlobal::pre_purge_nodes_ = + g_dtc_config->get_int_val("cache", "pre_purge_nodes", 0); + if (DTCGlobal::pre_purge_nodes_ < 0) { + DTCGlobal::pre_purge_nodes_ = 0; + } else if (DTCGlobal::pre_purge_nodes_ > 10000) { + DTCGlobal::pre_purge_nodes_ = 10000; + } + + RELATIVE_HOUR_CALCULATOR->set_base_hour( + g_dtc_config->get_int_val("cache", "RelativeYear", 2014)); + + log4cplus_info("Table %s: key/field# %d/%d, keysize %d", + dbConfig->tblName, + TableDefinitionManager::instance() + ->get_cur_table_def() + ->key_fields(), + TableDefinitionManager::instance() + ->get_cur_table_def() + ->num_fields() + + 1, + TableDefinitionManager::instance() + ->get_cur_table_def() + ->max_key_size()); + + return DTC_CODE_SUCCESS; } -void free_all_resource() { - // stop plugin - if (enable_plugin && init_plugin) { - plugin_stop(); - } - - DELETE(main_listener); - - if (g_buffer_multi_thread) { - g_buffer_multi_thread->interrupt(); - } - if (g_hot_backup_thread) { - g_hot_backup_thread->interrupt(); - } - if (g_datasource_thread) { - g_datasource_thread->interrupt(); - } - - if (g_remote_thread) { - g_remote_thread->interrupt(); - } - - if (g_main_thread) { - g_main_thread->interrupt(); - } - - StopTaskExecutor(); - - DELETE(g_buffer_process_ask_instance); - DELETE(g_data_connector_ask_instance); - DELETE(g_buffer_barrier_instance); - DELETE(g_key_route_ask_instance); - DELETE(g_connector_barrier_instance); - DELETE(g_buffer_bypass_ask_instance); - DELETE(g_hot_backup_ask_instance); - DELETE(g_remote_dtc_instance); - DELETE(g_black_hole_ask_instance); - DELETE(g_agent_hub_ask_instance); - DELETE(g_job_hub_ask_instance); - - DELETE(g_buffer_multi_thread); - DELETE(g_datasource_thread); - DELETE(g_remote_thread); - DELETE(g_main_thread); - DELETE(g_hot_backup_thread); - g_stat_mgr.stop_background_thread(); - log4cplus_info("--------%s-v%s END!--------", project_name, version); - daemon_cleanup(); +void free_all_resource() +{ + //stop plugin + if (enable_plugin && init_plugin) { + plugin_stop(); + } + + DELETE(main_listener); + + if (g_buffer_multi_thread) { + g_buffer_multi_thread->interrupt(); + } + if (g_hot_backup_thread) { + g_hot_backup_thread->interrupt(); + } + if (g_datasource_thread) { + g_datasource_thread->interrupt(); + } + + if (g_remote_thread) { + g_remote_thread->interrupt(); + } + + if (g_main_thread) { + g_main_thread->interrupt(); + } + + StopTaskExecutor(); + + DELETE(g_buffer_process_ask_instance); + DELETE(g_data_connector_ask_instance); + DELETE(g_buffer_barrier_instance); + DELETE(g_key_route_ask_instance); + DELETE(g_connector_barrier_instance); + DELETE(g_buffer_bypass_ask_instance); + DELETE(g_hot_backup_ask_instance); + DELETE(g_remote_dtc_instance); + DELETE(g_black_hole_ask_instance); + DELETE(g_agent_hub_ask_instance); + DELETE(g_job_hub_ask_instance); + + DELETE(g_buffer_multi_thread); + DELETE(g_datasource_thread); + DELETE(g_remote_thread); + DELETE(g_main_thread); + DELETE(g_hot_backup_thread); + g_stat_mgr.stop_background_thread(); + log4cplus_info("--------%s-v%s END!--------", project_name, version); + daemon_cleanup(); #if MEMCHECK - dump_non_delete(); - log4cplus_debug("memory allocated %lu virtual %lu", count_alloc_size(), - count_virtual_size()); + dump_non_delete(); + log4cplus_debug("memory allocated %lu virtual %lu", count_alloc_size(), + count_virtual_size()); #endif } \ No newline at end of file diff --git a/src/libs/common/config/config.cc b/src/libs/common/config/config.cc index edaa963..3cbe253 100644 --- a/src/libs/common/config/config.cc +++ b/src/libs/common/config/config.cc @@ -1,444 +1,484 @@ /* - * Copyright [2021] JD.com, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright [2021] JD.com, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include -#include -#include -#include #include +#include #include +#include +#include +#include +#include #include -#include +#include "mem_check.h" #include "config.h" #include "log/log.h" -#include "mem_check.h" -int str2int(const char *strval, int def) { - int ret_code = def; - if (isdigit(strval[0]) || (strval[0] == '-' && isdigit(strval[1]))) - return atoi(strval); - - if (!strcasecmp(strval, "On")) - ret_code = 1; - else if (!strcasecmp(strval, "Off")) - ret_code = 0; - else if (!strcasecmp(strval, "Yes")) - ret_code = 1; - else if (!strcasecmp(strval, "No")) - ret_code = 0; - else if (!strcasecmp(strval, "True")) - ret_code = 1; - else if (!strcasecmp(strval, "False")) - ret_code = 0; - else if (!strcasecmp(strval, "Enable")) - ret_code = 1; - else if (!strcasecmp(strval, "Disable")) - ret_code = 0; - else if (!strcasecmp(strval, "Enabled")) - ret_code = 1; - else if (!strcasecmp(strval, "Disabled")) - ret_code = 0; - - return ret_code; +int str2int(const char *strval, int def) +{ + int ret_code = def; + if (isdigit(strval[0]) || (strval[0] == '-' && isdigit(strval[1]))) + return atoi(strval); + + if (!strcasecmp(strval, "On")) + ret_code = 1; + else if (!strcasecmp(strval, "Off")) + ret_code = 0; + else if (!strcasecmp(strval, "Yes")) + ret_code = 1; + else if (!strcasecmp(strval, "No")) + ret_code = 0; + else if (!strcasecmp(strval, "True")) + ret_code = 1; + else if (!strcasecmp(strval, "False")) + ret_code = 0; + else if (!strcasecmp(strval, "Enable")) + ret_code = 1; + else if (!strcasecmp(strval, "Disable")) + ret_code = 0; + else if (!strcasecmp(strval, "Enabled")) + ret_code = 1; + else if (!strcasecmp(strval, "Disabled")) + ret_code = 0; + + return ret_code; } -int DTCConfig::Dump(const char *fn, bool dec) { - FILE *fp = fopen(fn, "w"); - if (fp == NULL) - return -1; - // fprintf(fp, "##### ORIGINAL FILE %s #####\n", filename_.c_str()); - for (YAML::const_iterator ite = table_config_.begin(); - ite != table_config_.end(); ++ite) { - YAML::Node inception_sec = ite->first; - std::string sec = inception_sec.as(); - fprintf(fp, "%s:\n", sec.c_str()); - YAML::Node key_map = ite->second; - for (YAML::const_iterator ite_map = key_map.begin(); - ite_map != key_map.end(); ++ite_map) { - YAML::Node key = ite_map->first; - YAML::Node value = ite_map->second; - std::string now_key = key.as(); - std::string now_value = value.as(); - if (dec == true) - fprintf(fp, "# %s NOT SET\n", now_key.c_str()); - if (dec == false) - fprintf(fp, " %s: %s\n", now_key.c_str(), now_value.c_str()); - } - } - fclose(fp); - return 0; +int DTCConfig::Dump(const char *fn, bool dec) +{ + FILE *fp = fopen(fn, "w"); + if (fp == NULL) + return -1; + //fprintf(fp, "##### ORIGINAL FILE %s #####\n", filename_.c_str()); + for (YAML::const_iterator ite = table_config_.begin(); + ite != table_config_.end(); ++ite) { + YAML::Node inception_sec = ite->first; + std::string sec = inception_sec.as(); + fprintf(fp, "%s:\n", sec.c_str()); + YAML::Node key_map = ite->second; + for (YAML::const_iterator ite_map = key_map.begin(); + ite_map != key_map.end(); ++ite_map) { + YAML::Node key = ite_map->first; + YAML::Node value = ite_map->second; + std::string now_key = key.as(); + std::string now_value = value.as(); + if (dec == true) + fprintf(fp, "# %s NOT SET\n", now_key.c_str()); + if (dec == false) + fprintf(fp, " %s: %s\n", now_key.c_str(), + now_value.c_str()); + } + } + fclose(fp); + return 0; } int DTCConfig::parse_buffered_config(char *buf, const char *fn, - const char *defsec, bool bakconfig) { - int ret_code = -1; - try { - if (defsec && strcmp(defsec, "cache") == 0) { - cache_config_ = YAML::Load(buf); - } else { - table_config_ = YAML::Load(buf); - } - ret_code = 0; - } catch (const YAML::Exception &e) { - printf("config file error:%s\n", e.what()); - return ret_code; - } - return; + const char *defsec, bool bakconfig) +{ + int ret_code = -1; + try { + printf("open config file:%s\n", fn); + if (defsec && strcmp(defsec, "cache") == 0) { + cache_config_ = YAML::Load(buf); + } else { + table_config_ = YAML::Load(buf); + } + ret_code = 0; + } catch (const YAML::Exception &e) { + printf("config file error:%s\n", e.what()); + return ret_code; + } + return; } -int DTCConfig::parse_config(const char *fn, const char *defsec, - bool bakconfig) { - int ret_code = -1; - - try { - printf("open config file:%s\n", fn); - if (strcmp(defsec, "cache") == 0) { - cache_config_ = YAML::LoadFile(fn); - } else { - table_config_ = YAML::LoadFile(fn); - } - ret_code = 0; - } catch (const YAML::Exception &e) { - printf("config file error:%s\n", e.what()); - return ret_code; - } - - if (bakconfig) { - char bak_config[1024]; - int err = 0; - snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn); - if (err == 0) - err = system(bak_config); - } - return ret_code; +int DTCConfig::parse_config(const char *fn, const char *defsec, bool bakconfig) +{ + int ret_code = -1; + + try { + printf("open config file:%s\n", fn); + if (strcmp(defsec, "cache") == 0) { + cache_config_ = YAML::LoadFile(fn); + } else { + table_config_ = YAML::LoadFile(fn); + } + ret_code = 0; + } catch (const YAML::Exception &e) { + printf("config file error:%s\n", e.what()); + return ret_code; + } + + if (bakconfig) { + char bak_config[1024]; + int err = 0; + snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn); + if (err == 0) + err = system(bak_config); + } + return ret_code; } -bool DTCConfig::has_section(const char *sec) { - YAML::Node inception = table_config_[sec]; - if (inception && inception.IsMap()) - return true; - else - return false; +bool DTCConfig::has_section(const char *sec) +{ + YAML::Node inception = table_config_[sec]; + if (inception && inception.IsMap()) + return true; + else + return false; } -bool DTCConfig::has_key(const char *sec, const char *key) { - if (!table_config_[sec]) - return false; +bool DTCConfig::has_key(const char *sec, const char *key) +{ + if (!table_config_[sec]) + return false; - YAML::Node inception = table_config_[sec][key]; - if (inception && inception.IsScalar()) - return true; - else - return false; + YAML::Node inception = table_config_[sec][key]; + if (inception && inception.IsScalar()) + return true; + else + return false; } /******************************************** * eg锛歡et_str_val("cache", "RemoteLogAddr") * 璇诲彇 conf/cache.conf涓璕emoteLogAdd鐨勫弬鏁 * ******************************************/ -const char *DTCConfig::get_str_val(const char *sec, const char *key) { - const char *val = NULL; - - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - - if (val == NULL) - return NULL; - - return val; +const char *DTCConfig::get_str_val(const char *sec, const char *key) +{ + const char *val = NULL; + + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + + if (val == NULL) + return NULL; + + return val; } -int DTCConfig::get_int_val(const char *sec, const char *key, int def) { - const char *val = NULL; - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - - if (val == NULL) - return def; - - return str2int(val, def); +int DTCConfig::get_int_val(const char *sec, const char *key, int def) +{ + const char *val = NULL; + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + + if (val == NULL) + return def; + + return str2int(val, def); } unsigned long long DTCConfig::get_size_val(const char *sec, const char *key, - unsigned long long def, char unit) { - const char *val = NULL; - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - - if (val == NULL || !isdigit(val[0])) - return def; - - const char *p; - double a = strtod(val, (char **)&p); - if (*p) - unit = *p; - switch (unit) { - case 'b': - break; - case 'B': - break; - case 'k': - a *= 1000; - break; - case 'K': - a *= 1 << 10; - break; - case 'm': - a *= 1000000; - break; - case 'M': - a *= 1 << 20; - break; - case 'g': - a *= 1000000000; - break; - case 'G': - a *= 1 << 30; - break; - case 't': - a *= 1000000000000LL; - break; - case 'T': - a *= 1ULL << 40; - break; - } - - return (unsigned long long)a; + unsigned long long def, char unit) +{ + const char *val = NULL; + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + + if (val == NULL || !isdigit(val[0])) + return def; + + const char *p; + double a = strtod(val, (char **)&p); + if (*p) + unit = *p; + switch (unit) { + case 'b': + break; + case 'B': + break; + case 'k': + a *= 1000; + break; + case 'K': + a *= 1 << 10; + break; + case 'm': + a *= 1000000; + break; + case 'M': + a *= 1 << 20; + break; + case 'g': + a *= 1000000000; + break; + case 'G': + a *= 1 << 30; + break; + case 't': + a *= 1000000000000LL; + break; + case 'T': + a *= 1ULL << 40; + break; + } + + return (unsigned long long)a; } int DTCConfig::get_idx_val(const char *sec, const char *key, - const char *const *array, int nDefault) { - const char *val = NULL; - if (strcmp(sec, "cache") == 0) { - if (cache_config_[sec]) { - if (cache_config_[sec][key]) { - std::string result = cache_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } else { - if (table_config_[sec]) { - if (table_config_[sec][key]) { - std::string result = table_config_[sec][key].as(); - if (result.length() > 0) { - val = result.c_str(); - } - } - } - } - if (val == NULL) - return nDefault; - - if (isdigit(val[0])) { - char *p; - int n = strtol(val, &p, 0); - if (*p == '\0') { - for (int i = 0; array[i]; ++i) { - if (n == i) - return i; - } - } - } - - for (int i = 0; array[i]; ++i) { - if (!strcasecmp(val, array[i])) - return i; - } - return -1; + const char *const *array, int nDefault) +{ + const char *val = NULL; + if (strcmp(sec, "cache") == 0) { + if (cache_config_[sec]) { + if (cache_config_[sec][key]) { + std::string result = cache_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } else { + if (table_config_[sec]) { + if (table_config_[sec][key]) { + std::string result = table_config_[sec][key] + .as(); + if (result.length() > 0) { + val = result.c_str(); + } + } + } + } + if (val == NULL) + return nDefault; + + if (isdigit(val[0])) { + char *p; + int n = strtol(val, &p, 0); + if (*p == '\0') { + for (int i = 0; array[i]; ++i) { + if (n == i) + return i; + } + } + } + + for (int i = 0; array[i]; ++i) { + if (!strcasecmp(val, array[i])) + return i; + } + return -1; } class AutoConfigSection : public AutoConfig { -private: - static pthread_mutex_t glock; - void GlobalLock(void) { pthread_mutex_lock(&glock); } - void GlobalUnlock(void) { pthread_mutex_unlock(&glock); } - -private: - DTCConfig *parent; - char *section; - // buf must have enough room place composed key name - char buf[256]; - char *last; - -public: - AutoConfigSection(DTCConfig *p, const char *sec); - ~AutoConfigSection(); - - virtual int get_int_val(const char *key, const char *inst, int def = 0); - virtual unsigned long long get_size_val(const char *key, const char *inst, - unsigned long long def = 0, - char unit = 0); - virtual int get_idx_val(const char *, const char *, const char *const *, - int = 0); - virtual const char *get_str_val(const char *key, const char *inst); - -private: - // return composed key, or vanilla key, always non-null - const char *findkey(const char *key, const char *inst); - // strip suffix digits - int stripnumber(void); - // strip suffix alphaphetic - int stripalpha(void); - // strip suffix punct - int strippunct(void); + private: + static pthread_mutex_t glock; + void GlobalLock(void) + { + pthread_mutex_lock(&glock); + } + void GlobalUnlock(void) + { + pthread_mutex_unlock(&glock); + } + + private: + DTCConfig *parent; + char *section; + // buf must have enough room place composed key name + char buf[256]; + char *last; + + public: + AutoConfigSection(DTCConfig *p, const char *sec); + ~AutoConfigSection(); + + virtual int get_int_val(const char *key, const char *inst, int def = 0); + virtual unsigned long long get_size_val(const char *key, + const char *inst, + unsigned long long def = 0, + char unit = 0); + virtual int get_idx_val(const char *, const char *, const char *const *, + int = 0); + virtual const char *get_str_val(const char *key, const char *inst); + + private: + // return composed key, or vanilla key, always non-null + const char *findkey(const char *key, const char *inst); + // strip suffix digits + int stripnumber(void); + // strip suffix alphaphetic + int stripalpha(void); + // strip suffix punct + int strippunct(void); }; pthread_mutex_t AutoConfigSection::glock = PTHREAD_MUTEX_INITIALIZER; -AutoConfigSection::AutoConfigSection(DTCConfig *p, const char *sec) { - this->parent = p; - this->section = STRDUP(sec); +AutoConfigSection::AutoConfigSection(DTCConfig *p, const char *sec) +{ + this->parent = p; + this->section = STRDUP(sec); +} + +AutoConfigSection::~AutoConfigSection() +{ + FREE_CLEAR(section); } -AutoConfigSection::~AutoConfigSection() { FREE_CLEAR(section); } - -int AutoConfigSection::stripnumber(void) { - int n = 0; - while (last >= buf && isdigit(*last)) { - last--; - n++; - } - last[1] = 0; - strippunct(); - return n; +int AutoConfigSection::stripnumber(void) +{ + int n = 0; + while (last >= buf && isdigit(*last)) { + last--; + n++; + } + last[1] = 0; + strippunct(); + return n; } -int AutoConfigSection::stripalpha(void) { - int n = 0; - while (last >= buf && isalpha(*last)) { - last--; - n++; - } - last[1] = 0; - strippunct(); - return n; +int AutoConfigSection::stripalpha(void) +{ + int n = 0; + while (last >= buf && isalpha(*last)) { + last--; + n++; + } + last[1] = 0; + strippunct(); + return n; } -int AutoConfigSection::strippunct(void) { - int n = 0; - while (last >= buf && *last != '@' && !isalnum(*last)) { - last--; - n++; - } - last[1] = 0; - return n; +int AutoConfigSection::strippunct(void) +{ + int n = 0; + while (last >= buf && *last != '@' && !isalnum(*last)) { + last--; + n++; + } + last[1] = 0; + return n; } -const char *AutoConfigSection::findkey(const char *key, const char *inst) { - snprintf(buf, sizeof(buf), "%s@%s", key, inst); - last = buf + strlen(buf) - 1; - strippunct(); +const char *AutoConfigSection::findkey(const char *key, const char *inst) +{ + snprintf(buf, sizeof(buf), "%s@%s", key, inst); + last = buf + strlen(buf) - 1; + strippunct(); - do { - if (parent->get_str_val(section, buf) != NULL) { - return buf; - } - } while (isdigit(*last) ? stripnumber() : stripalpha()); + do { + if (parent->get_str_val(section, buf) != NULL) { + return buf; + } + } while (isdigit(*last) ? stripnumber() : stripalpha()); - return key; + return key; } -int AutoConfigSection::get_int_val(const char *key, const char *inst, int def) { - int ret; - GlobalLock(); - ret = parent->get_int_val(section, findkey(key, inst), def); - GlobalUnlock(); - return ret; +int AutoConfigSection::get_int_val(const char *key, const char *inst, int def) +{ + int ret; + GlobalLock(); + ret = parent->get_int_val(section, findkey(key, inst), def); + GlobalUnlock(); + return ret; } unsigned long long AutoConfigSection::get_size_val(const char *key, - const char *inst, - unsigned long long def, - char unit) { - unsigned long long ret; - GlobalLock(); - ret = parent->get_size_val(section, findkey(key, inst), def, unit); - GlobalUnlock(); - return ret; + const char *inst, + unsigned long long def, + char unit) +{ + unsigned long long ret; + GlobalLock(); + ret = parent->get_size_val(section, findkey(key, inst), def, unit); + GlobalUnlock(); + return ret; } int AutoConfigSection::get_idx_val(const char *key, const char *inst, - const char *const *idxval, int def) { - int ret; - GlobalLock(); - ret = parent->get_idx_val(section, findkey(key, inst), idxval, def); - GlobalUnlock(); - return ret; + const char *const *idxval, int def) +{ + int ret; + GlobalLock(); + ret = parent->get_idx_val(section, findkey(key, inst), idxval, def); + GlobalUnlock(); + return ret; } -const char *AutoConfigSection::get_str_val(const char *key, const char *inst) { - const char *ret; - GlobalLock(); - ret = parent->get_str_val(section, findkey(key, inst)); - GlobalUnlock(); - return ret; +const char *AutoConfigSection::get_str_val(const char *key, const char *inst) +{ + const char *ret; + GlobalLock(); + ret = parent->get_str_val(section, findkey(key, inst)); + GlobalUnlock(); + return ret; } -AutoConfig *DTCConfig::get_auto_config_instance(const char *section) { - AutoConfigSection *inst; - NEW(AutoConfigSection(this, section), inst); - return inst; +AutoConfig *DTCConfig::get_auto_config_instance(const char *section) +{ + AutoConfigSection *inst; + NEW(AutoConfigSection(this, section), inst); + return inst; } -- Gitee From ee09f85632bdeac28622e9254fd34ae28759da02 Mon Sep 17 00:00:00 2001 From: wuxz <1067764612@qq.com> Date: Fri, 27 Aug 2021 14:42:28 +0800 Subject: [PATCH 36/39] fix: CMakeLists --- CMakeLists.txt | 6 ++++++ src/CMakeLists.txt | 19 ++++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..233d309 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +CMAKE_MINIMUM_REQUIRED (VERSION 2.8) +PROJECT(dtc) +ADD_SUBDIRECTORY(./src) + +#if you want to uninstall libraries, you should enter "build" folder, and use this command +# cat install_manifest.txt | sudo xargs rm \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d5914b..8f8b019 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,7 @@ -cmake_minimum_required (VERSION 2.8) -project (dtc) - -add_subdirectory(./agent) -add_subdirectory(./configcenter) -add_subdirectory(./libs) -add_subdirectory(./devel) -add_subdirectory(./daemons) -add_subdirectory(./core) +ADD_SUBDIRECTORY(./agent) +ADD_SUBDIRECTORY(./configcenter) +ADD_SUBDIRECTORY(./libs) +ADD_SUBDIRECTORY(./devel) +ADD_SUBDIRECTORY(./daemons) +ADD_SUBDIRECTORY(./core) #add_subdirectory(./connector) - - -#鎯冲嵏杞絤ake install瀹夎鐨勫簱锛岃繘鍏ュ埌build鏂囦欢澶癸紝鎵ц -# cat install_manifest.txt | sudo xargs rm \ No newline at end of file -- Gitee From 712103d29ccb6a2ae8b542206c738dc710706f4a Mon Sep 17 00:00:00 2001 From: wuxz <1067764612@qq.com> Date: Fri, 27 Aug 2021 16:50:46 +0800 Subject: [PATCH 37/39] fix: CMakeLists.txt --- CMakeLists.txt | 1 + src/agent/CMakeLists.txt | 2 +- src/configcenter/ca_api/CMakeLists.txt | 2 +- src/connector/CMakeLists.txt | 2 +- src/core/CMakeLists.txt | 16 ++++++++-------- src/daemons/CMakeLists.txt | 22 +++++++++++----------- src/devel/cpp/CMakeLists.txt | 15 ++++++--------- src/libs/common/CMakeLists.txt | 8 ++++---- src/libs/stat/CMakeLists.txt | 16 ++++++++-------- 9 files changed, 41 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 233d309..4ec79ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.8) PROJECT(dtc) + ADD_SUBDIRECTORY(./src) #if you want to uninstall libraries, you should enter "build" folder, and use this command diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt index 7cd2c4a..3b26eca 100644 --- a/src/agent/CMakeLists.txt +++ b/src/agent/CMakeLists.txt @@ -1,5 +1,5 @@ #璁剧疆搴撴枃浠惰緭鍑鸿矾寰 -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/agent) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/agent) IF("${GPROF}" EQUAL 1) ADD_COMPILE_OPTIONS(-pg) diff --git a/src/configcenter/ca_api/CMakeLists.txt b/src/configcenter/ca_api/CMakeLists.txt index e9b84f8..cc7d6cb 100644 --- a/src/configcenter/ca_api/CMakeLists.txt +++ b/src/configcenter/ca_api/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/configcenter/ca_api) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/configcenter/ca_api) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I INCLUDE_DIRECTORIES(.) diff --git a/src/connector/CMakeLists.txt b/src/connector/CMakeLists.txt index b0a72fd..b7d6a12 100644 --- a/src/connector/CMakeLists.txt +++ b/src/connector/CMakeLists.txt @@ -1,5 +1,5 @@ #璁剧疆搴撴枃浠惰緭鍑鸿矾寰 -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/connector) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/connector) IF(CMAKE_COMPILER_IS_GNUCXX) ADD_COMPILE_OPTIONS(-std=gnu++11) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 02db421..2da6c9f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,7 +1,7 @@ #璁剧疆搴撴枃浠惰緭鍑鸿矾寰 -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/core) #璁剧疆鍙墽琛屾枃浠惰緭鍑鸿矾寰 -SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/core) +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/core) if(CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-std=gnu++11) @@ -28,12 +28,12 @@ INCLUDE_DIRECTORIES( #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L LINK_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs - ${PROJECT_SOURCE_DIR}/libs/zlib/lib/ - ${PROJECT_SOURCE_DIR}/libs/common - ${PROJECT_SOURCE_DIR}/libs/stat - ${PROJECT_SOURCE_DIR}/daemons) + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/src/libs/zlib/lib/ + ${PROJECT_SOURCE_DIR}/src/libs/common + ${PROJECT_SOURCE_DIR}/src/libs/stat + ${PROJECT_SOURCE_DIR}/src/daemons) #娣诲姞閾炬帴搴擄紝鐩稿綋浜巊cc -l LINK_LIBRARIES(liblog4cplus.a) diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index f729c53..b0caf01 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -1,5 +1,5 @@ -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) -SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/daemons) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/daemons) +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/daemons) if(CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-std=gnu++11) @@ -7,18 +7,18 @@ endif(CMAKE_COMPILER_IS_GNUCXX) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I INCLUDE_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/daemons - ${PROJECT_SOURCE_DIR}/libs/common - ${PROJECT_SOURCE_DIR}/libs/stat - ${PROJECT_SOURCE_DIR}/libs/log4cplus/include - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) + ${PROJECT_SOURCE_DIR}/src/daemons + ${PROJECT_SOURCE_DIR}/src/libs/common + ${PROJECT_SOURCE_DIR}/src/libs/stat + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/include + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/include) #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L LINK_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs - ${PROJECT_SOURCE_DIR}/libs/common - ${PROJECT_SOURCE_DIR}/libs/stat) + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/src/libs/common + ${PROJECT_SOURCE_DIR}/src/libs/stat) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 FILE(GLOB_RECURSE SRC_LIST1 ./*.cc ./*.c) diff --git a/src/devel/cpp/CMakeLists.txt b/src/devel/cpp/CMakeLists.txt index f739dba..402d4f3 100644 --- a/src/devel/cpp/CMakeLists.txt +++ b/src/devel/cpp/CMakeLists.txt @@ -1,6 +1,6 @@ #璁剧疆搴撴枃浠惰緭鍑鸿矾寰 -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/devel/cpp) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/devel/cpp) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 FILE(GLOB SRC_LIST1 ./*.c) @@ -33,11 +33,11 @@ INCLUDE_DIRECTORIES( #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L LINK_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs - ${PROJECT_SOURCE_DIR}/libs/zlib/lib/ - ${PROJECT_SOURCE_DIR}/libs/common - ${PROJECT_SOURCE_DIR}/configcenter/ca_api/) + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/src/libs/zlib/lib/ + ${PROJECT_SOURCE_DIR}/src/libs/common + ${PROJECT_SOURCE_DIR}/src/configcenter/ca_api/) #閾炬帴鐩爣搴 LINK_LIBRARIES(dl) @@ -58,6 +58,3 @@ ADD_LIBRARY(dtc.pic SHARED ${SRC_LIST1} ${SRC_LIST2}) #璁剧疆make install 瀹夎璺緞 INSTALL(TARGETS dtc.2 LIBRARY DESTINATION /usr/lib/) -# SET_TARGET_PROPERTIES(dtc_static PROPERTIES OUTPUT_NAME "dtc") -# SET_TARGET_PROPERTIES (dtc_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) -# SET_TARGET_PROPERTIES (dtc PROPERTIES CLEAN_DIRECT_OUTPUT 1) \ No newline at end of file diff --git a/src/libs/common/CMakeLists.txt b/src/libs/common/CMakeLists.txt index 26bdc9a..b7b2413 100644 --- a/src/libs/common/CMakeLists.txt +++ b/src/libs/common/CMakeLists.txt @@ -1,5 +1,5 @@ #璁剧疆搴撴枃浠惰緭鍑鸿矾寰 -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/common) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/libs/common) IF(CMAKE_COMPILER_IS_GNUCXX) ADD_COMPILE_OPTIONS(-std=gnu++11) @@ -20,9 +20,9 @@ INCLUDE_DIRECTORIES ( #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L LINK_DIRECTORIES ( - ${PROJECT_SOURCE_DIR}/libs/zlib/lib/libz64.a - ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/src/libs/zlib/lib/libz64.a + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs ) #娣诲姞閾炬帴搴擄紝鐩稿綋浜巊cc -l diff --git a/src/libs/stat/CMakeLists.txt b/src/libs/stat/CMakeLists.txt index 66f3ff5..37e6253 100644 --- a/src/libs/stat/CMakeLists.txt +++ b/src/libs/stat/CMakeLists.txt @@ -1,19 +1,19 @@ -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/stat) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/libs/stat) if(CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-std=gnu++11) endif(CMAKE_COMPILER_IS_GNUCXX) #娣诲姞澶存枃浠舵悳绱㈣矾寰勶紝鐩稿綋浜巊cc -I INCLUDE_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/libs/stat - ${PROJECT_SOURCE_DIR}/libs/common - ${PROJECT_SOURCE_DIR}/libs/log4cplus/include - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/include) + ${PROJECT_SOURCE_DIR}/src/libs/stat + ${PROJECT_SOURCE_DIR}/src/libs/common + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/include + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/include) #娣诲姞.so/.a鏂囦欢鎼滅储璺緞锛岀浉褰撲簬gcc -L LINK_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs - ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs - ${PROJECT_SOURCE_DIR}/libs/common) + ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs + ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs + ${PROJECT_SOURCE_DIR}/src/libs/common) #鎶婂綋鍓嶇洰褰曚笅鐨勬簮鏂囦欢鍒楄〃瀛樻斁鍒板彉閲廠RC_LIST1閲 FILE(GLOB_RECURSE SRC_LIST1 ./*.cc ./*.c) -- Gitee From 393af4937fb077f5431f8a0cc678ecc480c85d9e Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 17:15:06 +0800 Subject: [PATCH 38/39] 1 --- conf/table.yaml | 12 +- dockerfiles/sdk-cpp/dockerfile | 10 +- test/allcase/Makefile | 38 -- test/allcase/dtcapi.h | 1019 -------------------------------- test/allcase/test.cpp | 410 ------------- test/auto_test.cpp | 391 ++++++++++++ 6 files changed, 402 insertions(+), 1478 deletions(-) delete mode 100755 test/allcase/Makefile delete mode 100755 test/allcase/dtcapi.h delete mode 100755 test/allcase/test.cpp create mode 100755 test/auto_test.cpp diff --git a/conf/table.yaml b/conf/table.yaml index cf4417a..38be91f 100755 --- a/conf/table.yaml +++ b/conf/table.yaml @@ -1,5 +1,5 @@ DB_DEFINE: - DbName: test + DbName: dtc_opensource DbNum: (1,1) dbMax: 1 MachineNum: 1 @@ -14,8 +14,8 @@ MACHINE1: CommitProcs: 10 DbIdx: 0 DbAddr: 127.0.0.1:3306 - DbUser: root - DbPass: DTC@ecc2014 + DbUser: username + DbPass: password TABLE_DEFINE: TableName: Table_Test @@ -32,14 +32,14 @@ FIELD1: FIELD2: FieldName: name - FieldType: 4 - FieldSize: 255 + FieldType: 5 + FieldSize: 50 UniqField: 0 FIELD3: FieldName: city FieldType: 4 - FieldSize: 255 + FieldSize: 50 UniqField: 0 FIELD4: diff --git a/dockerfiles/sdk-cpp/dockerfile b/dockerfiles/sdk-cpp/dockerfile index 3955d8c..a9b0d6a 100644 --- a/dockerfiles/sdk-cpp/dockerfile +++ b/dockerfiles/sdk-cpp/dockerfile @@ -1,4 +1,4 @@ -FROM centos:centos7.2.1511 +FROM centos:centos8 COPY start.sh /root/start.sh @@ -10,9 +10,9 @@ RUN ln -sf /usr/lib/$sofile /usr/lib/libdtc.so.1 && \ /sbin/ldconfig -v #cpp test -#RUN mkdir -p /usr/local/sdk-cpp -#COPY ../../tests/get.cc /usr/local/sdk-cpp/get.cc -#COPY ../../tests/insert.cc /usr/local/sdk-cpp/insert.cc -#COPY ../../tests/build.sh /usr/local/sdk-cpp/build.sh +RUN mkdir -p /usr/local/sdk-cpp +COPY ../../tests/get.cc /usr/local/sdk-cpp/get.cc +COPY ../../tests/insert.cc /usr/local/sdk-cpp/insert.cc +COPY ../../tests/build.sh /usr/local/sdk-cpp/build.sh CMD ["/bin/bash", "/root/start.sh"] \ No newline at end of file diff --git a/test/allcase/Makefile b/test/allcase/Makefile deleted file mode 100755 index 09a703d..0000000 --- a/test/allcase/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -LIB = ../../libdtc.so - -OUTPUT = test - -SOURCES = test.cpp - - -OBJECTS= test.o - CPPFLAGS = -g -O -Wall -fPIC -DMACROFOR64BIT -Wl,--no-undefined -Xlinker -zmuldefs - CFLAGS = $(CPPFLAGS) - -all:$(OUTPUT) - -.SUFFIXES: .o .cpp - .cpp.o: - $(CXX) $(CPPFLAGS) $(INCLUDE) -c $(filter %.cpp, $^) - -.o: - $(CXX) $(CPPFLAGS) $(INCLUDE) -o $@ $^ - -$(OUTPUT): $(OBJECTS) - $(CXX) $(CFLAGS) -fPIC -o $@ $^ $(LIB) - - -clean: - rm -f *.o *.so *.~ *.bak - rm -f $(OUTPUT) - -install: - cp -f $(OUTPUT) $(INSTALL_PATH) - -dep: - mkdep -p$(VPATH) $(INCLUDE) $(SOURCES) > .depend - -ifneq ($(wildcard .depend),) - include .depend -endif - diff --git a/test/allcase/dtcapi.h b/test/allcase/dtcapi.h deleted file mode 100755 index 93ea247..0000000 --- a/test/allcase/dtcapi.h +++ /dev/null @@ -1,1019 +0,0 @@ -#ifndef __DTC_API_H__ -#define __DTC_API_H__ - -#include -#include -#include -#include - -#define IP_LENGHT 16 - -namespace DTC { - - typedef struct route_node - { - int bid; - int port; - int status; - int weight; - char ip[IP_LENGHT]; - }ROUTE_NODE; - - class Server; - class ServerPool; - class Request; - class Result; - - const int kRequestSvrAdmin = 3; - const int kRequestGet = 4; - const int kRequestPurge = 5; - const int kRequestInsert = 6; - const int kRequestUpdate = 7; - const int kRequestDelete = 8; - const int kRequestReplace = 12; - const int kRequestFlush = 13; - const int kRequestInvalidate = 14; - - //mem monior Request;2014/06/6;by seanzheng - const int kRequestMonitor = 15; - - // sub-code of admin cmd - const int RegisterHB = 1; - const int LogoutHB = 2; - const int GetKeyList = 3; - const int GetUpdateKey = 4; - const int GetRawData = 5; - const int ReplaceRawData = 6; - const int AdjustLRU = 7; - const int VerifyHBT = 8; - const int GetHBTime = 9; - const int kSetReadOnly = 10; - const int kSetReadWrite = 11; - const int kQueryBinlogID = 12; - const int kNodeHandleChange = 13; - const int Migrate = 14; - const int kReloadClusterNodeList = 15; - const int kSetClusterNodeState = 16; - const int kChangeNodeAddress = 17; - const int kGetClusterState = 18; - const int kPurgeForHit = 19; - const int ClearCache = 21; - const int ColExpandStatus = 24; - const int kColExpand = 25; - const int ColExpandDone = 26; - const int ColExpandKey = 27; - - const int kKeyTypeNone = 0; // undefined - const int kKeyTypeInt = 1; // Signed Integer - const int kKeyTypeString = 4; // String, case insensitive, null ended - - const int kFieldTypeNone = 0; // undefined - const int kFieldTypeSigned = 1; // Signed Integer - const int kFieldTypeUnsigned = 2; // Unsigned Integer - const int kFieldTypeFloat = 3; // float - const int kFieldTypeString = 4; // String, case insensitive, null ended - const int kFieldTypeBinary = 5; // binary - - int set_key_value_max(unsigned int count); // 璁剧疆鎵归噺鎿嶄綔涓娆℃渶澶氬灏戜釜key(榛樿鏈澶32涓) -#ifndef WIN32 - void write_log (int level, - const char*file, const char *func, int lineno, - const char *fmt, ...) - __attribute__((format(printf,5,6))); -#endif - - class Result; - class Server { - private: - void *addr_; - long check; - public: - friend class Request; - friend class Result; - friend class ServerPool; - friend class QOSServerPool; - - Server(void); - ~Server(void); - Server(const Server &); - void clone_table_define(const Server& source); - int set_address(const char *host, const char *port=0); - int set_table_name(const char *); - //for compress - void set_compress_level(int); - //get address and tablename set by user - const char * get_address(void) const; - const char * get_table_name(void) const; - //get address and tablename set by dtc frame,for plugin only; - const char * get_server_address(void) const; - const char * get_server_table_name(void) const; - int int_key(void); - int binary_key(void); - int string_key(void); - int add_key(const char* name, int type); - int get_field_type(const char* name); - const char *get_error_message(void) const; - void SetTimeout(int); - void set_timeout(int); - int connect(void); - void close(void); - int ping(void); - void auto_ping(void); - void set_fd(int); // UNSUPPORTED API - void set_auto_Update_table(bool autoUpdate); - void set_auto_reconnect(int auto_reconnect); - int decode_packet(Result &, const char *, int); - int check_packet_size(const char *, int); - - void set_accesskey(const char *token); - - public: - void increase_error_count_(); - uint64_t get_error_count(); - void clear_error_count(); - - void increase_remove_count(); - int get_remove_count(); - void clear_remove_count(); - - void increase_total_request(); - uint64_t get_total_request(); - void clear_total_request(); - - void add_total_elaps(uint64_t iElaps); - uint64_t get_total_elaps(); - void clear_total_elaps(); - }; - - class DTCQosServer; - - class DTCServers - { - public: - DTCServers(); - ~DTCServers(); - - private: - DTCServers(const DTCServers&); - DTCServers& operator=(const DTCServers&); - - public: - int set_route_list(std::vector& ip_list); - void set_idc_no(int IDCNo); - Server* get_server(); - - int set_accesskey(const char *token); - int set_table_name(const char *tableName); - /* - Signed=1, // Signed Integer - String=4, // String, case insensitive, null ended - Binary=5, // opaque binary data - */ - int set_key_type(int type); - void set_agenttime(int t); - void set_timeout(int n); - std::string get_error_msg(); - - private: - int is_server_has_existed(ROUTE_NODE& ip); - int construct_servers(); - int construct_servers2(std::vector& IPList); - void disorder_list(int *tmpBuckets, int size); - int construct_balance_buckets(); - int refresh_balance_buckets(uint64_t ); - void remove_server_from_buckets(uint64_t ); - Server* get_one_server_from_buckets(); - void set_error_msg(int err, std::string from, std::string msg); - - private: - int m_time_out; - int m_agent_time; - int m_key_type; - char* m_table_name; - std::string m_access_token; - std::string m_err_msg; - - private: - bool m_set_route; - bool m_constructed_by_set_i_ps; - int m_bid; - int m_idc_no; - int m_buckets_pos; - int m_balance_bucket_size; - uint64_t m_bid_version; - uint64_t m_last_get_ca_time; - uint64_t m_refresh_buckets_time; - uint64_t m_remove_buckets_time; - int* m_load_balance_buckets; - DTCQosServer* m_qos_severs; - std::vector m_ip_list; - }; - - class Request { - private: - void *addr_; - long check; - Request(const Request &); - public: - friend class Server; - friend class Result; - friend class ServerPool; - - Request(Server *srv, int op); - Request(void); - ~Request(void); - void Reset(void); - void Reset(int); - int attach_server(Server *srv); - - void set_admin_code(int code); - void set_hotbackup_id(long long); - void set_master_hotbackup_timestamp(long long); - void set_slave_hotbackup_timestamp(long long); - -#define _API_DEFINE_LONG_(op, t) int op(const char *n, t a) { return op(n, (long long)a); } -#define _API_DEFINE_FLOAT_(op, t) int op(const char *n, t a) { return op(n, (double)a); } - int need(const char *); - int need(const char *, int); - int get_field_type(const char*); - void no_cache(void); - void no_next_server(void); - void limit(unsigned int, unsigned int); - int EQ(const char *, long long); - int NE(const char *, long long); - int LT(const char *, long long); - int LE(const char *, long long); - int GT(const char *, long long); - int GE(const char *, long long); - int EQ(const char *, const char *); - int NE(const char *, const char *); - int EQ(const char *, const char *, int); - int NE(const char *, const char *, int); - - _API_DEFINE_LONG_(EQ, unsigned long long); - _API_DEFINE_LONG_(EQ, long); - _API_DEFINE_LONG_(EQ, unsigned long); - _API_DEFINE_LONG_(EQ, int); - _API_DEFINE_LONG_(EQ, unsigned int); - _API_DEFINE_LONG_(EQ, short); - _API_DEFINE_LONG_(EQ, unsigned short); - _API_DEFINE_LONG_(EQ, char); - _API_DEFINE_LONG_(EQ, unsigned char); - - _API_DEFINE_LONG_(NE, unsigned long long); - _API_DEFINE_LONG_(NE, long); - _API_DEFINE_LONG_(NE, unsigned long); - _API_DEFINE_LONG_(NE, int); - _API_DEFINE_LONG_(NE, unsigned int); - _API_DEFINE_LONG_(NE, short); - _API_DEFINE_LONG_(NE, unsigned short); - _API_DEFINE_LONG_(NE, char); - _API_DEFINE_LONG_(NE, unsigned char); - - _API_DEFINE_LONG_(GT, unsigned long long); - _API_DEFINE_LONG_(GT, long); - _API_DEFINE_LONG_(GT, unsigned long); - _API_DEFINE_LONG_(GT, int); - _API_DEFINE_LONG_(GT, unsigned int); - _API_DEFINE_LONG_(GT, short); - _API_DEFINE_LONG_(GT, unsigned short); - _API_DEFINE_LONG_(GT, char); - _API_DEFINE_LONG_(GT, unsigned char); - - _API_DEFINE_LONG_(GE, unsigned long long); - _API_DEFINE_LONG_(GE, long); - _API_DEFINE_LONG_(GE, unsigned long); - _API_DEFINE_LONG_(GE, int); - _API_DEFINE_LONG_(GE, unsigned int); - _API_DEFINE_LONG_(GE, short); - _API_DEFINE_LONG_(GE, unsigned short); - _API_DEFINE_LONG_(GE, char); - _API_DEFINE_LONG_(GE, unsigned char); - - _API_DEFINE_LONG_(LT, unsigned long long); - _API_DEFINE_LONG_(LT, long); - _API_DEFINE_LONG_(LT, unsigned long); - _API_DEFINE_LONG_(LT, int); - _API_DEFINE_LONG_(LT, unsigned int); - _API_DEFINE_LONG_(LT, short); - _API_DEFINE_LONG_(LT, unsigned short); - _API_DEFINE_LONG_(LT, char); - _API_DEFINE_LONG_(LT, unsigned char); - - _API_DEFINE_LONG_(LE, unsigned long long); - _API_DEFINE_LONG_(LE, long); - _API_DEFINE_LONG_(LE, unsigned long); - _API_DEFINE_LONG_(LE, int); - _API_DEFINE_LONG_(LE, unsigned int); - _API_DEFINE_LONG_(LE, short); - _API_DEFINE_LONG_(LE, unsigned short); - _API_DEFINE_LONG_(LE, char); - _API_DEFINE_LONG_(LE, unsigned char); - - int Set(const char *, long long); - int OR(const char *, long long); - int Add(const char *, long long); - int Sub(const char *, long long); - int Set(const char *, double); - int Add(const char *, double); - int Sub(const char *, double); - int Set(const char *, const char *); - int Set(const char *, const char *, int); - - //just for compress,only support binary field - int compress_set(const char *, const char *, int); - //just compress and set. Don't need compressflag - int compress_set_force(const char *, const char *, int); - - //bits op - int set_multi_bits(const char *, int, int, unsigned int); - int set_bit (const char *f, int o) { return set_multi_bits(f, o, 1, 1);} - int clear_bit(const char *f, int o) { return set_multi_bits(f, o, 1, 0);} - - _API_DEFINE_LONG_(Set, unsigned long long); - _API_DEFINE_LONG_(Set, long); - _API_DEFINE_LONG_(Set, unsigned long); - _API_DEFINE_LONG_(Set, int); - _API_DEFINE_LONG_(Set, unsigned int); - _API_DEFINE_LONG_(Set, short); - _API_DEFINE_LONG_(Set, unsigned short); - _API_DEFINE_LONG_(Set, char); - _API_DEFINE_LONG_(Set, unsigned char); - _API_DEFINE_FLOAT_(Set, float); - _API_DEFINE_FLOAT_(Set, long double); - - _API_DEFINE_LONG_(OR, unsigned long long); - _API_DEFINE_LONG_(OR, long); - _API_DEFINE_LONG_(OR, unsigned long); - _API_DEFINE_LONG_(OR, int); - _API_DEFINE_LONG_(OR, unsigned int); - _API_DEFINE_LONG_(OR, short); - _API_DEFINE_LONG_(OR, unsigned short); - - _API_DEFINE_LONG_(Add, unsigned long long); - _API_DEFINE_LONG_(Add, long); - _API_DEFINE_LONG_(Add, unsigned long); - _API_DEFINE_LONG_(Add, int); - _API_DEFINE_LONG_(Add, unsigned int); - _API_DEFINE_LONG_(Add, short); - _API_DEFINE_LONG_(Add, unsigned short); - _API_DEFINE_LONG_(Add, char); - _API_DEFINE_LONG_(Add, unsigned char); - _API_DEFINE_FLOAT_(Add, float); - _API_DEFINE_FLOAT_(Add, long double); - - _API_DEFINE_LONG_(Sub, unsigned long long); - _API_DEFINE_LONG_(Sub, long); - _API_DEFINE_LONG_(Sub, unsigned long); - _API_DEFINE_LONG_(Sub, int); - _API_DEFINE_LONG_(Sub, unsigned int); - _API_DEFINE_LONG_(Sub, short); - _API_DEFINE_LONG_(Sub, unsigned short); - _API_DEFINE_LONG_(Sub, char); - _API_DEFINE_LONG_(Sub, unsigned char); - _API_DEFINE_FLOAT_(Sub, float); - _API_DEFINE_FLOAT_(Sub, long double); -#undef _API_DEFINE_LONG_ - - void unset_key(void); - int set_key(long long); - int set_key(const char *); - int set_key(const char *, int); -#define _API_DEFINE_LONG_(t) int set_key(t a) { return set_key((long long)a); } - _API_DEFINE_LONG_(unsigned long long); - _API_DEFINE_LONG_(long); - _API_DEFINE_LONG_(unsigned long); - _API_DEFINE_LONG_(int); - _API_DEFINE_LONG_(unsigned int); - _API_DEFINE_LONG_(short); - _API_DEFINE_LONG_(unsigned short); - _API_DEFINE_LONG_(char); - _API_DEFINE_LONG_(unsigned char); -#undef _API_DEFINE_LONG_ - - int add_key_value(const char* name, long long v); - int add_key_value(const char* name, const char *str); - int add_key_value(const char* name, const char *ptr, int len); -#define _API_DEFINE_LONG_(t) int add_key_value(const char* name, t a) { return add_key_value(name, (long long)a); } - _API_DEFINE_LONG_(unsigned long long); - _API_DEFINE_LONG_(long); - _API_DEFINE_LONG_(unsigned long); - _API_DEFINE_LONG_(int); - _API_DEFINE_LONG_(unsigned int); - _API_DEFINE_LONG_(short); - _API_DEFINE_LONG_(unsigned short); - _API_DEFINE_LONG_(char); - _API_DEFINE_LONG_(unsigned char); -#undef _API_DEFINE_LONG_ - - Result *do_execute(void); - Result *do_execute(long long); - Result *do_execute(const char *); - Result *do_execute(const char *, int); - -#define _API_DEFINE_LONG_(t) Result *do_execute(t a) { return do_execute((long long)a); } - _API_DEFINE_LONG_(unsigned long long); - _API_DEFINE_LONG_(long); - _API_DEFINE_LONG_(unsigned long); - _API_DEFINE_LONG_(int); - _API_DEFINE_LONG_(unsigned int); - _API_DEFINE_LONG_(short); - _API_DEFINE_LONG_(unsigned short); - _API_DEFINE_LONG_(char); - _API_DEFINE_LONG_(unsigned char); -#undef _API_DEFINE_LONG_ - - int do_execute(Result&); - int do_execute(Result&, long long); - int do_execute(Result&, const char *); - int do_execute(Result&, const char *, int); - -#define _API_DEFINE_LONG_(t) int do_execute(Result &r, t a) { return do_execute(r, (long long)a); } - _API_DEFINE_LONG_(unsigned long long); - _API_DEFINE_LONG_(long); - _API_DEFINE_LONG_(unsigned long); - _API_DEFINE_LONG_(int); - _API_DEFINE_LONG_(unsigned int); - _API_DEFINE_LONG_(short); - _API_DEFINE_LONG_(unsigned short); - _API_DEFINE_LONG_(char); - _API_DEFINE_LONG_(unsigned char); -#undef _API_DEFINE_LONG_ - - int encode_packet(char *&, int&, long long&); - int encode_packet(char *&, int&, long long&, long long); - int encode_packet(char *&, int&, long long&, const char *); - int encode_packet(char *&, int&, long long&, const char *, int); - -#define _API_DEFINE_LONG_(t) int encode_packet(char *&p, int &l, long long &m, t a) { return encode_packet(p,l,m,(long long)a); } - _API_DEFINE_LONG_(unsigned long long); - _API_DEFINE_LONG_(long); - _API_DEFINE_LONG_(unsigned long); - _API_DEFINE_LONG_(int); - _API_DEFINE_LONG_(unsigned int); - _API_DEFINE_LONG_(short); - _API_DEFINE_LONG_(unsigned short); - _API_DEFINE_LONG_(char); - _API_DEFINE_LONG_(unsigned char); -#undef _API_DEFINE_LONG_ - - int set_cache_id(long long); -#define _API_DEFINE_LONG_(t) int set_cache_id(t a) {return set_cache_id((long long)a);} - _API_DEFINE_LONG_(unsigned long long); - _API_DEFINE_LONG_(long); - _API_DEFINE_LONG_(unsigned long); - _API_DEFINE_LONG_(int); - _API_DEFINE_LONG_(unsigned int); - _API_DEFINE_LONG_(short); - _API_DEFINE_LONG_(unsigned short); - _API_DEFINE_LONG_(char); - _API_DEFINE_LONG_(unsigned char); -#undef _API_DEFINE_LONG_ - const char *get_error_message(void) const; - - //鏃犳簮妯″紡瓒呮椂鏃堕棿 add by xuxinxin, 2014/12/09 - int set_expire_time(const char* key, int time); - int get_expire_time(const char* key); - }; - - class GetRequest : public Request { - public: - GetRequest(Server *srv): Request(srv, kRequestGet) {} - GetRequest(): Request((Server *)0, kRequestGet) {} - }; - - class InsertRequest : public Request { - public: - InsertRequest(Server *srv) : Request(srv, kRequestInsert) {} - InsertRequest() : Request((Server *)0, kRequestInsert) {} - }; - - class DeleteRequest : public Request { - public: - DeleteRequest(Server *srv) : Request(srv, kRequestDelete) {} - DeleteRequest() : Request((Server *)0, kRequestDelete) {} - }; - - class UpdateRequest : public Request { - public: - UpdateRequest(Server *srv) : Request(srv, kRequestUpdate) {} - UpdateRequest() : Request((Server *)0, kRequestUpdate) {} - }; - - class PurgeRequest : public Request { - public: - PurgeRequest(Server *srv) : Request(srv, kRequestPurge) {} - PurgeRequest() : Request((Server *)0, kRequestPurge) {} - }; - - class ReplaceRequest:public Request { - public: - ReplaceRequest(Server *srv) : Request(srv, kRequestReplace) {} - ReplaceRequest() : Request((Server *)0, kRequestReplace) {} - }; - - class FlushRequest : public Request { - public: - FlushRequest(Server *srv) : Request(srv, kRequestFlush) {} - FlushRequest(void) : Request((Server *)0, kRequestFlush) {} - }; - - class InvalidateRequest: public Request { - public: - InvalidateRequest(Server *srv) : Request(srv, kRequestInvalidate) {} - }; - - class SvrAdminRequest: public Request { - public: - SvrAdminRequest(Server *srv) : Request(srv, kRequestSvrAdmin) {} - }; - - class MonitorRequest: public Request { - public: - MonitorRequest(Server *srv) : Request(srv, kRequestMonitor){} - }; - - class Result { - private: - void *addr_; - long check; - Result(const Result &); - char *ServerInfo() const; - public: - friend class Server; - friend class Request; - friend class ServerPool; - - Result(void); - ~Result(void); - void Reset(void); - - void set_error(int errcode, const char *from, const char *detail); // from will not dupped - int get_result_code(void) const; - const char *get_error_message(void) const; - const char *get_error_from(void) const; - long long get_hotbackup_id() const; - long long get_master_hotbackup_timestamp() const; - long long slave_hotbackup_timestamp() const; - long long get_binlog_id() const; - long long get_binlog_offset() const; - long long get_mem_size() const; - long long get_datd_size() const; - int get_num_row_size(void) const; - int get_total_rows_size(void) const; - int get_affected_rows_size(void) const; - int get_num_fields_size(void) const; - const char* get_field_name(int n) const; - int get_field_present(const char* name) const; - int get_field_type(int n) const; - long long get_tag(void) const; - void *get_tag_ptr(void) const; - long long magic(void) const; - long long get_server_timestamp(void) const; - long long get_insert_id(void) const; - long long int_key(void) const; - const char *binary_key(void) const; - const char *binary_key(int *) const; - const char *binary_key(int &) const; - const char *string_key(void) const; - const char *string_key(int *) const; - const char *string_key(int &) const; - long long int_value(const char *) const; - double float_value(const char *) const; - const char *string_value(const char *) const; - const char *string_value(const char *, int*) const; - const char *string_value(const char *, int&) const; - const char *binary_value(const char *) const; - const char *binary_value(const char *, int*) const; - const char *binary_value(const char *, int&) const; - int uncompress_binary_value(const char *name,char **buf,int *lenp); - //Uncompress Binary Value without check compressflag - int uncompress_binary_value_force(const char *name,char **buf,int *lenp); - const char * uncompress_error_message() const; - long long int_value(int) const; - double float_value(int) const; - const char *string_value(int) const; - const char *string_value(int, int*) const; - const char *string_value(int, int&) const; - const char *binary_value(int) const; - const char *binary_value(int, int*) const; - const char *binary_value(int, int&) const; - int fetch_row(void); - int rewind(void); - }; - - class ServerPool { - private: - void *addr_; - long check; - ServerPool(ServerPool &); - public: - friend class Server; - friend class Request; - friend class Result; - - ServerPool(int max_servers, int max_requests); - ~ServerPool(void); - - int get_epoll_fd(int size); - int add_server(Server *srv, int mReq=1, int mConn=0); - int add_request(Request *, long long); - int add_request(Request *, long long, long long); - int add_request(Request *, long long, const char *); - int add_request(Request *, long long, const char *, int); - int add_request(Request *, void *); - int add_request(Request *, void *, long long); - int add_request(Request *, void *, const char *); - int add_request(Request *, void *, const char *, int); - int do_execute(int msec); - int execute_all(int msec); - int cancel_request(int); - int cancel_all_request(int type); - int abort_request(int); - int abort_all_request(int type); - Result *get_result(void); - Result *get_result(int); - int get_result(Result&); - int get_result(Result&, int); - - int server_count(void) const; - int request_count(int type) const; - int request_state(int reqId) const; - }; - - const int WAIT = 1; - const int SEND = 2; - const int RECV = 4; - const int DONE = 8; - const int ALL_STATE = WAIT|SEND|RECV|DONE; - - enum { - EC_ERROR_BASE = 2000, - EC_BAD_COMMAND, // unsupported command - EC_MISSING_SECTION, // missing mandatory section - EC_EXTRA_SECTION, // incompatible section present - EC_DUPLICATE_TAG, // same tag appear twice - - EC_DUPLICATE_FIELD, //5: same field appear twice in .need() - EC_BAD_SECTION_LENGTH, // section length too short - EC_BAD_VALUE_LENGTH, // value length not allow - EC_BAD_STRING_VALUE, // string value w/o NULL - EC_BAD_FLOAT_VALUE, // invalid float format - - EC_BAD_FIELD_NUM, //10: invalid total field# - EC_EXTRA_SECTION_DATA, // section length too large - EC_BAD_VALUE_TYPE, // incompatible value type - EC_BAD_OPERATOR, // incompatible operator/comparison - EC_BAD_FIELD_ID, // invalid field ID - - EC_BAD_FIELD_NAME, //15: invalud field name - EC_BAD_FIELD_TYPE, // invalid field type - EC_BAD_FIELD_SIZE, // invalid field size - EC_TABLE_REDEFINED, // table defined twice - EC_TABLE_MISMATCH, // request table != server table - - EC_VERSION_MISMATCH, //20: unsupported protocol version - EC_CHECKSUM_MISMATCH, // table hash not equal - EC_NO_MORE_DATA, // End of Result - EC_NEED_FULL_FIELDSET, // only full field set accepted by helper - EC_BAD_KEY_TYPE, // key type incompatible - - EC_BAD_KEY_SIZE, // 25: key size incompatible - EC_SERVER_BUSY, //server error - EC_BAD_SOCKET, // network failed - EC_NOT_INITIALIZED, // object didn't initialized - EC_BAD_HOST_STRING, - - EC_BAD_TABLE_NAME, // 30 - EC_TASK_NEED_DELETE, - EC_KEY_NEEDED, - EC_SERVER_ERROR, - EC_UPSTREAM_ERROR, - - EC_KEY_OVERFLOW, // 35 - EC_BAD_MULTIKEY, - EC_READONLY_FIELD, - EC_BAD_ASYNC_CMD, - EC_OUT_OF_KEY_RANGE, - - EC_REQUEST_ABORTED, // 40 - EC_PARALLEL_MODE, - EC_KEY_NOTEXIST, - EC_SERVER_READONLY, - EC_BAD_INVALID_FIELD, - - EC_DUPLICATE_KEY, // 45 - EC_TOO_MANY_KEY_VALUE, - EC_BAD_KEY_NAME, - EC_BAD_RAW_DATA, - EC_BAD_HOTBACKUP_JID, - - EC_FULL_SYNC_COMPLETE, //50 - EC_FULL_SYNC_STAGE, - EC_INC_SYNC_STAGE, - EC_ERR_SYNC_STAGE, - EC_NOT_ALLOWED_INSERT, - - EC_COMPRESS_ERROR, //55 - EC_UNCOMPRESS_ERROR, - EC_TASKPOOL, - EC_STATE_ERROR, - EC_DATA_NEEDED, - - EC_TASK_TIMEOUT, - - EC_BUSINESS_WITHOUT_EXPIRETIME, //62 - EC_EMPTY_TBDEF, //63 - EC_INVALID_KEY_VALUE, //64 - EC_INVALID_EXPIRETIME, //65 - - EC_GET_EXPIRETIME_END_OF_RESULT, //66 - }; - - enum { - ER_HASHCHK=1000, - ER_NISAMCHK=1001, - ER_NO=1002, - ER_YES=1003, - ER_CANT_CREATE_FILE=1004, - ER_CANT_CREATE_TABLE=1005, - ER_CANT_CREATE_DB=1006, - ER_DB_CREATE_EXISTS=1007, - ER_DB_DROP_EXISTS=1008, - ER_DB_DROP_DELETE=1009, - ER_DB_DROP_RMDIR=1010, - ER_CANT_DELETE_FILE=1011, - ER_CANT_FIND_SYSTEM_REC=1012, - ER_CANT_GET_STAT=1013, - ER_CANT_GET_WD=1014, - ER_CANT_LOCK=1015, - ER_CANT_OPEN_FILE=1016, - ER_FILE_NOT_FOUND=1017, - ER_CANT_READ_DIR=1018, - ER_CANT_SET_WD=1019, - ER_CHECKREAD=1020, - ER_DISK_FULL=1021, - ER_DUP_KEY=1022, - ER_ERROR_ON_CLOSE=1023, - ER_ERROR_ON_READ=1024, - ER_ERROR_ON_RENAME=1025, - ER_ERROR_ON_WRITE=1026, - ER_FILE_USED=1027, - ER_FILSORT_ABORT=1028, - ER_FORM_NOT_FOUND=1029, - ER_GET_ERRNO=1030, - ER_ILLEGAL_HA=1031, - ER_KEY_NOT_FOUND=1032, - ER_NOT_FORM_FILE=1033, - ER_NOT_KEYFILE=1034, - ER_OLD_KEYFILE=1035, - ER_OPEN_AS_READONLY=1036, - ER_OUTOFMEMORY=1037, - ER_OUT_OF_SORTMEMORY=1038, - ER_UNEXPECTED_EOF=1039, - ER_CON_COUNT_ERROR=1040, - ER_OUT_OF_RESOURCES=1041, - ER_BAD_HOST_ERROR=1042, - ER_HANDSHAKE_ERROR=1043, - ER_DBACCESS_DENIED_ERROR=1044, - ER_ACCESS_DENIED_ERROR=1045, - ER_NO_DB_ERROR=1046, - ER_UNKNOWN_COM_ERROR=1047, - ER_BAD_NULL_ERROR=1048, - ER_BAD_DB_ERROR=1049, - ER_TABLE_EXISTS_ERROR=1050, - ER_BAD_TABLE_ERROR=1051, - ER_NON_UNIQ_ERROR=1052, - ER_SERVER_SHUTDOWN=1053, - ER_BAD_FIELD_ERROR=1054, - ER_WRONG_FIELD_WITH_GROUP=1055, - ER_WRONG_GROUP_FIELD=1056, - ER_WRONG_SUM_SELECT=1057, - ER_WRONG_VALUE_COUNT=1058, - ER_TOO_LONG_IDENT=1059, - ER_DUP_FIELDNAME=1060, - ER_DUP_KEYNAME=1061, - ER_DUP_ENTRY=1062, - ER_WRONG_FIELD_SPEC=1063, - ER_PARSE_ERROR=1064, - ER_EMPTY_QUERY=1065, - ER_NONUNIQ_TABLE=1066, - ER_INVALID_DEFAULT=1067, - ER_MULTIPLE_PRI_KEY=1068, - ER_TOO_MANY_KEYS=1069, - ER_TOO_MANY_KEY_PARTS=1070, - ER_TOO_LONG_KEY=1071, - ER_KEY_COLUMN_DOES_NOT_EXITS=1072, - ER_BLOB_USED_AS_KEY=1073, - ER_TOO_BIG_FIELDLENGTH=1074, - ER_WRONG_AUTO_KEY=1075, - ER_READY=1076, - ER_NORMAL_SHUTDOWN=1077, - ER_GOT_SIGNAL=1078, - ER_SHUTDOWN_COMPLETE=1079, - ER_FORCING_CLOSE=1080, - ER_IPSOCK_ERROR=1081, - ER_NO_SUCH_INDEX=1082, - ER_WRONG_FIELD_TERMINATORS=1083, - ER_BLOBS_AND_NO_TERMINATED=1084, - ER_TEXTFILE_NOT_READABLE=1085, - ER_FILE_EXISTS_ERROR=1086, - ER_LOAD_INFO=1087, - ER_ALTER_INFO=1088, - ER_WRONG_SUB_KEY=1089, - ER_CANT_REMOVE_ALL_FIELDS=1090, - ER_CANT_DROP_FIELD_OR_KEY=1091, - ER_INSERT_INFO=1092, - ER_INSERT_TABLE_USED=1093, - ER_NO_SUCH_THREAD=1094, - ER_KILL_DENIED_ERROR=1095, - ER_NO_TABLES_USED=1096, - ER_TOO_BIG_SET=1097, - ER_NO_UNIQUE_LOGFILE=1098, - ER_TABLE_NOT_LOCKED_FOR_WRITE=1099, - ER_TABLE_NOT_LOCKED=1100, - ER_BLOB_CANT_HAVE_DEFAULT=1101, - ER_WRONG_DB_NAME=1102, - ER_WRONG_TABLE_NAME=1103, - ER_TOO_BIG_SELECT=1104, - ER_UNKNOWN_ERROR=1105, - ER_UNKNOWN_PROCEDURE=1106, - ER_WRONG_PARAMCOUNT_TO_PROCEDURE=1107, - ER_WRONG_PARAMETERS_TO_PROCEDURE=1108, - ER_UNKNOWN_TABLE=1109, - ER_FIELD_SPECIFIED_TWICE=1110, - ER_INVALID_GROUP_FUNC_USE=1111, - ER_UNSUPPORTED_EXTENSION=1112, - ER_TABLE_MUST_HAVE_COLUMNS=1113, - ER_RECORD_FILE_FULL=1114, - ER_UNKNOWN_CHARACTER_SET=1115, - ER_TOO_MANY_TABLES=1116, - ER_TOO_MANY_FIELDS=1117, - ER_TOO_BIG_ROWSIZE=1118, - ER_STACK_OVERRUN=1119, - ER_WRONG_OUTER_JOIN=1120, - ER_NULL_COLUMN_IN_INDEX=1121, - ER_CANT_FIND_UDF=1122, - ER_CANT_INITIALIZE_UDF=1123, - ER_UDF_NO_PATHS=1124, - ER_UDF_EXISTS=1125, - ER_CANT_OPEN_LIBRARY=1126, - ER_CANT_FIND_DL_ENTRY=1127, - ER_FUNCTION_NOT_DEFINED=1128, - ER_HOST_IS_BLOCKED=1129, - ER_HOST_NOT_PRIVILEGED=1130, - ER_PASSWORD_ANONYMOUS_USER=1131, - ER_PASSWORD_NOT_ALLOWED=1132, - ER_PASSWORD_NO_MATCH=1133, - ER_UPDATE_INFO=1134, - ER_CANT_CREATE_THREAD=1135, - ER_WRONG_VALUE_COUNT_ON_ROW=1136, - ER_CANT_REOPEN_TABLE=1137, - ER_INVALID_USE_OF_NULL=1138, - ER_REGEXP_ERROR=1139, - ER_MIX_OF_GROUP_FUNC_AND_FIELDS=1140, - ER_NONEXISTING_GRANT=1141, - ER_TABLEACCESS_DENIED_ERROR=1142, - ER_COLUMNACCESS_DENIED_ERROR=1143, - ER_ILLEGAL_GRANT_FOR_TABLE=1144, - ER_GRANT_WRONG_HOST_OR_USER=1145, - ER_NO_SUCH_TABLE=1146, - ER_NONEXISTING_TABLE_GRANT=1147, - ER_NOT_ALLOWED_COMMAND=1148, - ER_SYNTAX_ERROR=1149, - ER_DELAYED_CANT_CHANGE_LOCK=1150, - ER_TOO_MANY_DELAYED_THREADS=1151, - ER_ABORTING_CONNECTION=1152, - ER_NET_PACKET_TOO_LARGE=1153, - ER_NET_READ_ERROR_FROM_PIPE=1154, - ER_NET_FCNTL_ERROR=1155, - ER_NET_PACKETS_OUT_OF_ORDER=1156, - ER_NET_UNCOMPRESS_ERROR=1157, - ER_NET_READ_ERROR=1158, - ER_NET_READ_INTERRUPTED=1159, - ER_NET_ERROR_ON_WRITE=1160, - ER_NET_WRITE_INTERRUPTED=1161, - ER_TOO_LONG_STRING=1162, - ER_TABLE_CANT_HANDLE_BLOB=1163, - ER_TABLE_CANT_HANDLE_AUTO_INCREMENT=1164, - ER_DELAYED_INSERT_TABLE_LOCKED=1165, - ER_WRONG_COLUMN_NAME=1166, - ER_WRONG_KEY_COLUMN=1167, - ER_WRONG_MRG_TABLE=1168, - ER_DUP_UNIQUE=1169, - ER_BLOB_KEY_WITHOUT_LENGTH=1170, - ER_PRIMARY_CANT_HAVE_NULL=1171, - ER_TOO_MANY_ROWS=1172, - ER_REQUIRES_PRIMARY_KEY=1173, - ER_NO_RAID_COMPILED=1174, - ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE=1175, - ER_KEY_DOES_NOT_EXITS=1176, - ER_CHECK_NO_SUCH_TABLE=1177, - ER_CHECK_NOT_IMPLEMENTED=1178, - ER_CANT_DO_THIS_DURING_AN_TRANSACTION=1179, - ER_ERROR_DURING_COMMIT=1180, - ER_ERROR_DURING_ROLLBACK=1181, - ER_ERROR_DURING_FLUSH_LOGS=1182, - ER_ERROR_DURING_CHECKPOINT=1183, - ER_NEW_ABORTING_CONNECTION=1184, - ER_DUMP_NOT_IMPLEMENTED= 1185, - ER_FLUSH_MASTER_BINLOG_CLOSED=1186, - ER_INDEX_REBUILD= 1187, - ER_MASTER=1188, - ER_MASTER_NET_READ=1189, - ER_MASTER_NET_WRITE=1190, - ER_FT_MATCHING_KEY_NOT_FOUND=1191, - ER_LOCK_OR_ACTIVE_TRANSACTION=1192, - ER_UNKNOWN_SYSTEM_VARIABLE=1193, - ER_CRASHED_ON_USAGE=1194, - ER_CRASHED_ON_REPAIR=1195, - ER_WARNING_NOT_COMPLETE_ROLLBACK=1196, - ER_TRANS_CACHE_FULL=1197, - ER_SLAVE_MUST_STOP=1198, - ER_SLAVE_NOT_RUNNING=1199, - ER_BAD_SLAVE=1200, - ER_MASTER_INFO=1201, - ER_SLAVE_THREAD=1202, - ER_TOO_MANY_USER_CONNECTIONS=1203, - ER_SET_CONSTANTS_ONLY=1204, - ER_LOCK_WAIT_TIMEOUT=1205, - ER_LOCK_TABLE_FULL=1206, - ER_READ_ONLY_TRANSACTION=1207, - ER_DROP_DB_WITH_READ_LOCK=1208, - ER_CREATE_DB_WITH_READ_LOCK=1209, - ER_WRONG_ARGUMENTS=1210, - ER_NO_PERMISSION_TO_CREATE_USER=1211, - ER_UNION_TABLES_IN_DIFFERENT_DIR=1212, - ER_LOCK_DEADLOCK=1213, - ER_TABLE_CANT_HANDLE_FULLTEXT=1214, - ER_CANNOT_ADD_FOREIGN=1215, - ER_NO_REFERENCED_ROW=1216, - ER_ROW_IS_REFERENCED=1217, - ER_CONNECT_TO_MASTER=1218, - ER_QUERY_ON_MASTER=1219, - ER_ERROR_WHEN_EXECUTING_COMMAND=1220, - ER_WRONG_USAGE=1221, - ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT=1222, - ER_CANT_UPDATE_WITH_READLOCK=1223, - ER_MIXING_NOT_ALLOWED=1224, - ER_DUP_ARGUMENT=1225, - ER_USER_LIMIT_REACHED=1226, - ER_SPECIFIC_ACCESS_DENIED_ERROR=1227, - ER_LOCAL_VARIABLE=1228, - ER_GLOBAL_VARIABLE=1229, - ER_NO_DEFAULT=1230, - ER_WRONG_VALUE_FOR_VAR=1231, - ER_WRONG_TYPE_FOR_VAR=1232, - ER_VAR_CANT_BE_READ=1233, - ER_CANT_USE_OPTION_HERE=1234, - ER_NOT_SUPPORTED_YET=1235, - ER_MASTER_FATAL_ERROR_READING_BINLOG=1236, - ER_SLAVE_IGNORED_TABLE=1237, - ER_INCORRECT_GLOBAL_LOCAL_VAR=1238, - CR_UNKNOWN_ERROR=1900, - CR_SOCKET_CREATE_ERROR=1901, - CR_CONNECTION_ERROR=1902, - CR_CONN_HOST_ERROR=1903, - CR_IPSOCK_ERROR =1904, - CR_UNKNOWN_HOST =1905, - CR_SERVER_GONE_ERROR=1906, - CR_VERSION_ERROR=1907, - CR_OUT_OF_MEMORY=1908, - CR_WRONG_HOST_INFO=1909, - CR_LOCALHOST_CONNECTION=1910, - CR_TCP_CONNECTION=1911, - CR_SERVER_HANDSHAKE_ERR=1912, - CR_SERVER_LOST=1913, - CR_COMMANDS_OUT_OF_SYNC=1914, - CR_NAMEDPIPE_CONNECTION=1915, - CR_NAMEDPIPEWAIT_ERROR=1916, - CR_NAMEDPIPEOPEN_ERROR=1917, - CR_NAMEDPIPESETSTATE_ERROR=1918, - CR_CANT_READ_CHARSET=1919, - CR_NET_PACKET_TOO_LARGE=1920, - CR_EMBEDDED_CONNECTION=1921, - CR_PROBE_SLAVE_STATUS=1922, - CR_PROBE_SLAVE_HOSTS=1923, - CR_PROBE_SLAVE_CONNECT=1924, - CR_PROBE_MASTER_CONNECT=1925, - CR_SSL_CONNECTION_ERROR=1926, - CR_MALFORMED_PACKET=1927, - CR_WRONG_LICENSE=1928, - }; - - enum{ - ER_SET_IPLIST_NULL = 20001, - ER_SET_INSTANCE_PROPERTIES_ERR, - ER_KEY_TYPE, - ER_CC_VERSION_ERR, - ER_ROUTE_INFO_NULL, - ER_BID_VERSION_ERR, - ER_PORT_OUT_RANGE, - ER_STATUS_ERROR_VALUE, - ER_WEIGHT_ERROR_VALUE, - ER_IP_ERROR_VALUE, - }; - -}; - -#endif diff --git a/test/allcase/test.cpp b/test/allcase/test.cpp deleted file mode 100755 index fed0698..0000000 --- a/test/allcase/test.cpp +++ /dev/null @@ -1,410 +0,0 @@ -#include -#include -#include -#include -#include - -#include "dtcapi.h" - -enum TypeIns{ - E_INSERT_CORRENT_DATA = 1, - E_INSERT_DELETION_FIELD, - E_INSERT_DELETION_KEY, - E_INSERT_BAD_TYPE, - E_INSERT_BAD_ORDER, - E_INSERT_SAME, - E_INSERT_ONCE_MULTIPLE, - - E_TOTAL_NUM_INS -}; - -enum TypeDel{ - E_DELETE_EXISTENCE =10, - E_DELETE_NO_EXISTENCE, - E_DELETE_BAD_TYPE_KEY, - E_DELETE_NO_KEY_FIELD, - E_DELETE_EMPTY_TABLE, - E_DELETE_ONCE_MULTIPLE, - - E_TOTAL_NUM_DEL -}; - -enum TypeUpd{ - E_UPDATE_CORRENT_DATA = 20, - E_UPDATE_KEY, - E_UPDATE_DELETION_FIELD, - E_UPDATE_DELETION_KEY, - E_UPDATE_ONCE_MULTIPLE, - E_UPDATE_EMPTY_TABLE, - E_SELECT_ADD_SUB, - E_TOTAL_NUM_UPD -}; - -enum TypeSel{ - E_SELECT_CORRENT_KEY = 30, - E_SELECT_BAD_KEY, - E_SELECT_BAD_TYPE_KEY, - E_SELECT_NO_KEY_FIELD, - E_SELECT_ONCE_MULTIPLE, - E_SELECT_EMPTY_TABLE, - E_SELECT_FIELD_TYPE, - E_SELECT_ADDRESS, - E_SELECT_TABLENAAE, - - E_SELECT_LIMIT, - E_SELECT_LIMIT_RESULT_NUM, - E_SELECT_NO_LIMIT_RESULT_NUM, - - E_TOTAL_NUM_SEL -}; - - -void insert(DTC::Server server,TypeIns type) -{ - int retCode = 0; - - DTC::InsertRequest insertReq(&server); - DTC::Result stResult; - switch (type) - { - case E_INSERT_CORRENT_DATA: - case E_INSERT_SAME: - /* 缁戝畾鎻掑叆鐨勫瓧娈靛拰鏁版嵁 */ - insertReq.set_key(1); - insertReq.Set("uid", 1); - insertReq.Set("name", "姹豹"); - insertReq.Set("city", "涓婃捣"); - insertReq.Set("age", 3); - insertReq.Set("sex", 1); - break; - case E_INSERT_DELETION_FIELD: - insertReq.set_key(1); - insertReq.Set("uid", 1); - insertReq.Set("name", "鍠靛柕"); - break; - case E_INSERT_DELETION_KEY: - insertReq.Set("city", "鏉窞"); - insertReq.Set("age", 9); - break; - case E_INSERT_BAD_TYPE: - insertReq.set_key("jd"); - break; - case E_INSERT_BAD_ORDER: - insertReq.set_key(1); - insertReq.Set("age", 2); - insertReq.Set("name", "鍛卞懕"); - insertReq.Set("uid", 1); - insertReq.Set("city", "涓婃捣"); - insertReq.Set("sex", 0); - break; - case E_INSERT_ONCE_MULTIPLE: - insertReq.set_key(1); - insertReq.Set("uid", 1); - insertReq.Set("name", "鍜╁挬"); - insertReq.Set("city", "瑗垮畨"); - insertReq.Set("age", 7); - insertReq.Set("sex", 1); - insertReq.do_execute(stResult); - insertReq.Reset(); - insertReq.set_key(2); - insertReq.Set("uid", 2); - insertReq.Set("name", "甯冭胺"); - insertReq.Set("city", "绂忓缓"); - insertReq.Set("age", 11); - insertReq.Set("sex", 0); - break; - default: - break; - } - retCode = insertReq.do_execute(stResult); - if(retCode != 0) - printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.get_error_message(), stResult.get_error_from()); - else - printf("insert success!\n"); - printf("==========================================================\n"); -} - -void delet(DTC::Server server,TypeDel type) -{ - - int retCode = 0; - - DTC::DeleteRequest deleteReq(&server); - DTC::Result stResult; - switch (type) - { - case E_DELETE_EXISTENCE: - deleteReq.set_key(1); - break; - case E_DELETE_NO_EXISTENCE: - deleteReq.set_key(-1); - break; - case E_DELETE_BAD_TYPE_KEY: - deleteReq.set_key("jd"); - break; - case E_DELETE_NO_KEY_FIELD: - deleteReq.Set("age", 12); - break; - case E_DELETE_EMPTY_TABLE: - deleteReq.set_key(10000); - break; - case E_DELETE_ONCE_MULTIPLE: - deleteReq.set_key(2); - deleteReq.do_execute(stResult); - deleteReq.Reset(); - deleteReq.set_key(3); - break; - default: - break; - } - retCode = deleteReq.do_execute(stResult); - if(retCode == 0) - printf("delete success!\n"); - if(retCode != 0) - printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.get_error_message(), stResult.get_error_from()); - printf("==========================================================\n"); -} -void updata(DTC::Server server,TypeUpd type) -{ - int retCode = 0; - - DTC::UpdateRequest UpdateReq(&server); - DTC::Result stResult; - UpdateReq.set_key(1); - - switch (type) - { - case E_UPDATE_CORRENT_DATA: - UpdateReq.Set("name", "娴风坏瀹濆疂"); - UpdateReq.Set("city", "澶ф捣"); - UpdateReq.Set("age", 5); - UpdateReq.Set("sex", 1); - break; - case E_UPDATE_KEY: - UpdateReq.Set("uid", 2); - break; - case E_UPDATE_DELETION_FIELD: - UpdateReq.Set("uid", 3); - UpdateReq.Set("age", 11); - break; - case E_UPDATE_EMPTY_TABLE: - UpdateReq.set_key(-2); - break; - case E_UPDATE_DELETION_KEY: - UpdateReq.set_key(10000); - break; - case E_UPDATE_ONCE_MULTIPLE: - UpdateReq.set_key(1); - UpdateReq.Set("name", "娲惧ぇ鏄"); - UpdateReq.Set("city", "娣辨捣"); - UpdateReq.Set("age", 8); - UpdateReq.Set("sex", 0); - UpdateReq.do_execute(stResult); - UpdateReq.Reset(); - UpdateReq.set_key(2); - UpdateReq.Set("name", "锜硅佹澘"); - UpdateReq.Set("city", "澶ф捣"); - UpdateReq.Set("age", 12); - UpdateReq.Set("sex", 1); - break; - case E_SELECT_ADD_SUB: - UpdateReq.set_key(1); - UpdateReq.Add("age", 8); - UpdateReq.Sub("sex", 1); - default: - break; - } - retCode = UpdateReq.do_execute(stResult); - if(retCode != 0) - printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.get_error_message(), stResult.get_error_from()); - else - printf("update success!\n"); - /* 鏌ヨ淇敼褰卞搷鐨勮鏁 */ - printf("affected rows size %d\n",stResult.get_affected_rows_size()); - printf("==========================================================\n"); -} - -void select(DTC::Server server,TypeSel type) -{ - /* 鐩存帴鏋勯犳寚瀹氭搷浣滅殑瀵硅薄锛氭煡璇㈡搷浣 */ - DTC::GetRequest get_request(&server); - int uid; - /* 鎵ц鐨勭粨鏋:鍖呭惈閿欒淇℃伅浠ュ強杩斿洖鐨剅ow鏁版嵁 */ - DTC::Result result; - int iRet; - switch (type) - { - case E_SELECT_CORRENT_KEY: - get_request.set_key(1); - uid = 1; - break; - case E_SELECT_BAD_KEY: - get_request.set_key(-1); - uid = -1; - break; - case E_SELECT_BAD_TYPE_KEY: - get_request.set_key("jd"); - break; - case E_SELECT_NO_KEY_FIELD: - get_request.need("age", 7); - break; - case E_SELECT_ONCE_MULTIPLE: - get_request.set_key(2); - uid = 2; - break; - case E_SELECT_EMPTY_TABLE: - get_request.set_key(10000); - uid = 10000; - break; - case E_SELECT_FIELD_TYPE: - /** - * Signed = 1, Signed Integer - * Unsigned = 2, Unsigned Integer - * FloatPoint = 3 FloatPoint - * String = 4, String, case insensitive, null ended - * Binary = 5, opaque binary data - */ - printf("FieldType uid: %d\n",server.get_field_type("uid")); - printf("FieldType name: %d\n",server.get_field_type("name")); - printf("FieldType city: %d\n",server.get_field_type("city")); - printf("FieldType age: %d\n",server.get_field_type("age")); - printf("FieldType sex: %d\n",server.get_field_type("sex")); - printf("==========================================================\n"); - return; - break; - case E_SELECT_ADDRESS: - /* 杩斿洖鏈嶅姟鍣ㄧip鍦板潃 */ - printf("ip_address: %s\n",server.get_address()); - printf("==========================================================\n"); - return; - break; - case E_SELECT_TABLENAAE: - /* 杩斿洖琛ㄥ悕 */ - printf("tablename: %s\n",server.get_table_name()); - printf("==========================================================\n"); - return; - break; - case E_SELECT_LIMIT: - case E_SELECT_LIMIT_RESULT_NUM: - get_request.set_key(1); - /* 杩斿洖缁撴瀯闆嗗紑濮嬩綅缃 浠ュ強缁撴灉琛屾暟 */ - get_request.limit(2, 2); - uid = 1; - break; - case E_SELECT_NO_LIMIT_RESULT_NUM: - get_request.set_key(1); - get_request.do_execute(result); - printf("total nubrow:%d\n", result.get_total_rows_size()); - uid = 1; - printf("==========================================================\n"); - return; - break; - default: - break; - } - - /* 璁剧疆闇瑕乻elect鐨勫瓧娈 */ - if(iRet == 0) - iRet = get_request.need("uid"); - if(iRet == 0) - iRet = get_request.need("name"); - if(iRet == 0) - iRet = get_request.need("city"); - if(iRet == 0) - iRet = get_request.need("age"); - if(iRet == 0) - iRet = get_request.need("sex"); - if(iRet != 0) - { - printf("get-req need error: %d", iRet); - fflush(stdout); - } - - /* 鎻愪氦璇锋眰锛屾墽琛岀粨鏋滃瓨鍦≧esult瀵硅薄閲 */ - iRet = get_request.do_execute(result); - /* 濡傛灉鍑洪敊,鍒欒緭鍑洪敊璇爜銆侀敊璇樁娈碉紝閿欒淇℃伅锛宻tResult.get_error_from(), result.get_error_message() 杩欎袱涓敊璇俊鎭緢閲嶈锛屼竴瀹氳鎵撳嵃鍑烘潵锛屾柟渚垮畾浣嶉棶棰 */ - if(iRet != 0) - { - printf ("uin[%u] dtc execute get error: %d, error_from:%s, msg:%s\n", - uid, // 鍑洪敊鐨刱ey鏄灏 - iRet, // 閿欒鐮佷负澶氬皯 - result.get_error_from(), // 杩斿洖閿欒闃舵 - result.get_error_message() // 杩斿洖閿欒淇℃伅 - ); - fflush(stdout); - } - /* 鏁版嵁涓嶅瓨鍦 */ - if(result.get_num_row_size() <= 0) - printf("uin[%u] data not exist.\n", uid); - - /* 璇诲彇缁撴灉鐨凨ey鍊 */ - printf("result key: %d\n", result.int_key()); - - /* 杈撳嚭缁撴灉鐨勮鏁 */ - printf("NumRows:%d\n", result.get_num_row_size()); - - /* 杈撳嚭缁撴灉 */ - for(int i=0;i<=result.get_num_row_size();++i) - { - /* 璇诲彇涓琛屾暟鎹 */ - iRet = result.fetch_row(); - if(iRet < 0) - { - printf ("uid[%lu] dtc fetch row error: %d\n", uid, iRet); - fflush(stdout); - } - /* 濡傛灉涓鍒囨纭紝鍒欏彲浠ヨ緭鍑烘暟鎹簡 */ - /* 杈撳嚭int绫诲瀷鐨勬暟鎹 */ - printf("uid: %d\n", result.int_value("uid")); - /* 杈撳嚭binary绫诲瀷鐨勬暟鎹 */ - printf("name: %s\n", result.binary_value("name")); - /* 杈撳嚭string绫诲瀷鐨勬暟鎹 */ - printf("city: %s\n", result.string_value("city")); - printf("age:%d\n", result.int_value("age")); - printf("sex:%d\n",result.int_value("sex")); - } - printf("==========================================================\n"); -} - -int main(int argc,char* argv[]) -{ - std::string ip; - ip = std::string(argv[1]); - - /* 鍙server涓嶆瀽鏋勶紝鍚庡彴浼氫繚鎸侀暱杩炴帴 */ - DTC::Server server; - - /* 璁剧疆鐨刣tc鐨刬p鍜岀鍙 */ - server.set_address(ip.c_str(), "20015"); - /* 璁剧疆缃戠粶瓒呮椂鏃堕棿,鍗曟缃戠粶IO鐨勮秴鏃,鍗曚綅绉 */ - server.SetTimeout(5); - /* 璁剧疆璁块棶鐮 AccessToken锛屽湪鐢宠dtc瀹炰緥鐨勬椂鍊欑綉绔欑浼氱敓鎴 */ - server.set_accesskey("000022907e64e117fa92f892a85307782a68afc6"); - /* 璁剧疆dtc鐨勮〃鍚 */ - server.set_table_name("dtc_opensource"); - /* 澹版槑key绫诲瀷 */ - server.int_key(); - - int i; - for(i = E_INSERT_CORRENT_DATA;i < E_TOTAL_NUM_INS;i++) - { - insert(server,(TypeIns)i); - } - select(server,E_SELECT_CORRENT_KEY); - for(i = E_UPDATE_CORRENT_DATA;i < E_TOTAL_NUM_UPD;i++) - { - updata(server,(TypeUpd)i); - } - for(i = E_SELECT_CORRENT_KEY;i < E_TOTAL_NUM_SEL;i++) - { - select(server,(TypeSel)i); - } - for(int i = E_DELETE_EXISTENCE;i < E_TOTAL_NUM_DEL;i++) - { - delet(server,(TypeDel)i); - } - return 0; -} - - - diff --git a/test/auto_test.cpp b/test/auto_test.cpp new file mode 100755 index 0000000..de5b9cc --- /dev/null +++ b/test/auto_test.cpp @@ -0,0 +1,391 @@ +#include +#include +#include +#include +#include + +#include "dtcapi.h" + +enum TypeIns { + E_INSERT_CORRENT_DATA = 1, + E_INSERT_DELETION_FIELD, + E_INSERT_DELETION_KEY, + E_INSERT_BAD_TYPE, + E_INSERT_BAD_ORDER, + E_INSERT_SAME, + E_INSERT_ONCE_MULTIPLE, + + E_TOTAL_NUM_INS +}; + +enum TypeDel { + E_DELETE_EXISTENCE = 10, + E_DELETE_NO_EXISTENCE, + E_DELETE_BAD_TYPE_KEY, + E_DELETE_NO_KEY_FIELD, + E_DELETE_EMPTY_TABLE, + E_DELETE_ONCE_MULTIPLE, + + E_TOTAL_NUM_DEL +}; + +enum TypeUpd { + E_UPDATE_CORRENT_DATA = 20, + E_UPDATE_KEY, + E_UPDATE_DELETION_FIELD, + E_UPDATE_DELETION_KEY, + E_UPDATE_ONCE_MULTIPLE, + E_UPDATE_EMPTY_TABLE, + E_SELECT_ADD_SUB, + E_TOTAL_NUM_UPD +}; + +enum TypeSel { + E_SELECT_CORRENT_KEY = 30, + E_SELECT_BAD_KEY, + E_SELECT_BAD_TYPE_KEY, + E_SELECT_NO_KEY_FIELD, + E_SELECT_ONCE_MULTIPLE, + E_SELECT_EMPTY_TABLE, + E_SELECT_FIELD_TYPE, + E_SELECT_ADDRESS, + E_SELECT_TABLENAAE, + + E_SELECT_LIMIT, + E_SELECT_LIMIT_RESULT_NUM, + E_SELECT_NO_LIMIT_RESULT_NUM, + + E_TOTAL_NUM_SEL +}; + +void insert(DTC::Server server, TypeIns type) { + int retCode = 0; + + DTC::InsertRequest insertReq(&server); + DTC::Result stResult; + switch (type) { + case E_INSERT_CORRENT_DATA: + case E_INSERT_SAME: + /* 缁戝畾鎻掑叆鐨勫瓧娈靛拰鏁版嵁 */ + insertReq.set_key(1); + insertReq.Set("uid", 1); + insertReq.Set("name", "姹豹"); + insertReq.Set("city", "涓婃捣"); + insertReq.Set("age", 3); + insertReq.Set("sex", 1); + break; + case E_INSERT_DELETION_FIELD: + insertReq.set_key(1); + insertReq.Set("uid", 1); + insertReq.Set("name", "鍠靛柕"); + break; + case E_INSERT_DELETION_KEY: + insertReq.Set("city", "鏉窞"); + insertReq.Set("age", 9); + break; + case E_INSERT_BAD_TYPE: + insertReq.set_key("jd"); + break; + case E_INSERT_BAD_ORDER: + insertReq.set_key(1); + insertReq.Set("age", 2); + insertReq.Set("name", "鍛卞懕"); + insertReq.Set("uid", 1); + insertReq.Set("city", "涓婃捣"); + insertReq.Set("sex", 0); + break; + case E_INSERT_ONCE_MULTIPLE: + insertReq.set_key(1); + insertReq.Set("uid", 1); + insertReq.Set("name", "鍜╁挬"); + insertReq.Set("city", "瑗垮畨"); + insertReq.Set("age", 7); + insertReq.Set("sex", 1); + insertReq.do_execute(stResult); + insertReq.Reset(); + insertReq.set_key(2); + insertReq.Set("uid", 2); + insertReq.Set("name", "甯冭胺"); + insertReq.Set("city", "绂忓缓"); + insertReq.Set("age", 11); + insertReq.Set("sex", 0); + break; + default: + break; + } + retCode = insertReq.do_execute(stResult); + if (retCode != 0) + printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, + stResult.get_error_message(), stResult.get_error_from()); + else + printf("insert success!\n"); + printf("==========================================================\n"); +} + +void delet(DTC::Server server, TypeDel type) { + + int retCode = 0; + + DTC::DeleteRequest deleteReq(&server); + DTC::Result stResult; + switch (type) { + case E_DELETE_EXISTENCE: + deleteReq.set_key(1); + break; + case E_DELETE_NO_EXISTENCE: + deleteReq.set_key(-1); + break; + case E_DELETE_BAD_TYPE_KEY: + deleteReq.set_key("jd"); + break; + case E_DELETE_NO_KEY_FIELD: + deleteReq.Set("age", 12); + break; + case E_DELETE_EMPTY_TABLE: + deleteReq.set_key(10000); + break; + case E_DELETE_ONCE_MULTIPLE: + deleteReq.set_key(2); + deleteReq.do_execute(stResult); + deleteReq.Reset(); + deleteReq.set_key(3); + break; + default: + break; + } + retCode = deleteReq.do_execute(stResult); + if (retCode == 0) + printf("delete success!\n"); + if (retCode != 0) + printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, + stResult.get_error_message(), stResult.get_error_from()); + printf("==========================================================\n"); +} +void updata(DTC::Server server, TypeUpd type) { + int retCode = 0; + + DTC::UpdateRequest UpdateReq(&server); + DTC::Result stResult; + UpdateReq.set_key(1); + + switch (type) { + case E_UPDATE_CORRENT_DATA: + UpdateReq.Set("name", "娴风坏瀹濆疂"); + UpdateReq.Set("city", "澶ф捣"); + UpdateReq.Set("age", 5); + UpdateReq.Set("sex", 1); + break; + case E_UPDATE_KEY: + UpdateReq.Set("uid", 2); + break; + case E_UPDATE_DELETION_FIELD: + UpdateReq.Set("uid", 3); + UpdateReq.Set("age", 11); + break; + case E_UPDATE_EMPTY_TABLE: + UpdateReq.set_key(-2); + break; + case E_UPDATE_DELETION_KEY: + UpdateReq.set_key(10000); + break; + case E_UPDATE_ONCE_MULTIPLE: + UpdateReq.set_key(1); + UpdateReq.Set("name", "娲惧ぇ鏄"); + UpdateReq.Set("city", "娣辨捣"); + UpdateReq.Set("age", 8); + UpdateReq.Set("sex", 0); + UpdateReq.do_execute(stResult); + UpdateReq.Reset(); + UpdateReq.set_key(2); + UpdateReq.Set("name", "锜硅佹澘"); + UpdateReq.Set("city", "澶ф捣"); + UpdateReq.Set("age", 12); + UpdateReq.Set("sex", 1); + break; + case E_SELECT_ADD_SUB: + UpdateReq.set_key(1); + UpdateReq.Add("age", 8); + UpdateReq.Sub("sex", 1); + default: + break; + } + retCode = UpdateReq.do_execute(stResult); + if (retCode != 0) + printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, + stResult.get_error_message(), stResult.get_error_from()); + else + printf("update success!\n"); + /* 鏌ヨ淇敼褰卞搷鐨勮鏁 */ + printf("affected rows size %d\n", stResult.get_affected_rows_size()); + printf("==========================================================\n"); +} + +void select(DTC::Server server, TypeSel type) { + /* 鐩存帴鏋勯犳寚瀹氭搷浣滅殑瀵硅薄锛氭煡璇㈡搷浣 */ + DTC::GetRequest get_request(&server); + int uid; + /* 鎵ц鐨勭粨鏋:鍖呭惈閿欒淇℃伅浠ュ強杩斿洖鐨剅ow鏁版嵁 */ + DTC::Result result; + int iRet; + switch (type) { + case E_SELECT_CORRENT_KEY: + get_request.set_key(1); + uid = 1; + break; + case E_SELECT_BAD_KEY: + get_request.set_key(-1); + uid = -1; + break; + case E_SELECT_BAD_TYPE_KEY: + get_request.set_key("jd"); + break; + case E_SELECT_NO_KEY_FIELD: + get_request.need("age", 7); + break; + case E_SELECT_ONCE_MULTIPLE: + get_request.set_key(2); + uid = 2; + break; + case E_SELECT_EMPTY_TABLE: + get_request.set_key(10000); + uid = 10000; + break; + case E_SELECT_FIELD_TYPE: + /** + * Signed = 1, Signed Integer + * Unsigned = 2, Unsigned Integer + * FloatPoint = 3 FloatPoint + * String = 4, String, case insensitive, null ended + * Binary = 5, opaque binary data + */ + printf("FieldType uid: %d\n", server.get_field_type("uid")); + printf("FieldType name: %d\n", server.get_field_type("name")); + printf("FieldType city: %d\n", server.get_field_type("city")); + printf("FieldType age: %d\n", server.get_field_type("age")); + printf("FieldType sex: %d\n", server.get_field_type("sex")); + printf("==========================================================\n"); + return; + break; + case E_SELECT_ADDRESS: + /* 杩斿洖鏈嶅姟鍣ㄧip鍦板潃 */ + printf("ip_address: %s\n", server.get_address()); + printf("==========================================================\n"); + return; + break; + case E_SELECT_TABLENAAE: + /* 杩斿洖琛ㄥ悕 */ + printf("tablename: %s\n", server.get_table_name()); + printf("==========================================================\n"); + return; + break; + case E_SELECT_LIMIT: + case E_SELECT_LIMIT_RESULT_NUM: + get_request.set_key(1); + /* 杩斿洖缁撴瀯闆嗗紑濮嬩綅缃 浠ュ強缁撴灉琛屾暟 */ + get_request.limit(2, 2); + uid = 1; + break; + case E_SELECT_NO_LIMIT_RESULT_NUM: + get_request.set_key(1); + get_request.do_execute(result); + printf("total nubrow:%d\n", result.get_total_rows_size()); + uid = 1; + printf("==========================================================\n"); + return; + break; + default: + break; + } + + /* 璁剧疆闇瑕乻elect鐨勫瓧娈 */ + if (iRet == 0) + iRet = get_request.need("uid"); + if (iRet == 0) + iRet = get_request.need("name"); + if (iRet == 0) + iRet = get_request.need("city"); + if (iRet == 0) + iRet = get_request.need("age"); + if (iRet == 0) + iRet = get_request.need("sex"); + if (iRet != 0) { + printf("get-req need error: %d", iRet); + fflush(stdout); + } + + /* 鎻愪氦璇锋眰锛屾墽琛岀粨鏋滃瓨鍦≧esult瀵硅薄閲 */ + iRet = get_request.do_execute(result); + /* 濡傛灉鍑洪敊,鍒欒緭鍑洪敊璇爜銆侀敊璇樁娈碉紝閿欒淇℃伅锛宻tResult.get_error_from(), + * result.get_error_message() + * 杩欎袱涓敊璇俊鎭緢閲嶈锛屼竴瀹氳鎵撳嵃鍑烘潵锛屾柟渚垮畾浣嶉棶棰 */ + if (iRet != 0) { + printf("uin[%u] dtc execute get error: %d, error_from:%s, msg:%s\n", + uid, // 鍑洪敊鐨刱ey鏄灏 + iRet, // 閿欒鐮佷负澶氬皯 + result.get_error_from(), // 杩斿洖閿欒闃舵 + result.get_error_message() // 杩斿洖閿欒淇℃伅 + ); + fflush(stdout); + } + /* 鏁版嵁涓嶅瓨鍦 */ + if (result.get_num_row_size() <= 0) + printf("uin[%u] data not exist.\n", uid); + + /* 璇诲彇缁撴灉鐨凨ey鍊 */ + printf("result key: %d\n", result.int_key()); + + /* 杈撳嚭缁撴灉鐨勮鏁 */ + printf("NumRows:%d\n", result.get_num_row_size()); + + /* 杈撳嚭缁撴灉 */ + for (int i = 0; i <= result.get_num_row_size(); ++i) { + /* 璇诲彇涓琛屾暟鎹 */ + iRet = result.fetch_row(); + if (iRet < 0) { + printf("uid[%lu] dtc fetch row error: %d\n", uid, iRet); + fflush(stdout); + } + /* 濡傛灉涓鍒囨纭紝鍒欏彲浠ヨ緭鍑烘暟鎹簡 */ + /* 杈撳嚭int绫诲瀷鐨勬暟鎹 */ + printf("uid: %d\n", result.int_value("uid")); + /* 杈撳嚭binary绫诲瀷鐨勬暟鎹 */ + printf("name: %s\n", result.binary_value("name")); + /* 杈撳嚭string绫诲瀷鐨勬暟鎹 */ + printf("city: %s\n", result.string_value("city")); + printf("age:%d\n", result.int_value("age")); + printf("sex:%d\n", result.int_value("sex")); + } + printf("==========================================================\n"); +} + +int main(int argc, char *argv[]) { + /* 鍙server涓嶆瀽鏋勶紝鍚庡彴浼氫繚鎸侀暱杩炴帴 */ + DTC::Server server; + + /* 璁剧疆鐨刣tc鐨刬p鍜岀鍙 */ + server.set_address("127.0.0.1", "20015"); + /* 璁剧疆缃戠粶瓒呮椂鏃堕棿,鍗曟缃戠粶IO鐨勮秴鏃,鍗曚綅绉 */ + server.SetTimeout(5); + /* 璁剧疆璁块棶鐮 AccessToken锛屽湪鐢宠dtc瀹炰緥鐨勬椂鍊欑綉绔欑浼氱敓鎴 */ + // server.set_accesskey("000022907e64e117fa92f892a85307782a68afc6"); + /* 璁剧疆dtc鐨勮〃鍚 */ + server.set_table_name("dtc_opensource"); + /* 澹版槑key绫诲瀷 */ + server.int_key(); + + int i; + for (i = E_INSERT_CORRENT_DATA; i < E_TOTAL_NUM_INS; i++) { + insert(server, (TypeIns)i); + } + select(server, E_SELECT_CORRENT_KEY); + for (i = E_UPDATE_CORRENT_DATA; i < E_TOTAL_NUM_UPD; i++) { + updata(server, (TypeUpd)i); + } + for (i = E_SELECT_CORRENT_KEY; i < E_TOTAL_NUM_SEL; i++) { + select(server, (TypeSel)i); + } + for (int i = E_DELETE_EXISTENCE; i < E_TOTAL_NUM_DEL; i++) { + delet(server, (TypeDel)i); + } + return 0; +} -- Gitee From 91cb062e9651265ba7e68ebd0276bd317db1dba0 Mon Sep 17 00:00:00 2001 From: yangshuang70 Date: Fri, 27 Aug 2021 17:17:30 +0800 Subject: [PATCH 39/39] 1 --- {src/conf => conf}/cache.yaml | 0 {src/conf => conf}/log4cplus.conf | 0 {src/conf => conf}/table.yaml | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {src/conf => conf}/cache.yaml (100%) rename {src/conf => conf}/log4cplus.conf (100%) rename {src/conf => conf}/table.yaml (100%) diff --git a/src/conf/cache.yaml b/conf/cache.yaml similarity index 100% rename from src/conf/cache.yaml rename to conf/cache.yaml diff --git a/src/conf/log4cplus.conf b/conf/log4cplus.conf similarity index 100% rename from src/conf/log4cplus.conf rename to conf/log4cplus.conf diff --git a/src/conf/table.yaml b/conf/table.yaml similarity index 100% rename from src/conf/table.yaml rename to conf/table.yaml -- Gitee