Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(infinity): treat dropping a missing table as a no-op (#20512)

Bharadwaj Pendyalad7c8e1730da3
diff --git a/internal/engine/infinity/common.go b/internal/engine/infinity/common.go
index 466d6fa83f..376f9d6916 100644
--- a/internal/engine/infinity/common.go
+++ b/internal/engine/infinity/common.go
@@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"fmt"
"ragflow/internal/common"
"ragflow/internal/engine/types"
@@ -44,16 +45,14 @@ func (e *Engine) dropTable(ctx context.Context, tableName string) error {
}
defer release()
- // Check if table exists
- exists, err := e.tableExistsWithDB(db, tableName)
- if err != nil {
- return fmt.Errorf("failed to check table existence: %w", err)
- }
- if !exists {
- return fmt.Errorf("table '%s' does not exist", tableName)
- }
-
_, err = db.DropTable(tableName, infinity.ConflictTypeError)
+ var infinityErr *infinity.InfinityException
+ if errors.As(err, &infinityErr) && infinity.ErrorCode(infinityErr.ErrorCode) == infinity.ErrorCodeTableNotExist {
+ // Tolerate a missing table, as Elasticsearch's dropIndex does: tables
+ // are created on first write, so callers dropping by dataset or
+ // tenant routinely name one that was never created.
+ return nil
+ }
if err != nil {
return fmt.Errorf("failed to drop table: %w", err)
}
diff --git a/internal/engine/infinity/integration_test.go b/internal/engine/infinity/integration_test.go
new file mode 100644
index 0000000000..dfb89850ee
--- /dev/null
+++ b/internal/engine/infinity/integration_test.go
@@ -0,0 +1,102 @@
+//go:build integration
+
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package infinity
+
+import (
+ "context"
+ "os"
+ "strconv"
+ "testing"
+ "time"
+
+ "ragflow/internal/common"
+ "ragflow/internal/server/config"
+
+ "go.uber.org/zap"
+ "go.uber.org/zap/zapcore"
+ "go.uber.org/zap/zaptest/observer"
+)
+
+func newTestEngine(t *testing.T) (context.Context, *Engine) {
+ t.Helper()
+ uri := os.Getenv("RAGFLOW_INFINITY_URI")
+ if uri == "" {
+ t.Skip("RAGFLOW_INFINITY_URI is not set")
+ }
+ ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute)
+ t.Cleanup(cancel)
+ engine, err := NewEngine(ctx, config.InfinityConfig{URI: uri, DBName: "default_db"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { engine.Close() })
+ return ctx, engine
+}
+
+func observeLogs(t *testing.T) *observer.ObservedLogs {
+ t.Helper()
+ prevLogger := common.Logger
+ t.Cleanup(func() { common.Logger = prevLogger })
+ core, logs := observer.New(zapcore.InfoLevel)
+ common.Logger = zap.New(core)
+ return logs
+}
+
+// Admin user deletion drops one chunk table per owned dataset and the tenant's
+// doc-meta table, and Infinity only creates either on first write.
+func TestDropStoresToleratesNeverCreatedTables(t *testing.T) {
+ ctx, engine := newTestEngine(t)
+ logs := observeLogs(t)
+
+ suffix := strconv.FormatInt(time.Now().UnixNano(), 10)
+ if err := engine.DropChunkStore(ctx, "ragflow_tenant"+suffix, "kb"+suffix); err != nil {
+ t.Fatalf("drop never-created chunk table: %v", err)
+ }
+ if err := engine.DropMetadataStore(ctx, "tenant"+suffix); err != nil {
+ t.Fatalf("drop never-created metadata table: %v", err)
+ }
+ if dropped := logs.FilterMessage("Infinity dropped table").Len(); dropped != 0 {
+ t.Fatalf("logged %d drops for tables that never existed", dropped)
+ }
+}
+
+func TestDropMetadataStoreLogsAnActualDrop(t *testing.T) {
+ ctx, engine := newTestEngine(t)
+ tenantID := "tenant" + strconv.FormatInt(time.Now().UnixNano(), 10)
+ if err := engine.CreateMetadataStore(ctx, tenantID); err != nil {
+ t.Fatal(err)
+ }
+ // t.Context is already cancelled when cleanups run
+ t.Cleanup(func() { _ = engine.DropMetadataStore(context.Background(), tenantID) })
+ logs := observeLogs(t)
+
+ if err := engine.DropMetadataStore(ctx, tenantID); err != nil {
+ t.Fatal(err)
+ }
+ if dropped := logs.FilterMessage("Infinity dropped table").Len(); dropped != 1 {
+ t.Fatalf("logged %d drops, want 1", dropped)
+ }
+ exists, err := engine.MetadataStoreExists(ctx, tenantID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if exists {
+ t.Fatalf("metadata table for %s still exists after drop", tenantID)
+ }
+}