GlusterFS Developer Documentation

repository·devel·Indexed 26 days ago

https://github.com/gluster/glusterfs

Documentation for Gluster, a software-defined distributed storage system for object, block, and file storage. This resource covers the translator (xlator) architecture, Xlator interface, and programming models using call frames. It includes guides on implementing File Operations (FOPs), using the Gluster Test Framework, debugging memory leaks via statedumps, and understanding the Self-Heal Daemon (SHD) and FUSE integration. Additionally, it provides details on the cliutils Python library for creating cluster-aware CLI tools.

Tokens
53.7K
Snippets
79
Records
345
Agent score
87%

What's inside GlusterFS

  1. Overview of cliutils

    devel

    cliutils is a Python library designed to create cluster-aware CLI tools for Gluster. It acts as a wrapper around the gluster system:: execute command, allowing a single executable to function as both a node component (running on all peers) and a user-facing CLI (run from a single node).

    Key Advantages:

    • Node Awareness: The execute_in_peers function merges output with gluster peer status to identify offline nodes, whereas the standard system:: execute simply skips them.
    • Error Handling: Provides utility functions like node_output_ok and node_output_notok that return JSON (including success/failure status and node UUID) instead of relying on shell exit codes, which can be unreliable when aggregating output from multiple nodes.
    • Simplified CLI: Provides easy handling of CLI arguments and allows for easy iteration over node-specific outputs.
  2. Understand Gluster Inode Scaling

    devel

    To prevent FUSE inode collisions (where a directory inode number might match a previous file inode number), Gluster distributes the 64-bit inode space among all children of a replicate volume.

    Each child receives an equal portion of the available space. For example, if there are 3 children, each gets 1/3 of the space. A lookup on a child returning inode 2 would be scaled to the corresponding value in that child's specific portion of the global space. Even with 1024 children, each child maintains a ~54-bit inode space, which is sufficient for real-world requirements.

  3. Understand Ganesha HA Resource Agents (ganesha_mon and ganesha_grace)

    devel

    GlusterFS 3.7 uses two specific Resource Agents (RAs) to manage High Availability (HA) for the ganesha.nfsd daemon:

    1. ganesha_mon: Monitors the ganesha.nfsd daemon. It manages two attributes:

      • ganesha-active: Its presence indicates the daemon is running. Deleting this attribute triggers the failover of the Virtual IP (IPaddr RA) to another node.
      • grace-active: Its presence indicates the system is healthy. Deleting this attribute triggers the transition of surviving nodes into NFS-GRACE mode.
    2. ganesha_grace: Monitors the grace-active attribute. If grace-active is deleted, this RA stops and will not restart. It uses a notify action to send DBUS messages to ganesha.nfsd on other cluster nodes, forcing them into NFS-GRACE mode.

  4. Understand GlusterFS Xlator Interface and Programming Model

    devel
    GlusterFS is built using a modular architecture where functionality is divided into modules called xlators (translators). To develop for or extend GlusterFS, you must understand the Xlator interface and the underlying programming model, which utilizes specific data structures like call frames to manage operations across the translator stack.
  5. Use the Mem-pool for efficient memory management

    devel

    GlusterFS uses a mem_pool data structure to reduce the latency caused by frequent system calls for memory allocation and de-allocation (e.g., during stack winding/unwinding in xlators). Instead of calling malloc/free repeatedly, you can allocate a pool of elements once and reuse them.

    When the pool is exhausted, the system falls back to standard heap allocations (calloc), but it tracks these as pool_misses to help you tune the pool size.

  6. Understand Consistent Time Attributes (ctime, atime, mtime) in Gluster

    devel

    Gluster implements a mechanism to ensure consistent time attributes (ctime, atime, mtime) across distributed and replicated bricks. Traditionally, these attributes were pulled from individual bricks, which caused inconsistencies in distributed/replicated volumes (e.g., causing tar to report "file changed as we read it").

    To solve this, Gluster now stores these time attributes as extended attributes (xattr) of the file. This ensures that regardless of which brick serves the stat request, the time attributes remain synchronized across the volume.

    Key behaviors:

    • Timestamp Generation: Timestamps are generated at the top layer during file operations (fops) and passed down through the translator stack.
    • Storage: The posix xlator stores these values in the inode context (memory) and periodically syncs them to disk as xattr.
    • Consistency: When an inode is initialized, it reads the xattr from disk into the inode context. The system compares timestamps and only updates the stored value if the new timestamp is greater than the existing one.
    • Dependency: This mechanism relies on NTP-synced clients and servers to minimize time drifts during operation.
  7. Understand DHT Atomicity Requirements

    devel

    In Distributed Hash Table (DHT) mode, GlusterFS requires atomicity for two critical design elements to prevent filesystem inconsistencies:

    1. Atomicity during namespace operations: Every subvolume must maintain a consistent mapping of (path of directory, gfid). Specifically:

      • Each subvolume must have the same gfid associated with a directory path.
      • A single gfid must not be associated with more than one path in any subvolume.
      • Operations like mkdir, renamedir, rmdir, and directory creation during self-heal must be atomic across all subvolumes.
    2. Atomicity during layout modification and reading: Each directory has an independent layout (partially stored on each subvolume) cached in the client's memory. Atomicity ensures that clients read or modify a single, complete layout even when parallel modifications are occurring.

  8. Understand GlusterFS Communication and Network Layer

    devel
    GlusterFS uses XDR (External Data Representation) to serialize and deserialize data within RPC (Remote Procedure Call) calls. This layer facilitates communication between client and server translators, handling the connection, disconnection, and reconnection processes.
  9. Understand the syncop framework concepts

    devel

    The syncop framework is a coroutines-based, cooperative multi-tasking framework used within Gluster. It relies on two primary components:

    • syncenv: An object that provides access to a pool of worker threads. All synctasks execute within a syncenv.
    • synctask: A unit of work defined by a pair of function pointers: synctask_fn_t (the 'call') and synctask_cbk_t (the 'callback').

    synctasks operate in two modes:

    1. Synchronous: The calling thread waits for the synctask to complete.
    2. Asynchronous: The calling thread schedules the synctask and continues execution immediately.

    The framework guarantees that the callback is executed after the call completes.

  10. Understand Self-Heal Daemon (shd) behavior

    devel

    The shd (self-heal daemon) is a GlusterFS process responsible for healing files in replicate or disperse volumes.

    Key behaviors:

    • Deployment: One shd instance runs on every server (brick) node. A single shd can handle multiple volumes if they share the same node.
    • Heal Types:
      • Metadata heal: Repairs extended attributes, mode, and permissions.
      • Data heal: Repairs file contents.
      • Entry self-heal: Repairs directory entries.
    • Split-brain handling:
      • Files in data/metadata split-brain are not healed automatically.
      • Directories in entry split-brain undergo a conservative merge (the union of entries from the replica pairs).