From dabbc852c8746a0b9864bc8fb83d48df231020c2 Mon Sep 17 00:00:00 2001 From: cutiechi Date: Mon, 16 Jun 2025 11:35:51 +0800 Subject: [PATCH] Fix: opendal storage health attribute not found & remove duplicate operator scheme initialization (#8265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? This PR fixes two issues in the OpenDAL storage connector: 1. The ‎`health` method was missing, which prevented health checks on the storage backend. 3. The initialization of the ‎`opendal.Operator` object included a redundant scheme parameter, causing unnecessary duplication and potential confusion. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Background - The absence of a ‎`health` method made it difficult to verify the availability and reliability of the storage service. - Initializing ‎`opendal.Operator` with both ‎`self._scheme` and unpacked ‎`**self._kwargs` could lead to errors or unexpected behavior if the scheme was already included in the kwargs. ### What is changed and how it works? - Adds a ‎`health` method that writes a test file to verify storage availability. - Removes the duplicate scheme parameter from the ‎`opendal.Operator` initialization to ensure clarity and prevent conflicts. before: 企业微信截图_46be646f-2e99-4e5e-be67-b1483426e77c image after: 企业微信截图_09d62997-8908-4985-b89f-7a78b5da55ac --- rag/utils/opendal_conn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rag/utils/opendal_conn.py b/rag/utils/opendal_conn.py index 255ccebef..715c18d19 100644 --- a/rag/utils/opendal_conn.py +++ b/rag/utils/opendal_conn.py @@ -58,10 +58,15 @@ class OpenDALStorage: if self._scheme == 'mysql': self.init_db_config() self.init_opendal_mysql_table() - self._operator = opendal.Operator(self._scheme, **self._kwargs) + self._operator = opendal.Operator(**self._kwargs) logging.info("OpenDALStorage initialized successfully") + def health(self): + bucket, fnm, binary = "txtxtxtxt1", "txtxtxtxt1", b"_t@@@1" + r = self._operator.write(f"{bucket}/{fnm}", binary) + return r + def put(self, bucket, fnm, binary): self._operator.write(f"{bucket}/{fnm}", binary)