Skip to content

Commit

Permalink
fix: alpine support (taosdata#19353)
Browse files Browse the repository at this point in the history
* fix: alpine support

* fix: ostimer thread_id

* fix: taosPrintTrace and tsStreamMax

* fix: make_install.sh and dnodes.py for alpine

* fix: cmake.platform and cut option for alpine

* fix: timer sigev and string convert

* fix: test case for alpine

* fix: fix test script for alpine

* fix: fix test script for alpine

* fix: fix taosLogTrace for Alpine

* fix: fix taosSort

* fix: vnode and mnode compare functions and test cases

* fix: sorting algorithms and unit tests

* fix: libtaosws.so build error on Alpine

* fix: libtaosws.so build error on Alpine

---------

Co-authored-by: t_max <1172915550@qq.com>
  • Loading branch information
sangshuduo and huskar-t authored Feb 10, 2023
1 parent 703c406 commit ea5d925
Show file tree
Hide file tree
Showing 42 changed files with 452 additions and 270 deletions.
15 changes: 15 additions & 0 deletions cmake/cmake.platform
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin
SET(TD_LINUX_32 TRUE)
ENDIF ()

EXECUTE_PROCESS(COMMAND chmod 777 ${CMAKE_CURRENT_LIST_DIR}/../packaging/tools/get_os.sh)
EXECUTE_PROCESS(COMMAND readlink /bin/sh OUTPUT_VARIABLE SHELL_LINK)
MESSAGE(STATUS "The shell is: " ${SHELL_LINK})

IF (${SHELL_LINK} MATCHES "dash")
EXECUTE_PROCESS(COMMAND ${CMAKE_CURRENT_LIST_DIR}/../packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
ELSE ()
EXECUTE_PROCESS(COMMAND sh ${CMAKE_CURRENT_LIST_DIR}/../packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
ENDIF ()
MESSAGE(STATUS "The current OS is " ${TD_OS_INFO})
IF (${TD_OS_INFO} MATCHES "Alpine")
SET(TD_ALPINE TRUE)
ADD_DEFINITIONS("-D_ALPINE")
ENDIF ()

ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

SET(TD_DARWIN TRUE)
Expand Down
2 changes: 1 addition & 1 deletion cmake/taosws_CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# taosws-rs
ExternalProject_Add(taosws-rs
GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git
GIT_TAG f406d51
GIT_TAG main
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
Expand Down
4 changes: 4 additions & 0 deletions include/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ extern "C" {

#if !defined(WINDOWS)
#include <dirent.h>

#if !defined(_ALPINE)
#include <execinfo.h>
#endif

#include <libgen.h>
#include <sched.h>
#include <unistd.h>
Expand Down
7 changes: 7 additions & 0 deletions include/os/osSysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ void taosSetCoreDump(bool enable);

#endif // WINDOWS

#if defined(_ALPINE)

#define _UTSNAME_LENGTH 65
#define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH

#endif

typedef struct {
char sysname[_UTSNAME_MACHINE_LENGTH];
char nodename[_UTSNAME_MACHINE_LENGTH];
Expand Down
254 changes: 171 additions & 83 deletions include/os/osSystem.h

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion include/os/osThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
extern "C" {
#endif

#ifndef WINDOWS
#if !defined(WINDOWS) && !defined(_ALPINE)
#ifndef __USE_XOPEN2K
#define TD_USE_SPINLOCK_AS_MUTEX
typedef pthread_mutex_t pthread_spinlock_t;
Expand Down Expand Up @@ -100,7 +100,11 @@ typedef pthread_key_t TdThreadKey;
#define pthread_condattr_init PTHREAD_CONDATTR_INIT_FUNC_TAOS_FORBID
#define pthread_condattr_setpshared PTHREAD_CONDATTR_SETPSHARED_FUNC_TAOS_FORBID
#define pthread_detach PTHREAD_DETACH_FUNC_TAOS_FORBID

#if !defined(_ALPINE)
#define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
#endif

#define pthread_exit PTHREAD_EXIT_FUNC_TAOS_FORBID
#define pthread_getschedparam PTHREAD_GETSCHEDPARAM_FUNC_TAOS_FORBID
#define pthread_getspecific PTHREAD_GETSPECIFIC_FUNC_TAOS_FORBID
Expand Down
4 changes: 2 additions & 2 deletions packaging/tools/make_install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# This file is used to install TAOS time-series database on linux systems. The operating system
# is required to use systemd to manage services at boot
Expand Down Expand Up @@ -340,7 +340,7 @@ function install_lib() {
#install_avro lib64

if [ "$osType" != "Darwin" ]; then
${csudo}ldconfig
${csudo}ldconfig /etc/ld.so.conf.d
fi
}

Expand Down
2 changes: 2 additions & 0 deletions source/common/src/tglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
if (cfgAddBool(pCfg, "SIMD-builtins", tsSIMDBuiltins, 0) != 0) return -1;

if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
#if !defined(_ALPINE)
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
#endif
if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
Expand Down
16 changes: 12 additions & 4 deletions source/dnode/mnode/impl/src/mndVgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,25 @@ SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId) {
return pArray;
}

static int32_t mndCompareDnodeId(int32_t *dnode1Id, int32_t *dnode2Id) { return *dnode1Id >= *dnode2Id ? 1 : 0; }
static int32_t mndCompareDnodeId(int32_t *dnode1Id, int32_t *dnode2Id) {
if (*dnode1Id == *dnode2Id) {
return 0;
}
return *dnode1Id > *dnode2Id ? 1 : -1;
}

static float mndGetDnodeScore(SDnodeObj *pDnode, int32_t additionDnodes, float ratio) {
float totalDnodes = pDnode->numOfVnodes + (float)pDnode->numOfOtherNodes * ratio + additionDnodes;
return totalDnodes / pDnode->numOfSupportVnodes;
}

static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) {
float d1Score = mndGetDnodeScore(pDnode1, 0, 0.9);
float d2Score = mndGetDnodeScore(pDnode2, 0, 0.9);
return d1Score >= d2Score ? 1 : 0;
float d1Score = mndGetDnodeScore(pDnode1, 0, 0.9);
float d2Score = mndGetDnodeScore(pDnode2, 0, 0.9);
if (d1Score == d2Score) {
return 0;
}
return d1Score > d2Score ? 1 : -1;
}

void mndSortVnodeGid(SVgObj *pVgroup) {
Expand Down
4 changes: 4 additions & 0 deletions source/os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ elseif(TD_DARWIN_64)
target_link_libraries(
os PUBLIC dl m iconv
)
elseif(TD_ALPINE)
target_link_libraries(
os PUBLIC dl m rt unwind
)
else()
target_link_libraries(
os PUBLIC dl m rt
Expand Down
4 changes: 2 additions & 2 deletions source/os/src/osMath.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include <stdlib.h>
#include "os.h"
#include "talgo.h"

#ifdef WINDOWS
void swapStr(char* j, char* J, int width) {
Expand All @@ -41,7 +41,7 @@ int32_t qsortHelper(const void* p1, const void* p2, const void* param) {
void taosSort(void* base, int64_t sz, int64_t width, __compar_fn_t compar) {
#ifdef _ALPINE
void* param = compar;
taosqsort(base, width, sz, param, qsortHelper);
taosqsort(base, sz, width, param, qsortHelper);
#else
qsort(base, sz, width, compar);
#endif
Expand Down
2 changes: 1 addition & 1 deletion source/os/src/osMemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ int64_t taosMemorySize(void *ptr) {
}

void taosMemoryTrim(int32_t size) {
#if defined(WINDOWS) || defined(DARWIN)
#if defined(WINDOWS) || defined(DARWIN) || defined(_ALPINE)
// do nothing
return;
#else
Expand Down
14 changes: 7 additions & 7 deletions source/os/src/osString.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ char *taosStrCaseStr(const char *str, const char *pattern) {

int64_t taosStr2Int64(const char *str, char **pEnd, int32_t radix) {
int64_t tmp = strtoll(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand All @@ -363,7 +363,7 @@ int64_t taosStr2Int64(const char *str, char **pEnd, int32_t radix) {

uint64_t taosStr2UInt64(const char *str, char **pEnd, int32_t radix) {
uint64_t tmp = strtoull(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand All @@ -375,7 +375,7 @@ uint64_t taosStr2UInt64(const char *str, char **pEnd, int32_t radix) {

int32_t taosStr2Int32(const char *str, char **pEnd, int32_t radix) {
int32_t tmp = strtol(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand All @@ -387,7 +387,7 @@ int32_t taosStr2Int32(const char *str, char **pEnd, int32_t radix) {

uint32_t taosStr2UInt32(const char *str, char **pEnd, int32_t radix) {
uint32_t tmp = strtol(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand All @@ -399,7 +399,7 @@ uint32_t taosStr2UInt32(const char *str, char **pEnd, int32_t radix) {

int16_t taosStr2Int16(const char *str, char **pEnd, int32_t radix) {
int32_t tmp = strtol(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand All @@ -413,7 +413,7 @@ int16_t taosStr2Int16(const char *str, char **pEnd, int32_t radix) {

uint16_t taosStr2UInt16(const char *str, char **pEnd, int32_t radix) {
uint32_t tmp = strtoul(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand All @@ -437,7 +437,7 @@ int8_t taosStr2Int8(const char *str, char **pEnd, int32_t radix) {

uint8_t taosStr2UInt8(const char *str, char **pEnd, int32_t radix) {
uint32_t tmp = strtoul(str, pEnd, radix);
#ifdef DARWIN
#if defined(DARWIN) || defined(_ALPINE)
if (errno == EINVAL) errno = 0;
#endif
#ifdef TD_CHECK_STR_TO_INT_ERROR
Expand Down
2 changes: 1 addition & 1 deletion source/os/src/osSysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static char tsProcIOFile[25] = {0};
static void taosGetProcIOnfos() {
tsPageSizeKB = sysconf(_SC_PAGESIZE) / 1024;
tsOpenMax = sysconf(_SC_OPEN_MAX);
tsStreamMax = sysconf(_SC_STREAM_MAX);
tsStreamMax = TMAX(sysconf(_SC_STREAM_MAX), 0);
tsProcId = (pid_t)syscall(SYS_gettid);

snprintf(tsProcMemFile, sizeof(tsProcMemFile), "/proc/%d/status", tsProcId);
Expand Down
4 changes: 2 additions & 2 deletions source/os/src/osTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ static void *taosProcessAlarmSignal(void *tharg) {
setThreadName("tmr");

#ifdef _ALPINE
sevent.sigev_notify = SIGEV_THREAD;
sevent.sigev_value.sival_int = syscall(__NR_gettid);
sevent.sigev_notify = SIGEV_THREAD_ID;
sevent.sigev_notify_thread_id = syscall(__NR_gettid);
#else
sevent.sigev_notify = SIGEV_THREAD_ID;
sevent._sigev_un._tid = syscall(__NR_gettid);
Expand Down
64 changes: 42 additions & 22 deletions tests/pytest/util/dnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import os
import os.path
import platform
import distro
import subprocess
from time import sleep
import base64
import json
import copy
from fabric2 import Connection
from util.log import *
from shutil import which


class TDSimClient:
Expand Down Expand Up @@ -166,9 +168,9 @@ def setAsan(self, value):
if value:
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
self.execPath = os.path.abspath(self.path + "/community/tests/script/sh/exec.sh")
self.execPath = os.path.abspath(self.path + "/community/tests/script/sh/exec.sh")
else:
self.execPath = os.path.abspath(self.path + "/tests/script/sh/exec.sh")
self.execPath = os.path.abspath(self.path + "/tests/script/sh/exec.sh")

def getDataSize(self):
totalSize = 0
Expand Down Expand Up @@ -686,7 +688,7 @@ def setAsan(self, value):
if ("community" in selfPath):
self.stopDnodesPath = os.path.abspath(self.path + "/community/tests/script/sh/stop_dnodes.sh")
self.stopDnodesSigintPath = os.path.abspath(self.path + "/community/tests/script/sh/sigint_stop_dnodes.sh")
else:
else:
self.stopDnodesPath = os.path.abspath(self.path + "/tests/script/sh/stop_dnodes.sh")
self.stopDnodesSigintPath = os.path.abspath(self.path + "/tests/script/sh/sigint_stop_dnodes.sh")
tdLog.info("run in address sanitizer mode")
Expand Down Expand Up @@ -765,7 +767,8 @@ def StopAllSigint(self):

def stopAll(self):
tdLog.info("stop all dnodes, asan:%d" % self.asan)
if self.asan:
distro_id = distro.id()
if self.asan and distro_id != "alpine":
tdLog.info("execute script: %s" % self.stopDnodesPath)
os.system(self.stopDnodesPath)
tdLog.info("execute finished")
Expand All @@ -777,24 +780,41 @@ def stopAll(self):
for i in range(len(self.dnodes)):
self.dnodes[i].stop()

psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep| grep -v defunct | awk '{print $2}' | xargs"
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
if processID:
cmd = "sudo systemctl stop taosd"
os.system(cmd)
# if os.system(cmd) != 0 :
# tdLog.exit(cmd)
psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}' | xargs"
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
while(processID):
if platform.system().lower() == 'windows':
killCmd = "kill -9 %s > nul 2>&1" % processID
else:
killCmd = "kill -9 %s > /dev/null 2>&1" % processID
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(
psCmd, shell=True).decode("utf-8").strip()

if (distro_id == "alpine"):
print(distro_id)
psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep| grep -v defunct | awk '{print $2}' | xargs"
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
while(processID):
print(processID)
if platform.system().lower() == 'windows':
killCmd = "kill -9 %s > nul 2>&1" % processID
else:
killCmd = "kill -9 %s > /dev/null 2>&1" % processID
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(
psCmd, shell=True).decode("utf-8").strip()

else:
psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep| grep -v defunct | awk '{print $2}' | xargs"
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
if processID:
cmd = "sudo systemctl stop taosd"
os.system(cmd)
# if os.system(cmd) != 0 :
# tdLog.exit(cmd)
psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}' | xargs"
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
while(processID):
if platform.system().lower() == 'windows':
killCmd = "kill -9 %s > nul 2>&1" % processID
else:
killCmd = "kill -9 %s > /dev/null 2>&1" % processID
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(
psCmd, shell=True).decode("utf-8").strip()

if self.killValgrind == 1:
psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}' | xargs"
Expand Down
4 changes: 4 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ fabric2
psutil
pandas
toml
distro
requests
pexpect
faker
6 changes: 1 addition & 5 deletions tests/script/sh/cfg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ fi
TAOS_DIR=`pwd`
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`

if [[ "$OS_TYPE" != "Darwin" ]]; then
cut_opt="--field="
else
cut_opt="-f "
fi
cut_opt="-f "

if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
Expand Down
Loading

0 comments on commit ea5d925

Please sign in to comment.