commit
90944de1f7
|
@ -31,7 +31,11 @@
|
||||||
#include "mnodeAcct.h"
|
#include "mnodeAcct.h"
|
||||||
#include "dnodeTelemetry.h"
|
#include "dnodeTelemetry.h"
|
||||||
|
|
||||||
static tsem_t tsExitSem;
|
// sem_timedwait is NOT implemented on MacOSX
|
||||||
|
// thus, we use pthread_mutex_t/pthread_cond_t to simulate
|
||||||
|
static pthread_mutex_t tsExitLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static pthread_cond_t tsExitCond = PTHREAD_COND_INITIALIZER;
|
||||||
|
static volatile int tsExit = 0;
|
||||||
static pthread_t tsTelemetryThread;
|
static pthread_t tsTelemetryThread;
|
||||||
|
|
||||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||||
|
@ -236,24 +240,19 @@ static void sendTelemetryReport() {
|
||||||
taosCloseSocket(fd);
|
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 // __APPLE__
|
|
||||||
|
|
||||||
static void* telemetryThread(void* param) {
|
static void* telemetryThread(void* param) {
|
||||||
struct timespec end = {0};
|
struct timespec end = {0};
|
||||||
clock_gettime(CLOCK_REALTIME, &end);
|
clock_gettime(CLOCK_REALTIME, &end);
|
||||||
end.tv_sec += 300; // wait 5 minutes before send first report
|
end.tv_sec += 300; // wait 5 minutes before send first report
|
||||||
|
|
||||||
while (1) {
|
while (!tsExit) {
|
||||||
if (sem_timedwait(&tsExitSem, &end) == 0) {
|
int r = 0;
|
||||||
break;
|
struct timespec ts = end;
|
||||||
} else if (errno != ETIMEDOUT) {
|
pthread_mutex_lock(&tsExitLock);
|
||||||
continue;
|
r = pthread_cond_timedwait(&tsExitCond, &tsExitLock, &ts);
|
||||||
}
|
pthread_mutex_unlock(&tsExitLock);
|
||||||
|
if (r==0) break;
|
||||||
|
if (r!=ETIMEDOUT) continue;
|
||||||
|
|
||||||
if (sdbIsMaster()) {
|
if (sdbIsMaster()) {
|
||||||
sendTelemetryReport();
|
sendTelemetryReport();
|
||||||
|
@ -284,12 +283,6 @@ int32_t dnodeInitTelemetry() {
|
||||||
|
|
||||||
dnodeGetEmail("/usr/local/taos/email");
|
dnodeGetEmail("/usr/local/taos/email");
|
||||||
|
|
||||||
if (tsem_init(&tsExitSem, 0, 0) == -1) {
|
|
||||||
// just log the error, it is ok for telemetry to fail
|
|
||||||
dTrace("failed to create semaphore for telemetry, reason:%s", strerror(errno));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
@ -310,8 +303,11 @@ void dnodeCleanupTelemetry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosCheckPthreadValid(tsTelemetryThread)) {
|
if (taosCheckPthreadValid(tsTelemetryThread)) {
|
||||||
tsem_post(&tsExitSem);
|
pthread_mutex_lock(&tsExitLock);
|
||||||
|
tsExit = 1;
|
||||||
|
pthread_cond_signal(&tsExitCond);
|
||||||
|
pthread_mutex_unlock(&tsExitLock);
|
||||||
|
|
||||||
pthread_join(tsTelemetryThread, NULL);
|
pthread_join(tsTelemetryThread, NULL);
|
||||||
tsem_destroy(&tsExitSem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue