hello-stephen commented on code in PR #70916:
URL: https://github.com/apache/doris/pull/70916#discussion_r4797187207


##########
be/src/load/group_commit/wal/wal_manager.cpp:
##########
@@ -111,19 +112,45 @@ Status WalManager::_init_wal_dirs_conf() {
     return Status::OK();
 }
 
+static Status create_and_sync_wal_root(io::Path dir) {
+    auto fs = io::global_local_filesystem();
+    std::vector<io::Path> missing;
+    bool exists;
+    RETURN_IF_ERROR(fs->exists(dir, &exists));
+    while (!exists) {
+        missing.push_back(dir);
+        dir = dir.parent_path();
+        RETURN_IF_ERROR(fs->exists(dir, &exists));
+    }
+
+    // A previous startup may have stopped between mkdir and syncing its 
parent.
+    // Only the deepest existing entry can be in that state, since we sync each
+    // new entry before creating its child.
+    std::string existing;
+    RETURN_IF_ERROR(fs->canonicalize(dir, &existing));
+    const io::Path ancestor(existing);
+    if (ancestor.has_relative_path()) {
+        RETURN_IF_ERROR(io::sync_dir(ancestor.parent_path()));

Review Comment:
   [P2] Preserve startup with an existing WAL root under a search-only parent
   
   An existing BE-owned WAL directory such as `/srv/private/wal` can sit below 
a root-owned parent with mode `0711`. The BE can traverse that parent and use 
the WAL directory, but this new startup call opens the parent with `O_RDONLY | 
O_DIRECTORY` and gets `EACCES`. That error aborts BE startup even with 
`group_commit_wal_sync_before_ack=false`. Preserve startup for pre-existing 
roots in the disabled mode, and validate the required directory sync before 
acknowledging durable loads if the setting is enabled later.



##########
be/src/load/group_commit/wal/wal_manager.cpp:
##########
@@ -228,14 +255,40 @@ std::string 
WalManager::get_last_replay_wal_failed_reason(int64_t table_id) {
     return "";
 }
 
+Status WalManager::_sync_wal_parent_dir(const io::Path& table_dir) {
+    auto fs = io::global_local_filesystem();
+    auto sync_directory_entry = [&](const io::Path& dir, WalDirectoryCache& 
cache) -> Status {
+        auto& slot = cache[std::filesystem::hash_value(dir) % cache.size()];
+        std::lock_guard lock(slot.mutex);
+        bool exists;
+        RETURN_IF_ERROR(fs->exists(dir, &exists));
+        if (exists && slot.synced_dir == dir) {
+            return Status::OK();
+        }
+        if (!exists) {
+            // A recreated directory needs a fresh parent sync even if mkdir 
succeeds and sync fails.
+            slot.synced_dir.clear();
+            RETURN_IF_ERROR(fs->create_directory(dir));
+        }
+        // A collision evicts the previous path. Its next lookup will sync its 
parent again.
+        RETURN_IF_ERROR(io::sync_dir(dir.parent_path()));
+        slot.synced_dir = dir;
+        return Status::OK();
+    };
+    RETURN_IF_ERROR(sync_directory_entry(table_dir.parent_path(), 
_wal_db_directories));
+    RETURN_IF_ERROR(sync_directory_entry(table_dir, _wal_table_directories));
+    return Status::OK();
+}
+
 Status WalManager::create_wal_path(int64_t db_id, int64_t table_id, int64_t 
wal_id,
                                    const std::string& label, std::string& 
base_path,
                                    uint32_t wal_version) {
     base_path = _wal_dirs_info->get_available_random_wal_dir();
+    const auto table_dir = io::Path(base_path) / std::to_string(db_id) / 
std::to_string(table_id);
+    RETURN_IF_ERROR(_sync_wal_parent_dir(table_dir));

Review Comment:
   [P2] Abort the FE transaction when WAL directory setup fails
   
   A directory sync error here returns from `_create_group_commit_load` after 
`streamLoadPut` has created the FE transaction, before the fragment has a 
finish callback that can roll it back. The retry path uses a fresh label on 
every attempt. A persistent directory sync error can therefore fill the 
shared-nothing database's running transaction quota with PREPARE transactions 
and reject writes to other tables until they time out. Roll back the 
just-created transaction before retrying WAL setup.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to