Skip to content

Commit

Permalink
[Fix](inverted index) fix inappropriate use of macro in inverted inde…
Browse files Browse the repository at this point in the history
…x fs directory error process (#32472)
  • Loading branch information
airborne12 committed Mar 21, 2024
1 parent b2239c6 commit d97b87b
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions be/src/olap/rowset/segment_v2/inverted_index_compound_directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@
#define PATH_DELIMITERA "/"
#endif

#define LOG_AND_THROW_IF_ERROR(status, msg) \
if (!status.ok()) { \
auto err = std::string(msg) + ": " + status.to_string(); \
LOG(WARNING) << err; \
_CLTHROWA(CL_ERR_IO, err.c_str()); \
}
#define LOG_AND_THROW_IF_ERROR(status, msg) \
do { \
auto _status_result = (status); \
if (!_status_result.ok()) { \
auto err = std::string(msg) + ": " + _status_result.to_string(); \
LOG(WARNING) << err; \
_CLTHROWA(CL_ERR_IO, err.c_str()); \
} \
} while (0)

namespace doris::segment_v2 {

const char* const DorisCompoundDirectory::WRITE_LOCK_FILE = "write.lock";
Expand Down Expand Up @@ -534,7 +538,8 @@ void DorisCompoundDirectory::init(const io::FileSystemSPtr& _fs, const char* _pa
return;
}
bool exists = false;
LOG_AND_THROW_IF_ERROR(fs->exists(directory, &exists), "Doris compound directory init IO error")
LOG_AND_THROW_IF_ERROR(fs->exists(directory, &exists),
"Doris compound directory init IO error");
if (!exists) {
auto e = "Doris compound directory init error: " + directory + " is not a directory";
LOG(WARNING) << e;
Expand Down Expand Up @@ -576,7 +581,7 @@ bool DorisCompoundDirectory::fileExists(const char* name) const {
char fl[CL_MAX_DIR];
priv_getFN(fl, name);
bool exists = false;
LOG_AND_THROW_IF_ERROR(fs->exists(fl, &exists), "File exists IO error")
LOG_AND_THROW_IF_ERROR(fs->exists(fl, &exists), "File exists IO error");
return exists;
}

Expand All @@ -603,7 +608,7 @@ void DorisCompoundDirectory::touchFile(const char* name) {

io::FileWriterPtr tmp_writer;
io::FileWriterOptions opts {.create_empty_file = false};
LOG_AND_THROW_IF_ERROR(fs->create_file(buffer, &tmp_writer, &opts), "Touch file IO error")
LOG_AND_THROW_IF_ERROR(fs->create_file(buffer, &tmp_writer, &opts), "Touch file IO error");
}

int64_t DorisCompoundDirectory::fileLength(const char* name) const {
Expand Down Expand Up @@ -638,7 +643,7 @@ bool DorisCompoundDirectory::doDeleteFile(const char* name) {
CND_PRECONDITION(directory[0] != 0, "directory is not open");
char fl[CL_MAX_DIR];
priv_getFN(fl, name);
LOG_AND_THROW_IF_ERROR(fs->delete_file(fl), "Delete file IO error")
LOG_AND_THROW_IF_ERROR(fs->delete_file(fl), "Delete file IO error");
return true;
}

Expand All @@ -647,7 +652,7 @@ bool DorisCompoundDirectory::deleteDirectory() {
char fl[CL_MAX_DIR];
priv_getFN(fl, "");
LOG_AND_THROW_IF_ERROR(fs->delete_directory(fl),
fmt::format("Delete directory {} IO error", fl))
fmt::format("Delete directory {} IO error", fl));
return true;
}

Expand All @@ -661,24 +666,24 @@ void DorisCompoundDirectory::renameFile(const char* from, const char* to) {
priv_getFN(nu, to);

bool exists = false;
LOG_AND_THROW_IF_ERROR(fs->exists(nu, &exists), "File exists IO error")
LOG_AND_THROW_IF_ERROR(fs->exists(nu, &exists), "File exists IO error");
if (exists) {
LOG_AND_THROW_IF_ERROR(fs->delete_directory(nu), fmt::format("Delete {} IO error", nu))
LOG_AND_THROW_IF_ERROR(fs->delete_directory(nu), fmt::format("Delete {} IO error", nu));
}
LOG_AND_THROW_IF_ERROR(fs->rename_dir(old, nu),
fmt::format("Rename {} to {} IO error", old, nu))
fmt::format("Rename {} to {} IO error", old, nu));
}

lucene::store::IndexOutput* DorisCompoundDirectory::createOutput(const char* name) {
CND_PRECONDITION(directory[0] != 0, "directory is not open");
char fl[CL_MAX_DIR];
priv_getFN(fl, name);
bool exists = false;
LOG_AND_THROW_IF_ERROR(fs->exists(fl, &exists), "Create output file exists IO error")
LOG_AND_THROW_IF_ERROR(fs->exists(fl, &exists), "Create output file exists IO error");
if (exists) {
LOG_AND_THROW_IF_ERROR(fs->delete_file(fl),
fmt::format("Create output delete file {} IO error", fl))
LOG_AND_THROW_IF_ERROR(fs->exists(fl, &exists), "Create output file exists IO error")
fmt::format("Create output delete file {} IO error", fl));
LOG_AND_THROW_IF_ERROR(fs->exists(fl, &exists), "Create output file exists IO error");
assert(!exists);
}
auto* ret = _CLNEW FSIndexOutput();
Expand Down Expand Up @@ -907,10 +912,10 @@ DorisCompoundDirectory* DorisCompoundDirectoryFactory::getDirectory(
dir = _CLNEW DorisRAMCompoundDirectory();
} else {
bool exists = false;
LOG_AND_THROW_IF_ERROR(_fs->exists(file, &exists), "Get directory exists IO error")
LOG_AND_THROW_IF_ERROR(_fs->exists(file, &exists), "Get directory exists IO error");
if (!exists) {
LOG_AND_THROW_IF_ERROR(_fs->create_directory(file),
"Get directory create directory IO error")
"Get directory create directory IO error");
}
dir = _CLNEW DorisCompoundDirectory();
}
Expand Down

0 comments on commit d97b87b

Please sign in to comment.