blob: d2c63597bfa9cbe9c6a7e4a1429688370925e420 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en" data-content_root="" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<title>Arrow Flight RPC &#8212; Apache Arrow v17.0.0.dev52</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
</script>
<!-- Loaded before other Sphinx assets -->
<link href="../_static/styles/theme.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
<link href="../_static/styles/bootstrap.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
<link href="../_static/styles/pydata-sphinx-theme.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
<link href="../_static/vendor/fontawesome/6.5.1/css/all.min.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.1/webfonts/fa-solid-900.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.1/webfonts/fa-brands-400.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.1/webfonts/fa-regular-400.woff2" />
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="../_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" />
<link rel="stylesheet" type="text/css" href="../_static/theme_overrides.css" />
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="../_static/scripts/bootstrap.js?digest=8d27b9dea8ad943066ae" />
<link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=8d27b9dea8ad943066ae" />
<script src="../_static/vendor/fontawesome/6.5.1/js/all.min.js?digest=8d27b9dea8ad943066ae"></script>
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/sphinx_highlight.js"></script>
<script src="../_static/clipboard.min.js"></script>
<script src="../_static/copybutton.js"></script>
<script src="../_static/design-tabs.js"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'cpp/flight';</script>
<script>
DOCUMENTATION_OPTIONS.theme_version = '0.15.2';
DOCUMENTATION_OPTIONS.theme_switcher_json_url = '/docs/_static/versions.json';
DOCUMENTATION_OPTIONS.theme_switcher_version_match = 'dev/';
DOCUMENTATION_OPTIONS.show_version_warning_banner = true;
</script>
<link rel="canonical" href="https://arrow.apache.org/docs/cpp/flight.html" />
<link rel="icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Debugging code using Arrow" href="gdb.html" />
<link rel="prev" title="Tabular Datasets" href="dataset.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
/* We explicitly disable cookie tracking to avoid privacy issues */
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.apache.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '20']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">
<a id="pst-skip-link" class="skip-link" href="#main-content">Skip to main content</a>
<div id="pst-scroll-pixel-helper"></div>
<button type="button" class="btn rounded-pill" id="pst-back-to-top">
<i class="fa-solid fa-arrow-up"></i>
Back to top
</button>
<input type="checkbox"
class="sidebar-toggle"
name="__primary"
id="__primary"/>
<label class="overlay overlay-primary" for="__primary"></label>
<input type="checkbox"
class="sidebar-toggle"
name="__secondary"
id="__secondary"/>
<label class="overlay overlay-secondary" for="__secondary"></label>
<div class="search-button__wrapper">
<div class="search-button__overlay"></div>
<div class="search-button__search-container">
<form class="bd-search d-flex align-items-center"
action="../search.html"
method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search"
class="form-control"
name="q"
id="search-input"
placeholder="Search the docs ..."
aria-label="Search the docs ..."
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"/>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form></div>
</div>
<header class="bd-header navbar navbar-expand-lg bd-navbar">
<div class="bd-header__inner bd-page-width">
<label class="sidebar-toggle primary-toggle" for="__primary">
<span class="fa-solid fa-bars"></span>
</label>
<div class="col-lg-3 navbar-header-items__start">
<div class="navbar-item">
<a class="navbar-brand logo" href="../index.html">
<img src="../_static/arrow.png" class="logo__image only-light" alt="Apache Arrow v17.0.0.dev52 - Home"/>
<script>document.write(`<img src="../_static/arrow-dark.png" class="logo__image only-dark" alt="Apache Arrow v17.0.0.dev52 - Home"/>`);</script>
</a></div>
</div>
<div class="col-lg-9 navbar-header-items">
<div class="me-auto navbar-header-items__center">
<div class="navbar-item">
<nav class="navbar-nav">
<ul class="bd-navbar-elements navbar-nav">
<li class="nav-item">
<a class="nav-link nav-internal" href="../format/index.html">
Specifications
</a>
</li>
<li class="nav-item">
<a class="nav-link nav-internal" href="../developers/index.html">
Development
</a>
</li>
<li class="nav-item dropdown">
<button class="btn dropdown-toggle nav-item" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-controls="pst-nav-more-links">
Implementations
</button>
<ul id="pst-nav-more-links" class="dropdown-menu">
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../c_glib/index.html">
C/GLib
</a>
</li>
<li class="nav-item current active">
<a class="nav-link dropdown-item nav-internal" href="index.html">
C++
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://github.com/apache/arrow/blob/main/csharp/README.md">
C#
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://pkg.go.dev/github.com/apache/arrow/go/v17">
Go
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../java/index.html">
Java
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../js/index.html">
JavaScript
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/julia/">
Julia
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://github.com/apache/arrow/blob/main/matlab/README.md">
MATLAB
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/nanoarrow/">
nanoarrow
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../python/index.html">
Python
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../r/index.html">
R
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://github.com/apache/arrow/blob/main/ruby/README.md">
Ruby
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://docs.rs/crate/arrow/">
Rust
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../status.html">
Implementation Status
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/cpp/">
C++ cookbook
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/java/">
Java cookbook
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/py/">
Python cookbook
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/r/">
R cookbook
</a>
</li>
</ul>
</li>
</ul>
</nav></div>
</div>
<div class="navbar-header-items__end">
<div class="navbar-item navbar-persistent--container">
<script>
document.write(`
<button class="btn navbar-btn search-button-field search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__default-text">Search</span>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
`);
</script>
</div>
<div class="navbar-item">
<script>
document.write(`
<div class="version-switcher__container dropdown">
<button id="pst-version-switcher-button-2"
type="button"
class="version-switcher__button btn btn-sm navbar-btn dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-2"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-2"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-2">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
`);
</script></div>
<div class="navbar-item">
<script>
document.write(`
<button class="btn btn-sm navbar-btn theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<span class="theme-switch nav-link" data-mode="light"><i class="fa-solid fa-sun fa-lg"></i></span>
<span class="theme-switch nav-link" data-mode="dark"><i class="fa-solid fa-moon fa-lg"></i></span>
<span class="theme-switch nav-link" data-mode="auto"><i class="fa-solid fa-circle-half-stroke fa-lg"></i></span>
</button>
`);
</script></div>
<div class="navbar-item"><ul class="navbar-icon-links navbar-nav"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://github.com/apache/arrow" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-brands fa-square-github fa-lg" aria-hidden="true"></i></span>
<span class="sr-only">GitHub</span></a>
</li>
<li class="nav-item">
<a href="https://twitter.com/ApacheArrow" title="X" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-brands fa-square-x-twitter fa-lg" aria-hidden="true"></i></span>
<span class="sr-only">X</span></a>
</li>
</ul></div>
</div>
</div>
<div class="navbar-persistent--mobile">
<script>
document.write(`
<button class="btn navbar-btn search-button-field search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__default-text">Search</span>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
`);
</script>
</div>
<label class="sidebar-toggle secondary-toggle" for="__secondary" tabindex="0">
<span class="fa-solid fa-outdent"></span>
</label>
</div>
</header>
<div class="bd-container">
<div class="bd-container__inner bd-page-width">
<div class="bd-sidebar-primary bd-sidebar">
<div class="sidebar-header-items sidebar-primary__section">
<div class="sidebar-header-items__center">
<div class="navbar-item">
<nav class="navbar-nav">
<ul class="bd-navbar-elements navbar-nav">
<li class="nav-item">
<a class="nav-link nav-internal" href="../format/index.html">
Specifications
</a>
</li>
<li class="nav-item">
<a class="nav-link nav-internal" href="../developers/index.html">
Development
</a>
</li>
<li class="nav-item dropdown">
<button class="btn dropdown-toggle nav-item" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-controls="pst-nav-more-links-2">
Implementations
</button>
<ul id="pst-nav-more-links-2" class="dropdown-menu">
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../c_glib/index.html">
C/GLib
</a>
</li>
<li class="nav-item current active">
<a class="nav-link dropdown-item nav-internal" href="index.html">
C++
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://github.com/apache/arrow/blob/main/csharp/README.md">
C#
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://pkg.go.dev/github.com/apache/arrow/go/v17">
Go
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../java/index.html">
Java
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../js/index.html">
JavaScript
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/julia/">
Julia
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://github.com/apache/arrow/blob/main/matlab/README.md">
MATLAB
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/nanoarrow/">
nanoarrow
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../python/index.html">
Python
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../r/index.html">
R
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://github.com/apache/arrow/blob/main/ruby/README.md">
Ruby
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://docs.rs/crate/arrow/">
Rust
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-internal" href="../status.html">
Implementation Status
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/cpp/">
C++ cookbook
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/java/">
Java cookbook
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/py/">
Python cookbook
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-item nav-external" href="https://arrow.apache.org/cookbook/r/">
R cookbook
</a>
</li>
</ul>
</li>
</ul>
</nav></div>
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<script>
document.write(`
<div class="version-switcher__container dropdown">
<button id="pst-version-switcher-button-3"
type="button"
class="version-switcher__button btn btn-sm navbar-btn dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-3"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-3"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-3">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
`);
</script></div>
<div class="navbar-item">
<script>
document.write(`
<button class="btn btn-sm navbar-btn theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<span class="theme-switch nav-link" data-mode="light"><i class="fa-solid fa-sun fa-lg"></i></span>
<span class="theme-switch nav-link" data-mode="dark"><i class="fa-solid fa-moon fa-lg"></i></span>
<span class="theme-switch nav-link" data-mode="auto"><i class="fa-solid fa-circle-half-stroke fa-lg"></i></span>
</button>
`);
</script></div>
<div class="navbar-item"><ul class="navbar-icon-links navbar-nav"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://github.com/apache/arrow" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-brands fa-square-github fa-lg" aria-hidden="true"></i></span>
<span class="sr-only">GitHub</span></a>
</li>
<li class="nav-item">
<a href="https://twitter.com/ApacheArrow" title="X" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-brands fa-square-x-twitter fa-lg" aria-hidden="true"></i></span>
<span class="sr-only">X</span></a>
</li>
</ul></div>
</div>
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
<div class="sidebar-primary-item">
<nav class="bd-docs-nav bd-links"
aria-label="Section Navigation">
<p class="bd-links__title" role="heading" aria-level="1">Section Navigation</p>
<div class="bd-toc-item navbar-nav"><ul class="current nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="getting_started.html">Getting Started</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-1"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="build_system.html">Using Arrow C++ in your own project</a></li>
<li class="toctree-l2"><a class="reference internal" href="conventions.html">Conventions</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorials/basic_arrow.html">Basic Arrow Data Structures</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorials/io_tutorial.html">Arrow File I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorials/compute_tutorial.html">Arrow Compute</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorials/datasets_tutorial.html">Arrow Datasets</a></li>
</ul>
</li>
<li class="toctree-l1 current active has-children"><a class="reference internal" href="user_guide.html">User Guide</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-2"><i class="fa-solid fa-chevron-down"></i></label><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="overview.html">High-Level Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html">Memory Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="arrays.html">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="datatypes.html">Data Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="tables.html">Tabular Data</a></li>
<li class="toctree-l2"><a class="reference internal" href="compute.html">Compute Functions</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="gandiva.html">The Gandiva Expression Compiler</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-3"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="gandiva/expr_projector_filter.html">Gandiva Expression, Projector, and Filter</a></li>
<li class="toctree-l3"><a class="reference internal" href="gandiva/external_func.html">Gandiva External Functions Development Guide</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="streaming_execution.html">Acero: A C++ streaming execution engine</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-4"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="acero/overview.html">Acero Overview</a></li>
<li class="toctree-l3"><a class="reference internal" href="acero/user_guide.html">Acero User’s Guide</a></li>
<li class="toctree-l3"><a class="reference internal" href="acero/substrait.html">Using Acero with Substrait</a></li>
<li class="toctree-l3"><a class="reference internal" href="acero/developer_guide.html">Developer’s Guide</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="io.html">Input / output and filesystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="ipc.html">Reading and writing the Arrow IPC format</a></li>
<li class="toctree-l2"><a class="reference internal" href="orc.html">Reading and Writing ORC files</a></li>
<li class="toctree-l2"><a class="reference internal" href="parquet.html">Reading and writing Parquet files</a></li>
<li class="toctree-l2"><a class="reference internal" href="csv.html">Reading and Writing CSV files</a></li>
<li class="toctree-l2"><a class="reference internal" href="json.html">Reading JSON files</a></li>
<li class="toctree-l2"><a class="reference internal" href="dataset.html">Tabular Datasets</a></li>
<li class="toctree-l2 current active"><a class="current reference internal" href="#">Arrow Flight RPC</a></li>
<li class="toctree-l2"><a class="reference internal" href="gdb.html">Debugging code using Arrow</a></li>
<li class="toctree-l2"><a class="reference internal" href="threading.html">Thread Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="opentelemetry.html">OpenTelemetry</a></li>
<li class="toctree-l2"><a class="reference internal" href="env_vars.html">Environment Variables</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="examples/index.html">Examples</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-5"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="examples/cmake_minimal_build.html">Minimal build using CMake</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/compute_and_write_example.html">Compute and Write CSV Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/dataset_documentation_example.html">Arrow Datasets example</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/dataset_skyhook_scan_example.html">Arrow Skyhook example</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/row_columnar_conversion.html">Row to columnar conversion</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/tuple_range_conversion.html">std::tuple-like ranges to Arrow</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/converting_recordbatch_to_tensor.html">Converting RecordBatch to Tensor</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="api.html">API Reference</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-6"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="api/support.html">Programming Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/memory.html">Memory (management)</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/thread.html">Thread (management)</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/datatype.html">Data Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/array.html">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/scalar.html">Scalars</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/builder.html">Array Builders</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/table.html">Two-dimensional Datasets</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/c_abi.html">C Interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/compute.html">Compute Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/acero.html">Streaming Execution (Acero)</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/gandiva.html">Gandiva Expression Compiler</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/tensor.html">Tensors</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/utilities.html">Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/async.html">Asynchronous programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/io.html">Input / output</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/ipc.html">Arrow IPC</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/formats.html">File Formats</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cuda.html">CUDA support</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/flight.html">Arrow Flight RPC</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/flightsql.html">Arrow Flight SQL</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/filesystem.html">Filesystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/dataset.html">Dataset</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/cookbook/cpp/">C++ cookbook</a></li>
</ul>
</div>
</nav></div>
</div>
<div class="sidebar-primary-items__end sidebar-primary__section">
</div>
<div id="rtd-footer-container"></div>
</div>
<main id="main-content" class="bd-main">
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article">
<div class="header-article-items header-article__inner">
<div class="header-article-items__start">
<div class="header-article-item">
<nav aria-label="Breadcrumb">
<ul class="bd-breadcrumbs">
<li class="breadcrumb-item breadcrumb-home">
<a href="../index.html" class="nav-link" aria-label="Home">
<i class="fa-solid fa-home"></i>
</a>
</li>
<li class="breadcrumb-item"><a href="index.html" class="nav-link">C++ Implementation</a></li>
<li class="breadcrumb-item"><a href="user_guide.html" class="nav-link">User Guide</a></li>
<li class="breadcrumb-item active" aria-current="page">Arrow Flight RPC</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<div id="searchbox"></div>
<article class="bd-article">
<section id="arrow-flight-rpc">
<h1>Arrow Flight RPC<a class="headerlink" href="#arrow-flight-rpc" title="Permalink to this heading">#</a></h1>
<p>Arrow Flight is an RPC framework for efficient transfer of Flight data
over the network.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="../format/Flight.html"><span class="doc">Flight protocol documentation</span></a></dt><dd><p>Documentation of the Flight protocol, including how to use
Flight conceptually.</p>
</dd>
<dt><a class="reference internal" href="api/flight.html"><span class="doc">Flight API documentation</span></a></dt><dd><p>C++ API documentation listing all of the various client and
server types.</p>
</dd>
<dt><a class="reference external" href="https://arrow.apache.org/cookbook/cpp/flight.html">C++ Cookbook</a></dt><dd><p>Recipes for using Arrow Flight in C++.</p>
</dd>
</dl>
</div>
<section id="writing-a-flight-service">
<h2>Writing a Flight Service<a class="headerlink" href="#writing-a-flight-service" title="Permalink to this heading">#</a></h2>
<p>Servers are subclasses of <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16FlightServerBaseE" title="arrow::flight::FlightServerBase"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::FlightServerBase</span></code></a>. To
implement individual RPCs, override the RPC methods on this class.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">MyFlightServer</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">FlightServerBase</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Status</span><span class="w"> </span><span class="nf">ListFlights</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">ServerCallContext</span><span class="o">&amp;</span><span class="w"> </span><span class="n">context</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">Criteria</span><span class="o">*</span><span class="w"> </span><span class="n">criteria</span><span class="p">,</span>
<span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o">&lt;</span><span class="n">FlightListing</span><span class="o">&gt;*</span><span class="w"> </span><span class="n">listings</span><span class="p">)</span><span class="w"> </span><span class="k">override</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">FlightInfo</span><span class="o">&gt;</span><span class="w"> </span><span class="n">flights</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">...;</span>
<span class="w"> </span><span class="o">*</span><span class="n">listings</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o">&lt;</span><span class="n">FlightListing</span><span class="o">&gt;</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">SimpleFlightListing</span><span class="p">(</span><span class="n">flights</span><span class="p">));</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">Status</span><span class="o">::</span><span class="n">OK</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">};</span>
</pre></div>
</div>
<p>Each RPC method always takes a
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight17ServerCallContextE" title="arrow::flight::ServerCallContext"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::ServerCallContext</span></code></a> for common parameters and
returns a <a class="reference internal" href="api/support.html#_CPPv4N5arrow6StatusE" title="arrow::Status"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Status</span></code></a> to indicate success or
failure. Flight-specific error codes can be returned via
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight15MakeFlightErrorE16FlightStatusCodeNSt6stringENSt6stringE" title="arrow::flight::MakeFlightError"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">arrow::flight::MakeFlightError()</span></code></a>.</p>
<p>RPC methods that return a value in addition to a status will use an
out parameter, as shown above. Often, there are helper classes
providing basic implementations of these out parameters. For instance,
above, <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight19SimpleFlightListingE" title="arrow::flight::SimpleFlightListing"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::SimpleFlightListing</span></code></a> uses a vector of
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight10FlightInfoE" title="arrow::flight::FlightInfo"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::FlightInfo</span></code></a> objects as the result of a
<code class="docutils literal notranslate"><span class="pre">ListFlights</span></code> RPC.</p>
<p>To start a server, create a <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight8LocationE" title="arrow::flight::Location"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::Location</span></code></a> to
specify where to listen, and call
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16FlightServerBase4InitERK19FlightServerOptions" title="arrow::flight::FlightServerBase::Init"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">arrow::flight::FlightServerBase::Init()</span></code></a>. This will start the
server, but won’t block the rest of the program. Use
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16FlightServerBase20SetShutdownOnSignalsEKNSt6vectorIiEE" title="arrow::flight::FlightServerBase::SetShutdownOnSignals"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">arrow::flight::FlightServerBase::SetShutdownOnSignals()</span></code></a> to
enable stopping the server if an interrupt signal is received, then
call <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16FlightServerBase5ServeEv" title="arrow::flight::FlightServerBase::Serve"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">arrow::flight::FlightServerBase::Serve()</span></code></a> to block until the
server stops.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o">&lt;</span><span class="n">arrow</span><span class="o">::</span><span class="n">flight</span><span class="o">::</span><span class="n">FlightServerBase</span><span class="o">&gt;</span><span class="w"> </span><span class="n">server</span><span class="p">;</span>
<span class="c1">// Initialize server</span>
<span class="n">arrow</span><span class="o">::</span><span class="n">flight</span><span class="o">::</span><span class="n">Location</span><span class="w"> </span><span class="n">location</span><span class="p">;</span>
<span class="c1">// Listen to all interfaces on a free port</span>
<span class="n">ARROW_CHECK_OK</span><span class="p">(</span><span class="n">arrow</span><span class="o">::</span><span class="n">flight</span><span class="o">::</span><span class="n">Location</span><span class="o">::</span><span class="n">ForGrpcTcp</span><span class="p">(</span><span class="s">&quot;0.0.0.0&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">location</span><span class="p">));</span>
<span class="n">arrow</span><span class="o">::</span><span class="n">flight</span><span class="o">::</span><span class="n">FlightServerOptions</span><span class="w"> </span><span class="nf">options</span><span class="p">(</span><span class="n">location</span><span class="p">);</span>
<span class="c1">// Start the server</span>
<span class="n">ARROW_CHECK_OK</span><span class="p">(</span><span class="n">server</span><span class="o">-&gt;</span><span class="n">Init</span><span class="p">(</span><span class="n">options</span><span class="p">));</span>
<span class="c1">// Exit with a clean error code (0) on SIGTERM</span>
<span class="n">ARROW_CHECK_OK</span><span class="p">(</span><span class="n">server</span><span class="o">-&gt;</span><span class="n">SetShutdownOnSignals</span><span class="p">({</span><span class="n">SIGTERM</span><span class="p">}));</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Server listening on localhost:&quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">server</span><span class="o">-&gt;</span><span class="n">port</span><span class="p">()</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="n">ARROW_CHECK_OK</span><span class="p">(</span><span class="n">server</span><span class="o">-&gt;</span><span class="n">Serve</span><span class="p">());</span>
</pre></div>
</div>
</section>
<section id="using-the-flight-client">
<h2>Using the Flight Client<a class="headerlink" href="#using-the-flight-client" title="Permalink to this heading">#</a></h2>
<p>To connect to a Flight service, create an instance of
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight12FlightClientE" title="arrow::flight::FlightClient"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::FlightClient</span></code></a> by calling <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight12FlightClient7ConnectERK8Location" title="arrow::flight::FlightClient::Connect"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">Connect</span></code></a>.</p>
<p>Each RPC method returns <a class="reference internal" href="api/support.html#_CPPv4I0EN5arrow6ResultE" title="arrow::Result"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Result</span></code></a> to indicate the
success/failure of the request, and the result object if the request
succeeded. Some calls are streaming calls, so they will return a
reader and/or a writer object; the final call status isn’t known until
the stream is completed.</p>
</section>
<section id="cancellation-and-timeouts">
<h2>Cancellation and Timeouts<a class="headerlink" href="#cancellation-and-timeouts" title="Permalink to this heading">#</a></h2>
<p>When making a call, clients can optionally provide
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight17FlightCallOptionsE" title="arrow::flight::FlightCallOptions"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">FlightCallOptions</span></code></a>. This
allows clients to set a timeout on calls or provide custom HTTP
headers, among other features. Also, some objects returned by client
RPC calls expose a <code class="docutils literal notranslate"><span class="pre">Cancel</span></code> method which allows terminating a call
early.</p>
<p>On the server side, no additional code is needed to implement
timeouts. For cancellation, the server needs to manually poll
<a class="reference internal" href="api/flight.html#_CPPv4NK5arrow6flight17ServerCallContext12is_cancelledEv" title="arrow::flight::ServerCallContext::is_cancelled"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">ServerCallContext::is_cancelled</span></code></a> to check if the
client has cancelled the call, and if so, break out of any processing
the server is currently doing.</p>
</section>
<section id="enabling-tls">
<h2>Enabling TLS<a class="headerlink" href="#enabling-tls" title="Permalink to this heading">#</a></h2>
<p>TLS can be enabled when setting up a server by providing a certificate
and key pair to <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16FlightServerBase4InitERK19FlightServerOptions" title="arrow::flight::FlightServerBase::Init"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">FlightServerBase::Init</span></code></a>.</p>
<p>On the client side, use <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight8Location10ForGrpcTlsERKNSt6stringEKi" title="arrow::flight::Location::ForGrpcTls"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">Location::ForGrpcTls</span></code></a> to construct the
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight8LocationE" title="arrow::flight::Location"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::Location</span></code></a> to listen on.</p>
</section>
<section id="enabling-authentication">
<h2>Enabling Authentication<a class="headerlink" href="#enabling-authentication" title="Permalink to this heading">#</a></h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Authentication is insecure without enabling TLS.</p>
</div>
<p>Handshake-based authentication can be enabled by implementing
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight17ServerAuthHandlerE" title="arrow::flight::ServerAuthHandler"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">ServerAuthHandler</span></code></a> and
providing this to the server during construction.</p>
<p>Authentication consists of two parts: on initial client connection,
the server and client authentication implementations can perform any
negotiation needed. The client authentication handler then provides a
token that will be attached to future calls. This is done by calling
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight12FlightClient12AuthenticateERK17FlightCallOptionsNSt10unique_ptrI17ClientAuthHandlerEE" title="arrow::flight::FlightClient::Authenticate"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">Authenticate</span></code></a> with
the desired client authentication implementation.</p>
<p>On each RPC thereafter, the client handler’s token is automatically
added to the call in the request headers. The server authentication
handler validates the token and provides the identity of the
client. On the server, this identity can be obtained from the
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight17ServerCallContextE" title="arrow::flight::ServerCallContext"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::flight::ServerCallContext</span></code></a>.</p>
</section>
<section id="custom-middleware">
<h2>Custom Middleware<a class="headerlink" href="#custom-middleware" title="Permalink to this heading">#</a></h2>
<p>Servers and clients support custom middleware (or interceptors) that
are called on every request and can modify the request in a limited
fashion. These can be implemented by subclassing <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16ServerMiddlewareE" title="arrow::flight::ServerMiddleware"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">ServerMiddleware</span></code></a> and <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight16ClientMiddlewareE" title="arrow::flight::ClientMiddleware"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">ClientMiddleware</span></code></a>, then providing them when creating
the client or server.</p>
<p>Middleware are fairly limited, but they can add headers to a
request/response. On the server, they can inspect incoming headers and
fail the request; hence, they can be used to implement custom
authentication methods.</p>
</section>
<section id="best-practices">
<span id="flight-best-practices"></span><h2>Best practices<a class="headerlink" href="#best-practices" title="Permalink to this heading">#</a></h2>
<section id="grpc">
<h3>gRPC<a class="headerlink" href="#grpc" title="Permalink to this heading">#</a></h3>
<p>When using the default gRPC transport, options can be passed to it via
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight19FlightClientOptions15generic_optionsE" title="arrow::flight::FlightClientOptions::generic_options"><code class="xref cpp cpp-member docutils literal notranslate"><span class="pre">arrow::flight::FlightClientOptions::generic_options</span></code></a>. For example:</p>
<div class="sd-tab-set docutils">
<input checked="checked" id="sd-tab-item-0" name="sd-tab-set-0" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-0">
C++</label><div class="sd-tab-content docutils">
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="k">auto</span><span class="w"> </span><span class="n">options</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">FlightClientOptions</span><span class="o">::</span><span class="n">Defaults</span><span class="p">();</span>
<span class="c1">// Set the period after which a keepalive ping is sent on transport.</span>
<span class="n">options</span><span class="p">.</span><span class="n">generic_options</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">GRPC_ARG_KEEPALIVE_TIME_MS</span><span class="p">,</span><span class="w"> </span><span class="mi">60000</span><span class="p">);</span>
</pre></div>
</div>
</div>
<input id="sd-tab-item-1" name="sd-tab-set-0" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-1">
Python</label><div class="sd-tab-content docutils">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Set the period after which a keepalive ping is sent on transport.</span>
<span class="n">generic_options</span> <span class="o">=</span> <span class="p">[(</span><span class="s2">&quot;GRPC_ARG_KEEPALIVE_TIME_MS&quot;</span><span class="p">,</span> <span class="mi">60000</span><span class="p">)]</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">pyarrow</span><span class="o">.</span><span class="n">flight</span><span class="o">.</span><span class="n">FlightClient</span><span class="p">(</span><span class="n">server_uri</span><span class="p">,</span> <span class="n">generic_options</span><span class="o">=</span><span class="n">generic_options</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<p>Also see <a class="reference external" href="https://grpc.io/docs/guides/performance/#general">best gRPC practices</a> and available <a class="reference external" href="https://grpc.github.io/grpc/cpp/group__grpc__arg__keys.html">gRPC keys</a>.</p>
</section>
<section id="re-use-clients-whenever-possible">
<h3>Re-use clients whenever possible<a class="headerlink" href="#re-use-clients-whenever-possible" title="Permalink to this heading">#</a></h3>
<p>Creating and closing clients requires setup and teardown on the client and
server side which can take away from actually handling RPCs. Reuse clients
whenever possible to avoid this. Note that clients are thread-safe, so a
single client can be shared across multiple threads.</p>
</section>
<section id="dont-round-robin-load-balance">
<h3>Don’t round-robin load balance<a class="headerlink" href="#dont-round-robin-load-balance" title="Permalink to this heading">#</a></h3>
<p><a class="reference external" href="https://github.com/grpc/grpc/blob/master/doc/load-balancing.md#round_robin">Round robin load balancing</a> means every client can have an open connection to
every server, causing an unexpected number of open connections and depleting
server resources.</p>
</section>
<section id="debugging-connection-issues">
<h3>Debugging connection issues<a class="headerlink" href="#debugging-connection-issues" title="Permalink to this heading">#</a></h3>
<p>When facing unexpected disconnects on long running connections use netstat to
monitor the number of open connections. If number of connections is much
greater than the number of clients it might cause issues.</p>
<p>For debugging, certain environment variables enable logging in gRPC. For
example, <code class="docutils literal notranslate"><span class="pre">env</span> <span class="pre">GRPC_VERBOSITY=info</span> <span class="pre">GRPC_TRACE=http</span></code> will print the initial
headers (on both sides) so you can see if gRPC established the connection or
not. It will also print when a message is sent, so you can tell if the
connection is open or not.</p>
<p>gRPC may not report connection errors until a call is actually made.
Hence, to detect connection errors when creating a client, some sort
of dummy RPC should be made.</p>
</section>
<section id="memory-management">
<h3>Memory management<a class="headerlink" href="#memory-management" title="Permalink to this heading">#</a></h3>
<p>Flight tries to reuse allocations made by gRPC to avoid redundant
data copies. However, this means that those allocations may not
be tracked by the Arrow memory pool, and that memory usage behavior,
such as whether free memory is returned to the system, is dependent
on the allocator that gRPC uses (usually the system allocator).</p>
<p>A quick way of testing: attach to the process with a debugger and call
<code class="docutils literal notranslate"><span class="pre">malloc_trim</span></code>, or call <a class="reference internal" href="api/memory.html#_CPPv4N5arrow10MemoryPool13ReleaseUnusedEv" title="arrow::MemoryPool::ReleaseUnused"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">ReleaseUnused</span></code></a>
on the system pool. If memory usage drops, then likely, there is memory
allocated by gRPC or by the application that the system allocator was holding
on to. This can be adjusted in platform-specific ways; see an investigation
in <a class="reference external" href="https://issues.apache.org/jira/browse/ARROW-16697">ARROW-16697</a> for an example of how this works on Linux/glibc. glibc malloc
can be explicitly told to dump caches.</p>
</section>
<section id="excessive-traffic">
<h3>Excessive traffic<a class="headerlink" href="#excessive-traffic" title="Permalink to this heading">#</a></h3>
<p>gRPC will spawn up to max threads quota of threads for concurrent clients. Those
threads are not necessarily cleaned up (a “cached thread pool” in Java parlance).
glibc malloc clears some per thread state and the default tuning never clears
caches in some workloads.</p>
<p>gRPC’s default behaviour allows one server to accept many connections from many
different clients, but if requests do a lot of work (as they may under Flight),
the server may not be able to keep up. Configuring clients to retry
with backoff (and potentially connect to a different node), would give more
consistent quality of service.</p>
<div class="sd-tab-set docutils">
<input checked="checked" id="sd-tab-item-2" name="sd-tab-set-1" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-2">
C++</label><div class="sd-tab-content docutils">
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="k">auto</span><span class="w"> </span><span class="n">options</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">FlightClientOptions</span><span class="o">::</span><span class="n">Defaults</span><span class="p">();</span>
<span class="c1">// Set the minimum time between subsequent connection attempts.</span>
<span class="n">options</span><span class="p">.</span><span class="n">generic_options</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">GRPC_ARG_MIN_RECONNECT_BACKOFF_MS</span><span class="p">,</span><span class="w"> </span><span class="mi">2000</span><span class="p">);</span>
</pre></div>
</div>
</div>
<input id="sd-tab-item-3" name="sd-tab-set-1" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-3">
Python</label><div class="sd-tab-content docutils">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Set the minimum time between subsequent connection attempts.</span>
<span class="n">generic_options</span> <span class="o">=</span> <span class="p">[(</span><span class="s2">&quot;GRPC_ARG_MIN_RECONNECT_BACKOFF_MS&quot;</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)]</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">pyarrow</span><span class="o">.</span><span class="n">flight</span><span class="o">.</span><span class="n">FlightClient</span><span class="p">(</span><span class="n">server_uri</span><span class="p">,</span> <span class="n">generic_options</span><span class="o">=</span><span class="n">generic_options</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</section>
<section id="limiting-doput-batch-size">
<h3>Limiting DoPut Batch Size<a class="headerlink" href="#limiting-doput-batch-size" title="Permalink to this heading">#</a></h3>
<p>You may wish to limit the maximum batch size a client can submit to a server through
DoPut, to prevent a request from taking up too much memory on the server. On
the client-side, set <a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight19FlightClientOptions22write_size_limit_bytesE" title="arrow::flight::FlightClientOptions::write_size_limit_bytes"><code class="xref cpp cpp-member docutils literal notranslate"><span class="pre">arrow::flight::FlightClientOptions::write_size_limit_bytes</span></code></a>.
On the server-side, set the gRPC option <code class="docutils literal notranslate"><span class="pre">GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH</span></code>.
The client-side option will return an error that can be retried with smaller batches,
while the server-side limit will close out the connection. Setting both can be wise, since
the former provides a better user experience but the latter may be necessary to defend
against impolite clients.</p>
</section>
<section id="closing-unresponsive-connections">
<h3>Closing unresponsive connections<a class="headerlink" href="#closing-unresponsive-connections" title="Permalink to this heading">#</a></h3>
<ol class="arabic">
<li><p>A stale call can be closed using
<a class="reference internal" href="api/flight.html#_CPPv4N5arrow6flight17FlightCallOptions10stop_tokenE" title="arrow::flight::FlightCallOptions::stop_token"><code class="xref cpp cpp-member docutils literal notranslate"><span class="pre">arrow::flight::FlightCallOptions::stop_token</span></code></a>. This requires recording the
stop token at call establishment time.</p>
<div class="sd-tab-set docutils">
<input checked="checked" id="sd-tab-item-4" name="sd-tab-set-2" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-4">
C++</label><div class="sd-tab-content docutils">
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">StopSource</span><span class="w"> </span><span class="n">stop_source</span><span class="p">;</span>
<span class="n">FlightCallOptions</span><span class="w"> </span><span class="n">options</span><span class="p">;</span>
<span class="n">options</span><span class="p">.</span><span class="n">stop_token</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stop_source</span><span class="p">.</span><span class="n">token</span><span class="p">();</span>
<span class="n">stop_source</span><span class="p">.</span><span class="n">RequestStop</span><span class="p">(</span><span class="n">Status</span><span class="o">::</span><span class="n">Cancelled</span><span class="p">(</span><span class="s">&quot;StopSource&quot;</span><span class="p">));</span>
<span class="n">flight_client</span><span class="o">-&gt;</span><span class="n">DoAction</span><span class="p">(</span><span class="n">options</span><span class="p">,</span><span class="w"> </span><span class="p">{});</span>
</pre></div>
</div>
</div>
</div>
</li>
<li><p>Use call timeouts. (This is a general gRPC best practice.)</p>
<div class="sd-tab-set docutils">
<input checked="checked" id="sd-tab-item-5" name="sd-tab-set-3" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-5">
C++</label><div class="sd-tab-content docutils">
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">FlightCallOptions</span><span class="w"> </span><span class="n">options</span><span class="p">;</span>
<span class="n">options</span><span class="p">.</span><span class="n">timeout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TimeoutDuration</span><span class="p">{</span><span class="mf">0.2</span><span class="p">};</span>
<span class="n">Status</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">client</span><span class="o">-&gt;</span><span class="n">GetFlightInfo</span><span class="p">(</span><span class="n">options</span><span class="p">,</span><span class="w"> </span><span class="n">FlightDescriptor</span><span class="p">{}).</span><span class="n">status</span><span class="p">();</span>
</pre></div>
</div>
</div>
<input id="sd-tab-item-6" name="sd-tab-set-3" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-6">
Java</label><div class="sd-tab-content docutils">
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Iterator</span><span class="o">&lt;</span><span class="n">Result</span><span class="o">&gt;</span><span class="w"> </span><span class="n">results</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">client</span><span class="p">.</span><span class="na">doAction</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">Action</span><span class="p">(</span><span class="s">&quot;hang&quot;</span><span class="p">),</span><span class="w"> </span><span class="n">CallOptions</span><span class="p">.</span><span class="na">timeout</span><span class="p">(</span><span class="mf">0.2</span><span class="p">,</span><span class="w"> </span><span class="n">TimeUnit</span><span class="p">.</span><span class="na">SECONDS</span><span class="p">));</span>
</pre></div>
</div>
</div>
<input id="sd-tab-item-7" name="sd-tab-set-3" type="radio">
</input><label class="sd-tab-label" for="sd-tab-item-7">
Python</label><div class="sd-tab-content docutils">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">options</span> <span class="o">=</span> <span class="n">pyarrow</span><span class="o">.</span><span class="n">flight</span><span class="o">.</span><span class="n">FlightCallOptions</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mf">0.2</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">do_action</span><span class="p">(</span><span class="n">action</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="n">options</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</li>
<li><p>Client timeouts are not great for long-running streaming calls, where it may
be hard to choose a timeout for the entire operation. Instead, what is often
desired is a per-read or per-write timeout so that the operation fails if it
isn’t making progress. This can be implemented with a background thread that
calls Cancel() on a timer, with the main thread resetting the timer every time
an operation completes successfully. For a fully-worked out example, see the
Cookbook.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is a long standing ticket for a per-write/per-read timeout
instead of a per call timeout (<a class="reference external" href="https://issues.apache.org/jira/browse/ARROW-6062">ARROW-6062</a>), but this is not (easily)
possible to implement with the blocking gRPC API.</p>
</div>
</li>
</ol>
</section>
</section>
<section id="alternative-transports">
<h2>Alternative Transports<a class="headerlink" href="#alternative-transports" title="Permalink to this heading">#</a></h2>
<p>The standard transport for Arrow Flight is <a class="reference external" href="https://grpc.io/">gRPC</a>. The C++
implementation also experimentally supports a transport based on
<a class="reference external" href="https://openucx.org/">UCX</a>. To use it, use the protocol scheme <code class="docutils literal notranslate"><span class="pre">ucx:</span></code> when starting a
server or creating a client.</p>
<section id="ucx-transport">
<h3>UCX Transport<a class="headerlink" href="#ucx-transport" title="Permalink to this heading">#</a></h3>
<p>Not all features of the gRPC transport are supported. See
<a class="reference internal" href="../status.html#status-flight-rpc"><span class="std std-ref">Flight RPC</span></a> for details. Also note these specific
caveats:</p>
<ul class="simple">
<li><p>The server creates an independent UCP worker for each client. This
consumes more resources but provides better throughput.</p></li>
<li><p>The client creates an independent UCP worker for each RPC
call. Again, this trades off resource consumption for
performance. This also means that unlike with gRPC, it is
essentially equivalent to make all calls with a single client or
with multiple clients.</p></li>
<li><p>The UCX transport attempts to avoid copies where possible. In some
cases, it can directly reuse UCX-allocated buffers to back
<a class="reference internal" href="api/memory.html#_CPPv4N5arrow6BufferE" title="arrow::Buffer"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Buffer</span></code></a> objects, however, this will also extend the
lifetime of associated UCX resources beyond the lifetime of the
Flight client or server object.</p></li>
<li><p>Depending on the transport that UCX itself selects, you may find
that increasing <code class="docutils literal notranslate"><span class="pre">UCX_MM_SEG_SIZE</span></code> from the default (around 8KB) to
around 60KB improves performance (UCX will copy more data in a
single call).</p></li>
</ul>
</section>
</section>
</section>
</article>
<footer class="prev-next-footer">
<div class="prev-next-area">
<a class="left-prev"
href="dataset.html"
title="previous page">
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Tabular Datasets</p>
</div>
</a>
<a class="right-next"
href="gdb.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Debugging code using Arrow</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
</div>
</footer>
</div>
<div class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">
<div class="sidebar-secondary-item">
<div
id="pst-page-navigation-heading-2"
class="page-toc tocsection onthispage">
<i class="fa-solid fa-list"></i> On this page
</div>
<nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#writing-a-flight-service">Writing a Flight Service</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#using-the-flight-client">Using the Flight Client</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#cancellation-and-timeouts">Cancellation and Timeouts</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#enabling-tls">Enabling TLS</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#enabling-authentication">Enabling Authentication</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#custom-middleware">Custom Middleware</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#best-practices">Best practices</a><ul class="visible nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#grpc">gRPC</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#re-use-clients-whenever-possible">Re-use clients whenever possible</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#dont-round-robin-load-balance">Don’t round-robin load balance</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#debugging-connection-issues">Debugging connection issues</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#memory-management">Memory management</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#excessive-traffic">Excessive traffic</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#limiting-doput-batch-size">Limiting DoPut Batch Size</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#closing-unresponsive-connections">Closing unresponsive connections</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#alternative-transports">Alternative Transports</a><ul class="visible nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#ucx-transport">UCX Transport</a></li>
</ul>
</li>
</ul>
</nav></div>
<div class="sidebar-secondary-item">
<div class="tocsection editthispage">
<a href="https://github.com/apache/arrow/edit/main/docs/source/cpp/flight.rst">
<i class="fa-solid fa-pencil"></i>
Edit on GitHub
</a>
</div>
</div>
</div></div>
</div>
<footer class="bd-footer-content">
</footer>
</main>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<script src="../_static/scripts/bootstrap.js?digest=8d27b9dea8ad943066ae"></script>
<script src="../_static/scripts/pydata-sphinx-theme.js?digest=8d27b9dea8ad943066ae"></script>
<footer class="bd-footer">
<div class="bd-footer__inner bd-page-width">
<div class="footer-items__start">
<div class="footer-item">
<p class="copyright">
© Copyright 2016-2024 Apache Software Foundation.
Apache Arrow, Arrow, Apache, the Apache feather logo, and the Apache Arrow project logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.
<br/>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 6.2.0.
<br/>
</p>
</div>
</div>
<div class="footer-items__end">
<div class="footer-item">
<p class="theme-version">
Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> 0.15.2.
</p></div>
</div>
</div>
</footer>
</body>
</html>