diff --git a/visualdl/logic/sdk_test.cc b/visualdl/logic/sdk_test.cc index 5f204095320e8a7377d325faeaf033a01b4df339..f800f31ee7368ebbb8eb9ae1fe17e3ec454ddf3e 100644 --- a/visualdl/logic/sdk_test.cc +++ b/visualdl/logic/sdk_test.cc @@ -7,13 +7,16 @@ namespace visualdl { struct ScalarTestHelper { ImHelper rim; ImHelper wim; - const std::string dir = "./tmp/1.test"; + const std::string dir = "./tmp/sdk_test.test"; void operator()(std::function read, std::function write) { wim.StartWriteSerice(dir, 200); write(); - rim.StartReadService(dir, 200); + // should wait for the write service create log's path + std::this_thread::sleep_for(std::chrono::milliseconds(400)); + rim.StartReadService(dir, 100); + // should wait for the read service to load "tag0" tablet into memory std::this_thread::sleep_for(std::chrono::milliseconds(600)); read(); } diff --git a/visualdl/storage/storage.cc b/visualdl/storage/storage.cc index ec02864773d38aee433f710a18b305462ac10316..d5b54166629195e32b19d3e0c18c72aa274897e2 100644 --- a/visualdl/storage/storage.cc +++ b/visualdl/storage/storage.cc @@ -44,7 +44,7 @@ void MemoryStorage::PersistToDisk(const std::string &dir) { CHECK(!dir.empty()); storage_.set_dir(dir); // make a directory if not exist - fs::TryMkdir(dir); + fs::TryRecurMkdir(dir); // write storage out LOG(INFO) << "to serize meta to dir " << dir; fs::SerializeToFile(storage_, meta_path(dir)); diff --git a/visualdl/utils/filesystem.h b/visualdl/utils/filesystem.h index 1a416749552ab538315f56a24fbe86bbc539335a..ed97d03b8c071d0f1379c3792fc212bedb1b28a3 100644 --- a/visualdl/utils/filesystem.h +++ b/visualdl/utils/filesystem.h @@ -44,13 +44,26 @@ bool DeSerializeFromFile(T* proto, const std::string& path) { } void TryMkdir(const std::string& dir) { - VLOG(1) << "try to mkdir " << dir; + LOG(INFO) << "try to mkdir " << dir; struct stat st = {0}; if (stat(dir.c_str(), &st) == -1) { ::mkdir(dir.c_str(), 0700); } } +// Create a path by recursively create directries +void TryRecurMkdir(const std::string& path) { + // split path by '/' + for (int i = 1; i < path.size() - 1; i++) { + if (path[i] == '/') { + auto dir = path.substr(0, i + 1); + TryMkdir(dir); + } + } + // the last level + TryMkdir(path); +} + inline void Write(const std::string& path, const std::string& buffer, std::ios::openmode open_mode = std::ios::binary) {