Apache Cloudberry Documentation

repository·main·Indexed 22 days ago

https://github.com/apache/cloudberry

Apache Cloudberry (Incubating) is an open-source Massively Parallel Processing (MPP) database evolved from Greenplum, featuring a PostgreSQL kernel for data warehousing, large-scale analytics, and AI/ML workloads. Documentation covers the Interconnect module, including implementation of MotionIPCLayer and statistics extensions, as well as the PAX (Partition Attributes Across) storage method for improved OLAP performance via hybrid row-column storage, vectorized engines, and advanced data encoding.

Tokens
172.1K
Snippets
239
Records
812
Agent score
79%

What's inside Apache Cloudberry

  1. Explore the Apache Cloudberry ecosystem repositories

    main

    In addition to the main repository, several ecosystem repositories provide specialized utilities and extensions:

    • apache/cloudberry-site: Website and documentation sources.
    • apache/cloudberry-backup: Backup utility for Cloudberry.
    • apache/cloudberry-go-libs: Go libraries for Cloudberry.
    • apache/cloudberry-pxf: Platform Extension Framework (PXF) for Cloudberry.
  2. Use the fixed-width data formatter

    main

    The contrib/formatter_fixedwidth directory provides a custom formatter designed for reading and writing fixed-width data files within Apache Cloudberry.

    Note on Writable External Tables: While this formatter supports both reading and writing, testing writable external tables using this formatter requires a running gpfdist server. If you are performing regression tests or manual verification of writing capabilities, ensure a gpfdist instance is available. Standard tests in this directory focus on readable external tables to avoid this dependency.

  3. Understand the PAX architecture and directory structure

    main

    PAX is organized into several functional layers and directories. The core logic resides in src/cpp/, which is subdivided into specific layers such as access, catalog, clustering, and storage. The storage implementation is further broken down into columns, filters, operators, ORC formats, and vectorized executors.

    Key directory mapping:

    • src/api/: Public API for other modules.
    • src/cpp/access/: Table access layer.
    • src/cpp/catalog/: Catalog layer.
    • src/cpp/storage/: Main storage implementation (includes columns, filters, operators, ORC, etc.).
    • src/test/: Regression tests.
    • sql/: SQL tests.
  4. What is PAX (Partition Attributes Across)?

    main

    PAX (Partition Attributes Across) is a database access method that combines the advantages of row storage (N-ary Storage Model) and column storage (Decomposition Storage Model). It is designed to improve query performance, particularly cache efficiency, in OLAP scenarios.

    Key features include:

    • CRUD Operations: Full support for Create, Read, Update, and Delete.
    • Concurrency Control: Uses Multiversion Concurrency Control (MVCC) at the individual data file granularity.
    • Data Encoding & Compression: Supports schemes like run-length encoding (RLE) and compression methods like zstd and zlib.
    • Statistics & Filtering: Includes statistical metadata for rapid filtering, sparse filtering, and row filtering to minimize data scanning.
    • Data Clustering: Supports sorting via specified algorithms on one or multiple columns.
    • Vectorized Engine: Includes an experimental engine for high-performance analytical workloads.
  5. Overview of PAX Catalog Implementations

    main

    PAX uses two different methods for its catalog implementation:

    1. Auxiliary table: Uses HEAP to implement auxiliary tables, providing Multi-Version Concurrency Control (MVCC). This is the implementation covered in this documentation.
    2. Manifest: Uses JSON to store metadata with an independent MVCC implementation. While it offers better readability, DDL operations often result in poor performance.

    All auxiliary tables reside in the pg_ext_aux namespace, which is automatically created when the PAX plugin is initialized. The relevant access methods, namespaces, and auxiliary tables are inserted into Cloudberry during plugin initialization via the pax-cdbinit--1.0.sql script generated during compilation.

  6. What is the Greenplum Partner Connector (GPPC)?

    main

    The Greenplum Partner Connector (GPPC) is a Greenplum Database extension that acts as a wrapper for C/C++ User-Defined Functions (UDFs).

    Instead of writing standard Postgres C UDFs, you use the GPPC API. This allows your UDF to be portable across different Greenplum Database platforms and versions without requiring recompilation or modification. GPPC translates your GPPC-compliant UDF into a format compatible with the specific GPDB platform being used.

  7. Understanding Local vs. Global Deadlocks in Apache Cloudberry

    main

    In a distributed system like Apache Cloudberry, deadlocks can occur at two levels:

    1. Local Deadlock: Occurs when all conflicting resources (e.g., specific rows/tuples) reside on the same segment. The segment can detect this locally using a cycle detection algorithm where transactions are vertices and waiting relations are directed edges.
    2. Global (Distributed) Deadlock: Occurs when conflicting resources are distributed across different segments. For example, Transaction A might be waiting for a resource on Segment 0 held by Transaction B, while Transaction B is waiting for a resource on Segment 1 held by Transaction A. Because no single segment sees the complete dependency graph, the deadlock cannot be detected locally.

    To prevent global deadlocks, Apache Cloudberry currently employs a policy of holding an exclusive table lock for UPDATE and DELETE commands, which effectively disables concurrent updates to avoid the performance-heavy complexity of distributed cycle detection.

  8. Use the DBMS_ALERT package to send and receive notifications

    main

    The DBMS_ALERT package allows a PL/pgSQL session to send alerts to multiple other PL/pgSQL sessions, facilitating 1:N communication.

    Key Workflow

    1. Register: A receiving session must call REGISTER for a specific alert name (alerts are case-sensitive).
    2. Signal: A sending session calls SIGNAL with the alert name and a message. Note: Notifications are only sent upon committing the transaction. If the transaction is rolled back, the signal is discarded.
    3. Wait: The receiving session uses WAITANY or WAITONE to block until an alert is received.
    4. Cleanup: Always use REMOVE or REMOVEALL to unregister alerts when they are no longer needed to prevent memory issues and ensure future signals can be received.

    Important Constraints

    • Memory: DBMS_ALERT and DBMS_PIPE share the same memory environment. Continuous signaling without receiving can lead to insufficient memory errors. If memory is low, call WAITANY or WAITONE to process accumulated messages.
    • Persistence: If a session closes without calling REMOVE or REMOVEALL, it may prevent other sessions from receiving signals for that same alert name.
    --- Sending side ---
    CREATE FUNCTION send_dbms_alert_exe() RETURNS VOID AS $$
    BEGIN
    	PERFORM DBMS_ALERT.SIGNAL('sample_alert','SIGNAL ALERT');
    END;
    $$ LANGUAGE plpgsql;
    SELECT send_dbms_alert_exe();
    
    --- Receiving side ---
    CREATE FUNCTION receive_dbms_alert_exe() RETURNS VOID AS $$
    DECLARE
    	alert_name    TEXT := 'sample_alert';
    	alert_message TEXT;
    	alert_status  INTEGER;
    BEGIN
    	PERFORM DBMS_ALERT.REGISTER(alert_name);
    	SELECT message,status INTO alert_message,alert_status FROM DBMS_ALERT.WAITONE(alert_name,300);
    	RAISE NOTICE 'Message : %', alert_message;
    	RAISE NOTICE 'Status  : %', alert_status;
    	PERFORM DBMS_ALERT.REMOVE(alert_name);
    END;
    $$ LANGUAGE plpgsql;
    SELECT receive_dbms_alert_exe();
  9. Interpret GP Stats Collector metric notations

    main

    When analyzing metrics from the GP Stats Collector, use the following notations to understand how values are calculated and scoped:

    • S / T / E / D: Represents the event timing: Submit, Tart, End, and Done.
    • DIFF: The metric is calculated as current_value - submit_value (the difference between the current state and the initial snapshot taken at submit).
    • ABS: The absolute value is provided (used when DIFF is not applicable).
    • Local*: Statistics that reset to zero for every new query (including nested queries).
    • Node: Refers to a specific Postgres process, either a Query Dispatcher (on master) or an Execute (on segment).
  10. Manage the lifecycle of Extend Protocol data

    main

    Data stored in ExtendProtocolData is allocated under the TopTransactionContext.

    Lifecycle Rules:

    • Data persists until it is explicitly consumed or the top-level transaction ends.
    • Consumption: Once data is consumed, it is marked as successfully consumed and removed from storage.
    • Unconsumed Data: If data remains unconsumed when the top-level transaction commits, a warning is printed.
    • Cleanup: All stored data is cleared automatically upon transaction termination.