diff --git a/src/system/src/dnodeSystem.c b/src/system/src/dnodeSystem.c index bc08d5b3c2a5e2f26fa7b9cc8c2dc2d20283469e..675e758dc68c8fd84c0d9e704f36f8376882611f 100644 --- a/src/system/src/dnodeSystem.c +++ b/src/system/src/dnodeSystem.c @@ -83,6 +83,17 @@ void taosCreateTierDirectory() { mkdir(fileName, 0755); } +void dnodeCheckDbRunning(const char* dir) { + char filepath[256] = {0}; + sprintf(filepath, "%s/.running", dir); + int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + int ret = flock(fd, LOCK_EX | LOCK_NB); + if (ret != 0) { + dError("failed to lock file:%s ret:%d, database may be running, quit", ret, filepath); + exit(0); + } +} + int dnodeInitSystem() { char temp[128]; struct stat dirstat; @@ -115,6 +126,7 @@ int dnodeInitSystem() { sprintf(mgmtDirectory, "%s/mgmt", tsDirectory); sprintf(tsDirectory, "%s/tsdb", dataDir); + dnodeCheckDbRunning(dataDir); tsPrintGlobalConfig(); dPrint("Server IP address is:%s", tsInternalIp);