提交 0c96f765 编写于 作者: F freemine

1. bugfix: eok.c: array of pointers rather than POD buffer

2. initial port of taosd for MacOSX
上级 c5dfa590
......@@ -128,6 +128,8 @@ IF (TD_DARWIN_64)
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
SET(RELEASE_FLAGS "-Og")
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc)
ENDIF ()
IF (TD_WINDOWS)
......
......@@ -12,4 +12,8 @@ ADD_SUBDIRECTORY(MsvcLibX)
IF (TD_LINUX AND TD_MQTT)
ADD_SUBDIRECTORY(MQTT-C)
ENDIF ()
\ No newline at end of file
ENDIF ()
IF (TD_DARWIN AND TD_MQTT)
ADD_SUBDIRECTORY(MQTT-C)
ENDIF ()
......@@ -21,7 +21,7 @@ else
cd ${script_dir}
script_dir="$(pwd)"
data_dir="/var/lib/taos"
log_dir="~/TDengineLog"
log_dir=~/TDengineLog
fi
log_link_dir="/usr/local/taos/log"
......
......@@ -24,7 +24,7 @@ data_dir="/var/lib/taos"
if [ "$osType" != "Darwin" ]; then
log_dir="/var/log/taos"
else
log_dir="~/TDengineLog"
log_dir=~/TDengineLog
fi
data_link_dir="/usr/local/taos/data"
......@@ -178,7 +178,9 @@ function install_bin() {
function install_lib() {
# Remove links
${csudo} rm -f ${lib_link_dir}/libtaos.* || :
${csudo} rm -f ${lib64_link_dir}/libtaos.* || :
if [ "$osType" != "Darwin" ]; then
${csudo} rm -f ${lib64_link_dir}/libtaos.* || :
fi
if [ "$osType" != "Darwin" ]; then
${csudo} cp ${binary_dir}/build/lib/libtaos.so.${verNumber} ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
......@@ -190,12 +192,14 @@ function install_lib() {
${csudo} ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so
fi
else
${csudo} cp ${binary_dir}/build/lib/libtaos.* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib
${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib ${lib_link_dir}/libtaos.1.dylib
${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib
fi
${csudo} ldconfig
if [ "$osType" != "Darwin" ]; then
${csudo} ldconfig
fi
}
function install_header() {
......
......@@ -11,3 +11,7 @@ AUX_SOURCE_DIRECTORY(src SRC)
IF (TD_LINUX)
ADD_LIBRARY(balance ${SRC})
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(balance ${SRC})
ENDIF ()
......@@ -28,6 +28,28 @@ IF (TD_LINUX)
ADD_SUBDIRECTORY(tests)
ELSEIF (TD_DARWIN)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
# set the static lib name
ADD_LIBRARY(taos_static STATIC ${SRC})
TARGET_LINK_LIBRARIES(taos_static common query trpc tutil pthread m)
SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static")
SET_TARGET_PROPERTIES(taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
# generate dynamic library (*.dylib)
ADD_LIBRARY(taos SHARED ${SRC})
TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m)
SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1)
#set version of .dylib
#VERSION dylib version
#SOVERSION dylib version
#MESSAGE(STATUS "build version ${TD_VER_NUMBER}")
SET_TARGET_PROPERTIES(taos PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
ADD_SUBDIRECTORY(tests)
ELSEIF (TD_WINDOWS)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32)
......
......@@ -10,7 +10,17 @@ IF (TD_LINUX)
ADD_LIBRARY(tcq ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(tcq tutil common taos_static)
ELSE ()
ELSE ()
TARGET_LINK_LIBRARIES(tcq tutil common taos)
ENDIF ()
ADD_SUBDIRECTORY(test)
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(tcq ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(tcq tutil common taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(tcq tutil common taos)
ENDIF ()
ADD_SUBDIRECTORY(test)
......
......@@ -23,7 +23,7 @@ IF (TD_LINUX)
IF (TD_ACCOUNT)
TARGET_LINK_LIBRARIES(taosd account)
ENDIF ()
IF (TD_GRANT)
TARGET_LINK_LIBRARIES(taosd grant)
ENDIF ()
......@@ -47,3 +47,42 @@ IF (TD_LINUX)
COMMENT "prepare taosd environment")
ADD_CUSTOM_TARGET(${PREPARE_ENV_TARGET} ALL WORKING_DIRECTORY ${TD_EXECUTABLE_OUTPUT_PATH} DEPENDS ${PREPARE_ENV_CMD})
ENDIF ()
IF (TD_DARWIN)
ADD_EXECUTABLE(taosd ${SRC})
TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lz4 balance sync)
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(taosd taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(taosd taos)
ENDIF ()
IF (TD_ACCOUNT)
TARGET_LINK_LIBRARIES(taosd account)
ENDIF ()
IF (TD_GRANT)
TARGET_LINK_LIBRARIES(taosd grant)
ENDIF ()
IF (TD_MQTT)
TARGET_LINK_LIBRARIES(taosd mqtt)
ENDIF ()
# SET(PREPARE_ENV_CMD "prepare_env_cmd")
# SET(PREPARE_ENV_TARGET "prepare_env_target")
# ADD_CUSTOM_COMMAND(OUTPUT ${PREPARE_ENV_CMD}
# POST_BUILD
# COMMAND echo "make test directory"
# DEPENDS taosd
# COMMAND ${CMAKE_COMMAND} -E make_directory ${TD_TESTS_OUTPUT_DIR}/cfg/
# COMMAND ${CMAKE_COMMAND} -E make_directory ${TD_TESTS_OUTPUT_DIR}/log/
# COMMAND ${CMAKE_COMMAND} -E make_directory ${TD_TESTS_OUTPUT_DIR}/data/
# COMMAND ${CMAKE_COMMAND} -E echo dataDir ${TD_TESTS_OUTPUT_DIR}/data > ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
# COMMAND ${CMAKE_COMMAND} -E echo logDir ${TD_TESTS_OUTPUT_DIR}/log >> ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
# COMMAND ${CMAKE_COMMAND} -E echo charset UTF-8 >> ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
# COMMENT "prepare taosd environment")
# ADD_CUSTOM_TARGET(${PREPARE_ENV_TARGET} ALL WORKING_DIRECTORY ${TD_EXECUTABLE_OUTPUT_PATH} DEPENDS ${PREPARE_ENV_CMD})
ENDIF ()
......@@ -160,7 +160,11 @@ static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
syslog(LOG_INFO, "Shut down signal is %d", signum);
syslog(LOG_INFO, "Shutting down TDengine service...");
// clean the system.
#ifdef __APPLE__
dInfo("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid);
#else // __APPLE__
dInfo("shut down signal is %d, sender PID:%d cmdline:%s", signum, sigInfo->si_pid, taosGetCmdlineByPID(sigInfo->si_pid));
#endif
// protect the application from receive another signal
struct sigaction act = {{0}};
......
......@@ -236,6 +236,13 @@ static void sendTelemetryReport() {
taosCloseSocket(fd);
}
#ifdef __APPLE__
static int sem_timedwait(tsem_t *sem, struct timespec *to) {
fprintf(stderr, "%s[%d]%s(): not implemented yet!\n", basename(__FILE__), __LINE__, __func__);
abort();
}
#endif
static void* telemetryThread(void* param) {
struct timespec end = {0};
clock_gettime(CLOCK_REALTIME, &end);
......
......@@ -9,14 +9,14 @@ IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(./src SRC)
LIST(REMOVE_ITEM SRC ./src/shellWindows.c)
LIST(REMOVE_ITEM SRC ./src/shellDarwin.c)
ADD_EXECUTABLE(shell ${SRC})
ADD_EXECUTABLE(shell ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(shell taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(shell taos)
ENDIF ()
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
ELSEIF (TD_WINDOWS)
LIST(APPEND SRC ./src/shellEngine.c)
......@@ -27,7 +27,7 @@ ELSEIF (TD_WINDOWS)
IF (TD_POWER)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME power)
ELSE ()
ELSE ()
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
ENDIF ()
ELSEIF (TD_DARWIN)
......@@ -37,7 +37,10 @@ ELSEIF (TD_DARWIN)
LIST(APPEND SRC ./src/shellCommand.c)
LIST(APPEND SRC ./src/shellImport.c)
ADD_EXECUTABLE(shell ${SRC})
TARGET_LINK_LIBRARIES(shell taos_static)
# linking with dylib
TARGET_LINK_LIBRARIES(shell taos)
# linking taos statically
# TARGET_LINK_LIBRARIES(shell taos_static)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
ENDIF ()
......@@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taosdemo ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(taosdemo taos_static)
ELSE ()
......@@ -17,4 +17,13 @@ ELSEIF (TD_WINDOWS)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taosdemo ${SRC})
TARGET_LINK_LIBRARIES(taosdemo taos_static)
ELSEIF (TD_DARWIN)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taosdemo ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(taosdemo taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(taosdemo taos)
ENDIF ()
ENDIF ()
......@@ -4,22 +4,44 @@ PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/libcurl/include)
IF (TD_LINUX)
IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taosdemox ${SRC})
#find_program(HAVE_CURL NAMES curl)
IF ((NOT TD_ARM_64) AND (NOT TD_ARM_32))
#find_program(HAVE_CURL NAMES curl)
IF ((NOT TD_ARM_64) AND (NOT TD_ARM_32))
ADD_DEFINITIONS(-DTD_LOWA_CURL)
LINK_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/libcurl/lib)
ADD_LIBRARY(curl STATIC IMPORTED)
SET_PROPERTY(TARGET curl PROPERTY IMPORTED_LOCATION ${TD_COMMUNITY_DIR}/deps/libcurl/lib/libcurl.a)
TARGET_LINK_LIBRARIES(taosdemox curl)
TARGET_LINK_LIBRARIES(taosdemox curl)
ENDIF ()
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(taosdemox taos_static cJson)
ELSE ()
TARGET_LINK_LIBRARIES(taosdemox taos cJson)
ENDIF ()
ENDIF ()
IF (TD_DARWIN)
# missing a few dependencies, such as <argp.h>
# AUX_SOURCE_DIRECTORY(. SRC)
# ADD_EXECUTABLE(taosdemox ${SRC})
#
# #find_program(HAVE_CURL NAMES curl)
# IF ((NOT TD_ARM_64) AND (NOT TD_ARM_32))
# ADD_DEFINITIONS(-DTD_LOWA_CURL)
# LINK_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/libcurl/lib)
# ADD_LIBRARY(curl STATIC IMPORTED)
# SET_PROPERTY(TARGET curl PROPERTY IMPORTED_LOCATION ${TD_COMMUNITY_DIR}/deps/libcurl/lib/libcurl.a)
# TARGET_LINK_LIBRARIES(taosdemox curl)
# ENDIF ()
#
# IF (TD_SOMODE_STATIC)
# TARGET_LINK_LIBRARIES(taosdemox taos_static cJson)
# ELSE ()
# TARGET_LINK_LIBRARIES(taosdemox taos cJson)
# ENDIF ()
ENDIF ()
......@@ -12,5 +12,15 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES(taosdump taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(taosdump taos)
ENDIF ()
ENDIF ()
ENDIF ()
IF (TD_DARWIN)
# missing <argp.h> for macosx
# ADD_EXECUTABLE(taosdump ${SRC})
# IF (TD_SOMODE_STATIC)
# TARGET_LINK_LIBRARIES(taosdump taos_static)
# ELSE ()
# TARGET_LINK_LIBRARIES(taosdump taos)
# ENDIF ()
ENDIF ()
......@@ -9,4 +9,15 @@ IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(mnode ${SRC})
ENDIF ()
\ No newline at end of file
ENDIF ()
IF (TD_DARWIN)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc)
INCLUDE_DIRECTORIES(inc)
AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(mnode ${SRC})
ENDIF ()
......@@ -138,6 +138,13 @@ void mnodeDecClusterRef(SClusterObj *pCluster) {
sdbDecRef(tsClusterSdb, pCluster);
}
#ifdef __APPLE__
bool taosGetSystemUid(char *uid) {
fprintf(stderr, "%s[%d]%s(): not implemented yet!\n", basename(__FILE__), __LINE__, __func__);
abort();
return false;
}
#endif // __APPLE__
static int32_t mnodeCreateCluster() {
int32_t numOfClusters = sdbGetNumOfRows(tsClusterSdb);
if (numOfClusters != 0) return TSDB_CODE_SUCCESS;
......
......@@ -103,9 +103,9 @@ struct eok_event_s {
typedef struct eoks_s eoks_t;
struct eoks_s {
pthread_mutex_t lock;
ep_over_kq_t *eoks;
int neoks;
ep_over_kq_t *eoks_free;
ep_over_kq_t **eoks; // note: this memory leaks when process terminates
int neoks; // we can add an extra api to let user clean
ep_over_kq_t *eoks_free; // currently, we just keep it simple stupid
};
static eoks_t eoks = {
......@@ -297,7 +297,7 @@ int epoll_create(int size) {
struct epoll_event ev = {0};
ev.events = EPOLLIN;
ev.data.ptr = &eok_dummy;
D("epoll_create epfd:[%d]", eok->idx);
D("epoll_create epfd:[%d] and sv0[%d]", eok->idx, eok->sv[0]);
if (epoll_ctl(eok->idx, EPOLL_CTL_ADD, eok->sv[0], &ev)) {
e = errno;
epoll_close(eok->idx);
......@@ -517,8 +517,8 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
eok_event_t *ev = (eok_event_t*)kev->udata;
A(kev->ident == ev->fd, "internal logic error");
if (kev->flags & EV_ERROR) {
D("error when processing change list for fd[%d], error[%s], kev_flags:[%04x:%s]",
ev->fd, strerror(kev->data), kev->flags, kev_flags_str(kev->flags, 0));
D("epfd[%d] error when processing change list for fd[%d], error[%s], kev_flags:[%04x:%s]",
epfd, ev->fd, strerror(kev->data), kev->flags, kev_flags_str(kev->flags, 0));
}
switch (kev->filter) {
case EVFILT_READ: {
......@@ -528,11 +528,11 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
char c = '\0';
A(1==recv(kev->ident, &c, 1, 0), "internal logic error");
A(0==memcmp(&c, "1", 1), "internal logic error");
D("wokenup");
D("epfd[%d] wokenup", epfd);
continue;
} else {
if (ev->changed==3) {
D("already requested to delete for fd[%d]", ev->fd);
D("epfd[%d] already requested to delete for fd[%d]", epfd, ev->fd);
// TODO: write a unit test for this case
// EV_DELETE?
continue;
......@@ -550,7 +550,8 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
}
// rounded to what user care
pev.events = pev.events & ev->epev.events;
D("events found for fd[%d]: [%04x:%s], which was registered: [%04x:%s], kev_flags: [%04x:%s]",
D("epfd[%d] events found for fd[%d]: [%04x:%s], which was registered: [%04x:%s], kev_flags: [%04x:%s]",
epfd,
ev->fd, pev.events, events_str(pev.events, 0),
ev->epev.events, events_str(ev->epev.events, 1),
kev->flags, kev_flags_str(kev->flags, 2));
......@@ -573,7 +574,7 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
while (p) {
eok_event_t *next = p->next;
if (p->changed==3) {
D("removing registered event for fd[%d]: [%04x:%s]", p->fd, p->epev.events, events_str(p->epev.events, 0));
D("epfd[%d] removing registered event for fd[%d]: [%04x:%s]", epfd, p->fd, p->epev.events, events_str(p->epev.events, 0));
eok_free_ev(eok, p);
}
p = next;
......@@ -591,13 +592,13 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
}
} while (cnts==0);
if (cnts>0) {
D("kevent64 waiting done with [%d] events", cnts);
D("kevent64 epfd[%d] waiting done with [%d] events", epfd, cnts);
}
A(0==pthread_mutex_unlock(&eok->lock), "");
if (e) {
errno = e;
E("epoll_wait failed");
E("epfd[%d] epoll_wait failed", epfd);
return -1;
}
......@@ -752,7 +753,7 @@ static int eok_chgs_refresh(ep_over_kq_t *eok, eok_event_t *oev, eok_event_t *ev
eok->kchanges[eok->ichanges++] = *kwev;
++n;
}
D("add #changes[%d] for fd[%d], and now #changes/registers [%d/%d]", n, ev->fd, eok->ichanges, eok->evs_count);
D("epfd[%d]: add #changes[%d] for fd[%d], and now #changes/registers [%d/%d]", eok->idx, n, ev->fd, eok->ichanges, eok->evs_count);
return 0;
}
......@@ -764,14 +765,21 @@ static ep_over_kq_t* eoks_alloc(void) {
if (eoks.eoks_free) {
eok = eoks.eoks_free;
eoks.eoks_free = eok->next;
A(eoks.eoks, "internal logic error");
A(eok->idx>=0 && eok->idx<eoks.neoks, "internal logic error");
A(*(eoks.eoks + eok->idx)==NULL, "internal logic error");
*(eoks.eoks + eok->idx) = eok;
eok->next = NULL;
eok->stopping = 0;
break;
}
ep_over_kq_t *p = (ep_over_kq_t*)realloc(eoks.eoks, sizeof(*p) * (eoks.neoks+1));
if (!p) break;
eoks.eoks = p;
eok = eoks.eoks + eoks.neoks;
memset(eok, 0, sizeof(*eok));
eok = (ep_over_kq_t*)calloc(1, sizeof(*eok));
if (!eok) break;
eok->idx = -1;
ep_over_kq_t **ar = (ep_over_kq_t**)realloc(eoks.eoks, sizeof(**ar) * (eoks.neoks+1));
if (!ar) break;
eoks.eoks = ar;
*(eoks.eoks + eoks.neoks) = eok;
eok->idx = eoks.neoks;
eok->kq = -1;
eok->sv[0] = -1;
......@@ -784,6 +792,11 @@ static ep_over_kq_t* eoks_alloc(void) {
errno = ENOMEM;
return NULL;
}
if (eok->idx==-1) {
free(eok);
errno = ENOMEM;
return NULL;
}
if (eok->lock_valid) {
return eok;
}
......@@ -801,23 +814,50 @@ static ep_over_kq_t* eoks_alloc(void) {
static void eoks_free(ep_over_kq_t *eok) {
A(0==pthread_mutex_lock(&eoks.lock), "");
do {
A(eok->idx>=0 && eok->idx<eoks.neoks, "internal logic error");
A(eok->next==NULL, "internal logic error");
// leave eok->kchanges as is
A(eok->ichanges==0, "internal logic error");
A(eok->waiting==0, "internal logic error");
if (eok->evs_count==1) {
A(eok->evs_head && eok->evs_tail && eok->evs_head==eok->evs_tail, "internal logic error");
A(eok->evs_head->fd==eok->sv[0] && eok->sv[0]!=-1 && eok->sv[1]!=-1, "internal logic error");
// fd is critical system resource
close(eok->sv[0]);
eok->sv[0] = -1;
close(eok->sv[1]);
eok->sv[1] = -1;
eok_free_ev(eok, eok->evs_head);
eok_event_t *ev = eok->evs_head;
while (ev) {
eok_event_t *next = ev->next;
if (ev->fd==eok->sv[0]) {
// fd is critical system resource
close(eok->sv[0]);
eok->sv[0] = -1;
close(eok->sv[1]);
eok->sv[1] = -1;
eok_free_ev(eok, ev);
} else {
// user forget calling epoll_ctl(EPOLL_CTL_DEL) before calling epoll_close/close?
// calling close(ev->fd) here smells really bad
#ifdef LET_IT_BE
// we just let it be and reclaim ev
eok_free_ev(eok, ev);
#else
// panic otherwise, if LET_IT_BE not defined
A(eok->evs_head==NULL && eok->evs_tail==NULL && eok->evs_count==0,
"epfd[%d] fd[%d]: internal logic error: have you epoll_ctl(EPOLL_CTL_DEL) everything before calling epoll_close?",
eok->idx, ev->fd);
#endif
}
ev = next;
}
A(eok->evs_head==NULL && eok->evs_tail==NULL && eok->evs_count==0, "internal logic error");
// if (eok->evs_count==1) {
// A(eok->evs_head && eok->evs_tail && eok->evs_head==eok->evs_tail, "internal logic error");
// A(eok->evs_head->fd==eok->sv[0] && eok->sv[0]!=-1 && eok->sv[1]!=-1, "internal logic error");
// // fd is critical system resource
// close(eok->sv[0]);
// eok->sv[0] = -1;
// close(eok->sv[1]);
// eok->sv[1] = -1;
// eok_free_ev(eok, eok->evs_head);
// }
A(eok->evs_head==NULL && eok->evs_tail==NULL && eok->evs_count==0,
"internal logic error: have you epoll_ctl(EPOLL_CTL_DEL) everything before calling epoll_close?");
A(eok->sv[0]==-1 && eok->sv[1]==-1, "internal logic error");
if (eok->kq!=-1) {
close(eok->kq);
......@@ -825,6 +865,7 @@ static void eoks_free(ep_over_kq_t *eok) {
}
eok->next = eoks.eoks_free;
eoks.eoks_free = eok;
*(eoks.eoks + eok->idx) = NULL;
} while (0);
A(0==pthread_mutex_unlock(&eoks.lock), "");
}
......@@ -837,7 +878,7 @@ static ep_over_kq_t* eoks_find(int epfd) {
break;
}
A(eoks.eoks, "internal logic error");
eok = eoks.eoks + epfd;
eok = *(eoks.eoks + epfd);
A(eok->next==NULL, "internal logic error");
A(eok->lock_valid, "internal logic error");
} while (0);
......
......@@ -13,3 +13,4 @@ TARGET_LINK_LIBRARIES(osdetail os)
IF (TD_ARM_32 OR TD_LINUX_32)
TARGET_LINK_LIBRARIES(osdetail atomic)
ENDIF ()
......@@ -8,14 +8,29 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
INCLUDE_DIRECTORIES(inc)
AUX_SOURCE_DIRECTORY(src SRC)
IF (TD_LINUX)
ADD_LIBRARY(http ${SRC})
TARGET_LINK_LIBRARIES(http z)
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(http taos_static)
ELSE ()
ELSE ()
TARGET_LINK_LIBRARIES(http taos)
ENDIF ()
IF (TD_ADMIN)
TARGET_LINK_LIBRARIES(http admin)
ENDIF ()
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(http ${SRC})
TARGET_LINK_LIBRARIES(http z)
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(http taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(http taos)
ENDIF ()
......
......@@ -31,11 +31,36 @@
static bool httpReadData(HttpContext *pContext);
#ifdef __APPLE__
static int sv_dummy = 0;
#endif
static void httpStopThread(HttpThread* pThread) {
pThread->stop = true;
// signal the thread to stop, try graceful method first,
// and use pthread_cancel when failed
#ifdef __APPLE__
int sv[2];
sv[0] = sv[1] = -1;
int r = socketpair(PF_LOCAL, SOCK_STREAM, 0, sv);
do {
if (r) break;
struct epoll_event ev = {0};
ev.events = EPOLLIN;
ev.data.ptr = &sv_dummy;
pThread->stop = true;
r = epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, sv[0], &ev);
if (r) break;
if (1!=send(sv[1], "1", 1, 0)) {
r = -1;
break;
}
} while (0);
if (r) {
pthread_cancel(pThread->thread);
}
#else // __APPLE__
struct epoll_event event = { .events = EPOLLIN };
eventfd_t fd = eventfd(1, 0);
if (fd == -1) {
......@@ -46,11 +71,23 @@ static void httpStopThread(HttpThread* pThread) {
httpError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno));
pthread_cancel(pThread->thread);
}
#endif // __APPLE__
pthread_join(pThread->thread, NULL);
#ifdef __APPLE__
if (sv[0]!=-1) {
close(sv[0]);
sv[0] = -1;
}
if (sv[1]!=-1) {
close(sv[1]);
sv[1] = -1;
}
#else // __APPLE__
if (fd != -1) {
close(fd);
}
#endif // __APPLE__
#ifdef __APPLE__
epoll_close(pThread->pollFd);
......@@ -97,6 +134,15 @@ static void httpProcessHttpData(void *param) {
if (fdNum <= 0) continue;
for (int32_t i = 0; i < fdNum; ++i) {
#ifdef __APPLE__
if (events[i].data.ptr == &sv_dummy) {
// no need to drain the recv buffer of sv[0]
// since there's only one time to send at most 1 byte to sv[0]
// btw, pThread->stop shall be already set, thus never reached here
httpDebug("if you see this line, there's internal logic error");
continue;
}
#endif // __APPLE__
pContext = httpGetContext(events[i].data.ptr);
if (pContext == NULL) {
httpError("context:%p, is already released, close connect", events[i].data.ptr);
......
......@@ -8,10 +8,20 @@ AUX_SOURCE_DIRECTORY(./src SRC)
IF (TD_LINUX)
ADD_LIBRARY(monitor ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(monitor taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(monitor taos)
ENDIF ()
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(monitor ${SRC})
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(monitor taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(monitor taos)
ENDIF ()
ENDIF ()
ENDIF ()
......@@ -18,3 +18,15 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES(mqtt taos)
ENDIF ()
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(mqtt ${SRC})
TARGET_LINK_LIBRARIES(mqtt cJson mqttc)
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(mqtt taos_static)
ELSE ()
TARGET_LINK_LIBRARIES(mqtt taos)
ENDIF ()
ENDIF ()
......@@ -14,3 +14,8 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES(query m rt)
ADD_SUBDIRECTORY(tests)
ENDIF ()
IF (TD_DARWIN)
TARGET_LINK_LIBRARIES(query m)
ADD_SUBDIRECTORY(tests)
ENDIF ()
......@@ -308,7 +308,10 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *
pthread_attr_destroy(&thattr);
if (code != 0) {
#ifdef __APPLE__
epoll_close(pThreadObj->pollFd);
if (pThreadObj->pollFd!=-1) {
epoll_close(pThreadObj->pollFd);
pThreadObj->pollFd = -1;
}
#else
taosCloseSocket(pThreadObj->pollFd);
#endif
......@@ -517,7 +520,10 @@ static void *taosProcessTcpData(void *param) {
}
#ifdef __APPLE__
if (pThreadObj->pollFd >=0) epoll_close(pThreadObj->pollFd);
if (pThreadObj->pollFd >=0) {
epoll_close(pThreadObj->pollFd);
pThreadObj->pollFd = -1;
}
#else
if (pThreadObj->pollFd >=0) taosCloseSocket(pThreadObj->pollFd);
#endif
......
......@@ -16,3 +16,17 @@ IF (TD_LINUX)
ADD_EXECUTABLE(rserver ${SERVER_SRC})
TARGET_LINK_LIBRARIES(rserver trpc)
ENDIF ()
IF (TD_DARWIN)
LIST(APPEND CLIENT_SRC ./rclient.c)
ADD_EXECUTABLE(rclient ${CLIENT_SRC})
TARGET_LINK_LIBRARIES(rclient trpc)
LIST(APPEND SCLIENT_SRC ./rsclient.c)
ADD_EXECUTABLE(rsclient ${SCLIENT_SRC})
TARGET_LINK_LIBRARIES(rsclient trpc)
LIST(APPEND SERVER_SRC ./rserver.c)
ADD_EXECUTABLE(rserver ${SERVER_SRC})
TARGET_LINK_LIBRARIES(rserver trpc)
ENDIF ()
......@@ -3,7 +3,7 @@ PROJECT(TDengine)
INCLUDE_DIRECTORIES(inc)
AUX_SOURCE_DIRECTORY(src SRC)
IF (TD_LINUX)
LIST(REMOVE_ITEM SRC src/syncArbitrator.c)
ADD_LIBRARY(sync ${SRC})
......@@ -16,3 +16,16 @@ IF (TD_LINUX)
#ADD_SUBDIRECTORY(test)
ENDIF ()
IF (TD_DARWIN)
LIST(REMOVE_ITEM SRC src/syncArbitrator.c)
ADD_LIBRARY(sync ${SRC})
TARGET_LINK_LIBRARIES(sync tutil pthread common)
LIST(APPEND BIN_SRC src/syncArbitrator.c)
LIST(APPEND BIN_SRC src/syncTcp.c)
ADD_EXECUTABLE(tarbitrator ${BIN_SRC})
TARGET_LINK_LIBRARIES(tarbitrator sync common osdetail tutil)
#ADD_SUBDIRECTORY(test)
ENDIF ()
......@@ -14,7 +14,7 @@
*/
#define _DEFAULT_SOURCE
#include <sys/inotify.h>
// #include <sys/inotify.h>
#include "os.h"
#include "taoserror.h"
#include "tlog.h"
......
......@@ -13,4 +13,3 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES(syncServer sync trpc common)
ENDIF ()
......@@ -5,7 +5,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(tutil ${SRC})
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z)
IF (TD_LINUX)
TARGET_LINK_LIBRARIES(tutil m rt)
# ADD_SUBDIRECTORY(tests)
......@@ -28,5 +28,6 @@ IF (TD_LINUX)
ELSEIF (TD_WINDOWS)
TARGET_LINK_LIBRARIES(tutil iconv regex winmm IPHLPAPI ws2_32 wepoll)
ELSEIF(TD_DARWIN)
TARGET_LINK_LIBRARIES(tutil m)
TARGET_LINK_LIBRARIES(tutil iconv)
ENDIF()
......@@ -13,3 +13,9 @@ IF (TD_LINUX)
ADD_LIBRARY(vnode ${SRC})
TARGET_LINK_LIBRARIES(vnode tsdb tcq)
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(vnode ${SRC})
TARGET_LINK_LIBRARIES(vnode tsdb tcq)
ENDIF ()
......@@ -8,4 +8,10 @@ IF (TD_LINUX)
ADD_LIBRARY(twal ${SRC})
TARGET_LINK_LIBRARIES(twal tutil common)
ADD_SUBDIRECTORY(test)
ENDIF ()
ENDIF ()
IF (TD_DARWIN)
ADD_LIBRARY(twal ${SRC})
TARGET_LINK_LIBRARIES(twal tutil common)
ADD_SUBDIRECTORY(test)
ENDIF ()
......@@ -10,4 +10,12 @@ IF (TD_LINUX)
ENDIF ()
IF (TD_DARWIN)
INCLUDE_DIRECTORIES(../inc)
LIST(APPEND WALTEST_SRC ./waltest.c)
ADD_EXECUTABLE(waltest ${WALTEST_SRC})
TARGET_LINK_LIBRARIES(waltest twal osdetail tutil)
ENDIF ()
......@@ -5,3 +5,8 @@ IF (TD_LINUX)
add_executable(tdengineTest tdengineTest.c)
target_link_libraries(tdengineTest taos_static tutil common pthread)
ENDIF()
IF (TD_DARWIN)
add_executable(tdengineTest tdengineTest.c)
target_link_libraries(tdengineTest taos_static tutil common pthread)
ENDIF()
......@@ -10,6 +10,9 @@ IF (TD_LINUX)
ENDIF ()
IF (TD_DARWIN)
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(demo demo.c)
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
ADD_EXECUTABLE(epoll epoll.c)
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread )
ENDIF ()
......@@ -86,7 +86,7 @@ void Test(TAOS *taos, char *qstr, int index) {
int i = 0;
for (i = 0; i < 10; ++i) {
sprintf(qstr, "insert into m1 values (%" PRId64 ", %d, %d, %d, %d, %f, %lf, '%s')", 1546300800000 + i * 1000, i, i, i, i*10000000, i*1.0, i*2.0, "hello");
sprintf(qstr, "insert into m1 values (%" PRId64 ", %d, %d, %d, %d, %f, %lf, '%s')", 1546300800000LL + i * 1000, i, i, i, i*10000000, i*1.0, i*2.0, "hello");
printf("qstr: %s\n", qstr);
// note: how do you wanna do if taos_query returns non-NULL
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册