Skip to content

DROP DIRECTORY TABLE WITH CONTENT deletes files of all directory tables sharing the same tablespace #1844

Description

@Chong-cn

Environment

  • Version: PostgreSQL 14.4 (Apache Cloudberry 2.1.0-devel+dev.30.g2800e887d8 build 127939) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.2.1, 64-bit

Problem Description

When multiple directory tables share the same external tablespace (OSS/HDFS), all uploaded files are stored under a common path:

<OSS_TABLESPACE_DIR>/<tablespace_oid>/<database_oid>/0_dirtable/

When DROP DIRECTORY TABLE ... WITH CONTENT is executed on one directory table, the entire <OSS_TABLESPACE_DIR> root path is deleted, causing all directory tables in the same database to lose their data files.

Steps to Reproduce

-- Step 1: Create Storage Server
CREATE STORAGE SERVER s3_server
  OPTIONS(protocol 'S3AV2', endpoint '10.14.6.166:9000',
          https 'false', virtual_host 'false');

-- Step 2: User Mapping
CREATE STORAGE USER MAPPING FOR PUBLIC
  STORAGE SERVER s3_server
  OPTIONS (accesskey 'minioadmin', secretkey 'minioadmin');

-- Step 3: Tablespace
CREATE TABLESPACE s3_tbs
  LOCATION '/test/tbs01'
  SERVER s3_server
  HANDLER '$libdir/dfs_tablespace, remote_file_handler';

-- Step 4: Create two directory tables sharing the same tablespace
CREATE DIRECTORY TABLE public.oss_dir1 TABLESPACE s3_tbs;
CREATE DIRECTORY TABLE public.oss_dir2 TABLESPACE s3_tbs;

-- Step 5: Upload files to both tables
\COPY BINARY oss_dir1 FROM '/tmp/data1.csv' 'data1.csv';
\COPY BINARY oss_dir2 FROM '/tmp/data2.csv' 'data2.csv';

-- Step 6: Drop only oss_dir1 with content
DROP DIRECTORY TABLE oss_dir1 WITH CONTENT;

Actual Result

After dropping oss_dir1, the data files of oss_dir2 are also deleted — the entire <OSS_TABLESPACE_DIR> root is removed instead of only the files belonging to oss_dir1.

Expected Result

DROP DIRECTORY TABLE oss_dir1 WITH CONTENT should only delete the physical files associated with oss_dir1, leaving the files of other directory tables (e.g., oss_dir2) intact.

Root Cause Analysis

The delete operation appears to remove the tablespace root directory rather than scoping the deletion to the specific directory table's subdirectory, causing unintended data loss for all co-located tables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions